diff lisp/gnus/gnus-util.el @ 110779:9d935b7bf464

Eliminate `remove-if-not' that is a cl function. gnus-util.el (gnus-remove-if): Allow hash table. gnus-util.el (gnus-remove-if-not): New function. gnus-art.el (gnus-mime-view-part-as-type): Replace remove-if-not with gnus-remove-if-not. gnus-score.el (gnus-summary-score-effect): Replace remove-if-not with gnus-remove-if-not. gnus-sum.el (gnus-read-move-group-name): Replace remove-if-not with gnus-remove-if-not. gnus-group.el (gnus-group-completing-read): Regard collection as a hash table if it is not a list.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Wed, 06 Oct 2010 01:09:32 +0000
parents 22b487462b5a
children d2b45bb936b6
line wrap: on
line diff
--- a/lisp/gnus/gnus-util.el	Tue Oct 05 23:42:01 2010 +0000
+++ b/lisp/gnus/gnus-util.el	Wed Oct 06 01:09:32 2010 +0000
@@ -1307,13 +1307,40 @@
        (with-current-buffer gnus-group-buffer
 	 (eq major-mode 'gnus-group-mode))))
 
-(defun gnus-remove-if (predicate list)
-  "Return a copy of LIST with all items satisfying PREDICATE removed."
+(defun gnus-remove-if (predicate sequence &optional hash-table-p)
+  "Return a copy of SEQUENCE with all items satisfying PREDICATE removed.
+SEQUENCE should be a list, a vector, or a string.  Returns always a list.
+If HASH-TABLE-P is non-nil, regards SEQUENCE as a hash table."
   (let (out)
-    (while list
-      (unless (funcall predicate (car list))
-	(push (car list) out))
-      (setq list (cdr list)))
+    (if hash-table-p
+	(mapatoms (lambda (symbol)
+		    (unless (funcall predicate symbol)
+		      (push symbol out)))
+		  sequence)
+      (unless (listp sequence)
+	(setq sequence (append sequence nil)))
+      (while sequence
+	(unless (funcall predicate (car sequence))
+	  (push (car sequence) out))
+	(setq sequence (cdr sequence))))
+    (nreverse out)))
+
+(defun gnus-remove-if-not (predicate sequence &optional hash-table-p)
+  "Return a copy of SEQUENCE with all items not satisfying PREDICATE removed.
+SEQUENCE should be a list, a vector, or a string.  Returns always a list.
+If HASH-TABLE-P is non-nil, regards SEQUENCE as a hash table."
+  (let (out)
+    (if hash-table-p
+	(mapatoms (lambda (symbol)
+		    (when (funcall predicate symbol)
+		      (push symbol out)))
+		  sequence)
+      (unless (listp sequence)
+	(setq sequence (append sequence nil)))
+      (while sequence
+	(when (funcall predicate (car sequence))
+	  (push (car sequence) out))
+	(setq sequence (cdr sequence))))
     (nreverse out)))
 
 (if (fboundp 'assq-delete-all)