]> code.delx.au - gnu-emacs/blobdiff - lisp/subr.el
*** empty log message ***
[gnu-emacs] / lisp / subr.el
index d99153bf8cd43dd3c8c4f84e4ca491637260681f..767e2a8cde3f452b823b246f73780eb4d7c31df1 100644 (file)
@@ -135,6 +135,22 @@ If N is bigger than the length of X, return X."
       (setq x (cdr x)))
     x))
 
+(defun remove (elt seq)
+  "Return a copy of SEQ with all occurences of ELT removed.
+SEQ must be a list, vector, or string.  The comparison is done with `equal'."
+  (if (nlistp seq)
+      ;; If SEQ isn't a list, there's no need to copy SEQ because
+      ;; `delete' will return a new object.
+      (delete elt seq)
+    (delete elt (copy-sequence seq))))
+
+(defun remq (elt list)
+  "Return a copy of LIST with all occurences of ELT removed.
+The comparison is done with `eq'."
+  (if (memq elt list)
+      (delq elt (copy-sequence list))
+    list))
+
 (defun assoc-default (key alist &optional test default)
   "Find object KEY in a pseudo-alist ALIST.
 ALIST is a list of conses or objects.  Each element (or the element's car,
@@ -615,8 +631,8 @@ as returned by the `event-start' and `event-end' functions."
 (defalias 'define-function 'defalias)
 
 (defalias 'sref 'aref)
-(make-obsolete 'sref 'aref)
-(make-obsolete 'char-bytes "Now this function always returns 1")
+(make-obsolete 'sref 'aref "20.4")
+(make-obsolete 'char-bytes "Now this function always returns 1" "20.4")
 
 ;; Some programs still use this as a function.
 (defun baud-rate ()
@@ -704,7 +720,7 @@ function, it is changed to a list of functions."
   (let ((hook-value (if local (symbol-value hook) (default-value hook))))
     ;; If the hook value is a single function, turn it into a list.
     (when (or (not (listp hook-value)) (eq (car hook-value) 'lambda))
-      (set hook-value (list hook-value)))
+      (setq hook-value (list hook-value)))
     ;; Do the actual addition if necessary
     (unless (member function hook-value)
       (setq hook-value
@@ -733,11 +749,10 @@ To make a hook variable buffer-local, always use
     (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook)))
       (setq local t)))
   (let ((hook-value (if local (symbol-value hook) (default-value hook))))
-    ;; If the hook value is a single function, turn it into a list.
-    (when (or (not (listp hook-value)) (eq (car hook-value) 'lambda))
-      (set hook-value (list hook-value)))
-    ;; Do the actual removal if necessary
-    (setq hook-value (delete function (copy-sequence hook-value)))
+    ;; Remove the function, for both the list and the non-list cases.
+    (if (or (not (listp hook-value)) (eq (car hook-value) 'lambda))
+       (if (equal hook-value function) (setq hook-value nil))
+      (setq hook-value (delete function (copy-sequence hook-value))))
     ;; If the function is on the global hook, we need to shadow it locally
     ;;(when (and local (member function (default-value hook))
     ;;        (not (member (cons 'not function) hook-value)))