annotate lisp/utils/regi.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
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 ;;; regi.el --- REGular expression Interpreting engine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Author: 1993 Barry A. Warsaw, Century Computing, Inc. <bwarsaw@cen.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Maintainer: bwarsaw@cen.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Created: 24-Feb-1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Version: 1.8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Last Modified: 1993/06/01 21:33:00
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Keywords: extensions, matching, wp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Copyright (C) 1993 Barry A. Warsaw
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; LCD Archive Entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; regi|Barry A. Warsaw|bwarsaw@cen.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; |REGular expression Interpreting engine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; |1993/06/01 21:33:00|1.8|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defun regi-pos (&optional position col-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 "Return the character position at various buffer positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 Optional POSITION can be one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 `bol' == beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 `boi' == beginning of indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 `eol' == end of line [default]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 `bonl' == beginning of next line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 `bopl' == beginning of previous line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 Optional COL-P non-nil returns `current-column' instead of character position."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ((eq position 'bol) (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ((eq position 'boi) (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ((eq position 'bonl) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ((eq position 'bopl) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (t (end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (if col-p (current-column) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defun regi-mapcar (predlist func &optional negate-p case-fold-search-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "Build a regi frame where each element of PREDLIST appears exactly once.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 The frame contains elements where each member of PREDLIST is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 associated with FUNC, and optionally NEGATE-P and CASE-FOLD-SEARCH-P."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (let (frame tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (if (or negate-p case-fold-search-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (setq tail (list negate-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if case-fold-search-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq tail (append tail (list case-fold-search-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (while predlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (let ((element (list (car predlist) func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (setq element (append element tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (setq frame (append frame (list element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 predlist (cdr predlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defun regi-interpret (frame &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "Interpret the regi frame FRAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 If optional START and END are supplied, they indicate the region of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 interest, and the buffer is narrowed to the beginning of the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 containing START, and beginning of the line after the line containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 END. Otherwise, point and mark are not set and processing continues
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 until your FUNC returns the `abort' symbol (see below). Beware! Not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 supplying a START or END could put you in an infinite loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 A regi frame is a list of entries of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (PRED FUNC [NEGATE-P [CASE-FOLD-SEARCH]])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 PRED is a predicate against which each line in the region is tested,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 and if a match occurs, FUNC is `eval'd. Point is then moved to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 beginning of the next line, the frame is reset and checking continues.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 If a match doesn't occur, the next entry is checked against the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 current line until all entries in the frame are checked. At this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 point, if no match occurred, the frame is reset and point is moved to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 the next line. Checking continues until every line in the region is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 checked. Optional NEGATE-P inverts the result of PRED before FUNC is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 called and `case-fold-search' is bound to the optional value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 CASE-FOLD-SEARCH for the PRED check.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 PRED can be a string, variable, function or one of the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 symbols: t, nil, `begin', `end', and `every'. If PRED is a string, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 a variable or list that evaluates to a string, it is interpreted as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 regular expression and is matched against the current line (from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 beginning) using `looking-at'. If PRED does not evaluate to a string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 it is interpreted as a binary value (nil or non-nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 PRED can also be one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 t -- always produces a true outcome
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 `begin' -- always executes before anything else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 `end' -- always executes after everything else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 `every' -- execute after frame is matched on a line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 Note that NEGATE-P and CASE-FOLD-SEARCH are meaningless if PRED is one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 of these special symbols. Only the first occurance of each symbol in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 a frame entry is used, the rest are ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 Your FUNC can return values which control regi processing. If a list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 is returned from your function, it can contain any combination of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 following elements:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 the symbol `continue'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Tells regi to continue processing frame-entries after a match,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 instead of resetting to the first entry and advancing to the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 line, as is the default behavior. When returning this symbol,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 you must take care not to enter an infinite loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 the symbol `abort'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 Tells regi to terminate processing this frame. any end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 frame-entry is still processed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 the list `(frame . NEWFRAME)'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 Tells regi to use NEWFRAME as its current frame. In other words,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 your FUNC can modify the executing regi frame on the fly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 the list `(step . STEP)'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 Tells regi to move STEP number of lines forward during normal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 processing. By default, regi moves forward 1 line. STEP can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 negative, but be careful of infinite loops.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 You should usually take care to explicitly return nil from your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 function if no action is to take place. Your FUNC will always be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 `eval'ed. The following variables will be temporarily bound to some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 useful information:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 `curline'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 the current line in the buffer, as a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 `curframe'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 the full, current frame being executed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 `curentry'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 the current frame entry being executed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (let (begin-tag end-tag every-tag current-frame working-frame donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; set up the narrowed region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (and start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (let* ((tstart start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (start (min start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (end (max start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (progn (goto-char end) (regi-pos 'bonl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (progn (goto-char start) (regi-pos 'bol)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; lets find the special tags and remove them from the working
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; frame. note that only the last special tag is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (lambda (entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (let ((pred (car entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (func (car (cdr entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ((eq pred 'begin) (setq begin-tag func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ((eq pred 'end) (setq end-tag func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ((eq pred 'every) (setq every-tag func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq working-frame (append working-frame (list entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ) ; end-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 frame) ; end-mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; execute the begin entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (eval begin-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; now process the frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (setq current-frame working-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (while (not (or donep (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (let* ((entry (car current-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (pred (nth 0 entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (func (nth 1 entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (negate-p (nth 2 entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (case-fold-search (nth 3 entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 match-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (catch 'regi-throw-top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; we are finished processing the frame for this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ((not current-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (setq current-frame working-frame) ;reset frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (throw 'regi-throw-top t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; see if predicate evaluates to a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ((stringp (setq match-p (eval pred)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setq match-p (looking-at match-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ) ; end-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; now that we've done the initial matching, check for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; negation of match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (and negate-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (setq match-p (not match-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; if the line matched, package up the argument list and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; funcall the FUNC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (if match-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (let* ((curline (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (regi-pos 'bol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (regi-pos 'eol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (curframe current-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (curentry entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (result (eval func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (step (or (cdr (assq 'step result)) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;; changing frame on the fly?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (if (assq 'frame result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (setq working-frame (cdr (assq 'frame result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; continue processing current frame?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (memq 'continue result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (setq current-frame (cdr current-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (forward-line step)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq current-frame working-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; abort current frame?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (if (memq 'abort result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq donep t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (throw 'regi-throw-top t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ) ; end-let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; else if no match occurred, then process the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; frame-entry on the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (setq current-frame (cdr current-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ) ; end-if match-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ) ; end catch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ) ; end let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; after every cycle, evaluate every-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (eval every-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ) ; end-while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; now process the end entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (eval end-tag)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (provide 'regi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;;; regi.el ends here