I've read What is inhibit-point-motion-hooks?.
Assume some minor-mode my-mode
that wants to do point-motion-y
things.
Assume my--point-entered
and my--point-left
functions that work
fine in Emacs < 25, when my-mode
sets point-entered
and
point-left
props to use them.
Assume I'd like to have the mode keep working on Emacs < 25, but also do the right thing if it finds itself on 25+. What is the right thing to do?
I could (setq-local inhibit-point-motion-hooks nil)
and call it a day. But that var is described as "obsolete", which seems stronger than
"deprecated". So that seems like not the right thing.
Is the following a good template to use instead?
;; When mode is enabled
(when (fboundp 'cursor-sensor-mode)
(cursor-sensor-mode 1))
;; When mode is disabled
(when (fboundp 'cursor-sensor-mode)
(cursor-sensor-mode -1))
(defun my--cursor-sensor-function (window old dir)
(let ((new (window-point window))) ;is this correct ???
(pcase dir
(`entered (my--point-entered old new))
(`left (my--point-left old new)))))
;; where my--point-* are existing point motion functions
;; Where the props are added:
(let ((motion-props (if (fboundp 'cursor-sensor-mode)
(list 'cursor-sensor-functions
(list #'my--cursor-sensor-function))
(list 'point-entered #'my--point-entered
'point-left #'my--point-left))))
(add-text-properties beg
end
(append (list 'some-other-prop some-val)
motion-props)))
Or if that's not a good approach, what is the recommended way to work with both older and newer versions of Emacs?
cursor-sensor-mode
is defined then the function is ultimately called with anil
argument. 2. Calling it with anil
arg or at
arg has the same effect, anyway. Use1
and-1
to turn it on and off, respectively.