Skip to content

Commit

Permalink
pre commands that require exception of the post command
Browse files Browse the repository at this point in the history
The value of `this-command` is not updated by every bound command.  Commands
such as `counsel-M-x` and `universal-argument` do not update `this-command` and
so we must use the value of `this-command` we stored during the pre-command hook.

Signed-off-by: Psionik K <[email protected]>
  • Loading branch information
psionic-k committed Nov 21, 2023
1 parent bddaa9e commit c2bcac9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion keypression.el
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,25 @@ update the value of `this-command'."
:type 'symbol
:options '(pre-command post-command))

(defcustom keypression-post-excepting-pre-commands
`(counsel-M-x
universal-argument-more
universal-argument
digit-argument
execute-extended-command
;; whatever the user's `M-x` remap is
,(command-remapping 'execute-extended-command))
"A list of commands that require some exception behavior.
When `keypression-log-preference' is set to `post-command` but
the command we observe in the `post-command-hook' is a member of
this list, the value of `this-command' has not been updated or is
invalid. In these cases, we fall back to `pre-command` behavior
and show the value of `this-command' logged in the
`pre-command-hook'. One common case is
`execute-extended-command' and it's usual re-mappings."
:group 'keypression
:type '(repeat symbol))

;;; Global variables

(defvar keypression--nactives 0)
Expand Down Expand Up @@ -469,7 +488,10 @@ hook."
(defun keypression--post-command ()
(let ((command (if (eq keypression-pre-or-post-command 'pre-command)
this-command
keypression--pre-command-command)))
(if (member keypression--pre-command-command
keypression-post-excepting-pre-commands)
this-command
keypression--pre-command-command))))
(unless (or (memq (event-basic-type last-command-event)
keypression-ignore-mouse-events)
(if (functionp keypression-ignored-commands)
Expand Down

0 comments on commit c2bcac9

Please sign in to comment.