annotate lisp/modes/scribe.el @ 124:9b50b4588a93 r20-1b15

Import from CVS: tag r20-1b15
author cvs
date Mon, 13 Aug 2007 09:26:39 +0200
parents 376386a54a3c
children 489f57a838ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; scribe.el --- scribe mode, and its idiosyncratic commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Keywords: wp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1985 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file might become part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; but without any warranty. No author or distributor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; accepts responsibility to anyone for the consequences of using it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; or for whether it serves any particular purpose or works at all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; unless he says so in writing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; Everyone is granted permission to copy, modify and redistribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; GNU Emacs, but only under the conditions described in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; document "GNU Emacs copying permission notice". An exact copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; of the document is supposed to have been given to you along with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU Emacs so that you can know how you may redistribute it all.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; It should be in a file named COPYING. Among other things, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; copyright notice and this notice must be preserved on all copies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (defvar scribe-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 "Syntax table used while in scribe mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (defvar scribe-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 "Abbrev table used while in scribe mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (defvar scribe-fancy-paragraphs nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 "*Non-NIL makes Scribe mode use a different style of paragraph separation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defvar scribe-electric-quote nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 "*Non-NIL makes insert of double quote use `` or '' depending on context.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defvar scribe-electric-parenthesis nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "*Non-NIL makes parenthesis char ( (]}> ) automatically insert its close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 if typed after an @Command form.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defconst scribe-open-parentheses "[({<"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 "Open parenthesis characters for Scribe.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defconst scribe-close-parentheses "])}>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "Close parenthesis characters for Scribe. These should match up with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 scribe-open-parenthesis.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if (null scribe-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (let ((st (syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq scribe-mode-syntax-table (copy-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 text-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (set-syntax-table scribe-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (modify-syntax-entry ?\" " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (modify-syntax-entry ?\\ " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (modify-syntax-entry ?@ "w ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (modify-syntax-entry ?< "(> ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (modify-syntax-entry ?> ")< ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (modify-syntax-entry ?[ "(] ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (modify-syntax-entry ?] ")[ ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (modify-syntax-entry ?{ "(} ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (modify-syntax-entry ?} "){ ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (modify-syntax-entry ?' "w "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (set-syntax-table st))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar scribe-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if scribe-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (setq scribe-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (define-key scribe-mode-map "\t" 'scribe-tab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (define-key scribe-mode-map "\e\t" 'tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (define-key scribe-mode-map "\es" 'center-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (define-key scribe-mode-map "\e}" 'up-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (define-key scribe-mode-map "\eS" 'center-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (define-key scribe-mode-map "\"" 'scribe-insert-quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (define-key scribe-mode-map "(" 'scribe-parenthesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (define-key scribe-mode-map "[" 'scribe-parenthesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (define-key scribe-mode-map "{" 'scribe-parenthesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (define-key scribe-mode-map "<" 'scribe-parenthesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (define-key scribe-mode-map "\^cc" 'scribe-chapter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (define-key scribe-mode-map "\^cS" 'scribe-section)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (define-key scribe-mode-map "\^cs" 'scribe-subsection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (define-key scribe-mode-map "\^ce" 'scribe-insert-environment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (define-key scribe-mode-map "\^c\^e" 'scribe-bracket-region-be)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (define-key scribe-mode-map "\^c[" 'scribe-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (define-key scribe-mode-map "\^c]" 'scribe-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (define-key scribe-mode-map "\^ci" 'scribe-italicize-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (define-key scribe-mode-map "\^cb" 'scribe-bold-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (define-key scribe-mode-map "\^cu" 'scribe-underline-word))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun scribe-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "Major mode for editing files of Scribe (a text formatter) source.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 Scribe-mode is similar text-mode, with a few extra commands added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 \\{scribe-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 Interesting variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 scribe-fancy-paragraphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 Non-nil makes Scribe mode use a different style of paragraph separation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 scribe-electric-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 Non-nil makes insert of double quote use `` or '' depending on context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 scribe-electric-parenthesis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Non-nil makes an open-parenthesis char (one of `([<{')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 automatically insert its close if typed after an @Command form."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (use-local-map scribe-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (setq mode-name "Scribe")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq major-mode 'scribe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (define-abbrev-table 'scribe-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq local-abbrev-table scribe-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq comment-start "@Comment[")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (setq comment-start-skip (concat "@Comment[" scribe-open-parentheses "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq comment-column 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (make-local-variable 'comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (setq comment-end "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (setq paragraph-start (concat "\\(^[\n\f]\\)\\|\\(^@\\w+["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 scribe-open-parentheses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "].*["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 scribe-close-parentheses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "]$\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (make-local-variable 'paragraph-separate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq paragraph-separate (if scribe-fancy-paragraphs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 paragraph-start "^$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (make-local-variable 'compile-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (setq compile-command (concat "scribe " (buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (set-syntax-table scribe-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (run-hooks 'text-mode-hook 'scribe-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defun scribe-tab ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (insert "@\\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; This algorithm could probably be improved somewhat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; Right now, it loses seriously...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defun scribe ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 "Run Scribe on the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (call-interactively 'compile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun scribe-envelop-word (string count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "Surround current word with Scribe construct @STRING[...]. COUNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 specifies how many words to surround. A negative count means to skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 backward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (let ((spos (point)) (epos (point)) (ccoun 0) noparens)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (if (not (zerop count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (progn (if (= (char-syntax (preceding-char)) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (forward-sexp (min -1 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (setq spos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if (looking-at (concat "@\\w[" scribe-open-parentheses "]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (forward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (goto-char epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (skip-chars-backward "\\W")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (forward-sexp (max count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (setq epos (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (goto-char spos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (while (and (< ccoun (length scribe-open-parentheses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (or (search-forward (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (aref scribe-open-parentheses ccoun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 epos t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (search-forward (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (aref scribe-close-parentheses ccoun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 epos t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setq ccoun (1+ ccoun))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (>= ccoun (length scribe-open-parentheses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (progn (goto-char epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (insert "@end(" string ")")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (goto-char spos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (insert "@begin(" string ")"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (goto-char epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (insert (aref scribe-close-parentheses ccoun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (goto-char spos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (insert "@" string (aref scribe-open-parentheses ccoun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (goto-char epos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (forward-char 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (skip-chars-forward scribe-close-parentheses))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (defun scribe-underline-word (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 "Underline COUNT words around point by means of Scribe constructs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (scribe-envelop-word "u" count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun scribe-bold-word (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "Boldface COUNT words around point by means of Scribe constructs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (scribe-envelop-word "b" count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (defun scribe-italicize-word (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 "Italicize COUNT words around point by means of Scribe constructs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (scribe-envelop-word "i" count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (defun scribe-begin ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (scribe-envelop-word "Begin" 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (re-search-forward (concat "[" scribe-open-parentheses "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun scribe-end ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (scribe-envelop-word "End" 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (re-search-forward (concat "[" scribe-open-parentheses "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun scribe-chapter ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (scribe-envelop-word "Chapter" 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (re-search-forward (concat "[" scribe-open-parentheses "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (defun scribe-section ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (scribe-envelop-word "Section" 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (re-search-forward (concat "[" scribe-open-parentheses "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defun scribe-subsection ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (scribe-envelop-word "SubSection" 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (re-search-forward (concat "[" scribe-open-parentheses "]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (defun scribe-bracket-region-be (env min max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (interactive "sEnvironment: \nr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (goto-char max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (insert "@end(" env ")\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (goto-char min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (insert "@begin(" env ")\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defun scribe-insert-environment (env)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (interactive "sEnvironment: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (scribe-bracket-region-be env (point) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun scribe-insert-quote (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 "If scribe-electric-quote is non-NIL, insert ``, '' or \" according
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 to preceding character. With numeric arg N, always insert N \" characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 Else just insert \"."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if (or count (not scribe-electric-quote))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (self-insert-command (prefix-numeric-value count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (let (lastfore lastback lastquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ((= (preceding-char) ?\\) ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ((bobp) "``")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (setq lastfore (save-excursion (and (search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "``" (- (point) 1000) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 lastback (save-excursion (and (search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 "''" (- (point) 1000) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 lastquote (save-excursion (and (search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 "\"" (- (point) 100) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if (not lastquote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (cond ((not lastfore) "``")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ((not lastback) "''")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ((> lastfore lastback) "''")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (t "``"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (cond ((and (not lastback) (not lastfore)) "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ((and lastback (not lastfore) (> lastquote lastback)) "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ((and lastback (not lastfore) (> lastback lastquote)) "``")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ((and lastfore (not lastback) (> lastquote lastfore)) "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ((and lastfore (not lastback) (> lastfore lastquote)) "''")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ((and (> lastquote lastfore) (> lastquote lastback)) "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ((> lastfore lastback) "''")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (t "``")))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (defun scribe-parenthesis (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 "If scribe-electric-parenthesis is non-NIL, insertion of an open-parenthesis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 character inserts the following close parenthesis character if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 preceding text is of the form @Command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (self-insert-command (prefix-numeric-value count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (let (at-command paren-char point-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (if (or count (not scribe-electric-parenthesis))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq point-save (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (skip-chars-backward (concat "^ \n\t\f" scribe-open-parentheses))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (setq at-command (and (equal (following-char) ?@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (/= (point) (1- point-save)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (if (and at-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (setq paren-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (string-match (regexp-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (char-to-string (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 scribe-open-parentheses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (insert (aref scribe-close-parentheses paren-char)))))))