bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll


From: Keith David Bershatsky
Subject: bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
Date: Sun, 25 Jan 2015 09:42:44 -0800

Thank you (Eli, Stefan and Martin) for helping me to better understand how the 
redisplay process works.

I was surprised to learn that I could not depend upon either `this-command` or 
`last-command` when using the `window-scroll-functions` hook because a forced 
redisplay prior thereto -- e.g., `(redisplay)` -- makes a difference in the 
values.

To obtain the name of the interactive function that ran before the 
`window-scroll-functions` hook was triggered:

  `this-command` may be used in the `window-scroll-functions` when there IS a 
forced redisplay prior thereto.

  `last command` may be used in the `window-scroll-functions` when there is NOT 
a forced redisplay prior thereto.

I am unaware of any documentation that could have helped me to discover the 
behavior described above.  Perhaps the Emacs team might consider adding 
something to the doc-string and/or the manual so that a user is advised as to 
the behavior, and to suggest an alternative approach:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar my-command nil)

(defun set-my-command ()
  (setq my-command this-command))

(add-hook 'post-command-hook 'set-my-command)

(defun wsf-fn (win _start)
"NOTE:  Since the `window-scroll-functions` hook may be called more than
once, the user may not wish to set `my-command` to `nil` at this time."
  (message "my-command:  %s | this-command: %s | last-command: %s"
    my-command this-command last-command)
  (setq my-command nil))

(add-hook 'window-scroll-functions-hook 'wsf-fn)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Thanks,

Keith





reply via email to

[Prev in Thread] Current Thread [Next in Thread]