annotate lisp/regi.el @ 25909:7a5095e7e171

Add item for bitmap-spec-p.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 07 Oct 1999 20:27:04 +0000
parents 83f275dcd93a
children b174db545cfd
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
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; Code:
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
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (defun regi-pos (&optional position col-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 "Return the character position at various buffer positions.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 Optional POSITION can be one of the following symbols:
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 `bol' == beginning of line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 `boi' == beginning of indentation
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 `eol' == end of line [default]
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 `bonl' == beginning of next line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 `bopl' == beginning of previous line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 Optional COL-P non-nil returns `current-column' instead of character position."
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (save-excursion
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ((eq position 'bol) (beginning-of-line))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ((eq position 'boi) (back-to-indentation))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ((eq position 'bonl) (forward-line 1))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ((eq position 'bopl) (forward-line -1))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (t (end-of-line)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (if col-p (current-column) (point))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (defun regi-mapcar (predlist func &optional negate-p case-fold-search-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 "Build a regi frame where each element of PREDLIST appears exactly once.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 The frame contains elements where each member of PREDLIST is
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 associated with FUNC, and optionally NEGATE-P and CASE-FOLD-SEARCH-P."
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (let (frame tail)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (if (or negate-p case-fold-search-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (setq tail (list negate-p)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (if case-fold-search-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (setq tail (append tail (list case-fold-search-p))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (while predlist
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (let ((element (list (car predlist) func)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (if tail
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (setq element (append element tail)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (setq frame (append frame (list element))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 predlist (cdr predlist))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 frame))
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
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (defun regi-interpret (frame &optional start end)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 "Interpret the regi frame FRAME.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 If optional START and END are supplied, they indicate the region of
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 interest, and the buffer is narrowed to the beginning of the line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 containing START, and beginning of the line after the line containing
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 END. Otherwise, point and mark are not set and processing continues
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 until your FUNC returns the `abort' symbol (see below). Beware! Not
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 supplying a START or END could put you in an infinite loop.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 A regi frame is a list of entries of the form:
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 (PRED FUNC [NEGATE-P [CASE-FOLD-SEARCH]])
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 is a predicate against which each line in the region is tested,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 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
86 beginning of the next line, the frame is reset and checking continues.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 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
88 current line until all entries in the frame are checked. At this
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 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
90 the next line. Checking continues until every line in the region is
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 checked. Optional NEGATE-P inverts the result of PRED before FUNC is
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 called and `case-fold-search' is bound to the optional value of
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 CASE-FOLD-SEARCH for the PRED check.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 PRED can be a string, variable, function or one of the following
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 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
97 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
98 regular expression and is matched against the current line (from the
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 beginning) using `looking-at'. If PRED does not evaluate to a string,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 it is interpreted as a binary value (nil or non-nil).
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 PRED can also be one of the following symbols:
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 t -- always produces a true outcome
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 `begin' -- always executes before anything else
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 `end' -- always executes after everything else
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 `every' -- execute after frame is matched on a line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 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
110 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
111 a frame entry is used, the rest are ignored.
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 Your FUNC can return values which control regi processing. If a list
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 is returned from your function, it can contain any combination of the
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 following elements:
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 the symbol `continue'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 Tells regi to continue processing frame-entries after a match,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 instead of resetting to the first entry and advancing to the next
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 line, as is the default behavior. When returning this symbol,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 you must take care not to enter an infinite loop.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 the symbol `abort'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 Tells regi to terminate processing this frame. any end
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 frame-entry is still processed.
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 list `(frame . NEWFRAME)'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 Tells regi to use NEWFRAME as its current frame. In other words,
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 your FUNC can modify the executing regi frame on the fly.
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 `(step . STEP)'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 Tells regi to move STEP number of lines forward during normal
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 processing. By default, regi moves forward 1 line. STEP can be
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 negative, but be careful of infinite loops.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 You should usually take care to explicitly return nil from your
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 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
138 `eval'ed. The following variables will be temporarily bound to some
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 useful information:
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 `curline'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 the current line in the buffer, as a string
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 `curframe'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 the full, current frame being executed
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 `curentry'
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 the current frame entry being executed."
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (save-excursion
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (save-restriction
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (let (begin-tag end-tag every-tag current-frame working-frame donep)
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 ;; set up the narrowed region
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (and start
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 end
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (let* ((tstart start)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (start (min start end))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (end (max start end)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (narrow-to-region
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (progn (goto-char end) (regi-pos 'bonl))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (progn (goto-char start) (regi-pos 'bol)))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; lets find the special tags and remove them from the working
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;; frame. note that only the last special tag is used.
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (mapcar
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (function
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (lambda (entry)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (let ((pred (car entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (func (car (cdr entry))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ((eq pred 'begin) (setq begin-tag func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ((eq pred 'end) (setq end-tag func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ((eq pred 'every) (setq every-tag func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (t
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (setq working-frame (append working-frame (list entry))))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ) ; end-cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 )))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 frame) ; end-mapcar
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 ;; execute the begin entry
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (eval begin-tag)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 ;; now process the frame
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (setq current-frame working-frame)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (while (not (or donep (eobp)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (let* ((entry (car current-frame))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (pred (nth 0 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (func (nth 1 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (negate-p (nth 2 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (case-fold-search (nth 3 entry))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 match-p)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (catch 'regi-throw-top
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ;; we are finished processing the frame for this line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 ((not current-frame)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (setq current-frame working-frame) ;reset frame
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (forward-line 1)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (throw 'regi-throw-top t))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;; see if predicate evaluates to a string
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 ((stringp (setq match-p (eval pred)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (setq match-p (looking-at match-p)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 ) ; end-cond
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; now that we've done the initial matching, check for
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; negation of match
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (and negate-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (setq match-p (not match-p)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; if the line matched, package up the argument list and
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; funcall the FUNC
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (if match-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (let* ((curline (buffer-substring
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (regi-pos 'bol)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (regi-pos 'eol)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (curframe current-frame)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (curentry entry)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (result (eval func))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (step (or (cdr (assq 'step result)) 1))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 )
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;; changing frame on the fly?
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (if (assq 'frame result)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (setq working-frame (cdr (assq 'frame result))))
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 ;; continue processing current frame?
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (if (memq 'continue result)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (setq current-frame (cdr current-frame))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (forward-line step)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (setq current-frame working-frame))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ;; abort current frame?
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (if (memq 'abort result)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (progn
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (setq donep t)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (throw 'regi-throw-top t)))
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ) ; end-let
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ;; else if no match occurred, then process the next
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ;; frame-entry on the current line
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (setq current-frame (cdr current-frame))
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 ) ; end-if match-p
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 ) ; end catch
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ) ; end let
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 ;; after every cycle, evaluate every-tag
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (eval every-tag)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 ) ; end-while
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 ;; now process the end entry
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (eval end-tag)))))
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
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (provide 'regi)
ce5f4afb1113 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 ;;; regi.el ends here