Mercurial > emacs
annotate lisp/textmodes/scribe.el @ 12981:7a540e9cb21a
(save_window_save): Pass the new arg to Fcopy_marker.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 01 Sep 1995 02:01:29 +0000 |
parents | 966c6625a963 |
children | 83f275dcd93a |
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 |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
7 | 23 |
2315
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
24 ;;; Commentary: |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
25 |
9e7ec92a4fdf
Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
26 ;; 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
|
27 ;; 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
|
28 ;; 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
|
29 |
787
3cece0106722
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
30 ;;; Code: |
7 | 31 |
32 (defvar scribe-mode-syntax-table nil | |
33 "Syntax table used while in scribe mode.") | |
34 | |
35 (defvar scribe-mode-abbrev-table nil | |
36 "Abbrev table used while in scribe mode.") | |
37 | |
38 (defvar scribe-fancy-paragraphs nil | |
39 "*Non-NIL makes Scribe mode use a different style of paragraph separation.") | |
40 | |
41 (defvar scribe-electric-quote nil | |
42 "*Non-NIL makes insert of double quote use `` or '' depending on context.") | |
43 | |
44 (defvar scribe-electric-parenthesis nil | |
45 "*Non-NIL makes parenthesis char ( (]}> ) automatically insert its close | |
46 if typed after an @Command form.") | |
47 | |
48 (defconst scribe-open-parentheses "[({<" | |
49 "Open parenthesis characters for Scribe.") | |
50 | |
51 (defconst scribe-close-parentheses "])}>" | |
1539 | 52 "Close parenthesis characters for Scribe. |
53 These should match up with `scribe-open-parenthesis'.") | |
7 | 54 |
55 (if (null scribe-mode-syntax-table) | |
56 (let ((st (syntax-table))) | |
57 (unwind-protect | |
58 (progn | |
59 (setq scribe-mode-syntax-table (copy-syntax-table | |
60 text-mode-syntax-table)) | |
61 (set-syntax-table scribe-mode-syntax-table) | |
62 (modify-syntax-entry ?\" " ") | |
63 (modify-syntax-entry ?\\ " ") | |
64 (modify-syntax-entry ?@ "w ") | |
65 (modify-syntax-entry ?< "(> ") | |
66 (modify-syntax-entry ?> ")< ") | |
67 (modify-syntax-entry ?[ "(] ") | |
68 (modify-syntax-entry ?] ")[ ") | |
69 (modify-syntax-entry ?{ "(} ") | |
70 (modify-syntax-entry ?} "){ ") | |
71 (modify-syntax-entry ?' "w ")) | |
72 (set-syntax-table st)))) | |
73 | |
74 (defvar scribe-mode-map nil) | |
75 | |
76 (if scribe-mode-map | |
77 nil | |
78 (setq scribe-mode-map (make-sparse-keymap)) | |
79 (define-key scribe-mode-map "\t" 'scribe-tab) | |
80 (define-key scribe-mode-map "\e\t" 'tab-to-tab-stop) | |
81 (define-key scribe-mode-map "\es" 'center-line) | |
82 (define-key scribe-mode-map "\e}" 'up-list) | |
83 (define-key scribe-mode-map "\eS" 'center-paragraph) | |
84 (define-key scribe-mode-map "\"" 'scribe-insert-quote) | |
85 (define-key scribe-mode-map "(" 'scribe-parenthesis) | |
86 (define-key scribe-mode-map "[" 'scribe-parenthesis) | |
87 (define-key scribe-mode-map "{" 'scribe-parenthesis) | |
88 (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
|
89 (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
|
90 (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
|
91 (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
|
92 (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
|
93 (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
|
94 (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
|
95 (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
|
96 (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
|
97 (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
|
98 (define-key scribe-mode-map "\C-c\C-u" 'scribe-underline-word)) |
7 | 99 |
258 | 100 ;;;###autoload |
7 | 101 (defun scribe-mode () |
102 "Major mode for editing files of Scribe (a text formatter) source. | |
103 Scribe-mode is similar text-mode, with a few extra commands added. | |
104 \\{scribe-mode-map} | |
105 | |
106 Interesting variables: | |
107 | |
108 scribe-fancy-paragraphs | |
109 Non-nil makes Scribe mode use a different style of paragraph separation. | |
110 | |
111 scribe-electric-quote | |
112 Non-nil makes insert of double quote use `` or '' depending on context. | |
113 | |
114 scribe-electric-parenthesis | |
115 Non-nil makes an open-parenthesis char (one of `([<{') | |
116 automatically insert its close if typed after an @Command form." | |
117 (interactive) | |
118 (kill-all-local-variables) | |
119 (use-local-map scribe-mode-map) | |
120 (setq mode-name "Scribe") | |
121 (setq major-mode 'scribe-mode) | |
122 (define-abbrev-table 'scribe-mode-abbrev-table ()) | |
123 (setq local-abbrev-table scribe-mode-abbrev-table) | |
124 (make-local-variable 'comment-start) | |
125 (setq comment-start "@Comment[") | |
126 (make-local-variable 'comment-start-skip) | |
127 (setq comment-start-skip (concat "@Comment[" scribe-open-parentheses "]")) | |
128 (make-local-variable 'comment-column) | |
129 (setq comment-column 0) | |
130 (make-local-variable 'comment-end) | |
131 (setq comment-end "]") | |
132 (make-local-variable 'paragraph-start) | |
10893
e9418d324071
(scribe-mode): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10460
diff
changeset
|
133 (setq paragraph-start (concat "\\([\n\f]\\)\\|\\(@\\w+[" |
7 | 134 scribe-open-parentheses |
135 "].*[" | |
136 scribe-close-parentheses | |
137 "]$\\)")) | |
138 (make-local-variable 'paragraph-separate) | |
139 (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
|
140 paragraph-start "$")) |
10460
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
141 (make-local-variable 'sentence-end) |
b2e37a1d2347
(scribe-mode): Treat @: as a sentence end.
Richard M. Stallman <rms@gnu.org>
parents:
2315
diff
changeset
|
142 (setq sentence-end "\\([.?!]\\|@:\\)[]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") |
7 | 143 (make-local-variable 'compile-command) |
144 (setq compile-command (concat "scribe " (buffer-file-name))) | |
145 (set-syntax-table scribe-mode-syntax-table) | |
146 (run-hooks 'text-mode-hook 'scribe-mode-hook)) | |
147 | |
148 (defun scribe-tab () | |
149 (interactive) | |
150 (insert "@\\")) | |
151 | |
152 ;; This algorithm could probably be improved somewhat. | |
153 ;; Right now, it loses seriously... | |
154 | |
155 (defun scribe () | |
156 "Run Scribe on the current buffer." | |
157 (interactive) | |
158 (call-interactively 'compile)) | |
159 | |
160 (defun scribe-envelop-word (string count) | |
1539 | 161 "Surround current word with Scribe construct @STRING[...]. |
162 COUNT specifies how many words to surround. A negative count means | |
163 to skip backward." | |
7 | 164 (let ((spos (point)) (epos (point)) (ccoun 0) noparens) |
165 (if (not (zerop count)) | |
166 (progn (if (= (char-syntax (preceding-char)) ?w) | |
167 (forward-sexp (min -1 count))) | |
168 (setq spos (point)) | |
169 (if (looking-at (concat "@\\w[" scribe-open-parentheses "]")) | |
170 (forward-char 2) | |
171 (goto-char epos) | |
172 (skip-chars-backward "\\W") | |
173 (forward-char -1)) | |
174 (forward-sexp (max count 1)) | |
175 (setq epos (point)))) | |
176 (goto-char spos) | |
177 (while (and (< ccoun (length scribe-open-parentheses)) | |
178 (save-excursion | |
179 (or (search-forward (char-to-string | |
180 (aref scribe-open-parentheses ccoun)) | |
181 epos t) | |
182 (search-forward (char-to-string | |
183 (aref scribe-close-parentheses ccoun)) | |
184 epos t))) | |
185 (setq ccoun (1+ ccoun)))) | |
186 (if (>= ccoun (length scribe-open-parentheses)) | |
187 (progn (goto-char epos) | |
188 (insert "@end(" string ")") | |
189 (goto-char spos) | |
190 (insert "@begin(" string ")")) | |
191 (goto-char epos) | |
192 (insert (aref scribe-close-parentheses ccoun)) | |
193 (goto-char spos) | |
194 (insert "@" string (aref scribe-open-parentheses ccoun)) | |
195 (goto-char epos) | |
196 (forward-char 3) | |
197 (skip-chars-forward scribe-close-parentheses)))) | |
198 | |
199 (defun scribe-underline-word (count) | |
200 "Underline COUNT words around point by means of Scribe constructs." | |
201 (interactive "p") | |
202 (scribe-envelop-word "u" count)) | |
203 | |
204 (defun scribe-bold-word (count) | |
205 "Boldface COUNT words around point by means of Scribe constructs." | |
206 (interactive "p") | |
207 (scribe-envelop-word "b" count)) | |
208 | |
209 (defun scribe-italicize-word (count) | |
210 "Italicize COUNT words around point by means of Scribe constructs." | |
211 (interactive "p") | |
212 (scribe-envelop-word "i" count)) | |
213 | |
214 (defun scribe-begin () | |
215 (interactive) | |
216 (insert "\n") | |
217 (forward-char -1) | |
218 (scribe-envelop-word "Begin" 0) | |
219 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
220 | |
221 (defun scribe-end () | |
222 (interactive) | |
223 (insert "\n") | |
224 (forward-char -1) | |
225 (scribe-envelop-word "End" 0) | |
226 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
227 | |
228 (defun scribe-chapter () | |
229 (interactive) | |
230 (insert "\n") | |
231 (forward-char -1) | |
232 (scribe-envelop-word "Chapter" 0) | |
233 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
234 | |
235 (defun scribe-section () | |
236 (interactive) | |
237 (insert "\n") | |
238 (forward-char -1) | |
239 (scribe-envelop-word "Section" 0) | |
240 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
241 | |
242 (defun scribe-subsection () | |
243 (interactive) | |
244 (insert "\n") | |
245 (forward-char -1) | |
246 (scribe-envelop-word "SubSection" 0) | |
247 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
248 | |
249 (defun scribe-bracket-region-be (env min max) | |
250 (interactive "sEnvironment: \nr") | |
251 (save-excursion | |
252 (goto-char max) | |
253 (insert "@end(" env ")\n") | |
254 (goto-char min) | |
255 (insert "@begin(" env ")\n"))) | |
256 | |
257 (defun scribe-insert-environment (env) | |
258 (interactive "sEnvironment: ") | |
259 (scribe-bracket-region-be env (point) (point)) | |
260 (forward-line 1) | |
261 (insert ?\n) | |
262 (forward-char -1)) | |
263 | |
264 (defun scribe-insert-quote (count) | |
1539 | 265 "Insert ``, '' or \" according to preceding character. |
266 If `scribe-electric-quote' is non-NIL, insert ``, '' or \" according | |
7 | 267 to preceding character. With numeric arg N, always insert N \" characters. |
268 Else just insert \"." | |
269 (interactive "P") | |
270 (if (or count (not scribe-electric-quote)) | |
271 (self-insert-command (prefix-numeric-value count)) | |
272 (let (lastfore lastback lastquote) | |
273 (insert | |
274 (cond | |
275 ((= (preceding-char) ?\\) ?\") | |
276 ((bobp) "``") | |
277 (t | |
278 (setq lastfore (save-excursion (and (search-backward | |
279 "``" (- (point) 1000) t) | |
280 (point))) | |
281 lastback (save-excursion (and (search-backward | |
282 "''" (- (point) 1000) t) | |
283 (point))) | |
284 lastquote (save-excursion (and (search-backward | |
285 "\"" (- (point) 100) t) | |
286 (point)))) | |
287 (if (not lastquote) | |
288 (cond ((not lastfore) "``") | |
289 ((not lastback) "''") | |
290 ((> lastfore lastback) "''") | |
291 (t "``")) | |
292 (cond ((and (not lastback) (not lastfore)) "\"") | |
293 ((and lastback (not lastfore) (> lastquote lastback)) "\"") | |
294 ((and lastback (not lastfore) (> lastback lastquote)) "``") | |
295 ((and lastfore (not lastback) (> lastquote lastfore)) "\"") | |
296 ((and lastfore (not lastback) (> lastfore lastquote)) "''") | |
297 ((and (> lastquote lastfore) (> lastquote lastback)) "\"") | |
298 ((> lastfore lastback) "''") | |
299 (t "``"))))))))) | |
300 | |
301 (defun scribe-parenthesis (count) | |
302 "If scribe-electric-parenthesis is non-NIL, insertion of an open-parenthesis | |
303 character inserts the following close parenthesis character if the | |
304 preceding text is of the form @Command." | |
305 (interactive "P") | |
306 (self-insert-command (prefix-numeric-value count)) | |
307 (let (at-command paren-char point-save) | |
308 (if (or count (not scribe-electric-parenthesis)) | |
309 nil | |
310 (save-excursion | |
311 (forward-char -1) | |
312 (setq point-save (point)) | |
313 (skip-chars-backward (concat "^ \n\t\f" scribe-open-parentheses)) | |
314 (setq at-command (and (equal (following-char) ?@) | |
315 (/= (point) (1- point-save))))) | |
316 (if (and at-command | |
317 (setq paren-char | |
318 (string-match (regexp-quote | |
319 (char-to-string (preceding-char))) | |
320 scribe-open-parentheses))) | |
321 (save-excursion | |
322 (insert (aref scribe-close-parentheses paren-char))))))) | |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
323 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
324 ;;; scribe.el ends here |