annotate lisp/regi.el @ 11714:b62d02709ec7

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