Mercurial > emacs
annotate lisp/obsolete/scribe.el @ 102400:934376007cef
* nsfont.m (nsfont_draw): Compare ns_antialias_text against lisp value.
author | Adrian Robert <Adrian.B.Robert@gmail.com> |
---|---|
date | Wed, 04 Mar 2009 21:21:25 +0000 |
parents | bf139d0bd1ac |
children | 1d1d5d9bd884 |
rev | line source |
---|---|
51342 | 1 ;;; scribe.el --- scribe mode, and its idiosyncratic commands |
2 | |
101110
bf139d0bd1ac
Comment (add Author:, based on ack.texi).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
3 ;; Copyright (C) 1985, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
bf139d0bd1ac
Comment (add Author:, based on ack.texi).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
4 ;; 2009 Free Software Foundation, Inc. |
51342 | 5 |
101110
bf139d0bd1ac
Comment (add Author:, based on ack.texi).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
6 ;; Author: William Sommerfeld |
bf139d0bd1ac
Comment (add Author:, based on ack.texi).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
7 ;; (according to ack.texi) |
51342 | 8 ;; Maintainer: FSF |
9 ;; Keywords: wp | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
94667
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
51342 | 14 ;; it under the terms of the GNU General Public License as published by |
94667
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
16 ;; (at your option) any later version. |
51342 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94667
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
51342 | 25 |
26 ;;; Commentary: | |
27 | |
94000
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
28 ;; This file has been obsolete since Emacs 22.1. |
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
29 |
51342 | 30 ;; A major mode for editing source in written for the Scribe text formatter. |
31 ;; Knows about Scribe syntax and standard layout rules. The command to | |
32 ;; run Scribe on a buffer is bogus; someone interested should fix it. | |
33 | |
34 ;;; Code: | |
35 | |
65189
2b9801f22b5e
(compile-command): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
36 (defvar compile-command) |
2b9801f22b5e
(compile-command): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
37 |
51342 | 38 (defgroup scribe nil |
39 "Scribe mode." | |
40 :prefix "scribe-" | |
41 :group 'wp) | |
42 | |
43 (defvar scribe-mode-syntax-table nil | |
44 "Syntax table used while in scribe mode.") | |
45 | |
46 (defvar scribe-mode-abbrev-table nil | |
47 "Abbrev table used while in scribe mode.") | |
48 | |
49 (defcustom scribe-fancy-paragraphs nil | |
50 "*Non-nil makes Scribe mode use a different style of paragraph separation." | |
51 :type 'boolean | |
52 :group 'scribe) | |
53 | |
54 (defcustom scribe-electric-quote nil | |
55 "*Non-nil makes insert of double quote use `` or '' depending on context." | |
56 :type 'boolean | |
57 :group 'scribe) | |
58 | |
59 (defcustom scribe-electric-parenthesis nil | |
60 "*Non-nil makes parenthesis char ( (]}> ) automatically insert its close | |
61 if typed after an @Command form." | |
62 :type 'boolean | |
63 :group 'scribe) | |
64 | |
65 (defconst scribe-open-parentheses "[({<" | |
66 "Open parenthesis characters for Scribe.") | |
67 | |
68 (defconst scribe-close-parentheses "])}>" | |
69 "Close parenthesis characters for Scribe. | |
70 These should match up with `scribe-open-parenthesis'.") | |
71 | |
72 (if (null scribe-mode-syntax-table) | |
73 (let ((st (syntax-table))) | |
74 (unwind-protect | |
75 (progn | |
76 (setq scribe-mode-syntax-table (copy-syntax-table | |
77 text-mode-syntax-table)) | |
78 (set-syntax-table scribe-mode-syntax-table) | |
79 (modify-syntax-entry ?\" " ") | |
80 (modify-syntax-entry ?\\ " ") | |
81 (modify-syntax-entry ?@ "w ") | |
82 (modify-syntax-entry ?< "(> ") | |
83 (modify-syntax-entry ?> ")< ") | |
84 (modify-syntax-entry ?[ "(] ") | |
85 (modify-syntax-entry ?] ")[ ") | |
86 (modify-syntax-entry ?{ "(} ") | |
87 (modify-syntax-entry ?} "){ ") | |
88 (modify-syntax-entry ?' "w ")) | |
89 (set-syntax-table st)))) | |
90 | |
91 (defvar scribe-mode-map nil) | |
92 | |
93 (if scribe-mode-map | |
94 nil | |
95 (setq scribe-mode-map (make-sparse-keymap)) | |
96 (define-key scribe-mode-map "\t" 'scribe-tab) | |
97 (define-key scribe-mode-map "\e\t" 'tab-to-tab-stop) | |
98 (define-key scribe-mode-map "\es" 'center-line) | |
99 (define-key scribe-mode-map "\e}" 'up-list) | |
100 (define-key scribe-mode-map "\eS" 'center-paragraph) | |
101 (define-key scribe-mode-map "\"" 'scribe-insert-quote) | |
102 (define-key scribe-mode-map "(" 'scribe-parenthesis) | |
103 (define-key scribe-mode-map "[" 'scribe-parenthesis) | |
104 (define-key scribe-mode-map "{" 'scribe-parenthesis) | |
105 (define-key scribe-mode-map "<" 'scribe-parenthesis) | |
106 (define-key scribe-mode-map "\C-c\C-c" 'scribe-chapter) | |
107 (define-key scribe-mode-map "\C-c\C-t" 'scribe-section) | |
108 (define-key scribe-mode-map "\C-c\C-s" 'scribe-subsection) | |
109 (define-key scribe-mode-map "\C-c\C-v" 'scribe-insert-environment) | |
110 (define-key scribe-mode-map "\C-c\C-e" 'scribe-bracket-region-be) | |
111 (define-key scribe-mode-map "\C-c[" 'scribe-begin) | |
112 (define-key scribe-mode-map "\C-c]" 'scribe-end) | |
113 (define-key scribe-mode-map "\C-c\C-i" 'scribe-italicize-word) | |
114 (define-key scribe-mode-map "\C-c\C-b" 'scribe-bold-word) | |
115 (define-key scribe-mode-map "\C-c\C-u" 'scribe-underline-word)) | |
116 | |
117 ;;;###autoload | |
118 (define-derived-mode scribe-mode text-mode "Scribe" | |
119 "Major mode for editing files of Scribe (a text formatter) source. | |
120 Scribe-mode is similar to text-mode, with a few extra commands added. | |
121 \\{scribe-mode-map} | |
122 | |
123 Interesting variables: | |
124 | |
125 `scribe-fancy-paragraphs' | |
126 Non-nil makes Scribe mode use a different style of paragraph separation. | |
127 | |
128 `scribe-electric-quote' | |
129 Non-nil makes insert of double quote use `` or '' depending on context. | |
130 | |
131 `scribe-electric-parenthesis' | |
132 Non-nil makes an open-parenthesis char (one of `([<{') | |
133 automatically insert its close if typed after an @Command form." | |
134 (set (make-local-variable 'comment-start) "@Comment[") | |
135 (set (make-local-variable 'comment-start-skip) (concat "@Comment[" scribe-open-parentheses "]")) | |
136 (set (make-local-variable 'comment-column) 0) | |
137 (set (make-local-variable 'comment-end) "]") | |
138 (set (make-local-variable 'paragraph-start) | |
139 (concat "\\([\n\f]\\)\\|\\(@\\w+[" | |
140 scribe-open-parentheses | |
141 "].*[" | |
142 scribe-close-parentheses | |
143 "]$\\)")) | |
144 (set (make-local-variable 'paragraph-separate) | |
145 (if scribe-fancy-paragraphs paragraph-start "$")) | |
146 (set (make-local-variable 'sentence-end) | |
147 "\\([.?!]\\|@:\\)[]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") | |
148 (set (make-local-variable 'compile-command) | |
149 (concat "scribe " (buffer-file-name)))) | |
150 | |
151 (defun scribe-tab () | |
152 (interactive) | |
153 (insert "@\\")) | |
154 | |
155 ;; This algorithm could probably be improved somewhat. | |
156 ;; Right now, it loses seriously... | |
157 | |
158 (defun scribe () | |
159 "Run Scribe on the current buffer." | |
160 (interactive) | |
161 (call-interactively 'compile)) | |
162 | |
163 (defun scribe-envelop-word (string count) | |
164 "Surround current word with Scribe construct @STRING[...]. | |
165 COUNT specifies how many words to surround. A negative count means | |
166 to skip backward." | |
167 (let ((spos (point)) (epos (point)) (ccoun 0) noparens) | |
168 (if (not (zerop count)) | |
169 (progn (if (= (char-syntax (preceding-char)) ?w) | |
170 (forward-sexp (min -1 count))) | |
171 (setq spos (point)) | |
172 (if (looking-at (concat "@\\w[" scribe-open-parentheses "]")) | |
173 (forward-char 2) | |
174 (goto-char epos) | |
175 (skip-chars-backward "\\W") | |
176 (forward-char -1)) | |
177 (forward-sexp (max count 1)) | |
178 (setq epos (point)))) | |
179 (goto-char spos) | |
180 (while (and (< ccoun (length scribe-open-parentheses)) | |
181 (save-excursion | |
182 (or (search-forward (char-to-string | |
183 (aref scribe-open-parentheses ccoun)) | |
184 epos t) | |
185 (search-forward (char-to-string | |
186 (aref scribe-close-parentheses ccoun)) | |
187 epos t))) | |
188 (setq ccoun (1+ ccoun)))) | |
189 (if (>= ccoun (length scribe-open-parentheses)) | |
190 (progn (goto-char epos) | |
191 (insert "@end(" string ")") | |
192 (goto-char spos) | |
193 (insert "@begin(" string ")")) | |
194 (goto-char epos) | |
195 (insert (aref scribe-close-parentheses ccoun)) | |
196 (goto-char spos) | |
197 (insert "@" string (aref scribe-open-parentheses ccoun)) | |
198 (goto-char epos) | |
199 (forward-char 3) | |
200 (skip-chars-forward scribe-close-parentheses)))) | |
201 | |
202 (defun scribe-underline-word (count) | |
203 "Underline COUNT words around point by means of Scribe constructs." | |
204 (interactive "p") | |
205 (scribe-envelop-word "u" count)) | |
206 | |
207 (defun scribe-bold-word (count) | |
208 "Boldface COUNT words around point by means of Scribe constructs." | |
209 (interactive "p") | |
210 (scribe-envelop-word "b" count)) | |
211 | |
212 (defun scribe-italicize-word (count) | |
213 "Italicize COUNT words around point by means of Scribe constructs." | |
214 (interactive "p") | |
215 (scribe-envelop-word "i" count)) | |
216 | |
217 (defun scribe-begin () | |
218 (interactive) | |
219 (insert "\n") | |
220 (forward-char -1) | |
221 (scribe-envelop-word "Begin" 0) | |
222 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
223 | |
224 (defun scribe-end () | |
225 (interactive) | |
226 (insert "\n") | |
227 (forward-char -1) | |
228 (scribe-envelop-word "End" 0) | |
229 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
230 | |
231 (defun scribe-chapter () | |
232 (interactive) | |
233 (insert "\n") | |
234 (forward-char -1) | |
235 (scribe-envelop-word "Chapter" 0) | |
236 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
237 | |
238 (defun scribe-section () | |
239 (interactive) | |
240 (insert "\n") | |
241 (forward-char -1) | |
242 (scribe-envelop-word "Section" 0) | |
243 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
244 | |
245 (defun scribe-subsection () | |
246 (interactive) | |
247 (insert "\n") | |
248 (forward-char -1) | |
249 (scribe-envelop-word "SubSection" 0) | |
250 (re-search-forward (concat "[" scribe-open-parentheses "]"))) | |
251 | |
252 (defun scribe-bracket-region-be (env min max) | |
253 (interactive "sEnvironment: \nr") | |
254 (save-excursion | |
255 (goto-char max) | |
256 (insert "@end(" env ")\n") | |
257 (goto-char min) | |
258 (insert "@begin(" env ")\n"))) | |
259 | |
260 (defun scribe-insert-environment (env) | |
261 (interactive "sEnvironment: ") | |
262 (scribe-bracket-region-be env (point) (point)) | |
263 (forward-line 1) | |
264 (insert ?\n) | |
265 (forward-char -1)) | |
266 | |
267 (defun scribe-insert-quote (count) | |
268 "Insert ``, '' or \" according to preceding character. | |
269 If `scribe-electric-quote' is non-nil, insert ``, '' or \" according | |
270 to preceding character. With numeric arg N, always insert N \" characters. | |
271 Else just insert \"." | |
272 (interactive "P") | |
273 (if (or count (not scribe-electric-quote)) | |
274 (self-insert-command (prefix-numeric-value count)) | |
275 (let (lastfore lastback lastquote) | |
276 (insert | |
277 (cond | |
278 ((= (preceding-char) ?\\) ?\") | |
279 ((bobp) "``") | |
280 (t | |
281 (setq lastfore (save-excursion (and (search-backward | |
282 "``" (- (point) 1000) t) | |
283 (point))) | |
284 lastback (save-excursion (and (search-backward | |
285 "''" (- (point) 1000) t) | |
286 (point))) | |
287 lastquote (save-excursion (and (search-backward | |
288 "\"" (- (point) 100) t) | |
289 (point)))) | |
290 (if (not lastquote) | |
291 (cond ((not lastfore) "``") | |
292 ((not lastback) "''") | |
293 ((> lastfore lastback) "''") | |
294 (t "``")) | |
295 (cond ((and (not lastback) (not lastfore)) "\"") | |
296 ((and lastback (not lastfore) (> lastquote lastback)) "\"") | |
297 ((and lastback (not lastfore) (> lastback lastquote)) "``") | |
298 ((and lastfore (not lastback) (> lastquote lastfore)) "\"") | |
299 ((and lastfore (not lastback) (> lastfore lastquote)) "''") | |
300 ((and (> lastquote lastfore) (> lastquote lastback)) "\"") | |
301 ((> lastfore lastback) "''") | |
302 (t "``"))))))))) | |
303 | |
304 (defun scribe-parenthesis (count) | |
305 "If scribe-electric-parenthesis is non-nil, insertion of an open-parenthesis | |
306 character inserts the following close parenthesis character if the | |
307 preceding text is of the form @Command." | |
308 (interactive "P") | |
309 (self-insert-command (prefix-numeric-value count)) | |
310 (let (at-command paren-char point-save) | |
311 (if (or count (not scribe-electric-parenthesis)) | |
312 nil | |
313 (save-excursion | |
314 (forward-char -1) | |
315 (setq point-save (point)) | |
316 (skip-chars-backward (concat "^ \n\t\f" scribe-open-parentheses)) | |
317 (setq at-command (and (equal (following-char) ?@) | |
318 (/= (point) (1- point-save))))) | |
319 (if (and at-command | |
320 (setq paren-char | |
321 (string-match (regexp-quote | |
322 (char-to-string (preceding-char))) | |
323 scribe-open-parentheses))) | |
324 (save-excursion | |
325 (insert (aref scribe-close-parentheses paren-char))))))) | |
326 | |
327 (provide 'scribe) | |
328 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79715
diff
changeset
|
329 ;; arch-tag: 64f454c4-7544-4ea2-9d14-f0b668f2cdc6 |
51342 | 330 ;;; scribe.el ends here |