Subject: gnus-treat-predicate: allow function predicates

From: Geoff Kuenning <[email-masked]>
Date: Mon, 07 Jan 2013 18:32:46 -0800

Gnus v5.13
GNU Emacs 24.2.1 (x86_64-suse-linux-gnu, GTK+ Version 3.4.4)
 of 2012-10-10 on build20

Gnus-treat-predicate is a bit silly, because it limits you predicates
the author thought of.  It's easy to extend it to be generalized, which
is what elisp is for in the first place.  This version lets any function
be called; it can access things via free variables.  See "TWO NEW LINES"
below:

(defun gnus-treat-predicate (val)
  (cond
   ((null val)
    nil)
   (gnus-treat-condition
    (eq gnus-treat-condition val))
   ((and (listp val)
	 (stringp (car val)))
    (apply 'gnus-or (mapcar `(lambda (s)
			       (string-match s ,(or gnus-newsgroup-name "")))
			    val)))
   ((listp val)
    (let ((pred (pop val)))
      (cond
       ((eq pred 'or)
	(apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
       ((eq pred 'and)
	(apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
       ((eq pred 'not)
	(not (gnus-treat-predicate (car val))))
       ((eq pred 'typep)
	(equal (car val) gnus-treat-type))
       ; TWO NEW LINES
       ((functionp pred)
	(funcall pred))
       (t
	(error "%S is not a valid predicate" pred)))))
   ((eq val t)
    t)
   ((eq val 'head)
    nil)
   ((eq val 'first)
    (eq part-number 1))
   ((eq val 'last)
    (eq part-number total-parts))
   ((numberp val)
    (< gnus-treat-length val))
   (t
    (error "%S is not a valid value" val))))
-- 
    Geoff Kuenning   [email-masked]   http://www.cs.hmc.edu/~geoff/

Orchestra retrospectively extremely satisfied with symphony [No. 1] as
result of barrel of free beer.
	-- Gustav Mahler, post-premiere letter to Arnold Berliner