annotate lisp/hyperbole/wrolo-logic.el @ 147:e186c2b7192d xemacs-20-2

Added tag r20-2p1 for changeset 2af401a6ecca
author cvs
date Mon, 13 Aug 2007 09:34:48 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: wrolo-logic.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Performs logical retrievals on rolodex files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: hypermedia, matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; ORG: Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 13-Jun-89 at 22:57:33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; LAST-MOD: 14-Apr-95 at 16:27:43 by Bob Weiner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Copyright (C) 1989-1995, Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; INSTALLATION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; See also wrolo.el. These functions are separated from wrolo.el since many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; users may never want or need them. They can be automatically loaded when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; desired by adding the following to one of your Emacs init files:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; (autoload 'rolo-logic "wrolo-logic" "Logical rolodex search filters." t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; FEATURES:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; 1. One command, 'rolo-logic' which takes a logical search expression as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; an argument and displays any matching entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; 2. Logical 'and', 'or', 'not', and 'xor' rolodex entry retrieval filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; functions. They take any number of string or boolean arguments and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; may be nested. NOTE THAT THESE FUNCTIONS SHOULD NEVER BE CALLED
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; DIRECTLY UNLESS THE FREE VARIABLES 'start' and 'end' ARE BOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; BEFOREHAND.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; EXAMPLE:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; (rolo-logic (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; (rolo-and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; (rolo-not "Tool-And-Die")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; "secretary"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; would find all non-Tool-And-Die Corp. secretaries in your rolodex.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; The logical matching routines are not at all optimal, but then most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; rolodex files are not terribly lengthy either.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (require 'wrolo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defun rolo-logic (func &optional in-bufs count-only include-sub-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 no-sub-entries-out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "Apply FUNC to all entries in optional IN-BUFS, display entries where FUNC is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 If IN-BUFS is nil, 'rolo-file-list' is used. If optional COUNT-ONLY is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 non-nil, don't display entries, return count of matching entries only. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 optional INCLUDE-SUB-ENTRIES flag is non-nil, FUNC will be applied across all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 sub-entries at once. Default is to apply FUNC to each entry and sub-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 separately. Entries are displayed with all of their sub-entries unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 INCLUDE-SUB-ENTRIES is nil and optional NO-SUB-ENTRIES-OUT flag is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 FUNC should use the free variables 'start' and 'end' which contain the limits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 of the region on which it should operate. Returns number of applications of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 FUNC that return non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (interactive "xLogic function of no arguments, (lambda () (<function calls>): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (let ((obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (display-buf (if count-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (prog1 (set-buffer (get-buffer-create rolo-display-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (erase-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (let ((result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (lambda (in-bufs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (rolo-map-logic func in-bufs count-only include-sub-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 no-sub-entries-out)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (cond ((null in-bufs) rolo-file-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ((listp in-bufs) in-bufs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ((list in-bufs))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (let ((total-matches (apply '+ result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if (or count-only (= total-matches 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (pop-to-buffer display-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (let ((buf (get-buffer-window obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if buf (select-window buf) (switch-to-buffer buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (message (concat (if (= total-matches 0) "No" total-matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 " matching entr"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (if (= total-matches 1) "y" "ies")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 " found in rolodex.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 total-matches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defun rolo-map-logic (func rolo-buf &optional count-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 include-sub-entries no-sub-entries-out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "Apply FUNC to all entries in ROLO-BUF, write to buffer entries where FUNC is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 If optional COUNT-ONLY is non-nil, don't display entries, return count of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 matching entries only. If optional INCLUDE-SUB-ENTRIES flag is non-nil, FUNC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 will be applied across all sub-entries at once. Default is to apply FUNC to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 each entry and sub-entry separately. Entries are displayed with all of their
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 sub-entries unless INCLUDE-SUB-ENTRIES is nil and optional NO-SUB-ENTRIES-OUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 flag is non-nil. FUNC should use the free variables 'start' and 'end' which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 contain the limits of the region on which it should operate. Returns number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 of applications of FUNC that return non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (or (bufferp rolo-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (if (file-exists-p rolo-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq rolo-buf (find-file-noselect rolo-buf t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (let* ((display-buf (set-buffer (get-buffer-create rolo-display-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (let ((hdr-pos) (num-found 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (set-buffer rolo-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if (re-search-forward rolo-hdr-regexp nil t 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (progn (forward-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (setq hdr-pos (cons (point-min) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (let* ((start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (end-entry-hdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (curr-entry-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (while (re-search-forward rolo-entry-regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq start (save-excursion (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 next-entry-exists nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 end-entry-hdr (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 curr-entry-level (buffer-substring start end-entry-hdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 end (rolo-to-entry-end include-sub-entries curr-entry-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (let ((fun (funcall func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (or count-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (and fun (= num-found 0) hdr-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (append-to-buffer display-buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (car hdr-pos) (cdr hdr-pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (if fun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (progn (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (setq num-found (1+ num-found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 end (if (or include-sub-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 no-sub-entries-out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (goto-char (rolo-to-entry-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 t curr-entry-level))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (or count-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (append-to-buffer display-buf start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (goto-char end-entry-hdr)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (rolo-kill-buffer rolo-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 num-found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; INTERNAL FUNCTIONS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; Do NOT call the following functions directly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; Send them as parts of a lambda expression to 'rolo-logic'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defun rolo-not (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 "Logical <not> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (let ((pat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (or (not (setq pat (car pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (and (not (eq pat t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (not (search-forward pat end t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if pat-list nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun rolo-or (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "Logical <or> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (if (memq t pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (let ((pat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (or (not (setq pat (car pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (and (not (eq pat t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (not (search-forward pat end t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if pat-list t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (defun rolo-xor (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 "Logical <xor> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (let ((pat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (matches 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (or (not (setq pat (car pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (and (or (eq pat t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (not (goto-char start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (search-forward pat end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (setq matches (1+ matches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (< matches 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (= matches 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun rolo-and (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "Logical <and> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (if (memq nil pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (let ((pat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq pat (car pat-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (or (eq pat t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (not (goto-char start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (search-forward pat end t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (if pat-list nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; Work with regular expression patterns rather than strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (defun rolo-r-not (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 "Logical <not> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (let ((pat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (or (not (setq pat (car pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (and (not (eq pat t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (not (re-search-forward pat end t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (if pat-list nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (defun rolo-r-or (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "Logical <or> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (memq t pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (let ((pat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (or (not (setq pat (car pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (and (not (eq pat t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (not (re-search-forward pat end t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (if pat-list t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defun rolo-r-xor (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "Logical <xor> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (let ((pat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (matches 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (or (not (setq pat (car pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (and (or (eq pat t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (not (goto-char start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (re-search-forward pat end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq matches (1+ matches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (< matches 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (= matches 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (defun rolo-r-and (&rest pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 "Logical <and> rolodex entry filter. PAT-LIST is a list of pattern elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Each element may be t, nil, or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if (memq nil pat-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (let ((pat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (while (and pat-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (setq pat (car pat-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (or (eq pat t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (not (goto-char start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (re-search-forward pat end t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (setq pat-list (cdr pat-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if pat-list nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (provide 'wrolo-logic)