annotate lisp/modes/scribe.el @ 189:489f57a838ef r20-3b21

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