GNU bug report logs -
#19684
25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
Previous Next
Reported by: Keith David Bershatsky <esq <at> lawlist.com>
Date: Sun, 25 Jan 2015 07:21:02 UTC
Severity: normal
Tags: notabug
Found in version 25.0.50
Done: Stefan Kangas <stefan <at> marxist.se>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
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
This bug report was last modified 5 years and 295 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.