annotate lisp/regi.el @ 50706:371e62e112b2

(mh-version): Set to 7.3+cvs.
author Bill Wohler <wohler@newt.com>
date Fri, 25 Apr 2003 17:18:24 +0000
parents b174db545cfd
children
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
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14003
diff changeset
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14003
diff changeset
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14003
diff changeset
27 ;; Boston, MA 02111-1307, USA.
5139
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14169
diff changeset
29 ;;; Commentary:
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14169
diff changeset
30
5139
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; Code:
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
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (defun regi-pos (&optional position col-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 "Return the character position at various buffer positions.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 Optional POSITION can be one of the following symbols:
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 `bol' == beginning of line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 `boi' == beginning of indentation
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 `eol' == end of line [default]
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 `bonl' == beginning of next line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 `bopl' == beginning of previous line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 Optional COL-P non-nil returns `current-column' instead of character position."
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (save-excursion
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ((eq position 'bol) (beginning-of-line))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ((eq position 'boi) (back-to-indentation))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ((eq position 'bonl) (forward-line 1))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ((eq position 'bopl) (forward-line -1))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (t (end-of-line)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (if col-p (current-column) (point))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (defun regi-mapcar (predlist func &optional negate-p case-fold-search-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 "Build a regi frame where each element of PREDLIST appears exactly once.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 The frame contains elements where each member of PREDLIST is
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 associated with FUNC, and optionally NEGATE-P and CASE-FOLD-SEARCH-P."
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (let (frame tail)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (if (or negate-p case-fold-search-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (setq tail (list negate-p)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (if case-fold-search-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (setq tail (append tail (list case-fold-search-p))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (while predlist
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (let ((element (list (car predlist) func)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (if tail
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (setq element (append element tail)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (setq frame (append frame (list element))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 predlist (cdr predlist))
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 frame))
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
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (defun regi-interpret (frame &optional start end)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 "Interpret the regi frame FRAME.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 If optional START and END are supplied, they indicate the region of
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 interest, and the buffer is narrowed to the beginning of the line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 containing START, and beginning of the line after the line containing
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 END. Otherwise, point and mark are not set and processing continues
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 until your FUNC returns the `abort' symbol (see below). Beware! Not
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 supplying a START or END could put you in an infinite loop.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 A regi frame is a list of entries of the form:
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 (PRED FUNC [NEGATE-P [CASE-FOLD-SEARCH]])
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 is a predicate against which each line in the region is tested,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 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
88 beginning of the next line, the frame is reset and checking continues.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 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
90 current line until all entries in the frame are checked. At this
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 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
92 the next line. Checking continues until every line in the region is
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 checked. Optional NEGATE-P inverts the result of PRED before FUNC is
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 called and `case-fold-search' is bound to the optional value of
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 CASE-FOLD-SEARCH for the PRED check.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 PRED can be a string, variable, function or one of the following
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 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
99 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
100 regular expression and is matched against the current line (from the
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 beginning) using `looking-at'. If PRED does not evaluate to a string,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 it is interpreted as a binary value (nil or non-nil).
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 PRED can also be one of the following symbols:
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 t -- always produces a true outcome
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 `begin' -- always executes before anything else
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 `end' -- always executes after everything else
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 `every' -- execute after frame is matched on a line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 Note that NEGATE-P and CASE-FOLD-SEARCH are meaningless if PRED is one
14003
f2bec77fbc58 (regi-interpret): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 12860
diff changeset
112 of these special symbols. Only the first occurrence of each symbol in
5139
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 a frame entry is used, the rest are ignored.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 Your FUNC can return values which control regi processing. If a list
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 is returned from your function, it can contain any combination of the
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 following elements:
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 the symbol `continue'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 Tells regi to continue processing frame-entries after a match,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 instead of resetting to the first entry and advancing to the next
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 line, as is the default behavior. When returning this symbol,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 you must take care not to enter an infinite loop.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 the symbol `abort'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 Tells regi to terminate processing this frame. any end
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 frame-entry is still processed.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 the list `(frame . NEWFRAME)'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 Tells regi to use NEWFRAME as its current frame. In other words,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 your FUNC can modify the executing regi frame on the fly.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 the list `(step . STEP)'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 Tells regi to move STEP number of lines forward during normal
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 processing. By default, regi moves forward 1 line. STEP can be
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 negative, but be careful of infinite loops.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 You should usually take care to explicitly return nil from your
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 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
140 `eval'ed. The following variables will be temporarily bound to some
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 useful information:
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 `curline'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 the current line in the buffer, as a string
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 `curframe'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 the full, current frame 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 `curentry'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 the current frame entry being executed."
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (save-excursion
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (save-restriction
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (let (begin-tag end-tag every-tag current-frame working-frame donep)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; set up the narrowed region
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (and start
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 end
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (let* ((tstart start)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (start (min start end))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (end (max start end)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (narrow-to-region
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (progn (goto-char end) (regi-pos 'bonl))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (progn (goto-char start) (regi-pos 'bol)))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; lets find the special tags and remove them from the working
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; frame. note that only the last special tag is used.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (mapcar
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (function
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (lambda (entry)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (let ((pred (car entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (func (car (cdr entry))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ((eq pred 'begin) (setq begin-tag func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ((eq pred 'end) (setq end-tag func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 ((eq pred 'every) (setq every-tag func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (t
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (setq working-frame (append working-frame (list entry))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ) ; end-cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 )))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 frame) ; end-mapcar
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 ;; execute the begin entry
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (eval begin-tag)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;; now process the frame
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (setq current-frame working-frame)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (while (not (or donep (eobp)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (let* ((entry (car current-frame))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (pred (nth 0 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (func (nth 1 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (negate-p (nth 2 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (case-fold-search (nth 3 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 match-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (catch 'regi-throw-top
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; we are finished processing the frame for this line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ((not current-frame)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (setq current-frame working-frame) ;reset frame
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (forward-line 1)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (throw 'regi-throw-top t))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;; see if predicate evaluates to a string
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 ((stringp (setq match-p (eval pred)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (setq match-p (looking-at match-p)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ) ; end-cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 ;; now that we've done the initial matching, check for
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;; negation of match
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (and negate-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (setq match-p (not match-p)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; if the line matched, package up the argument list and
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 ;; funcall the FUNC
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (if match-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (let* ((curline (buffer-substring
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (regi-pos 'bol)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (regi-pos 'eol)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (curframe current-frame)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (curentry entry)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (result (eval func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (step (or (cdr (assq 'step result)) 1))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 )
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; changing frame on the fly?
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (if (assq 'frame result)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (setq working-frame (cdr (assq 'frame result))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;; continue processing current frame?
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (if (memq 'continue result)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (setq current-frame (cdr current-frame))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (forward-line step)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (setq current-frame working-frame))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 ;; abort current frame?
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (if (memq 'abort result)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (progn
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (setq donep t)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (throw 'regi-throw-top t)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ) ; end-let
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ;; else if no match occurred, then process the next
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;; frame-entry on the current line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (setq current-frame (cdr current-frame))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ) ; end-if match-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ) ; end catch
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 ) ; end let
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 ;; after every cycle, evaluate every-tag
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (eval every-tag)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ) ; end-while
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 ;; now process the end entry
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (eval end-tag)))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (provide 'regi)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 14169
diff changeset
257
5139
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;;; regi.el ends here