hishamhm/htop — pull request #146 by cben (2014-11-15 18:18:05+00:00)
Title: Automatically follow on process accross tree view / sort order changes

The first commit closes #51. I think that's a clear win - it's useful to follow a busy process to/from tree view to find its children/parent, and I can't think of any use for staying at the same screen position.
It also keeps following after the switch. Let me know if you prefer to restore follow=false afterwards, but I think that'd be worse - e.g. going from tree view to CPU sort (which jumps around a lot), you'd follow the current process only to lose it a second later.

The second commit also enables following on any sort order change (if I covered all code paths that do that...).
I'm not sure that's always desired. The main use case for *not* following is staying at the top of the screen to look at worse offenders for each resource (which is certainly common use of top!). But if following is default, one can always go to top of the list with `Home`, whereas if you have to press `F` before switching but forgot, there is no easy way to undo losing the selected process.
The most dubious case is following on inverting sort order (`I`) — the likely reason to press it is wanting to look at opposite processes, not same process on other end of screen...

Finally, if you like both changes, the `continue` vs `break` structure (the latter implying `follow = false;`) is IMHO getting messy.
It made more sense when most cases that did change it were to false, but now it's more symmetric.
I'd refactor to explicitly assigning false/true in every case that changes it — let me know what you prefer.

P.S. Thanks for htop, it's the first thing I install on every machine I use!