mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
(add-hook): Change a single function into a list.
This commit is contained in:
parent
47f3858d11
commit
322959764a
1 changed files with 20 additions and 6 deletions
26
lisp/subr.el
26
lisp/subr.el
|
|
@ -296,7 +296,8 @@ The normal global definition of the character C-x indirects to this keymap.")
|
|||
(defun event-modifiers (event)
|
||||
"Returns a list of symbols representing the modifier keys in event EVENT.
|
||||
The elements of the list may include `meta', `control',
|
||||
`shift', `hyper', `super', `alt', `click', `drag', and `down'."
|
||||
`shift', `hyper', `super', `alt', `click', `double', `triple', `drag',
|
||||
and `down'."
|
||||
(let ((type event))
|
||||
(if (listp type)
|
||||
(setq type (car type)))
|
||||
|
|
@ -352,6 +353,11 @@ The return value is of the form
|
|||
The `posn-' functions access elements of such lists."
|
||||
(nth (if (consp (nth 2 event)) 2 1) event))
|
||||
|
||||
(defsubst event-click-count (event)
|
||||
"Return the multi-click count of EVENT, a click or drag event.
|
||||
The return value is a positive integer."
|
||||
(if (integerp (nth 2 event)) (nth 2 event) 1))
|
||||
|
||||
(defsubst posn-window (position)
|
||||
"Return the window in POSITION.
|
||||
POSITION should be a list of the form
|
||||
|
|
@ -460,12 +466,20 @@ If it is a list, the elements are called, in order, with no arguments."
|
|||
Don't change it.")
|
||||
|
||||
(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."
|
||||
"Add to the value of HOOK the function FUNCTION.
|
||||
FUNCTION is not added if already present.
|
||||
FUNCTION is added (if necessary) at the beginning of the hook list
|
||||
unless the optional argument APPEND is non-nil, in which case
|
||||
FUNCTION is added at the end.
|
||||
|
||||
HOOK should be a symbol, and FUNCTION may be any valid function. If
|
||||
HOOK is void, it is first set to nil. If HOOK's value is a single
|
||||
function, it is changed to a list of functions."
|
||||
(or (boundp hook) (set hook nil))
|
||||
;; If the hook value is a single function, turn it into a list.
|
||||
(let ((old (symbol-value hook)))
|
||||
(if (or (not (listp old)) (eq (car old) 'lambda))
|
||||
(set hook (list old))))
|
||||
(or (if (consp function)
|
||||
;; Clever way to tell whether a given lambda-expression
|
||||
;; is equal to anything in the hook.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue