comparison lisp/subr.el @ 2383:b7941d286c3f

(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.
author Eric S. Raymond <esr@snark.thyrsus.com>
date Sat, 27 Mar 1993 01:58:44 +0000
parents 8f410f56d98f
children 83319ce2d2f3
comparison
equal deleted inserted replaced
2382:030b76db285a 2383:b7941d286c3f
405 ;; Tell C code how to call this function. 405 ;; Tell C code how to call this function.
406 (defconst run-hooks 'run-hooks 406 (defconst run-hooks 'run-hooks
407 "Variable by which C primitives find the function `run-hooks'. 407 "Variable by which C primitives find the function `run-hooks'.
408 Don't change it.") 408 Don't change it.")
409 409
410 (defun add-hook (hook function) 410 (defun add-hook (hook function &optional append)
411 "Add to the value of HOOK the function FUNCTION unless already present. 411 "Add to the value of HOOK the function FUNCTION unless already present (it
412 HOOK should be a symbol, and FUNCTION may be any valid function. 412 becomes the first hook on the list unless optional APPEND is non-nil, in
413 HOOK's value should be a list of functions, not a single function. 413 which case it becomes the last). HOOK should be a symbol, and FUNCTION may be
414 If HOOK is void, it is first set to nil." 414 any valid function. HOOK's value should be a list of functions, not a single
415 function. If HOOK is void, it is first set to nil."
415 (or (boundp hook) (set hook nil)) 416 (or (boundp hook) (set hook nil))
416 (or (if (consp function) 417 (or (if (consp function)
417 ;; Clever way to tell whether a given lambda-expression 418 ;; Clever way to tell whether a given lambda-expression
418 ;; is equal to anything in the hook. 419 ;; is equal to anything in the hook.
419 (let ((tail (assoc (cdr function) (symbol-value hook)))) 420 (let ((tail (assoc (cdr function) (symbol-value hook))))
420 (equal function tail)) 421 (equal function tail))
421 (memq function (symbol-value hook))) 422 (memq function (symbol-value hook)))
422 (set hook (cons function (symbol-value hook))))) 423 (set hook
424 (if append
425 (nconc (symbol-value hook) (list function))
426 (cons function (symbol-value hook))))))
423 427
424 (defun momentary-string-display (string pos &optional exit-char message) 428 (defun momentary-string-display (string pos &optional exit-char message)
425 "Momentarily display STRING in the buffer at POS. 429 "Momentarily display STRING in the buffer at POS.
426 Display remains until next character is typed. 430 Display remains until next character is typed.
427 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed; 431 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;