* bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
@ 2015-01-25 7:19 Keith David Bershatsky
2015-01-25 10:38 ` martin rudalics
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Keith David Bershatsky @ 2015-01-25 7:19 UTC (permalink / raw)
To: 19684
To the extent that a user wishes to use the value of `this-command` within a function attached to the `window-scroll-functions` hook, a workaround is needed because the default value is `nil`. In other words, something at the C source code level is setting the value to `nil` before the `window-scroll-functions` hook runs.
There are two (2) workarounds that I am aware of.
1. Expressly call `redisplay` at the tail end of the series of functions attached to the `post-command-hook`. Calling `redisplay` somehow prevents `this-command` from being reset to `nil` and the `window-scroll-functions` hook can then take advantage of the existing value of `this-command`.
2. Create a separate variable -- e.g., `my-this-command` and set the value within a function attached to the `post-command-hook`. Like so: (setq my-this-command this-command). And, then use the value of `my-this-command` within the function attached to the `window-scroll-functions` hook.
The most reliable test I have discovered to pinpoint when the `window-scroll-functions` hook will activate is by having the following code within a function attached to the `post-command-hook`: (pos-visible-in-window-p (point) (get-buffer-window (current-buffer) (selected-frame))). If the result is `t`, then the `window-scroll-functions` hook will be activating.
I do not see a visual difference between either of the two workarounds mentioned above, even though I would expect to see a flicker on the screen with the first workaround. However, there is no flicker. The second workaround is probably a safer bet.
Although this bug report has been submitted with Emacs Trunk from October 1, 2014; the behavior is the same with Emacs Trunk built on January 1, 2015.
Thanks,
Keith
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.0.50.1 (x86_64-apple-darwin10.8.0, NS appkit-1038.36 Version 10.6.8 (Build 10K549))
of 2014-10-01 on MP.local
Repository revision: 117996 dmantipov@yandex.ru-20141001132108-zdsxru2390mqyjlu
Windowing system distributor `Apple', version 10.3.1038
Configured using:
`configure --with-ns'
Configured features:
ACL LIBXML2 ZLIB
Important settings:
locale-coding-system: utf-8-unix
Major mode: Fundamental
Minor modes in effect:
sd-mode: t
sb-mode: t
tb-mode: t
shell-dirtrack-mode: t
cm-mode: t
frame-bufs-mode: t
bc-mode: t
ds-mode: t
ml-mode: t
Recent input:
<escape> x r e p o r t - e m a c s - b u g <return
>
Recent messages:
Wrote /Users/HOME/.0.data/.0.emacs/.lock
Load-path shadows:
/Users/HOME/.0.data/.0.emacs/.0.wl/md4 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/md4
/Users/HOME/.0.data/.0.emacs/.0.wl/hex-util hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/hex-util
/Users/HOME/.0.data/.0.emacs/.0.wl/sasl hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl
/Users/HOME/.0.data/.0.emacs/.0.wl/sasl-ntlm hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl-ntlm
/Users/HOME/.0.data/.0.emacs/.0.wl/sasl-digest hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl-digest
/Users/HOME/.0.data/.0.emacs/.0.wl/sasl-cram hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl-cram
/Users/HOME/.0.data/.0.emacs/.0.wl/ntlm hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/ntlm
/Users/HOME/.0.data/.0.emacs/.0.wl/hmac-md5 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/hmac-md5
/Users/HOME/.0.data/.0.emacs/.0.wl/hmac-def hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/hmac-def
/Users/HOME/.0.data/.0.emacs/.0.wl/rfc2368 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/mail/rfc2368
/Users/HOME/.0.data/.0.emacs/.0.wl/utf7 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/gnus/utf7
/Users/HOME/.0.data/.0.emacs/.0.wl/smime hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/gnus/smime
/Users/HOME/.0.data/.0.emacs/.0.wl/pgg hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg
/Users/HOME/.0.data/.0.emacs/.0.wl/pgg-pgp5 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-pgp5
/Users/HOME/.0.data/.0.emacs/.0.wl/pgg-pgp hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-pgp
/Users/HOME/.0.data/.0.emacs/.0.wl/pgg-parse hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-parse
/Users/HOME/.0.data/.0.emacs/.0.wl/pgg-gpg hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-gpg
/Users/HOME/.0.data/.0.emacs/.0.wl/pgg-def hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-def
Features:
(shadow disp-table mime-setup mail-mime-setup semi-setup mime-image
modb-standard elmo-imap4 emacsbug lawlist-desktop frameset lawlist-bk
lawlist-arc lawlist-dv lawlist-mc rect lawlist-ztree lawlist-wl
w3m-load mime-w3m w3m browse-url doc-view jka-compr image-mode
w3m-hist w3m-fb bookmark-w3m w3m-ems mule-util w3m-ccl w3m-favicon
w3m-image w3m-proc w3m-util wl-demo wl-spam elmo-spam elsp-header
elsp-generic wl-fldmgr wl-score smtp sasl sasl-anonymous sasl-login
sasl-plain wl-news wl-address pldap wl-thread wl-action wl-e21
wl-draft wl-template wl-summary ps-print ps-def lpr wl-refile
wl-message wl-mime pgg mime-pgp mime-play filename mime-edit
eword-encode pgg-parse pccl pccl-20 ccl pgg-def signature sendmail
elmo-mime mmelmo-buffer mmelmo-imap mime-view mime-conf calist
semi-def mmimap mime-parse mmbuffer wl-highlight elmo-filter
elmo-multi elmo-nntp wl-folder wl wl-util crm pp elmo-pop3 elmo-net
elmo-cache elmo-map elmo-dop elmo-flag elmo-localdir wl-vars elmo
elmo-signal elmo-msgdb modb modb-generic modb-entity mime mmgeneric
elmo-util emu invisible inv-23 poem poem-e20 poem-e20_3 utf7
eword-decode mel mime-def alist std11 mcharset mcs-20 mcs-e20 pces
pces-e20 pces-20 broken pcustom elmo-date elmo-vars path-util poe pym
static product wl-version elmo-version apel-ver luna lawlist-vr-hr
lawlist-test lawlist-sb lawlist-vl lawlist-ln lawlist-hl
lawlist-parens lawlist-dired tramp-sh lawlist-ws lawlist-calc
lawlist-flyspell lawlist-yas lawlist-elisp lawlist-tex-mode skeleton
compare-w lawlist-txt-mode lawlist-tabbar lawlist-github ido view
vc-git vc vc-dispatcher tramp tramp-compat tramp-loaddefs trampver
shell thingatpt time-stamp log-view log-edit message mml mml-sec
mm-decode mm-bodies mm-encode gmm-utils mailheader pcvs-util add-log
json help-mode grep compile find-lisp epa epg epg-config ediff-merg
ediff-wind ediff-diff ediff-mult ediff-help ediff-init ediff-util
ediff ert ewoc debug eieio-base diff-mode conf-mode autorevert
filenotify lorg-calendar org-element lorg-search org-agenda
context-menu dired-read-filename dired count-business-days
lawlist-toodledo url-http tls url url-proxy url-privacy url-expand
url-methods url-history mailcap url-auth url-cookie url-domsuf
url-util url-parse auth-source eieio eieio-core password-cache url-gw
url-vars lawlist-org lawlist-calendar org byte-opt bytecomp
byte-compile cconv org-macro org-footnote org-pcomplete pcomplete
org-list org-faces org-entities noutline outline org-version
ob-emacs-lisp ob ob-tangle org-src ob-ref ob-lob ob-table ob-keys
ob-exp ob-comint ob-core ob-eval org-compat org-macs org-loaddefs
find-func cal-menu easymenu calendar cal-loaddefs format-spec
lawlist-frame lawlist-cm lawlist-bbdb gnus gnus-ems nnheader gnus-util
mail-utils wid-edit mail-parse rfc2231 rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mailabbrev mail-extr rfc822 cl timezone
lawlist-grep lawlist-compile rx comint ansi-color ring
lawlist-frame-bufs advice derived lawlist-window lawlist-print
lawlist-undo pcase lawlist-tm lawlist-bc lawlist-as cl-macs gv
lawlist-ds lawlist-ml easy-mmode lawlist-misc lawlist-keymap edmacro
kmacro eldoc cl-loaddefs cl-lib help-fns savehist saveplace server
time-date tooltip electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel ns-win tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode
register page menu-bar rfn-eshadow timer select scroll-bar mouse
jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
cocoa ns multi-tty emacs)
Memory information:
((conses 16 1229677 95833)
(symbols 48 61646 0)
(miscs 40 105 150)
(strings 32 132512 13095)
(string-bytes 1 4616193)
(vectors 16 33496)
(vector-slots 8 697599 22896)
(floats 8 942 252)
(intervals 56 4202 0)
(buffers 976 11))
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
2015-01-25 7:19 bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs Keith David Bershatsky
@ 2015-01-25 10:38 ` martin rudalics
2015-01-25 15:33 ` Eli Zaretskii
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: martin rudalics @ 2015-01-25 10:38 UTC (permalink / raw)
To: Keith David Bershatsky, 19684
> To the extent that a user wishes to use the value of `this-command`
> within a function attached to the `window-scroll-functions` hook, a
> workaround is needed because the default value is `nil`. In other
> words, something at the C source code level is setting the value to
> `nil` before the `window-scroll-functions` hook runs.
Couldn't you use `last-command' here?
martin
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
2015-01-25 7:19 bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs Keith David Bershatsky
2015-01-25 10:38 ` martin rudalics
@ 2015-01-25 15:33 ` Eli Zaretskii
2015-01-25 16:14 ` Stefan Monnier
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2015-01-25 15:33 UTC (permalink / raw)
To: Keith David Bershatsky; +Cc: 19684
> Date: Sat, 24 Jan 2015 23:19:48 -0800
> From: Keith David Bershatsky <esq@lawlist.com>
>
> To the extent that a user wishes to use the value of `this-command` within a
> function attached to the `window-scroll-functions` hook, a workaround is needed
> because the default value is `nil`. In other words, something at the C source
> code level is setting the value to `nil` before the `window-scroll-functions`
> hook runs.
That "something" is the command loop itself: it resets 'this-command'
when the command finishes and returns to the loop.
Recall that in Emacs, execution of commands running the Lisp
interpreter is separated from redisplay: the latter runs when Emacs is
idle and is waiting for input. Since most of the calls to
window-scroll-functions are made by the display engine, the command
already returned to the command loop by that time.
> Calling `redisplay` somehow prevents `this-command` from being reset
> to `nil`
I hope it is now clear why this happens: in this scenario redisplay is
entered before the command finishes, so 'this-command' was still not
reset.
> The most reliable test I have discovered to pinpoint when the
> `window-scroll-functions` hook will activate is by having the following code
> within a function attached to the `post-command-hook`:
> (pos-visible-in-window-p (point) (get-buffer-window (current-buffer)
> (selected-frame))). If the result is `t`, then the `window-scroll-functions`
> hook will be activating.
You are well-advised not to depend on such implementation details.
> Although this bug report has been submitted with Emacs Trunk from October 1,
> 2014; the behavior is the same with Emacs Trunk built on January 1, 2015.
Emacs always behaved like that. And it's not a bug.
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
2015-01-25 7:19 bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs Keith David Bershatsky
2015-01-25 10:38 ` martin rudalics
2015-01-25 15:33 ` Eli Zaretskii
@ 2015-01-25 16:14 ` Stefan Monnier
2015-01-25 17:42 ` Keith David Bershatsky
2019-10-01 20:16 ` Stefan Kangas
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2015-01-25 16:14 UTC (permalink / raw)
To: Keith David Bershatsky; +Cc: 19684
tags 19684 notabug
thanks
> 1. Expressly call `redisplay` at the tail end of the series of
> functions attached to the `post-command-hook`.
> Calling `redisplay` somehow prevents `this-command` from being
> reset to `nil` and the `window-scroll-functions` hook can then
> take advantage of the existing value of `this-command`.
It's not that calling `redisplay' prevents it. It's that the normal
redisplay is run later (potentially much later if there are other things
pending), at a point which is not directly connected with the command,
hence this-command is not set any more because we're really not in the
process of running that command any more.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
2015-01-25 7:19 bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs Keith David Bershatsky
` (2 preceding siblings ...)
2015-01-25 16:14 ` Stefan Monnier
@ 2015-01-25 17:42 ` Keith David Bershatsky
2019-10-01 20:16 ` Stefan Kangas
4 siblings, 0 replies; 6+ messages in thread
From: Keith David Bershatsky @ 2015-01-25 17:42 UTC (permalink / raw)
To: Martin Rudalics, Eli Zaretskii, Stefan Monnier; +Cc: 19684
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs.
2015-01-25 7:19 bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs Keith David Bershatsky
` (3 preceding siblings ...)
2015-01-25 17:42 ` Keith David Bershatsky
@ 2019-10-01 20:16 ` Stefan Kangas
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Kangas @ 2019-10-01 20:16 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Keith David Bershatsky, 19684-done
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
> tags 19684 notabug
> thanks
>
>> 1. Expressly call `redisplay` at the tail end of the series of
>> functions attached to the `post-command-hook`.
>> Calling `redisplay` somehow prevents `this-command` from being
>> reset to `nil` and the `window-scroll-functions` hook can then
>> take advantage of the existing value of `this-command`.
>
> It's not that calling `redisplay' prevents it. It's that the normal
> redisplay is run later (potentially much later if there are other things
> pending), at a point which is not directly connected with the command,
> hence this-command is not set any more because we're really not in the
> process of running that command any more.
This was already tagged notabug; I'm now also closing it.
Best regards,
Stefan Kangas
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-10-01 20:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-25 7:19 bug#19684: 25.0.50; `this-command` is set to `nil` before `window-scroll-functions` hook runs Keith David Bershatsky
2015-01-25 10:38 ` martin rudalics
2015-01-25 15:33 ` Eli Zaretskii
2015-01-25 16:14 ` Stefan Monnier
2015-01-25 17:42 ` Keith David Bershatsky
2019-10-01 20:16 ` Stefan Kangas
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).