annotate lisp/regi.el @ 13907:c4f965637f22

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