]> git.eshelyaron.com Git - emacs.git/commitdiff
(add-hook): Change a single function into a list.
authorRichard M. Stallman <rms@gnu.org>
Mon, 2 Aug 1993 07:23:07 +0000 (07:23 +0000)
committerRichard M. Stallman <rms@gnu.org>
Mon, 2 Aug 1993 07:23:07 +0000 (07:23 +0000)
lisp/subr.el

index 031c7ff442135ccc83f0a26ba72bd1b979840f75..c1717f553d30ec84ad63d325f52d7b636ee7d7eb 100644 (file)
@@ -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.