Mercurial > emacs
annotate lisp/textmodes/scribe.el @ 35574:ede82ab0ae24
Many small improvements in tagging accuracy and capability,
better tagging of DEFUNs, code cleanups.
2001-01-25 Francesco Potorti` <pot@potorti.it>
* etags.c (struct tok): Renamed from struct token.
(token): Renamed from tok.
(structtype): Make it a local variable.
[DEBUG]: Use assert.
(xrnew): Change the synopsis.
(typedefs_or_cplusplus): Renamed from typedefs_and_cplusplus.
(grow_linebuffer): Don't call xrnew when not needed.
(token): buffer renamed to line.
(C_entries): Three calls to inibuffer moved here from main.
(C_entries): Removed all references to var methodlen, delete it.
(linebuffer_setlen): Was grow_buffer, now also sets len.
(consider_token, C_entries, Pascal_functions): Use it.
(C_entries): Preventing problems relative to extern "C".
(C_entries): Can tag more than one variable or func separated by
comma when --declarations is used.
(C_entries): More accurate tagging of members and declarations.
(yacc_rules): Was global, made local to C_entries.
(next_token_is_func): Removed.
(fvdef): New constants fdefunkey, fdefunname.
(consider_token, C_entries): Use them.
(C_entries): Build proper lisp names for Emacs DEFUNs.
author | Francesco Potortì <pot@gnu.org> |
---|---|
date | Thu, 25 Jan 2001 18:19:57 +0000 |
parents | 3e37953dc2d5 |
children | 253f761ad37b |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; scribe.el --- scribe mode, and its idiosyncratic commands. |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | |
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
5 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1539
diff
changeset
|
6 ;; Keywords: wp |
7 | 7 |
10460
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
9 |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
13 ;; any later version. |
7 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
10460
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
18 ;; GNU General Public License for more details. |
7 | 19 |
10460
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
7 | 24 |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
25 ;;; Commentary: |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
26 |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 ;; A major mode for editing source in written for the Scribe text formatter. |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
28 ;; Knows about Scribe syntax and standard layout rules. The command to |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
29 ;; run Scribe on a buffer is bogus; someone interested should fix it. |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
30 |
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
31 ;;; Code: |
7 | 32 |
20959 | 33 (defgroup scribe nil |
34 "Scribe mode." | |
35 :prefix "scribe-" | |
36 :group 'wp) | |
37 | |
7 | 38 (defvar scribe-mode-syntax-table nil |
39 "Syntax table used while in scribe mode.") | |
40 | |
41 (defvar scribe-mode-abbrev-table nil | |
42 "Abbrev table used while in scribe mode.") | |
43 | |
20959 | 44 (defcustom scribe-fancy-paragraphs nil |
45 "*Non-NIL makes Scribe mode use a different style of paragraph separation." | |
46 :type 'boolean | |
47 :group 'scribe) | |
7 | 48 |
20959 | 49 (defcustom scribe-electric-quote nil |
50 "*Non-NIL makes insert of double quote use `` or '' depending on context." | |
51 :type 'boolean | |
52 :group 'scribe) | |
7 | 53 |
20959 | 54 (defcustom scribe-electric-parenthesis nil |
7 | 55 "*Non-NIL makes parenthesis char ( (]}> ) automatically insert its close |
20959 | 56 if typed after an @Command form." |
57 :type 'boolean | |
58 :group 'scribe) | |
7 | 59 |
60 (defconst scribe-open-parentheses "[({<" | |
61 "Open parenthesis characters for Scribe.") | |
62 | |
63 (defconst scribe-close-parentheses "])}>" | |
1539 | 64 "Close parenthesis characters for Scribe. |
65 These should match up with `scribe-open-parenthesis'.") | |
7 | 66 |
67 (if (null scribe-mode-syntax-table) | |
68 (let ((st (syntax-table))) | |
69 (unwind-protect | |
70 (progn | |
71 (setq scribe-mode-syntax-table (copy-syntax-table | |
72 text-mode-syntax-table)) | |
73 (set-syntax-table scribe-mode-syntax-table) | |
74 (modify-syntax-entry ?\" " ") | |
75 (modify-syntax-entry ?\\ " ") | |
76 (modify-syntax-entry ?@ "w ") | |
77 (modify-syntax-entry ?< "(> ") | |
78 (modify-syntax-entry ?> ")< ") | |
79 (modify-syntax-entry ?[ "(] ") | |
80 (modify-syntax-entry ?] ")[ ") | |
81 (modify-syntax-entry ?{ "(} ") | |
82 (modify-syntax-entry ?} "){ ") | |
83 (modify-syntax-entry ?' "w ")) | |
84 (set-syntax-table st)))) | |
85 | |
86 (defvar scribe-mode-map nil) | |
87 | |
88 (if scribe-mode-map | |
89 nil | |
90 (setq scribe-mode-map (make-sparse-keymap)) | |
91 (define-key scribe-mode-map "\t" 'scribe-tab) | |
92 (define-key scribe-mode-map "\e\t" 'tab-to-tab-stop) | |
93 (define-key scribe-mode-map "\es" 'center-line) | |
94 (define-key scribe-mode-map "\e}" 'up-list) | |
95 (define-key scribe-mode-map "\eS" 'center-paragraph) | |
96 (define-key scribe-mode-map "\"" 'scribe-insert-quote) | |
97 (define-key scribe-mode-map "(" 'scribe-parenthesis) | |
98 (define-key scribe-mode-map "[" 'scribe-parenthesis) | |
99 (define-key scribe-mode-map "{" 'scribe-parenthesis) | |
100 (define-key scribe-mode-map "<" 'scribe-parenthesis) | |
11664
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
101 (define-key scribe-mode-map "\C-c\C-c" 'scribe-chapter) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
102 (define-key scribe-mode-map "\C-c\C-t" 'scribe-section) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
103 (define-key scribe-mode-map "\C-c\C-s" 'scribe-subsection) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
104 (define-key scribe-mode-map "\C-c\C-v" 'scribe-insert-environment) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
105 (define-key scribe-mode-map "\C-c\C-e" 'scribe-bracket-region-be) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
106 (define-key scribe-mode-map "\C-c[" 'scribe-begin) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
107 (define-key scribe-mode-map "\C-c]" 'scribe-end) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
108 (define-key scribe-mode-map "\C-c\C-i" 'scribe-italicize-word) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
109 (define-key scribe-mode-map "\C-c\C-b" 'scribe-bold-word) |
966c6625a963
(scribe-chapter): Change to C-c C-c.
Karl Heuer <kwzh@gnu.org>
parents:
10893
diff
changeset
|
110 (define-key scribe-mode-map "\C-c\C-u" 'scribe-underline-word)) |
7 | 111 |
258 | 112 ;;;###autoload |
7 | 113 (defun scribe-mode () |
114 "Major mode for editing files of Scribe (a text formatter) source. | |
26433 | 115 Scribe-mode is similar to text-mode, with a few extra commands added. |
7 | 116 \\{scribe-mode-map} |
117 | |
118 Interesting variables: | |
119 | |
120 scribe-fancy-paragraphs | |
121 Non-nil makes Scribe mode use a different style of paragraph separation. | |
122 | |
123 scribe-electric-quote | |
124 Non-nil makes insert of double quote use `` or '' depending on context. | |
125 | |
126 scribe-electric-parenthesis | |
127 Non-nil makes an open-parenthesis char (one of `([<{') | |
128 automatically insert its close if typed after an @Command form." | |
129 (interactive) | |
130 (kill-all-local-variables) | |
131 (use-local-map scribe-mode-map) | |
132 (setq mode-name "Scribe") | |
133 (setq major-mode 'scribe-mode) | |
134 (define-abbrev-table 'scribe-mode-abbrev-table ()) | |
135 (setq local-abbrev-table scribe-mode-abbrev-table) | |
136 (make-local-variable 'comment-start) | |
137 (setq comment-start "@Comment[") | |
138 (make-local-variable 'comment-start-skip) | |
139 (setq comment-start-skip (concat "@Comment[" scribe-open-parentheses "]")) | |
140 (make-local-variable 'comment-column) | |
141 (setq comment-column 0) | |
142 (make-local-variable 'comment-end) | |
143 (setq comment-end "]") | |
144 (make-local-variable 'paragraph-start) | |
10893
e9418d324071
(scribe-mode): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10460
diff
changeset
|
145 (setq paragraph-start (concat "\\([\n\f]\\)\\|\\(@\\w+[" |
7 | 146 scribe-open-parentheses |
147 "].*[" | |
148 scribe-close-parentheses | |
149 "]$\\)")) | |
150 (make-local-variable 'paragraph-separate) | |
151 (setq paragraph-separate (if scribe-fancy-paragraphs | |
10893
e9418d324071
(scribe-mode): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10460
diff
changeset
|
152 paragraph-start "$")) |
10460
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
153 (make-local-variable 'sentence-end) |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
154 (setq sentence-end "\\([.?!]\\|@:\\)[]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") |
7 | 155 (make-local-variable 'compile-command) |
156 (setq compile-command (concat "scribe " (buffer-file-name))) | |
157 (set-syntax-table scribe-mode-syntax-table) | |
158 (run-hooks 'text-mode-hook 'scribe-mode-hook)) | |
159 | |
160 (defun scribe-tab () | |
161 (interactive) | |
162 (insert "@\\")) | |
163 | |
164 ;; This algorithm could probably be improved somewhat. | |
165 ;; Right now, it loses seriously... | |
166 | |
167 (defun scribe () | |
168 "Run Scribe on the current buffer." | |
169 (interactive) | |
170 (call-interactively 'compile)) | |
171 | |
172 (defun scribe-envelop-word (string count) | |
1539 | 173 "Surround current word with Scribe construct @STRING[...]. |
174 COUNT specifies how many words to surround. A negative count means | |
175 to skip backward." | |
7 | 176 (let ((spos (point)) (epos (point)) (ccoun 0) noparens) |
177 (if (not (zerop count)) | |
178 (progn (if (= (char-syntax (preceding-char)) ?w) | |
179 (forward-sexp (min -1 count))) | |
180 (setq spos (point)) | |
181 (if (looking-at (concat "@\\w[" scribe-open-parentheses "]")) | |
182 (forward-char 2) | |
183 (goto-char epos) | |
184 (skip-chars-backward "\\W") | |
185 (forward-char -1)) | |
186 (forward-sexp (max count 1)) | |
187 (setq epos (point)))) | |
188 (goto-char spos) | |
189 (while (and (< ccoun (length scribe-open-parentheses)) | |
190 (save-excursion | |
191 (or (search-forward (char-to-string | |
192 (aref scribe-open-parentheses ccoun)) | |
193 epos t) | |
194 (search-forward (char-to-string | |
195 (aref scribe-close-parentheses ccoun)) | |
196 epos t))) | |
197 (setq ccoun (1+ ccoun)))) | |
198 (if (>= ccoun (length scribe-open-parentheses)) | |
199 (progn (goto-char epos) | |
200 (insert "@end(" string ")") | |
201 (goto-char spos) | |
202 (insert "@begin(" string ")")) | |
203 (goto-char epos) | |
204 (insert (aref scribe-close-parentheses ccoun)) | |
205 (goto-char spos) | |
206 (insert "@" string (aref scribe-open-parentheses ccoun)) | |
207 (goto-char epos) | |
208 (forward-char 3) | |
209 (skip-chars-forward scribe-close-parentheses)))) | |
210 | |
211 (defun scribe-underline-word (count) | |
212 "Underline COUNT words around point by means of Scribe constructs." | |
213 (interactive "p") | |
214 (scribe-envelop-word "u" count)) | |
215 | |
216 (defun scribe-bold-word (count) | |
217 "Boldface COUNT words around point by means of Scribe constructs." | |
218 (interactive "p") | |
219 (scribe-envelop-word "b" count)) | |
220 | |
221 (defun scribe-italicize-word (count) | |
222 "Italicize COUNT words around point by means of Scribe constructs." | |
223 (interactive "p") | |
224 (scribe-envelop-word "i" count)) | |
225 | |
226 (defun scribe-begin () | |
227 (interactive) | |
228 (insert "\n") | |
229 (forward-char -1) | |
230 (scribe-envelop-word "Begin" 0) | |
231 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
232 | |
233 (defun scribe-end () | |
234 (interactive) | |
235 (insert "\n") | |
236 (forward-char -1) | |
237 (scribe-envelop-word "End" 0) | |
238 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
239 | |
240 (defun scribe-chapter () | |
241 (interactive) | |
242 (insert "\n") | |
243 (forward-char -1) | |
244 (scribe-envelop-word "Chapter" 0) | |
245 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
246 | |
247 (defun scribe-section () | |
248 (interactive) | |
249 (insert "\n") | |
250 (forward-char -1) | |
251 (scribe-envelop-word "Section" 0) | |
252 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
253 | |
254 (defun scribe-subsection () | |
255 (interactive) | |
256 (insert "\n") | |
257 (forward-char -1) | |
258 (scribe-envelop-word "SubSection" 0) | |
259 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
260 | |
261 (defun scribe-bracket-region-be (env min max) | |
262 (interactive "sEnvironment: \nr") | |
263 (save-excursion | |
264 (goto-char max) | |
265 (insert "@end(" env ")\n") | |
266 (goto-char min) | |
267 (insert "@begin(" env ")\n"))) | |
268 | |
269 (defun scribe-insert-environment (env) | |
270 (interactive "sEnvironment: ") | |
271 (scribe-bracket-region-be env (point) (point)) | |
272 (forward-line 1) | |
273 (insert ?\n) | |
274 (forward-char -1)) | |
275 | |
276 (defun scribe-insert-quote (count) | |
1539 | 277 "Insert ``, '' or \" according to preceding character. |
278 If `scribe-electric-quote' is non-NIL, insert ``, '' or \" according | |
7 | 279 to preceding character. With numeric arg N, always insert N \" characters. |
280 Else just insert \"." | |
281 (interactive "P") | |
282 (if (or count (not scribe-electric-quote)) | |
283 (self-insert-command (prefix-numeric-value count)) | |
284 (let (lastfore lastback lastquote) | |
285 (insert | |
286 (cond | |
287 ((= (preceding-char) ?\\) ?\") | |
288 ((bobp) "``") | |
289 (t | |
290 (setq lastfore (save-excursion (and (search-backward | |
291 "``" (- (point) 1000) t) | |
292 (point))) | |
293 lastback (save-excursion (and (search-backward | |
294 "''" (- (point) 1000) t) | |
295 (point))) | |
296 lastquote (save-excursion (and (search-backward | |
297 "\"" (- (point) 100) t) | |
298 (point)))) | |
299 (if (not lastquote) | |
300 (cond ((not lastfore) "``") | |
301 ((not lastback) "''") | |
302 ((> lastfore lastback) "''") | |
303 (t "``")) | |
304 (cond ((and (not lastback) (not lastfore)) "\"") | |
305 ((and lastback (not lastfore) (> lastquote lastback)) "\"") | |
306 ((and lastback (not lastfore) (> lastback lastquote)) "``") | |
307 ((and lastfore (not lastback) (> lastquote lastfore)) "\"") | |
308 ((and lastfore (not lastback) (> lastfore lastquote)) "''") | |
309 ((and (> lastquote lastfore) (> lastquote lastback)) "\"") | |
310 ((> lastfore lastback) "''") | |
311 (t "``"))))))))) | |
312 | |
313 (defun scribe-parenthesis (count) | |
314 "If scribe-electric-parenthesis is non-NIL, insertion of an open-parenthesis | |
315 character inserts the following close parenthesis character if the | |
316 preceding text is of the form @Command." | |
317 (interactive "P") | |
318 (self-insert-command (prefix-numeric-value count)) | |
319 (let (at-command paren-char point-save) | |
320 (if (or count (not scribe-electric-parenthesis)) | |
321 nil | |
322 (save-excursion | |
323 (forward-char -1) | |
324 (setq point-save (point)) | |
325 (skip-chars-backward (concat "^ \n\t\f" scribe-open-parentheses)) | |
326 (setq at-command (and (equal (following-char) ?@) | |
327 (/= (point) (1- point-save))))) | |
328 (if (and at-command | |
329 (setq paren-char | |
330 (string-match (regexp-quote | |
331 (char-to-string (preceding-char))) | |
332 scribe-open-parentheses))) | |
333 (save-excursion | |
334 (insert (aref scribe-close-parentheses paren-char))))))) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
335 |
18383 | 336 (provide 'scribe) |
337 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
338 ;;; scribe.el ends here |