unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Keith David Bershatsky <esq@lawlist.com>
To: Martin Rudalics <rudalics@gmx.at>, Eli Zaretskii <eliz@gnu.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 19684@debbugs.gnu.org
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	[thread overview]
Message-ID: <m24mre3gff.wl%esq@lawlist.com> (raw)
In-Reply-To: <m2ppa3xr6z.wl%esq@lawlist.com>

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





  parent reply	other threads:[~2015-01-25 17:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-10-01 20:16 ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m24mre3gff.wl%esq@lawlist.com \
    --to=esq@lawlist.com \
    --cc=19684@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).