Mercurial > emacs
annotate lisp/textmodes/scribe.el @ 40765:3e02d6f71d09
Minor clarification of previous change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 06 Nov 2001 04:53:41 +0000 |
parents | 942e743c5598 |
children | 7308bbc423d5 |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
26433
diff
changeset
|
1 ;;; scribe.el --- scribe mode, and its idiosyncratic commands |
658
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 |
39893
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
113 (define-derived-mode scribe-mode text-mode "Scribe" |
7 | 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 | |
39893
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
120 `scribe-fancy-paragraphs' |
7 | 121 Non-nil makes Scribe mode use a different style of paragraph separation. |
122 | |
39893
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
123 `scribe-electric-quote' |
7 | 124 Non-nil makes insert of double quote use `` or '' depending on context. |
125 | |
39893
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
126 `scribe-electric-parenthesis' |
7 | 127 Non-nil makes an open-parenthesis char (one of `([<{') |
128 automatically insert its close if typed after an @Command form." | |
39893
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
129 (set (make-local-variable 'comment-start) "@Comment[") |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
130 (set (make-local-variable 'comment-start-skip) (concat "@Comment[" scribe-open-parentheses "]")) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
131 (set (make-local-variable 'comment-column) 0) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
132 (set (make-local-variable 'comment-end) "]") |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
133 (set (make-local-variable 'paragraph-start) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
134 (concat "\\([\n\f]\\)\\|\\(@\\w+[" |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
135 scribe-open-parentheses |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
136 "].*[" |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
137 scribe-close-parentheses |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
138 "]$\\)")) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
139 (set (make-local-variable 'paragraph-separate) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
140 (if scribe-fancy-paragraphs paragraph-start "$")) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
141 (set (make-local-variable 'sentence-end) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
142 "\\([.?!]\\|@:\\)[]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
143 (set (make-local-variable 'compile-command) |
942e743c5598
(scribe-mode): Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
144 (concat "scribe " (buffer-file-name)))) |
7 | 145 |
146 (defun scribe-tab () | |
147 (interactive) | |
148 (insert "@\\")) | |
149 | |
150 ;; This algorithm could probably be improved somewhat. | |
151 ;; Right now, it loses seriously... | |
152 | |
153 (defun scribe () | |
154 "Run Scribe on the current buffer." | |
155 (interactive) | |
156 (call-interactively 'compile)) | |
157 | |
158 (defun scribe-envelop-word (string count) | |
1539 | 159 "Surround current word with Scribe construct @STRING[...]. |
160 COUNT specifies how many words to surround. A negative count means | |
161 to skip backward." | |
7 | 162 (let ((spos (point)) (epos (point)) (ccoun 0) noparens) |
163 (if (not (zerop count)) | |
164 (progn (if (= (char-syntax (preceding-char)) ?w) | |
165 (forward-sexp (min -1 count))) | |
166 (setq spos (point)) | |
167 (if (looking-at (concat "@\\w[" scribe-open-parentheses "]")) | |
168 (forward-char 2) | |
169 (goto-char epos) | |
170 (skip-chars-backward "\\W") | |
171 (forward-char -1)) | |
172 (forward-sexp (max count 1)) | |
173 (setq epos (point)))) | |
174 (goto-char spos) | |
175 (while (and (< ccoun (length scribe-open-parentheses)) | |
176 (save-excursion | |
177 (or (search-forward (char-to-string | |
178 (aref scribe-open-parentheses ccoun)) | |
179 epos t) | |
180 (search-forward (char-to-string | |
181 (aref scribe-close-parentheses ccoun)) | |
182 epos t))) | |
183 (setq ccoun (1+ ccoun)))) | |
184 (if (>= ccoun (length scribe-open-parentheses)) | |
185 (progn (goto-char epos) | |
186 (insert "@end(" string ")") | |
187 (goto-char spos) | |
188 (insert "@begin(" string ")")) | |
189 (goto-char epos) | |
190 (insert (aref scribe-close-parentheses ccoun)) | |
191 (goto-char spos) | |
192 (insert "@" string (aref scribe-open-parentheses ccoun)) | |
193 (goto-char epos) | |
194 (forward-char 3) | |
195 (skip-chars-forward scribe-close-parentheses)))) | |
196 | |
197 (defun scribe-underline-word (count) | |
198 "Underline COUNT words around point by means of Scribe constructs." | |
199 (interactive "p") | |
200 (scribe-envelop-word "u" count)) | |
201 | |
202 (defun scribe-bold-word (count) | |
203 "Boldface COUNT words around point by means of Scribe constructs." | |
204 (interactive "p") | |
205 (scribe-envelop-word "b" count)) | |
206 | |
207 (defun scribe-italicize-word (count) | |
208 "Italicize COUNT words around point by means of Scribe constructs." | |
209 (interactive "p") | |
210 (scribe-envelop-word "i" count)) | |
211 | |
212 (defun scribe-begin () | |
213 (interactive) | |
214 (insert "\n") | |
215 (forward-char -1) | |
216 (scribe-envelop-word "Begin" 0) | |
217 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
218 | |
219 (defun scribe-end () | |
220 (interactive) | |
221 (insert "\n") | |
222 (forward-char -1) | |
223 (scribe-envelop-word "End" 0) | |
224 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
225 | |
226 (defun scribe-chapter () | |
227 (interactive) | |
228 (insert "\n") | |
229 (forward-char -1) | |
230 (scribe-envelop-word "Chapter" 0) | |
231 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
232 | |
233 (defun scribe-section () | |
234 (interactive) | |
235 (insert "\n") | |
236 (forward-char -1) | |
237 (scribe-envelop-word "Section" 0) | |
238 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
239 | |
240 (defun scribe-subsection () | |
241 (interactive) | |
242 (insert "\n") | |
243 (forward-char -1) | |
244 (scribe-envelop-word "SubSection" 0) | |
245 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
246 | |
247 (defun scribe-bracket-region-be (env min max) | |
248 (interactive "sEnvironment: \nr") | |
249 (save-excursion | |
250 (goto-char max) | |
251 (insert "@end(" env ")\n") | |
252 (goto-char min) | |
253 (insert "@begin(" env ")\n"))) | |
254 | |
255 (defun scribe-insert-environment (env) | |
256 (interactive "sEnvironment: ") | |
257 (scribe-bracket-region-be env (point) (point)) | |
258 (forward-line 1) | |
259 (insert ?\n) | |
260 (forward-char -1)) | |
261 | |
262 (defun scribe-insert-quote (count) | |
1539 | 263 "Insert ``, '' or \" according to preceding character. |
264 If `scribe-electric-quote' is non-NIL, insert ``, '' or \" according | |
7 | 265 to preceding character. With numeric arg N, always insert N \" characters. |
266 Else just insert \"." | |
267 (interactive "P") | |
268 (if (or count (not scribe-electric-quote)) | |
269 (self-insert-command (prefix-numeric-value count)) | |
270 (let (lastfore lastback lastquote) | |
271 (insert | |
272 (cond | |
273 ((= (preceding-char) ?\\) ?\") | |
274 ((bobp) "``") | |
275 (t | |
276 (setq lastfore (save-excursion (and (search-backward | |
277 "``" (- (point) 1000) t) | |
278 (point))) | |
279 lastback (save-excursion (and (search-backward | |
280 "''" (- (point) 1000) t) | |
281 (point))) | |
282 lastquote (save-excursion (and (search-backward | |
283 "\"" (- (point) 100) t) | |
284 (point)))) | |
285 (if (not lastquote) | |
286 (cond ((not lastfore) "``") | |
287 ((not lastback) "''") | |
288 ((> lastfore lastback) "''") | |
289 (t "``")) | |
290 (cond ((and (not lastback) (not lastfore)) "\"") | |
291 ((and lastback (not lastfore) (> lastquote lastback)) "\"") | |
292 ((and lastback (not lastfore) (> lastback lastquote)) "``") | |
293 ((and lastfore (not lastback) (> lastquote lastfore)) "\"") | |
294 ((and lastfore (not lastback) (> lastfore lastquote)) "''") | |
295 ((and (> lastquote lastfore) (> lastquote lastback)) "\"") | |
296 ((> lastfore lastback) "''") | |
297 (t "``"))))))))) | |
298 | |
299 (defun scribe-parenthesis (count) | |
300 "If scribe-electric-parenthesis is non-NIL, insertion of an open-parenthesis | |
301 character inserts the following close parenthesis character if the | |
302 preceding text is of the form @Command." | |
303 (interactive "P") | |
304 (self-insert-command (prefix-numeric-value count)) | |
305 (let (at-command paren-char point-save) | |
306 (if (or count (not scribe-electric-parenthesis)) | |
307 nil | |
308 (save-excursion | |
309 (forward-char -1) | |
310 (setq point-save (point)) | |
311 (skip-chars-backward (concat "^ \n\t\f" scribe-open-parentheses)) | |
312 (setq at-command (and (equal (following-char) ?@) | |
313 (/= (point) (1- point-save))))) | |
314 (if (and at-command | |
315 (setq paren-char | |
316 (string-match (regexp-quote | |
317 (char-to-string (preceding-char))) | |
318 scribe-open-parentheses))) | |
319 (save-excursion | |
320 (insert (aref scribe-close-parentheses paren-char))))))) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
321 |
18383 | 322 (provide 'scribe) |
323 | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
324 ;;; scribe.el ends here |