vermiculus / sx.el

Stack Exchange for Emacs
http://stackapps.com/q/3950
709 stars 40 forks source link

Hitting `p` from top-most question causes refresh. Option to disable that? #278

Closed kaushalmodi closed 9 years ago

kaushalmodi commented 9 years ago

I was casually navigating the questions and I slammed on the p key to go the top (I know that I could have also done M-< to prevent this issue).

The issue is that once I was at the top of the question list, each p hit caused the buffer to refresh; I was unaware of that behavior. So my emacs froze for few seconds and then I see this in the Messages buffer:

Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.
Contacting host: api.stackexchange.com:443
[sx] Done.

It looks like this behavior was putting in intentionally.

Suggestions:

  1. Option to disable this behavior?
  2. Use a timer so that the refresh is not done at each stroke of p or while p is slammed down. I must have held down p for about a second or two longer and that caused these many refresh requests.
Malabarba commented 9 years ago

Oh dear, that's an unforeseen consequence. Yes, the behavior was put in intentionally, but the result you got is definitely something I would consider a bug, and I'd like to fix that.

Anyone have any suggestion on how we can keep the p key for refreshing but prevent these sequential refreshs due to keyboard repeat?

vermiculus commented 9 years ago

Add a hook to post-command-functions (or whatever it may be called) to toggle a flag on/off. I'm thinking about it like a state machine – press p from state A and we refresh and move to state B. p from B does nothing, but anything but p moves back to A.

Malabarba commented 9 years ago

I went with the lazy option and implemented 1 second timeout between refreshs. The problem I had with toggling a state is that the user wouldn't be able to keep periodically hitting p if he actually wanted to refresh again. With the timeout at least it will work one second later.

kaushalmodi commented 9 years ago

I think that's a fine, practical solution. I agree with the limitation if the same were implemented using states. I wish we were able to distinguish between the pressed and released states of a key; then this solution would have become even better. If that were possible, you can limit the refresh to happen only once per key-pressed state.