I am looking for an example, please, to programmatically control the order of functions within a particular hook:
First in time, which is easy -- i.e., don't append using
add-hook
.Last in time, which is easy -- i.e., append using
add-hook
.Second to last -- not so easy?
In the context of this particular question, there are three (3) functions assigned to the post-command-hook
.
An overlay removal function, which must always be first in time.
A
flyspell-post-command-hook
function that must always be last in time -- ifflyspell-mode
is active.A overlay placement function that must be last in time when
flyspell-mode
is not active, or second to last whenflyspell-mode
is active.
Essentially, I would like to control the overlay placement function to programmatically check to see whether flyspell-mode
is active, and if so, then place it second to last. If flyspell-mode
is not active, then just append so that the overlay placement function becomes the last in the hook.
(defun append-butlast (elt list) (append (butlast list) (list elt) (last list)))
. – Dan Dec 22 '14 at 21:57t
that sometimes appears inside the hook when I inspect thepost-command-hook
? I thinkadd-hook
may place thatt
somewhere specifically, but I'm not sure how that is determined or under what circumstance at
is added. Here is a specific example:(vr-remove-vertical-ruler t pch-hr-function parens flyspell-post-command-hook)
– lawlist Dec 22 '14 at 22:05t
comes from. I imagine you could inspectpost-command-hook
for thatt
in deciding where to assign your function (last, second-to-last, etc., either countingt
or not). – Dan Dec 22 '14 at 22:12t
(if applicable) somewhere when adding the second to the last. – lawlist Dec 22 '14 at 22:14t
stands for the global part of the hook (i.e. the list of functions kept on(default-value <hook>)
. – Stefan Dec 23 '14 at 13:58