I’m having a small issue with a minor mode I’m writing. I’m using mark-active within pre-command-hook and post-command-hook in order to know whether a command just enabled/disabled the mark/region (I’m using transient mark mode). It’s mostly working, for instance C-SPC, or Shift+arrows or selecting with the mouse all do exactly as I expect, but not the kill-ring-save command (M-w). In the post-command-hook after kill-ring-save, the variable mark-active is still true even though M-w actually disables the mark (visually at least).

Any idea what is going on? I’m now working around it by explicitly checking whether this-command is kill-ring-save, but it feels like I shouldn’t have to do that.

Code to test:

(defun before-hook ()
  (message "(before) Mark active: %s, region: %d to %d" mark-active (region-beginning) (region-end)))

(defun after-hook ()
  (message "(after)  Mark active: %s, region: %d to %d" mark-active (region-beginning) (region-end)))

(add-hook 'pre-command-hook 'before-hook nil t)
(add-hook 'post-command-hook 'after-hook nil t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.