Mercurial > emacs
annotate lisp/regi.el @ 51195:3cbf29813eea
(struct frame): Rename members height to text_lines,
width to text_cols, window_height to total_lines, window_width to
total_cols, new_height to new_text_lines, new_width to
new_text_cols. All uses changed.
(struct frame): New members which consolidate common members of
x_output, w32_output, and mac_output structures: left_pos,
top_pos, pixel_height, pixel_width, x_pixels_diff, y_pixels_diff,
win_gravity, size_hint_flags, border_width, internal_border_width,
line_height, fringe_cols, left_fringe_width, right_fringe_width,
want_fullscreen. All uses changed.
(struct frame): New member column_width contaning the canonical
column width, analogue to line_height. All uses changed.
(struct frame): Rename members scroll_bar_pixel_width to
config_scroll_bar_width, and scroll_bar_cols to
config_scroll_bar_cols. All uses changed.
(struct frame): New member scroll_bar_actual_width which
consolidates and renames the vertical_scroll_bar_extra member of
x_output, w32_output, and mac_output structures. All uses changed.
(FRAME_PIXEL_HEIGHT): Renamed from PIXEL_HEIGHT and moved
from x/w32/macterm.h files. All uses changed. Also change code
which referred to f->output_data...->pixel_height.
(FRAME_PIXEL_WIDTH): Renamed from PIXEL_WIDTH and moved
from x/w32/macterm.h files. All uses changed. Also change code
which referred to f->output_data...->pixel_width.
(FRAME_LINES): Renamed from FRAME_HEIGHT. All uses changed.
Also change code which referred to f->height.
(FRAME_COLS): Renamed from FRAME_WIDTH. All uses changed.
Also change code which referred to f->width.
(FRAME_NEW_HEIGHT, FRAME_NEW_WIDTH): Remove macros; change uses
to update new_text_lines and new_text_cols members directly.
(FRAME_CONFIG_SCROLL_BAR_WIDTH): Renamed from
FRAME_SCROLL_BAR_PIXEL_WIDTH. All uses changed.
(FRAME_CONFIG_SCROLL_BAR_COLS): Renamed from
FRAME_SCROLL_BAR_COLS. All uses changed.
(FRAME_LEFT_SCROLL_BAR_COLS, FRAME_RIGHT_SCROLL_BAR_COLS):
Renamed from FRAME_LEFT_SCROLL_BAR_WIDTH and
FRAME_RIGHT_SCROLL_BAR_WIDTH, resp. All uses changed.
(FRAME_SCROLL_BAR_AREA_WIDTH, FRAME_LEFT_SCROLL_BAR_AREA_WIDTH)
(FRAME_RIGHT_SCROLL_BAR_AREA_WIDTH): New macros.
(FRAME_TOTAL_COLS): Renamed from FRAME_WINDOW_WIDTH.
(SET_FRAME_COLS): Renamed from SET_FRAME_WIDTH.
(FRAME_TOTAL_COLS_ARG): Renamed from FRAME_WINDOW_WIDTH_ARG.
(WINDOW_VERTICAL_SCROLL_BAR_COLUMN): Remove unused macro.
(WINDOW_VERTICAL_SCROLL_BAR_HEIGHT): Remove unused macro.
(FRAME_LINE_HEIGHT): Renamed from CANON_Y_UNIT. Unconditionally
return line_height member (it now has proper value also for
non-window frames).
(FRAME_COLUMN_WIDTH): Renamed from CANON_X_UNIT. Unconditionally
return new column_width member (rather than the default font width).
(FRAME_FRINGE_COLS, FRAME_LEFT_FRINGE_WIDTH)
(FRAME_RIGHT_FRINGE_WIDTH): Renamed from FRAME_X_... and moved
from x/w32/macterm.h files. Unconditionally return corresponding
member of frame structure (they now have proper values also for
non-window frames).
(FRAME_TOTAL_FRINGE_WIDTH): Renamed from FRAME_FRINGE_WIDTH.
Calculate return value from left and right widths.
(FRAME_INTERNAL_BORDER_WIDTH): Unconditionally return
internal_border_width member (has proper value for non-window frame).
(FRAME_PIXEL_X_FROM_CANON_X): Renamed from PIXEL_X_FROM_CANON_X.
(FRAME_PIXEL_Y_FROM_CANON_Y): Renamed from PIXEL_Y_FROM_CANON_Y.
(FRAME_CANON_X_FROM_PIXEL_X): Renamed from CANON_X_FROM_PIXEL_X.
(FRAME_CANON_Y_FROM_PIXEL_Y): Renamed from CANON_Y_FROM_PIXEL_Y.
(FRAME_LINE_TO_PIXEL_Y): Renamed from CHAR_TO_PIXEL_ROW,
consolidated from xterm.h, macterm.h, and w32term.h.
(FRAME_COL_TO_PIXEL_X): Renamed from CHAR_TO_PIXEL_COL,
consolidated from xterm.h, macterm.h, and w32term.h.
(FRAME_TEXT_COLS_TO_PIXEL_WIDTH): Renamed from
CHAR_TO_PIXEL_WIDTH consolidated from x/mac/w32term.h.
(FRAME_TEXT_LINES_TO_PIXEL_HEIGHT): Renamed from
CHAR_TO_PIXEL_HEIGHT consolidated from x/mac/w32term.h.
(FRAME_PIXEL_Y_TO_LINE): Renamed from PIXEL_TO_CHAR_ROW
consolidated from x/mac/w32term.h.
(FRAME_PIXEL_X_TO_COL): Renamed from PIXEL_TO_CHAR_COL
consolidated from x/mac/w32term.h.
(FRAME_PIXEL_WIDTH_TO_TEXT_COLS): Renamed from
PIXEL_TO_CHAR_WIDTH consolidated from x/mac/w32term.h.
(FRAME_PIXEL_HEIGHT_TO_TEXT_LINES): Renamed from
PIXEL_TO_CHAR_HEIGHT consolidated from x/mac/w32term.h.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Sat, 24 May 2003 21:58:07 +0000 |
parents | b174db545cfd |
children |
rev | line source |
---|---|
5139 | 1 ;;; regi.el --- REGular expression Interpreting engine |
2 | |
12860 | 3 ;; Copyright (C) 1993 Free Software Foundation, Inc. |
4 | |
5139 | 5 ;; Author: 1993 Barry A. Warsaw, Century Computing, Inc. <bwarsaw@cen.com> |
6 ;; Maintainer: bwarsaw@cen.com | |
7 ;; Created: 24-Feb-1993 | |
8 ;; Version: 1.8 | |
9 ;; Last Modified: 1993/06/01 21:33:00 | |
5140 | 10 ;; Keywords: extensions, matching |
5139 | 11 |
12860 | 12 ;; This file is part of GNU Emacs. |
5139 | 13 |
12860 | 14 ;; GNU Emacs is free software; you can redistribute it and/or modify |
5139 | 15 ;; it under the terms of the GNU General Public License as published by |
12860 | 16 ;; the Free Software Foundation; either version 2, or (at your option) |
17 ;; any later version. | |
18 | |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
5139 | 20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
12860 | 23 |
5139 | 24 ;; You should have received a copy of the GNU General Public License |
14169 | 25 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
27 ;; Boston, MA 02111-1307, USA. | |
5139 | 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 | 31 ;;; Code: |
32 | |
33 | |
34 (defun regi-pos (&optional position col-p) | |
35 "Return the character position at various buffer positions. | |
36 Optional POSITION can be one of the following symbols: | |
37 | |
38 `bol' == beginning of line | |
39 `boi' == beginning of indentation | |
40 `eol' == end of line [default] | |
41 `bonl' == beginning of next line | |
42 `bopl' == beginning of previous line | |
43 | |
44 Optional COL-P non-nil returns `current-column' instead of character position." | |
45 (save-excursion | |
46 (cond | |
47 ((eq position 'bol) (beginning-of-line)) | |
48 ((eq position 'boi) (back-to-indentation)) | |
49 ((eq position 'bonl) (forward-line 1)) | |
50 ((eq position 'bopl) (forward-line -1)) | |
51 (t (end-of-line))) | |
52 (if col-p (current-column) (point)))) | |
53 | |
54 (defun regi-mapcar (predlist func &optional negate-p case-fold-search-p) | |
55 "Build a regi frame where each element of PREDLIST appears exactly once. | |
56 The frame contains elements where each member of PREDLIST is | |
57 associated with FUNC, and optionally NEGATE-P and CASE-FOLD-SEARCH-P." | |
58 (let (frame tail) | |
59 (if (or negate-p case-fold-search-p) | |
60 (setq tail (list negate-p))) | |
61 (if case-fold-search-p | |
62 (setq tail (append tail (list case-fold-search-p)))) | |
63 (while predlist | |
64 (let ((element (list (car predlist) func))) | |
65 (if tail | |
66 (setq element (append element tail))) | |
67 (setq frame (append frame (list element)) | |
68 predlist (cdr predlist)) | |
69 )) | |
70 frame)) | |
71 | |
72 | |
73 (defun regi-interpret (frame &optional start end) | |
74 "Interpret the regi frame FRAME. | |
75 If optional START and END are supplied, they indicate the region of | |
76 interest, and the buffer is narrowed to the beginning of the line | |
77 containing START, and beginning of the line after the line containing | |
78 END. Otherwise, point and mark are not set and processing continues | |
79 until your FUNC returns the `abort' symbol (see below). Beware! Not | |
80 supplying a START or END could put you in an infinite loop. | |
81 | |
82 A regi frame is a list of entries of the form: | |
83 | |
84 (PRED FUNC [NEGATE-P [CASE-FOLD-SEARCH]]) | |
85 | |
86 PRED is a predicate against which each line in the region is tested, | |
87 and if a match occurs, FUNC is `eval'd. Point is then moved to the | |
88 beginning of the next line, the frame is reset and checking continues. | |
89 If a match doesn't occur, the next entry is checked against the | |
90 current line until all entries in the frame are checked. At this | |
91 point, if no match occurred, the frame is reset and point is moved to | |
92 the next line. Checking continues until every line in the region is | |
93 checked. Optional NEGATE-P inverts the result of PRED before FUNC is | |
94 called and `case-fold-search' is bound to the optional value of | |
95 CASE-FOLD-SEARCH for the PRED check. | |
96 | |
97 PRED can be a string, variable, function or one of the following | |
98 symbols: t, nil, `begin', `end', and `every'. If PRED is a string, or | |
99 a variable or list that evaluates to a string, it is interpreted as a | |
100 regular expression and is matched against the current line (from the | |
101 beginning) using `looking-at'. If PRED does not evaluate to a string, | |
102 it is interpreted as a binary value (nil or non-nil). | |
103 | |
104 PRED can also be one of the following symbols: | |
105 | |
106 t -- always produces a true outcome | |
107 `begin' -- always executes before anything else | |
108 `end' -- always executes after everything else | |
109 `every' -- execute after frame is matched on a line | |
110 | |
111 Note that NEGATE-P and CASE-FOLD-SEARCH are meaningless if PRED is one | |
14003 | 112 of these special symbols. Only the first occurrence of each symbol in |
5139 | 113 a frame entry is used, the rest are ignored. |
114 | |
115 Your FUNC can return values which control regi processing. If a list | |
116 is returned from your function, it can contain any combination of the | |
117 following elements: | |
118 | |
119 the symbol `continue' | |
120 Tells regi to continue processing frame-entries after a match, | |
121 instead of resetting to the first entry and advancing to the next | |
122 line, as is the default behavior. When returning this symbol, | |
123 you must take care not to enter an infinite loop. | |
124 | |
125 the symbol `abort' | |
126 Tells regi to terminate processing this frame. any end | |
127 frame-entry is still processed. | |
128 | |
129 the list `(frame . NEWFRAME)' | |
130 Tells regi to use NEWFRAME as its current frame. In other words, | |
131 your FUNC can modify the executing regi frame on the fly. | |
132 | |
133 the list `(step . STEP)' | |
134 Tells regi to move STEP number of lines forward during normal | |
135 processing. By default, regi moves forward 1 line. STEP can be | |
136 negative, but be careful of infinite loops. | |
137 | |
138 You should usually take care to explicitly return nil from your | |
139 function if no action is to take place. Your FUNC will always be | |
140 `eval'ed. The following variables will be temporarily bound to some | |
141 useful information: | |
142 | |
143 `curline' | |
144 the current line in the buffer, as a string | |
145 | |
146 `curframe' | |
147 the full, current frame being executed | |
148 | |
149 `curentry' | |
150 the current frame entry being executed." | |
151 | |
152 (save-excursion | |
153 (save-restriction | |
154 (let (begin-tag end-tag every-tag current-frame working-frame donep) | |
155 | |
156 ;; set up the narrowed region | |
157 (and start | |
158 end | |
159 (let* ((tstart start) | |
160 (start (min start end)) | |
161 (end (max start end))) | |
162 (narrow-to-region | |
163 (progn (goto-char end) (regi-pos 'bonl)) | |
164 (progn (goto-char start) (regi-pos 'bol))))) | |
165 | |
166 ;; lets find the special tags and remove them from the working | |
167 ;; frame. note that only the last special tag is used. | |
168 (mapcar | |
169 (function | |
170 (lambda (entry) | |
171 (let ((pred (car entry)) | |
172 (func (car (cdr entry)))) | |
173 (cond | |
174 ((eq pred 'begin) (setq begin-tag func)) | |
175 ((eq pred 'end) (setq end-tag func)) | |
176 ((eq pred 'every) (setq every-tag func)) | |
177 (t | |
178 (setq working-frame (append working-frame (list entry)))) | |
179 ) ; end-cond | |
180 ))) | |
181 frame) ; end-mapcar | |
182 | |
183 ;; execute the begin entry | |
184 (eval begin-tag) | |
185 | |
186 ;; now process the frame | |
187 (setq current-frame working-frame) | |
188 (while (not (or donep (eobp))) | |
189 (let* ((entry (car current-frame)) | |
190 (pred (nth 0 entry)) | |
191 (func (nth 1 entry)) | |
192 (negate-p (nth 2 entry)) | |
193 (case-fold-search (nth 3 entry)) | |
194 match-p) | |
195 (catch 'regi-throw-top | |
196 (cond | |
197 ;; we are finished processing the frame for this line | |
198 ((not current-frame) | |
199 (setq current-frame working-frame) ;reset frame | |
200 (forward-line 1) | |
201 (throw 'regi-throw-top t)) | |
202 ;; see if predicate evaluates to a string | |
203 ((stringp (setq match-p (eval pred))) | |
204 (setq match-p (looking-at match-p))) | |
205 ) ; end-cond | |
206 | |
207 ;; now that we've done the initial matching, check for | |
208 ;; negation of match | |
209 (and negate-p | |
210 (setq match-p (not match-p))) | |
211 | |
212 ;; if the line matched, package up the argument list and | |
213 ;; funcall the FUNC | |
214 (if match-p | |
215 (let* ((curline (buffer-substring | |
216 (regi-pos 'bol) | |
217 (regi-pos 'eol))) | |
218 (curframe current-frame) | |
219 (curentry entry) | |
220 (result (eval func)) | |
221 (step (or (cdr (assq 'step result)) 1)) | |
222 ) | |
223 ;; changing frame on the fly? | |
224 (if (assq 'frame result) | |
225 (setq working-frame (cdr (assq 'frame result)))) | |
226 | |
227 ;; continue processing current frame? | |
228 (if (memq 'continue result) | |
229 (setq current-frame (cdr current-frame)) | |
230 (forward-line step) | |
231 (setq current-frame working-frame)) | |
232 | |
233 ;; abort current frame? | |
234 (if (memq 'abort result) | |
235 (progn | |
236 (setq donep t) | |
237 (throw 'regi-throw-top t))) | |
238 ) ; end-let | |
239 | |
240 ;; else if no match occurred, then process the next | |
241 ;; frame-entry on the current line | |
242 (setq current-frame (cdr current-frame)) | |
243 | |
244 ) ; end-if match-p | |
245 ) ; end catch | |
246 ) ; end let | |
247 | |
248 ;; after every cycle, evaluate every-tag | |
249 (eval every-tag) | |
250 ) ; end-while | |
251 | |
252 ;; now process the end entry | |
253 (eval end-tag))))) | |
254 | |
255 | |
256 (provide 'regi) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
14169
diff
changeset
|
257 |
5139 | 258 ;;; regi.el ends here |