changeset 4414:3356419b94c1

(add-hook): Change a single function into a list.
author Richard M. Stallman <rms@gnu.org>
date Mon, 02 Aug 1993 07:23:07 +0000
parents 5a00cec8e9b0
children b9ce445fb406
files lisp/subr.el
diffstat 1 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Mon Aug 02 05:55:56 1993 +0000
+++ b/lisp/subr.el	Mon Aug 02 07:23:07 1993 +0000
@@ -296,7 +296,8 @@
 (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 `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 @@
 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.