diff options
author | Eric S. Raymond <[email protected]> | 1993-03-27 01:58:44 +0000 |
---|---|---|
committer | Eric S. Raymond <[email protected]> | 1993-03-27 01:58:44 +0000 |
commit | 08159178ca75f2b6fb226988e1905849d7906f3a (patch) | |
tree | 60b304a2070b827816c86d463475695c48aa6711 /lisp | |
parent | 1c2df06340453138e48857c93e6eee1842833c14 (diff) |
(add-hook) Added optional arg to cause hook to be appended rather than
prepended to the hook list. This obviates the 23 different hook-bashing
packages in LCD.
(get-word) Added. Lots of help and default-generator functions in LCD use
it, and it's remarkably difficult to get right, especially given the new
syntax primitives.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/subr.el | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 464fea25f9..e6ec3b3b61 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -407,11 +407,12 @@ If it is a list, the elements are called, in order, with no arguments." "Variable by which C primitives find the function `run-hooks'. Don't change it.") -(defun add-hook (hook function) - "Add to the value of HOOK the function FUNCTION unless already present. -HOOK should be a symbol, and FUNCTION may be any valid function. -HOOK's value should be a list of functions, not a single function. -If HOOK is void, it is first set to nil." +(defun add-hook (hook function &optional append) + "Add to the value of HOOK the function FUNCTION unless already present (it +becomes the first hook on the list unless optional APPEND is non-nil, in +which case it becomes the last). HOOK should be a symbol, and FUNCTION may be +any valid function. HOOK's value should be a list of functions, not a single +function. If HOOK is void, it is first set to nil." (or (boundp hook) (set hook nil)) (or (if (consp function) ;; Clever way to tell whether a given lambda-expression @@ -419,7 +420,10 @@ If HOOK is void, it is first set to nil." (let ((tail (assoc (cdr function) (symbol-value hook)))) (equal function tail)) (memq function (symbol-value hook))) - (set hook (cons function (symbol-value hook))))) + (set hook + (if append + (nconc (symbol-value hook) (list function)) + (cons function (symbol-value hook)))))) (defun momentary-string-display (string pos &optional exit-char message) "Momentarily display STRING in the buffer at POS. |