rev |
line source |
yuuji@0
|
1 ;;; -*- Emacs-Lisp -*-
|
yuuji@0
|
2 ;;; Yet Another tex-mode for emacs.
|
yuuji@3
|
3 ;;; yatex.el rev.1.32
|
yuuji@0
|
4 ;;; (c)1991 by Hirose Yuuji.[yuuji@ae.keio.ac.jp]
|
yuuji@3
|
5 ;;; Last modified Tue Nov 17 01:01:12 1992 on 98fa
|
yuuji@0
|
6
|
yuuji@0
|
7 (provide 'yatex-mode)
|
yuuji@3
|
8 (require 'comment)
|
yuuji@3
|
9 (defconst YaTeX-revision-number "1.32"
|
yuuji@0
|
10 "Revision number of running yatex.el"
|
yuuji@0
|
11 )
|
yuuji@0
|
12
|
yuuji@0
|
13 ;---------- Local variables ----------
|
yuuji@0
|
14 ;;;
|
yuuji@0
|
15 ;; Initialize local variable for yatex-mode.
|
yuuji@0
|
16 ;; Preserving user preferred definitions.
|
yuuji@0
|
17 ;; ** Check all of these defvar-ed values **
|
yuuji@0
|
18 ;; ** and setq other values more suitable **
|
yuuji@0
|
19 ;; ** for your site, if nedded. **
|
yuuji@0
|
20 ;;;
|
yuuji@0
|
21 (defvar YaTeX-prefix "\^C"
|
yuuji@0
|
22 "Prefix key to trigger YaTeX functions.
|
yuuji@0
|
23 You can select favorite prefix key by setq in your ~/.emacs."
|
yuuji@0
|
24 )
|
yuuji@0
|
25 (defvar YaTeX-open-lines 1
|
yuuji@0
|
26 "Blank lines between text and \??{??}"
|
yuuji@0
|
27 )
|
yuuji@1
|
28 (defvar YaTeX-fill-prefix ""
|
yuuji@0
|
29 "fill-prefix used for auto-fill-mode.
|
yuuji@0
|
30 The defalut value is single TAB."
|
yuuji@0
|
31 )
|
yuuji@0
|
32 (defvar YaTeX-user-completion-table "~/.yatexrc"
|
yuuji@0
|
33 "Default filename in which user completion table is saved."
|
yuuji@0
|
34 )
|
yuuji@0
|
35 (defvar tex-command "jlatex"
|
yuuji@0
|
36 "Default command for compiling LaTeX text."
|
yuuji@0
|
37 )
|
yuuji@0
|
38 (defvar dvi2-command ;previewer command for your site
|
yuuji@0
|
39 (concat
|
yuuji@0
|
40 "xdvi -geo +0+0 -s 4 -display "
|
yuuji@0
|
41 (getenv "DISPLAY"))
|
yuuji@0
|
42 "Default previewer command including its option.
|
yuuji@0
|
43 This default value is for X window system. If you want to use this
|
yuuji@0
|
44 default, you have to make sure the environment variable DISPLAY is
|
yuuji@0
|
45 correctly set."
|
yuuji@0
|
46 )
|
yuuji@0
|
47 (defvar latex-warning-regexp "line.* [0-9]*"
|
yuuji@0
|
48 "Regular expression of line number of warning message by latex command."
|
yuuji@0
|
49 )
|
yuuji@0
|
50 (defvar latex-error-regexp "l\\.[1-9][0-9]*"
|
yuuji@0
|
51 "Regular expression of line number of latex error. Perhaps your latex
|
yuuji@0
|
52 command stops at this error message with line number of LaTeX source text."
|
yuuji@0
|
53 )
|
yuuji@1
|
54 (defvar latex-dos-emergency-message
|
yuuji@3
|
55 "Emergency stop" ;<- for Micro tex, ASCII-pTeX 1.6
|
yuuji@0
|
56 "Because Demacs (GNU Emacs on DOS) cannot have pararell process, the
|
yuuji@0
|
57 latex command which is stopping on a LaTeX error, is terminated by Demacs.
|
yuuji@0
|
58 Many latex command on DOS display some message when it is terminated by
|
yuuji@0
|
59 other process, user or OS. Define this variable a message string of your
|
yuuji@0
|
60 latex command on DOS shows at abnormal termination.
|
yuuji@0
|
61 Remember Demacs's call-process function is not oriented for interactive
|
yuuji@0
|
62 process."
|
yuuji@0
|
63 )
|
yuuji@0
|
64
|
yuuji@0
|
65 ;------------ Completion table ------------
|
yuuji@0
|
66 ; Set tex-section-like command possible completion
|
yuuji@0
|
67 (setq section-table
|
yuuji@0
|
68 '(("part") ("section") ("subsection") ("subsubsection")
|
yuuji@0
|
69 ("author") ("documentstyle") ("pagestyle")
|
yuuji@0
|
70 ("documentstyle[10pt]") ("documentstyle[11pt]")
|
yuuji@0
|
71 ("documentstyle[12pt]")
|
yuuji@3
|
72 ("title") ("chapter") ("part") ("paragraph")
|
yuuji@0
|
73 ("subparagraph") ("underline") ("label") ("footnote")
|
yuuji@0
|
74 ("hspace*") ("vspace*") ("bibliography") ("bibitem[]") ("cite[]")
|
yuuji@0
|
75 ("nocite") ("input") ("include") ("includeonly") ("mbox") ("hbox")
|
yuuji@0
|
76 ("caption") ("newcommand") ("setlength") ("addtolength")
|
yuuji@0
|
77 ("newenvironment") ("newtheorem")
|
yuuji@0
|
78 ))
|
yuuji@0
|
79 (defvar user-section-table nil)
|
yuuji@0
|
80
|
yuuji@0
|
81 ; Set style possible completion
|
yuuji@0
|
82 (setq article-table
|
yuuji@0
|
83 '(("article") ("jarticle") ("report") ("jreport") ("jbook")
|
yuuji@0
|
84 ("4em") ("2ex")
|
yuuji@0
|
85 ("empty") ("headings") ("\\textwidth")
|
yuuji@0
|
86 ("\\oddsidemargin") ("\\evensidemargin")
|
yuuji@0
|
87 ("\\textheight") ("\\topmargin")
|
yuuji@0
|
88 ("\\bottommargin") ("\\footskip") ("\\footheight")
|
yuuji@0
|
89 ))
|
yuuji@0
|
90 (defvar user-article-table nil)
|
yuuji@0
|
91
|
yuuji@0
|
92 ; Set tex-environment possible completion
|
yuuji@0
|
93 (setq env-table
|
yuuji@0
|
94 '(("quote") ("quotation") ("center") ("verse") ("document")
|
yuuji@0
|
95 ("verbatim") ("itemize") ("enumerate") ("description")
|
yuuji@0
|
96 ("list{}") ("tabular") ("table") ("titlepage")
|
yuuji@0
|
97 ("sloppypar") ("ref") ("quotation") ("quote") ("picture")
|
yuuji@0
|
98 ("eqnarray") ("figure") ("equation") ("abstract") ("array")
|
yuuji@0
|
99 ("thebibliography") ("theindex")
|
yuuji@0
|
100 ))
|
yuuji@0
|
101 (defvar user-env-table nil)
|
yuuji@0
|
102
|
yuuji@0
|
103 ; Set {\Large }-like comletion
|
yuuji@0
|
104 (setq fontsize-table
|
yuuji@0
|
105 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
|
yuuji@0
|
106 ("dg") ("dm")
|
yuuji@0
|
107 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
|
yuuji@0
|
108 ("large") ("Large") ("LARGE") ("huge") ("Huge")
|
yuuji@0
|
109 ))
|
yuuji@0
|
110 (defvar user-fontsize-table nil)
|
yuuji@0
|
111
|
yuuji@0
|
112 (setq singlecmd-table
|
yuuji@0
|
113 '(("maketitle") ("sloppy")
|
yuuji@0
|
114 ("alpha") ("beta") ("gamma") ("delta") ("epsilon") ("varepsilon")
|
yuuji@0
|
115 ("zeta") ("eta") ("theta")("vartheta") ("iota") ("kappa")
|
yuuji@0
|
116 ("lambda") ("mu") ("nu") ("xi") ("pi") ("varpi") ("rho") ("varrho")
|
yuuji@0
|
117 ("sigma") ("varsigma") ("tau") ("upsilon") ("phi") ("varphi")
|
yuuji@0
|
118 ("chi") ("psi") ("omega") ("Gamma") ("Delta") ("Theta") ("Lambda")
|
yuuji@0
|
119 ("Xi") ("Pi") ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")
|
yuuji@3
|
120 ("LaTeX") ("TeX") ("item[]")
|
yuuji@0
|
121 ))
|
yuuji@0
|
122 (defvar user-singlecmd-table nil)
|
yuuji@0
|
123
|
yuuji@0
|
124 ;---------- Key mode map ----------
|
yuuji@0
|
125 ;;;
|
yuuji@0
|
126 ;; Create new key map: YaTeX-mode-map
|
yuuji@0
|
127 ;; Do not change this section.
|
yuuji@0
|
128 ;;;
|
yuuji@0
|
129 (defvar YaTeX-mode-map nil
|
yuuji@0
|
130 "Keymap used in YaTeX mode."
|
yuuji@0
|
131 )
|
yuuji@0
|
132 (defvar YaTeX-compilation-mode-map nil
|
yuuji@0
|
133 "Keymap userd in YaTeX compilation buffer."
|
yuuji@0
|
134 )
|
yuuji@0
|
135
|
yuuji@0
|
136 ;---------- Define deafult key bindings on YaTeX mode map ----------
|
yuuji@0
|
137 ;;;
|
yuuji@0
|
138 ;; Define key table
|
yuuji@0
|
139 ;;;
|
yuuji@0
|
140 (if YaTeX-mode-map
|
yuuji@0
|
141 nil
|
yuuji@0
|
142 (global-unset-key (concat YaTeX-prefix "b"))
|
yuuji@0
|
143 (setq YaTeX-mode-map (make-sparse-keymap))
|
yuuji@0
|
144 (define-key YaTeX-mode-map (concat YaTeX-prefix "tj")
|
yuuji@0
|
145 'YaTeX-compile)
|
yuuji@0
|
146 (define-key YaTeX-mode-map (concat YaTeX-prefix "tx")
|
yuuji@0
|
147 'YaTeX-preview)
|
yuuji@0
|
148 (define-key YaTeX-mode-map (concat YaTeX-prefix "tv")
|
yuuji@0
|
149 'YaTeX-view-error)
|
yuuji@0
|
150 (define-key YaTeX-mode-map (concat YaTeX-prefix "tb")
|
yuuji@0
|
151 '(lambda () (interactive) (YaTeX-insert-string "\\")))
|
yuuji@0
|
152 (define-key YaTeX-mode-map (concat YaTeX-prefix "'")
|
yuuji@0
|
153 'YaTeX-prev-error)
|
yuuji@0
|
154 (define-key YaTeX-mode-map (concat YaTeX-prefix " ")
|
yuuji@0
|
155 'YaTeX-do-completion)
|
yuuji@0
|
156 (define-key YaTeX-mode-map (concat YaTeX-prefix "v")
|
yuuji@0
|
157 'YaTeX-version)
|
yuuji@0
|
158
|
yuuji@0
|
159 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
|
yuuji@0
|
160 (define-key YaTeX-mode-map (concat YaTeX-prefix "{")
|
yuuji@0
|
161 'YaTeX-insert-braces)
|
yuuji@0
|
162 (define-key YaTeX-mode-map (concat YaTeX-prefix "}")
|
yuuji@0
|
163 'YaTeX-insert-braces-region)
|
yuuji@0
|
164 (define-key YaTeX-mode-map (concat YaTeX-prefix "d")
|
yuuji@0
|
165 'YaTeX-insert-dollar)
|
yuuji@0
|
166 (define-key YaTeX-mode-map (concat YaTeX-prefix "\\")
|
yuuji@0
|
167 '(lambda () (interactive) (YaTeX-insert-string "$\\backslash$")))
|
yuuji@0
|
168 (define-key YaTeX-mode-map (concat YaTeX-prefix "bd")
|
yuuji@0
|
169 '(lambda (arg) (interactive "P")
|
yuuji@0
|
170 (YaTeX-insert-begin-end "document" arg)))
|
yuuji@0
|
171 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bd")
|
yuuji@0
|
172 '(lambda () (interactive)
|
yuuji@0
|
173 (YaTeX-insert-begin-end "document" t)))
|
yuuji@0
|
174 (define-key YaTeX-mode-map (concat YaTeX-prefix "bD")
|
yuuji@0
|
175 '(lambda (arg) (interactive "P")
|
yuuji@0
|
176 (YaTeX-insert-begin-end "description" arg)))
|
yuuji@0
|
177 (define-key YaTeX-mode-map (concat YaTeX-prefix "BD")
|
yuuji@0
|
178 '(lambda () (interactive)
|
yuuji@0
|
179 (YaTeX-insert-begin-end "description" t)))
|
yuuji@0
|
180 (define-key YaTeX-mode-map (concat YaTeX-prefix "be")
|
yuuji@0
|
181 '(lambda (arg) (interactive "P")
|
yuuji@0
|
182 (YaTeX-insert-begin-end "enumerate" arg)))
|
yuuji@0
|
183 (define-key YaTeX-mode-map (concat YaTeX-prefix "Be")
|
yuuji@0
|
184 '(lambda () (interactive)
|
yuuji@0
|
185 (YaTeX-insert-begin-end "enumerate" t)))
|
yuuji@0
|
186 (define-key YaTeX-mode-map (concat YaTeX-prefix "bi")
|
yuuji@0
|
187 '(lambda (arg) (interactive "P")
|
yuuji@0
|
188 (YaTeX-insert-begin-end "itemize" arg)))
|
yuuji@0
|
189 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bi")
|
yuuji@0
|
190 '(lambda () (interactive)
|
yuuji@0
|
191 (YaTeX-insert-begin-end "itemize" t)))
|
yuuji@0
|
192 (define-key YaTeX-mode-map (concat YaTeX-prefix "bt")
|
yuuji@0
|
193 '(lambda (arg) (interactive "P")
|
yuuji@0
|
194 (YaTeX-insert-begin-end "tabbing" arg)))
|
yuuji@0
|
195 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bt")
|
yuuji@0
|
196 '(lambda () (interactive)
|
yuuji@0
|
197 (YaTeX-insert-begin-end "tabbing" t)))
|
yuuji@0
|
198 (define-key YaTeX-mode-map (concat YaTeX-prefix "bT")
|
yuuji@0
|
199 '(lambda (arg) (interactive "P")
|
yuuji@0
|
200 (YaTeX-insert-begin-end "tabular" arg)))
|
yuuji@0
|
201 (define-key YaTeX-mode-map (concat YaTeX-prefix "BT")
|
yuuji@0
|
202 '(lambda () (interactive)
|
yuuji@0
|
203 (YaTeX-insert-begin-end "tabular" t)))
|
yuuji@0
|
204 (define-key YaTeX-mode-map (concat YaTeX-prefix "bq")
|
yuuji@0
|
205 '(lambda (arg) (interactive "P")
|
yuuji@0
|
206 (YaTeX-insert-begin-end "quote" arg)))
|
yuuji@0
|
207 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bq")
|
yuuji@0
|
208 '(lambda () (interactive)
|
yuuji@0
|
209 (YaTeX-insert-begin-end "quote" t)))
|
yuuji@0
|
210 (define-key YaTeX-mode-map (concat YaTeX-prefix "bQ")
|
yuuji@0
|
211 '(lambda (arg) (interactive "P")
|
yuuji@0
|
212 (YaTeX-insert-begin-end "quotation" arg)))
|
yuuji@0
|
213 (define-key YaTeX-mode-map (concat YaTeX-prefix "BQ")
|
yuuji@0
|
214 '(lambda () (interactive)
|
yuuji@0
|
215 (YaTeX-insert-begin-end "quotation" t)))
|
yuuji@3
|
216 (define-key YaTeX-mode-map (concat YaTeX-prefix ".")
|
yuuji@3
|
217 'YaTeX-comment-paragraph)
|
yuuji@3
|
218 (define-key YaTeX-mode-map (concat YaTeX-prefix ",")
|
yuuji@3
|
219 'YaTeX-uncomment-paragraph)
|
yuuji@3
|
220 (define-key YaTeX-mode-map (concat YaTeX-prefix ">")
|
yuuji@3
|
221 '(lambda () (interactive) (comment-region "%")))
|
yuuji@3
|
222 (define-key YaTeX-mode-map (concat YaTeX-prefix "<")
|
yuuji@3
|
223 '(lambda () (interactive) (uncomment-region "%")))
|
yuuji@0
|
224 (define-key YaTeX-mode-map (concat YaTeX-prefix "b ")
|
yuuji@0
|
225 'YaTeX-make-begin-end)
|
yuuji@0
|
226 (define-key YaTeX-mode-map (concat YaTeX-prefix "B ")
|
yuuji@0
|
227 'YaTeX-make-begin-end-region)
|
yuuji@3
|
228 (define-key YaTeX-mode-map (concat YaTeX-prefix "e")
|
yuuji@3
|
229 'YaTeX-end-environment)
|
yuuji@0
|
230 (define-key YaTeX-mode-map (concat YaTeX-prefix "s")
|
yuuji@0
|
231 'YaTeX-make-section)
|
yuuji@0
|
232 (define-key YaTeX-mode-map (concat YaTeX-prefix "l")
|
yuuji@0
|
233 'YaTeX-make-fontsize)
|
yuuji@0
|
234 (define-key YaTeX-mode-map (concat YaTeX-prefix "L")
|
yuuji@0
|
235 'YaTeX-make-fontsize-region)
|
yuuji@0
|
236 (define-key YaTeX-mode-map (concat YaTeX-prefix "m")
|
yuuji@0
|
237 'YaTeX-make-singlecmd)
|
yuuji@3
|
238 (define-key YaTeX-mode-map (concat YaTeX-prefix "g")
|
yuuji@3
|
239 'YaTeX-goto-corresponding-environment)
|
yuuji@0
|
240 (define-key YaTeX-mode-map (concat YaTeX-prefix "\C-m")
|
yuuji@0
|
241 '(lambda () (interactive) (YaTeX-insert-string "\\\\")))
|
yuuji@0
|
242 (if (eq system-type 'ms-dos)
|
yuuji@0
|
243 (define-key YaTeX-mode-map (concat YaTeX-prefix "\^L")
|
yuuji@0
|
244 '(lambda () (interactive)
|
yuuji@3
|
245 (set-screen-height YaTeX-saved-screen-height) (recenter))))
|
yuuji@0
|
246 )
|
yuuji@0
|
247
|
yuuji@0
|
248 (if YaTeX-compilation-mode-map nil
|
yuuji@0
|
249 (setq YaTeX-compilation-mode-map (make-keymap))
|
yuuji@0
|
250 (suppress-keymap YaTeX-compilation-mode-map t)
|
yuuji@0
|
251 (define-key YaTeX-compilation-mode-map " "
|
yuuji@0
|
252 'YaTeX-jump-error-line)
|
yuuji@0
|
253 )
|
yuuji@0
|
254
|
yuuji@0
|
255 ;---------- Customize as you like above ----------
|
yuuji@0
|
256
|
yuuji@0
|
257 ;---------- Define other variable ----------
|
yuuji@0
|
258 (defvar env-name "document") ;Initial tex-environment completion
|
yuuji@0
|
259 (defvar section-name "documentstyle[12pt]") ;Initial tex-section completion
|
yuuji@0
|
260 (defvar fontsize-name "large") ;Initial fontsize completion
|
yuuji@0
|
261 (defvar single-command "maketitle") ;Initial LaTeX single command
|
yuuji@0
|
262 (defvar YaTeX-user-table-has-read nil
|
yuuji@0
|
263 "Flag that means whether user completion table has read or not."
|
yuuji@0
|
264 )
|
yuuji@0
|
265 (defvar yatex-mode-hook nil
|
yuuji@0
|
266 "List of functions to be called after .tex file is read
|
yuuji@0
|
267 and yatex-mode starts.")
|
yuuji@0
|
268
|
yuuji@0
|
269 ;---------- Produce YaTeX-mode ----------
|
yuuji@0
|
270 ;;;
|
yuuji@0
|
271 ;; Major mode definition
|
yuuji@0
|
272 ;;;
|
yuuji@0
|
273 (defun yatex-mode ()
|
yuuji@0
|
274 (interactive)
|
yuuji@0
|
275 (kill-all-local-variables)
|
yuuji@0
|
276 (setq major-mode 'YaTeX-mode)
|
yuuji@1
|
277 (setq mode-name "‚â‚Ä‚Ó‚à[‚Ç")
|
yuuji@0
|
278 (turn-on-auto-fill)
|
yuuji@1
|
279 (make-local-variable 'kanji-display-code)
|
yuuji@1
|
280 (make-local-variable 'kanji-fileio-code)
|
yuuji@1
|
281 (if (eq system-type 'ms-dos)
|
yuuji@1
|
282 (setq YaTeX-kanji-code 1)
|
yuuji@1
|
283 (defvar YaTeX-kanji-code 2))
|
yuuji@1
|
284 (setq kanji-display-code YaTeX-kanji-code
|
yuuji@1
|
285 kanji-fileio-code YaTeX-kanji-code)
|
yuuji@0
|
286 (make-local-variable 'fill-column)
|
yuuji@0
|
287 (make-local-variable 'fill-prefix)
|
yuuji@0
|
288 (setq fill-column 72
|
yuuji@0
|
289 fill-prefix YaTeX-fill-prefix)
|
yuuji@0
|
290 (use-local-map YaTeX-mode-map)
|
yuuji@0
|
291 (if (eq system-type 'ms-dos)
|
yuuji@3
|
292 (setq YaTeX-saved-screen-height (screen-height)))
|
yuuji@0
|
293 (if YaTeX-user-table-has-read nil
|
yuuji@0
|
294 (YaTeX-read-user-completion-table)
|
yuuji@0
|
295 (setq YaTeX-user-table-has-read t))
|
yuuji@0
|
296 (run-hooks 'yatex-mode-hook)
|
yuuji@0
|
297 )
|
yuuji@0
|
298
|
yuuji@0
|
299 ;---------- Define YaTeX-mode functions ----------
|
yuuji@0
|
300 ;;;
|
yuuji@0
|
301 ;; YaTeX-mode functions
|
yuuji@0
|
302 ;;;
|
yuuji@0
|
303 (defun YaTeX-insert-begin-end (env arg)
|
yuuji@0
|
304 "Insert \begin{mode-name} and \end{mode-name}."
|
yuuji@0
|
305 (if arg
|
yuuji@0
|
306 (save-excursion
|
yuuji@0
|
307 (if (> (point) (mark)) (exchange-point-and-mark))
|
yuuji@0
|
308 (insert "\\begin{" env "}\n")
|
yuuji@0
|
309 (exchange-point-and-mark)
|
yuuji@0
|
310 (insert "\\end{" env "}\n"))
|
yuuji@0
|
311 (delete-blank-lines)
|
yuuji@0
|
312 (insert "\\begin{" env "}\n")
|
yuuji@0
|
313 (newline (1+ (* 2 YaTeX-open-lines)))
|
yuuji@0
|
314 (insert "\\end{" env "}\n")
|
yuuji@0
|
315 (previous-line (+ 2 YaTeX-open-lines)))
|
yuuji@0
|
316 )
|
yuuji@0
|
317
|
yuuji@0
|
318 (defun YaTeX-exist-completion-table (elm table)
|
yuuji@0
|
319 "Return nil, if single list element:elm was
|
yuuji@0
|
320 not found in possible completion table."
|
yuuji@0
|
321 (while (not (or (null table) (equal elm (car table))))
|
yuuji@0
|
322 (setq table (cdr table)))
|
yuuji@0
|
323 table
|
yuuji@0
|
324 )
|
yuuji@0
|
325
|
yuuji@0
|
326 (defun YaTeX-make-begin-end (arg)
|
yuuji@0
|
327 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
|
yuuji@0
|
328 by completing read.
|
yuuji@0
|
329 If you invoke this command with universal argument,
|
yuuji@0
|
330 \(C-u or ESC-1 is typical prefix to invoke commands with ARG.\)
|
yuuji@0
|
331 you can put REGION into that environment between \\begin and \\end."
|
yuuji@0
|
332 (interactive "P")
|
yuuji@0
|
333 (let*
|
yuuji@0
|
334 ((mode (if arg " region" ""))
|
yuuji@0
|
335 (env
|
yuuji@0
|
336 (completing-read
|
yuuji@0
|
337 (format "Begin environment%s(default %s): " mode env-name)
|
yuuji@0
|
338 (append user-env-table env-table) nil nil)))
|
yuuji@0
|
339 (if (string= env "")
|
yuuji@0
|
340 (setq env env-name))
|
yuuji@0
|
341 (setq env-name env)
|
yuuji@0
|
342 (if (not (YaTeX-exist-completion-table
|
yuuji@0
|
343 (list env-name) (append user-env-table env-table)))
|
yuuji@0
|
344 (setq user-env-table (cons (list env-name) user-env-table)))
|
yuuji@0
|
345 (YaTeX-insert-begin-end env-name arg))
|
yuuji@0
|
346 )
|
yuuji@0
|
347
|
yuuji@0
|
348 (defun YaTeX-make-begin-end-region ()
|
yuuji@0
|
349 "Call YaTeX-make-begin-end with ARG to specify region mode."
|
yuuji@0
|
350 (interactive)
|
yuuji@0
|
351 (YaTeX-make-begin-end t)
|
yuuji@0
|
352 )
|
yuuji@0
|
353
|
yuuji@3
|
354 (defun YaTeX-end-environment ()
|
yuuji@3
|
355 "Close opening environment"
|
yuuji@3
|
356 (interactive)
|
yuuji@3
|
357 (let ((curp (point))
|
yuuji@3
|
358 (s)(env nil)(nest 0))
|
yuuji@3
|
359 (save-excursion
|
yuuji@3
|
360 (while
|
yuuji@3
|
361 (and
|
yuuji@3
|
362 (>= nest 0)
|
yuuji@3
|
363 (re-search-backward
|
yuuji@3
|
364 "^[^\\%]*\\(\\\\begin{.*}\\)\\|\\(\\\\end{.*}\\)" (point-min) t))
|
yuuji@3
|
365 (setq nest (if (re-search-forward "begin{" (match-end 0) t)
|
yuuji@3
|
366 (1- nest) (1+ nest))))
|
yuuji@3
|
367 (if (>= nest 0)
|
yuuji@3
|
368 (message "No premature environment")
|
yuuji@3
|
369 (goto-char (match-end 0))
|
yuuji@3
|
370 (setq s (point))
|
yuuji@3
|
371 (skip-chars-forward "0-9_A-z")
|
yuuji@3
|
372 (setq env (buffer-substring s (point)))
|
yuuji@3
|
373 ;;(recursive-edit)
|
yuuji@3
|
374 ))
|
yuuji@3
|
375 (if (null env) nil
|
yuuji@3
|
376 (save-excursion
|
yuuji@3
|
377 (if (and (re-search-forward "^[^\\%]*\\\\end{.*}" (point-max) t)
|
yuuji@3
|
378 (progn (goto-char (match-beginning 0))
|
yuuji@3
|
379 (re-search-forward env (match-end 0) t)))
|
yuuji@3
|
380 (if (y-or-n-p
|
yuuji@3
|
381 (concat "Environment `" env
|
yuuji@3
|
382 "' was already closed. Force close?"))
|
yuuji@3
|
383 nil
|
yuuji@3
|
384 (setq env nil))))
|
yuuji@3
|
385 (message "") ;Erase (y or n) message.
|
yuuji@3
|
386 (if (null env) nil
|
yuuji@3
|
387 (insert "\\end{" env "}")
|
yuuji@3
|
388 (setq curp (point))
|
yuuji@3
|
389 (goto-char s)
|
yuuji@3
|
390 (if (pos-visible-in-window-p)
|
yuuji@3
|
391 (sit-for 1)
|
yuuji@3
|
392 (message (concat "Matches \\begin{" env
|
yuuji@3
|
393 (format "} at line %d"
|
yuuji@3
|
394 (count-lines (point-min) s)))))
|
yuuji@3
|
395 (goto-char curp)))
|
yuuji@3
|
396 )
|
yuuji@3
|
397 )
|
yuuji@3
|
398
|
yuuji@0
|
399 (defun YaTeX-make-section (arg)
|
yuuji@0
|
400 "Make LaTeX \\section{} type command with completing read.
|
yuuji@0
|
401 With ARG of numeric, you can specify the number of argument of
|
yuuji@0
|
402 LaTeX command.
|
yuuji@0
|
403 For example, if you want to produce LaTeX command
|
yuuji@0
|
404
|
yuuji@0
|
405 \\addtolength{\\topmargin}{8mm}
|
yuuji@0
|
406
|
yuuji@0
|
407 which has two argument. You can produce that sequence by typing...
|
yuuji@0
|
408 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
|
yuuji@0
|
409 \(by default\)
|
yuuji@0
|
410 You can complete symbol at LaTeX command and 1st argument."
|
yuuji@0
|
411 (interactive "p")
|
yuuji@0
|
412 (let*
|
yuuji@0
|
413 ((section
|
yuuji@0
|
414 (completing-read
|
yuuji@0
|
415 (format "\\???{} (default %s): " section-name)
|
yuuji@0
|
416 (append user-section-table section-table)
|
yuuji@0
|
417 nil nil))
|
yuuji@0
|
418 (section (if (string= section "") section-name section))
|
yuuji@0
|
419 (title
|
yuuji@0
|
420 (completing-read (concat "\\" section "{???}: ")
|
yuuji@0
|
421 (append user-article-table article-table)
|
yuuji@0
|
422 nil nil)))
|
yuuji@0
|
423 (setq section-name section)
|
yuuji@0
|
424 (if (not (YaTeX-exist-completion-table
|
yuuji@0
|
425 (list section-name) (append user-section-table section-table)))
|
yuuji@0
|
426 (setq user-section-table
|
yuuji@0
|
427 (cons (list section-name) user-section-table)))
|
yuuji@0
|
428 (insert "\\" section-name "{" title "}")
|
yuuji@0
|
429 (let ((j 2))
|
yuuji@0
|
430 (while (<= j arg)
|
yuuji@0
|
431 (insert (concat "{" (read-string (format "Argument %d: " j))))
|
yuuji@0
|
432 (insert "}")
|
yuuji@0
|
433 (setq j (1+ j)))
|
yuuji@0
|
434 )
|
yuuji@0
|
435 (if (string= title "") (forward-char -1)
|
yuuji@0
|
436 nil))
|
yuuji@0
|
437 )
|
yuuji@0
|
438
|
yuuji@0
|
439 ;(defun YaTeX-make-section-region ()
|
yuuji@0
|
440 ; "Call YaTeX-make-section with ARG to specify region mode."
|
yuuji@0
|
441 ; (interactive)
|
yuuji@0
|
442 ; (YaTeX-make-section t)
|
yuuji@0
|
443 ;)
|
yuuji@0
|
444
|
yuuji@0
|
445 (defun YaTeX-make-fontsize (arg)
|
yuuji@0
|
446 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
|
yuuji@0
|
447 If you invoke this command with universal argument, you can put region
|
yuuji@0
|
448 into {\\xxx } braces.
|
yuuji@0
|
449 \(C-u or ESC-1 are default key bindings of universal-argument.\)"
|
yuuji@0
|
450 (interactive "P")
|
yuuji@0
|
451 (let* ((mode (if arg "region" ""))
|
yuuji@0
|
452 (fontsize
|
yuuji@0
|
453 (completing-read
|
yuuji@0
|
454 (format "{\\??? %s} (default %s): " mode fontsize-name)
|
yuuji@0
|
455 (append user-fontsize-table fontsize-table)
|
yuuji@0
|
456 nil nil )))
|
yuuji@0
|
457 (if (string= fontsize "")
|
yuuji@0
|
458 (setq fontsize fontsize-name))
|
yuuji@0
|
459 (setq fontsize-name fontsize)
|
yuuji@0
|
460 (if (not (YaTeX-exist-completion-table
|
yuuji@0
|
461 (list fontsize-name)
|
yuuji@0
|
462 (append user-fontsize-table fontsize-table)))
|
yuuji@0
|
463 (setq user-fontsize-table
|
yuuji@0
|
464 (cons (list fontsize-name) user-fontsize-table)))
|
yuuji@0
|
465 (if arg
|
yuuji@0
|
466 (save-excursion
|
yuuji@0
|
467 (if (> (point) (mark)) (exchange-point-and-mark))
|
yuuji@0
|
468 (insert "{\\" fontsize-name " ")
|
yuuji@0
|
469 (exchange-point-and-mark)
|
yuuji@0
|
470 (insert "}"))
|
yuuji@0
|
471 (insert "{\\" fontsize-name " }")
|
yuuji@0
|
472 (forward-char -1)))
|
yuuji@0
|
473 )
|
yuuji@0
|
474
|
yuuji@0
|
475 (defun YaTeX-make-fontsize-region ()
|
yuuji@0
|
476 "Call functino:YaTeX-make-fontsize with ARG to specify region mode."
|
yuuji@0
|
477 (interactive)
|
yuuji@0
|
478 (YaTeX-make-fontsize t)
|
yuuji@0
|
479 )
|
yuuji@0
|
480
|
yuuji@0
|
481 (defun YaTeX-make-singlecmd (single)
|
yuuji@0
|
482 (interactive
|
yuuji@0
|
483 (list (completing-read
|
yuuji@0
|
484 (format "\\??? (default %s): " single-command)
|
yuuji@0
|
485 (append user-singlecmd-table singlecmd-table)
|
yuuji@0
|
486 nil nil )))
|
yuuji@0
|
487 (if (string= single "")
|
yuuji@0
|
488 (setq single single-command))
|
yuuji@0
|
489 (setq single-command single)
|
yuuji@0
|
490 (if (not (YaTeX-exist-completion-table
|
yuuji@0
|
491 (list single-command)
|
yuuji@0
|
492 (append user-singlecmd-table singlecmd-table)))
|
yuuji@0
|
493 (setq user-singlecmd-table
|
yuuji@0
|
494 (cons (list single-command) user-singlecmd-table)))
|
yuuji@0
|
495 (insert "\\" single-command " ")
|
yuuji@0
|
496 )
|
yuuji@0
|
497
|
yuuji@0
|
498 (defvar YaTeX-completion-begin-regexp "[{\\]"
|
yuuji@0
|
499 "Regular expression of limit where LaTeX command's
|
yuuji@0
|
500 completion begins.")
|
yuuji@0
|
501
|
yuuji@0
|
502 (defun YaTeX-do-completion ()
|
yuuji@0
|
503 "Try completion on LaTeX command preceding point."
|
yuuji@0
|
504 (interactive)
|
yuuji@0
|
505 (if
|
yuuji@0
|
506 (or (eq (preceding-char) ? )
|
yuuji@0
|
507 (eq (preceding-char) ?\t)
|
yuuji@0
|
508 (eq (preceding-char) ?\n)
|
yuuji@0
|
509 (bobp))
|
yuuji@0
|
510 (message "Nothing to complete.") ;Do not complete
|
yuuji@0
|
511 (let* ((end (point))
|
yuuji@0
|
512 (limit (save-excursion (beginning-of-line) (point)))
|
yuuji@0
|
513 (completion-begin
|
yuuji@0
|
514 (progn (re-search-backward "[ \t\n]" limit 1)
|
yuuji@0
|
515 (point)))
|
yuuji@0
|
516 (begin (progn
|
yuuji@0
|
517 (goto-char end)
|
yuuji@0
|
518 (if (re-search-backward YaTeX-completion-begin-regexp
|
yuuji@0
|
519 completion-begin t)
|
yuuji@0
|
520 (1+ (point))
|
yuuji@0
|
521 nil))))
|
yuuji@0
|
522 (goto-char end)
|
yuuji@0
|
523 (cond
|
yuuji@0
|
524 ((null begin)
|
yuuji@0
|
525 (message "I think it is not LaTeX sequence."))
|
yuuji@0
|
526 (t
|
yuuji@0
|
527 (let* ((pattern (buffer-substring begin end))
|
yuuji@0
|
528 (all-table (append section-table user-section-table
|
yuuji@0
|
529 article-table user-article-table
|
yuuji@0
|
530 env-table user-env-table
|
yuuji@0
|
531 singlecmd-table user-singlecmd-table))
|
yuuji@0
|
532 ;; First,
|
yuuji@0
|
533 ;; search completion without backslash.
|
yuuji@0
|
534 (completion (try-completion pattern all-table nil)))
|
yuuji@0
|
535 (if
|
yuuji@0
|
536 (eq completion nil)
|
yuuji@0
|
537 ;; Next,
|
yuuji@0
|
538 ;; search completion with backslash
|
yuuji@0
|
539 (setq completion
|
yuuji@0
|
540 (try-completion (buffer-substring (1- begin) end)
|
yuuji@0
|
541 all-table nil)
|
yuuji@0
|
542 begin (1- begin)))
|
yuuji@0
|
543 (cond
|
yuuji@0
|
544 ((null completion)
|
yuuji@0
|
545 (message (concat "Can't find completion for '" pattern "'"))
|
yuuji@0
|
546 (ding))
|
yuuji@0
|
547 ((eq completion t) (message "Sole completion."))
|
yuuji@0
|
548 ((not (string= completion pattern))
|
yuuji@0
|
549 (kill-region begin end)
|
yuuji@0
|
550 (insert completion)
|
yuuji@0
|
551 )
|
yuuji@0
|
552 (t
|
yuuji@0
|
553 (message "Making completion list...")
|
yuuji@0
|
554 (with-output-to-temp-buffer "*Help*"
|
yuuji@0
|
555 (display-completion-list
|
yuuji@0
|
556 (all-completions pattern all-table))) )
|
yuuji@0
|
557 ))))))
|
yuuji@0
|
558 )
|
yuuji@0
|
559
|
yuuji@0
|
560 (defun YaTeX-insert-quote ()
|
yuuji@0
|
561 (interactive)
|
yuuji@0
|
562 (insert
|
yuuji@0
|
563 (cond
|
yuuji@0
|
564 ((= (preceding-char) ?\\ ) ?\")
|
yuuji@0
|
565 ((= (preceding-char) ?\( ) ?\")
|
yuuji@0
|
566 ((= (preceding-char) 32) "``")
|
yuuji@0
|
567 ((= (preceding-char) 9) "``")
|
yuuji@0
|
568 ((= (preceding-char) ?\n) "``")
|
yuuji@0
|
569 ((bobp) "``")
|
yuuji@0
|
570 (t "''")
|
yuuji@0
|
571 )))
|
yuuji@0
|
572
|
yuuji@0
|
573
|
yuuji@0
|
574 (defun YaTeX-insert-braces-region (beg end)
|
yuuji@0
|
575 (interactive "r")
|
yuuji@0
|
576 (save-excursion
|
yuuji@0
|
577 (goto-char end)
|
yuuji@0
|
578 (insert "}")
|
yuuji@0
|
579 (goto-char beg)
|
yuuji@0
|
580 (insert "{"))
|
yuuji@0
|
581 )
|
yuuji@0
|
582
|
yuuji@0
|
583 (defun YaTeX-insert-braces ()
|
yuuji@0
|
584 (interactive)
|
yuuji@0
|
585 (insert "{}")
|
yuuji@0
|
586 (forward-char -1)
|
yuuji@0
|
587 )
|
yuuji@0
|
588
|
yuuji@0
|
589 (defun YaTeX-insert-dollar ()
|
yuuji@0
|
590 (interactive)
|
yuuji@0
|
591 (insert "$$")
|
yuuji@0
|
592 (forward-char -1)
|
yuuji@0
|
593 )
|
yuuji@0
|
594
|
yuuji@0
|
595 (defun YaTeX-insert-string (s)
|
yuuji@0
|
596 (insert s)
|
yuuji@0
|
597 )
|
yuuji@0
|
598
|
yuuji@0
|
599 (defun YaTeX-version ()
|
yuuji@0
|
600 "Return string of the version of running YaTeX."
|
yuuji@0
|
601 (interactive)
|
yuuji@0
|
602 (message
|
yuuji@1
|
603 (concat "Yet Another TeX mode u–ì’¹v Revision "
|
yuuji@0
|
604 YaTeX-revision-number))
|
yuuji@0
|
605 )
|
yuuji@0
|
606
|
yuuji@0
|
607 (defun YaTeX-compile-sentinel (proc mes)
|
yuuji@0
|
608 (cond ((null (buffer-name (process-buffer proc)))
|
yuuji@0
|
609 ;; buffer killed
|
yuuji@0
|
610 (set-process-buffer proc nil))
|
yuuji@0
|
611 ((memq (process-status proc) '(signal exit))
|
yuuji@0
|
612 (let* ((obuf (current-buffer)))
|
yuuji@0
|
613 ;; save-excursion isn't the right thing if
|
yuuji@0
|
614 ;; process-buffer is current-buffer
|
yuuji@0
|
615 (unwind-protect
|
yuuji@0
|
616 (progn
|
yuuji@0
|
617 ;; Write something in *compilation* and hack its mode line
|
yuuji@0
|
618 (set-buffer (process-buffer proc))
|
yuuji@0
|
619 (goto-char (point-max))
|
yuuji@0
|
620 (insert ?\n "jlatex compilation " mes)
|
yuuji@0
|
621 (forward-char -1)
|
yuuji@0
|
622 (insert " at "
|
yuuji@0
|
623 (substring (current-time-string) 0 -5))
|
yuuji@0
|
624 (insert "\n * Hit any key to return * ")
|
yuuji@0
|
625 (forward-char 1)
|
yuuji@0
|
626 (setq mode-line-process
|
yuuji@0
|
627 (concat ": "
|
yuuji@0
|
628 (symbol-name (process-status proc))))
|
yuuji@0
|
629 ;; If buffer and mode line will show that the process
|
yuuji@0
|
630 ;; is dead, we can delete it now. Otherwise it
|
yuuji@0
|
631 ;; will stay around until M-x list-processes.
|
yuuji@0
|
632 (delete-process proc)
|
yuuji@0
|
633 )
|
yuuji@0
|
634 (setq YaTeX-compilation-process nil)
|
yuuji@0
|
635 ;; Force mode line redisplay soon
|
yuuji@0
|
636 (set-buffer-modified-p (buffer-modified-p))
|
yuuji@0
|
637 )
|
yuuji@0
|
638 (set-buffer obuf)
|
yuuji@0
|
639 )))
|
yuuji@0
|
640 )
|
yuuji@0
|
641
|
yuuji@0
|
642 (defvar YaTeX-compilation-process nil
|
yuuji@0
|
643 "Process identifier for jlatex"
|
yuuji@0
|
644 )
|
yuuji@0
|
645
|
yuuji@0
|
646 (defun YaTeX-compile ()
|
yuuji@0
|
647 "Execute jlatex (or other) to LaTeX compile."
|
yuuji@0
|
648 (interactive)
|
yuuji@0
|
649 (if YaTeX-compilation-process
|
yuuji@0
|
650 (if (eq (process-status YaTeX-compilation-process) 'run)
|
yuuji@0
|
651 (progn (interrupt-process YaTeX-compilation-process)
|
yuuji@0
|
652 (sit-for 1)
|
yuuji@0
|
653 (delete-process YaTeX-compilation-process))
|
yuuji@0
|
654 nil) nil)
|
yuuji@0
|
655 ; (compile1 (concat tex-command " " (buffer-name))
|
yuuji@0
|
656 ; "TeX error" "*TeX compilation*")
|
yuuji@0
|
657 (setq YaTeX-compilation-process nil)
|
yuuji@0
|
658 (if (eq system-type 'ms-dos) ;if MS-DOS
|
yuuji@0
|
659 (with-output-to-temp-buffer "*YaTeX-compilation*"
|
yuuji@0
|
660 (message (concat "Compiling " (buffer-name) "..."))
|
yuuji@1
|
661 (YaTeX-put-nonstopmode)
|
yuuji@1
|
662 (basic-save-buffer)
|
yuuji@1
|
663 (call-process shell-file-name
|
yuuji@1
|
664 nil
|
yuuji@1
|
665 "*YaTeX-compilation*" nil
|
yuuji@1
|
666 "/c" (YaTeX-get-latex-command))
|
yuuji@1
|
667 ;;;"/c " tex-command (buffer-name) )
|
yuuji@1
|
668 (YaTeX-remove-nonstopmode))
|
yuuji@0
|
669 (setq YaTeX-compilation-process ;if UNIX
|
yuuji@0
|
670 (with-output-to-temp-buffer "*YaTeX-compilation*"
|
yuuji@1
|
671 (basic-save-buffer)
|
yuuji@0
|
672 (start-process "LaTeX" "*YaTeX-compilation*" shell-file-name "-c"
|
yuuji@1
|
673 (YaTeX-get-latex-command))
|
yuuji@1
|
674 ;;;tex-command (buffer-name) "")
|
yuuji@0
|
675 ))
|
yuuji@0
|
676 (set-process-sentinel YaTeX-compilation-process 'YaTeX-compile-sentinel))
|
yuuji@0
|
677 (setq current-TeX-buffer (buffer-name))
|
yuuji@0
|
678 (other-window 1)
|
yuuji@0
|
679 (use-local-map YaTeX-compilation-mode-map)
|
yuuji@0
|
680 (set-kanji-process-code YaTeX-kanji-code)
|
yuuji@0
|
681 (message "Type SPC to continue.")
|
yuuji@0
|
682 (goto-char (point-max))
|
yuuji@0
|
683 (sit-for 30)
|
yuuji@0
|
684 (read-char) ;hit any key
|
yuuji@0
|
685 (other-window -1)
|
yuuji@0
|
686 )
|
yuuji@0
|
687
|
yuuji@0
|
688 (defun YaTeX-preview (preview-command preview-file)
|
yuuji@0
|
689 "Execute xdvi (or other) to tex-preview."
|
yuuji@0
|
690 (interactive
|
yuuji@0
|
691 (list (read-string "Preview command: " dvi2-command)
|
yuuji@0
|
692 (read-string "Prefiew file[.dvi]: "
|
yuuji@3
|
693 ;;(substring (buffer-name) 0 -4)
|
yuuji@3
|
694 (YaTeX-get-preview-file-name) ;ver 1.31
|
yuuji@0
|
695 )))
|
yuuji@0
|
696 (setq dvi2-command preview-command)
|
yuuji@0
|
697 (with-output-to-temp-buffer "*dvi-preview*"
|
yuuji@0
|
698 (if (eq system-type 'ms-dos)
|
yuuji@0
|
699 (progn (send-string-to-terminal "\e[2J") ;if MS-DOS
|
yuuji@0
|
700 (call-process shell-file-name "con" "*dvi-preview*" nil
|
yuuji@0
|
701 "/c " dvi2-command preview-file)
|
yuuji@0
|
702 (redraw-display))
|
yuuji@0
|
703 (start-process "xdvi" "*dvi-preview*" shell-file-name "-c"
|
yuuji@0
|
704 (concat dvi2-command " " preview-file)) ;if UNIX
|
yuuji@0
|
705 (message (concat "Starting " dvi2-command " to preview " preview-file)))
|
yuuji@0
|
706 )
|
yuuji@0
|
707 )
|
yuuji@0
|
708
|
yuuji@0
|
709 (defun YaTeX-prev-error ()
|
yuuji@0
|
710 "Visit previous error. The reason why not NEXT-error is to
|
yuuji@0
|
711 avoid make confliction of line numbers by editing."
|
yuuji@0
|
712 (interactive)
|
yuuji@0
|
713 (setq cur-buf (buffer-name)
|
yuuji@0
|
714 YaTeX-error-line nil)
|
yuuji@0
|
715 (if (null (get-buffer "*YaTeX-compilation*"))
|
yuuji@0
|
716 (message "There is no output buffer of compilation.")
|
yuuji@0
|
717 (pop-to-buffer "*YaTeX-compilation*")
|
yuuji@0
|
718 (if (eq system-type 'ms-dos)
|
yuuji@0
|
719 (if (search-backward latex-dos-emergency-message nil t)
|
yuuji@0
|
720 (progn (goto-char (point-max))
|
yuuji@0
|
721 (setq error-regexp latex-error-regexp))
|
yuuji@0
|
722 (beginning-of-line)
|
yuuji@0
|
723 (forward-char -1)
|
yuuji@0
|
724 (setq error-regexp latex-warning-regexp))
|
yuuji@0
|
725 (if YaTeX-compilation-process ; if jlatex on UNIX
|
yuuji@0
|
726 (if (eq (process-status YaTeX-compilation-process) 'run)
|
yuuji@0
|
727 (progn
|
yuuji@0
|
728 (goto-char (point-max))
|
yuuji@0
|
729 (setq error-regexp latex-error-regexp)))
|
yuuji@0
|
730 (beginning-of-line)
|
yuuji@0
|
731 (setq error-regexp latex-warning-regexp)))
|
yuuji@0
|
732 (if (re-search-backward error-regexp nil t)
|
yuuji@0
|
733 (save-restriction
|
yuuji@0
|
734 (set-mark-command nil)
|
yuuji@0
|
735 (end-of-line)
|
yuuji@0
|
736 (narrow-to-region (point) (mark))
|
yuuji@0
|
737 (goto-char (point-min))
|
yuuji@0
|
738 (re-search-forward "[0-9]")
|
yuuji@0
|
739 (forward-char -1)
|
yuuji@0
|
740 (set-mark (point))
|
yuuji@1
|
741 (skip-chars-forward "0-9")
|
yuuji@0
|
742 (narrow-to-region (point) (mark))
|
yuuji@0
|
743 (goto-char (point-min))
|
yuuji@0
|
744 (setq YaTeX-error-line (read (current-buffer))))
|
yuuji@0
|
745 (message "No more error on %s" cur-buf)
|
yuuji@0
|
746 (ding)
|
yuuji@0
|
747 )
|
yuuji@0
|
748 (other-window -1)
|
yuuji@0
|
749 (switch-to-buffer cur-buf)
|
yuuji@0
|
750 (if (null YaTeX-error-line)
|
yuuji@0
|
751 nil
|
yuuji@0
|
752 (goto-line YaTeX-error-line)
|
yuuji@0
|
753 (message "latex error or warning at line: %d" YaTeX-error-line)
|
yuuji@0
|
754 (other-window 1)
|
yuuji@0
|
755 (skip-chars-backward "[0-9]")
|
yuuji@0
|
756 (recenter (/ (window-height) 2))
|
yuuji@0
|
757 (sit-for 3)
|
yuuji@0
|
758 (forward-line -1)
|
yuuji@0
|
759 (other-window -1)
|
yuuji@0
|
760 ))
|
yuuji@0
|
761 )
|
yuuji@0
|
762
|
yuuji@0
|
763 (defun YaTeX-jump-error-line ()
|
yuuji@0
|
764 "Jump corresponding line on latex command's error message."
|
yuuji@0
|
765 (interactive)
|
yuuji@0
|
766 (let ((end (progn (end-of-line) (point)))
|
yuuji@0
|
767 (begin (progn (beginning-of-line)(point))))
|
yuuji@0
|
768 (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t))
|
yuuji@0
|
769 (message "No line number expression")
|
yuuji@0
|
770 (goto-char (match-beginning 0))
|
yuuji@0
|
771 (re-search-forward "[1-9][0-9]*" end t)
|
yuuji@0
|
772 (save-restriction
|
yuuji@0
|
773 (narrow-to-region (match-beginning 0) (match-end 0))
|
yuuji@0
|
774 (goto-char (point-min))
|
yuuji@0
|
775 (let ((error-line (read (current-buffer))))
|
yuuji@0
|
776 (other-window -1)
|
yuuji@0
|
777 (switch-to-buffer current-TeX-buffer)
|
yuuji@0
|
778 (goto-line error-line)))))
|
yuuji@0
|
779 )
|
yuuji@0
|
780
|
yuuji@0
|
781 (defun YaTeX-view-error ()
|
yuuji@0
|
782 (interactive)
|
yuuji@0
|
783 (other-window 1)
|
yuuji@0
|
784 (goto-char (point-max))
|
yuuji@0
|
785 (other-window -1)
|
yuuji@0
|
786 )
|
yuuji@0
|
787
|
yuuji@1
|
788 (defun YaTeX-put-nonstopmode ()
|
yuuji@1
|
789 (if (boundp 'YaTeX-need-nonstop)
|
yuuji@1
|
790 (if (re-search-backward "\\nonstopmode{}" (point-min) t)
|
yuuji@1
|
791 nil ;if already written in text then do nothing
|
yuuji@1
|
792 (save-excursion
|
yuuji@1
|
793 (goto-char (point-min))
|
yuuji@1
|
794 (insert "\\nonstopmode{}%_YaTeX_%\n")))
|
yuuji@1
|
795 )
|
yuuji@1
|
796 )
|
yuuji@1
|
797
|
yuuji@1
|
798 (defun YaTeX-remove-nonstopmode ()
|
yuuji@1
|
799 (if (boundp 'YaTeX-need-nonstop) ;for speed
|
yuuji@1
|
800 (save-excursion
|
yuuji@1
|
801 (goto-char (point-min))
|
yuuji@1
|
802 (forward-line 1)
|
yuuji@1
|
803 (narrow-to-region (point-min) (point))
|
yuuji@1
|
804 (goto-char (point-min))
|
yuuji@1
|
805 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
|
yuuji@1
|
806 (widen)))
|
yuuji@1
|
807 )
|
yuuji@1
|
808
|
yuuji@3
|
809 (defun YaTeX-get-preview-file-name ()
|
yuuji@3
|
810 "Get file name to preview by inquiring YaTeX-get-latex-command"
|
yuuji@3
|
811 (let* ((latex-cmd (YaTeX-get-latex-command))
|
yuuji@3
|
812 (fname (substring latex-cmd (1+ (rindex latex-cmd ? ))))
|
yuuji@3
|
813 (period))
|
yuuji@3
|
814 (if (eq fname "")
|
yuuji@3
|
815 (setq fname (substring (buffer-name) 0 -4))
|
yuuji@3
|
816 (setq period (rindex fname ?.))
|
yuuji@3
|
817 (setq fname (substring fname 0 (if (eq -1 period) nil period)))
|
yuuji@3
|
818 ))
|
yuuji@3
|
819 )
|
yuuji@3
|
820
|
yuuji@1
|
821 (defun YaTeX-get-latex-command ()
|
yuuji@1
|
822 "Specify the latex-command name and its argument.
|
yuuji@1
|
823 If there is a line which begins by string: \"%#!\", the following
|
yuuji@1
|
824 strings are assumed to be the latex-command and arguments. The
|
yuuji@1
|
825 default value of latex-command is:
|
yuuji@1
|
826 tex-command (buffer-name)
|
yuuji@1
|
827 and if you write \"%#!jlatex\" in the beginning of certain line.
|
yuuji@1
|
828 \"jlatex \" (buffer-name)
|
yuuji@1
|
829 will be the latex-command,
|
yuuji@1
|
830 and you write \"%#!jlatex main.tex\"
|
yuuji@1
|
831 \"jlatex main.tex\"
|
yuuji@1
|
832 will be given to the shell."
|
yuuji@1
|
833 (let*
|
yuuji@1
|
834 ((default-command
|
yuuji@1
|
835 (concat tex-command " " (buffer-name)))) ;default value
|
yuuji@1
|
836 (save-excursion
|
yuuji@1
|
837 (goto-char (point-min))
|
yuuji@1
|
838 (if (null (re-search-forward "^%#!" (point-max) t))
|
yuuji@1
|
839 default-command
|
yuuji@1
|
840 (skip-chars-forward "%#! ")
|
yuuji@1
|
841 (if (eolp)
|
yuuji@1
|
842 default-command
|
yuuji@1
|
843 (let ((s (point)))
|
yuuji@1
|
844 (skip-chars-forward "A-z") ;Skip command name
|
yuuji@1
|
845 ;(setq YaTeX-latex-command (buffer-substring s (point)))
|
yuuji@1
|
846 (if (eolp) ;Only change command name
|
yuuji@1
|
847 (concat (buffer-substring s (point)) " " (buffer-name))
|
yuuji@1
|
848 (end-of-line) ;Change entire command name
|
yuuji@1
|
849 (buffer-substring s (point)) ;including arguments.
|
yuuji@1
|
850 ))
|
yuuji@1
|
851 ))))
|
yuuji@1
|
852 )
|
yuuji@1
|
853
|
yuuji@3
|
854 (defun YaTeX-goto-corresponding-environment ()
|
yuuji@3
|
855 "Go to corresponding begin/end enclosure."
|
yuuji@3
|
856 (interactive)
|
yuuji@3
|
857 (beginning-of-line)
|
yuuji@3
|
858 (if (not (re-search-forward
|
yuuji@3
|
859 "\\(begin{\\)\\|\\(end{\\)" (point-end-of-line) t))
|
yuuji@3
|
860 (error "No environment declaration"))
|
yuuji@3
|
861 (let ((p (point) env)
|
yuuji@3
|
862 (m0 (match-beginning 0))
|
yuuji@3
|
863 (m1 (match-beginning 1))
|
yuuji@3
|
864 (m2 (match-beginning 2)))
|
yuuji@3
|
865 (if (not (re-search-forward "}" (point-end-of-line) t))
|
yuuji@3
|
866 (error "Unterminated brackets for begin/end"))
|
yuuji@3
|
867 (setq env (buffer-substring p (match-beginning 0))) ;get current env
|
yuuji@3
|
868 (cond
|
yuuji@3
|
869 ((equal m0 m1) ;if begin{xxx}
|
yuuji@3
|
870 (re-search-forward (concat "end{" env "}")))
|
yuuji@3
|
871 ((equal m0 m2) ;if end{xxx}
|
yuuji@3
|
872 (re-search-backward (concat "begin{" env "}")))
|
yuuji@3
|
873 )
|
yuuji@3
|
874 (beginning-of-line)
|
yuuji@3
|
875 );let
|
yuuji@3
|
876 )
|
yuuji@3
|
877
|
yuuji@3
|
878 (defun YaTeX-comment-paragraph ()
|
yuuji@3
|
879 "Comment out current paragraph."
|
yuuji@3
|
880 (interactive)
|
yuuji@3
|
881 (save-excursion
|
yuuji@3
|
882 (mark-paragraph)
|
yuuji@3
|
883 (if (not (bobp)) (forward-line 1))
|
yuuji@3
|
884 (comment-region "%"))
|
yuuji@3
|
885 )
|
yuuji@3
|
886
|
yuuji@3
|
887 (defun YaTeX-uncomment-paragraph ()
|
yuuji@3
|
888 "Uncomment current paragraph."
|
yuuji@3
|
889 (interactive)
|
yuuji@3
|
890 (save-excursion
|
yuuji@3
|
891 (let ((prefix fill-prefix))
|
yuuji@3
|
892 (setq fill-prefix "")
|
yuuji@3
|
893 (mark-paragraph)
|
yuuji@3
|
894 (if (not (bobp)) (forward-line 1))
|
yuuji@3
|
895 (uncomment-region "%")
|
yuuji@3
|
896 (setq fill-prefix prefix)))
|
yuuji@3
|
897 )
|
yuuji@3
|
898
|
yuuji@0
|
899 (defun YaTeX-read-user-completion-table ()
|
yuuji@0
|
900 "Append user completion table of LaTeX word"
|
yuuji@0
|
901 (message "Loading personal completion table")
|
yuuji@0
|
902 (let ((user-table (expand-file-name YaTeX-user-completion-table)))
|
yuuji@0
|
903 (if (file-exists-p user-table)
|
yuuji@0
|
904 (load-file user-table)
|
yuuji@0
|
905 (message "Personal completion table not found."))
|
yuuji@0
|
906 ))
|
yuuji@0
|
907
|
yuuji@0
|
908 (defun YaTeX-save-table ()
|
yuuji@0
|
909 "Save personal completion table as dictionary."
|
yuuji@0
|
910 (interactive)
|
yuuji@0
|
911 (message "Saving user table in %s" YaTeX-user-completion-table)
|
yuuji@0
|
912 (find-file (expand-file-name YaTeX-user-completion-table))
|
yuuji@0
|
913 (erase-buffer)
|
yuuji@0
|
914 ; (prin1-to-string user-section-table)
|
yuuji@0
|
915 (insert "(setq user-section-table '(\n")
|
yuuji@0
|
916 (mapcar '(lambda (s)
|
yuuji@0
|
917 (insert (prin1-to-string s))
|
yuuji@0
|
918 (insert "\n"))
|
yuuji@0
|
919 user-section-table)
|
yuuji@0
|
920 (insert "))\n\n")
|
yuuji@0
|
921
|
yuuji@0
|
922 (insert "(setq user-article-table '(\n")
|
yuuji@0
|
923 (mapcar '(lambda (s)
|
yuuji@0
|
924 (insert (prin1-to-string s))
|
yuuji@0
|
925 (insert "\n"))
|
yuuji@0
|
926 user-article-table)
|
yuuji@0
|
927 (insert "))\n\n")
|
yuuji@0
|
928
|
yuuji@0
|
929 (insert "(setq user-env-table '(\n")
|
yuuji@0
|
930 (mapcar '(lambda (s)
|
yuuji@0
|
931 (insert (prin1-to-string s))
|
yuuji@0
|
932 (insert "\n"))
|
yuuji@0
|
933 user-env-table)
|
yuuji@0
|
934 (insert "))\n\n")
|
yuuji@0
|
935
|
yuuji@0
|
936 (insert "(setq user-fontsize-table '(\n")
|
yuuji@0
|
937 (mapcar '(lambda (s)
|
yuuji@0
|
938 (insert (prin1-to-string s))
|
yuuji@0
|
939 (insert "\n"))
|
yuuji@0
|
940 user-fontsize-table)
|
yuuji@0
|
941 (insert "))\n\n")
|
yuuji@0
|
942
|
yuuji@0
|
943 (insert "(setq user-singlecmd-table '(\n")
|
yuuji@0
|
944 (mapcar '(lambda (s)
|
yuuji@0
|
945 (insert (prin1-to-string s))
|
yuuji@0
|
946 (insert "\n"))
|
yuuji@0
|
947 user-singlecmd-table)
|
yuuji@0
|
948 (insert "))\n")
|
yuuji@0
|
949
|
yuuji@0
|
950 (basic-save-buffer)
|
yuuji@0
|
951 (kill-buffer (current-buffer))
|
yuuji@0
|
952 (message "")
|
yuuji@0
|
953 )
|
yuuji@0
|
954
|
yuuji@3
|
955 ;; --------------- General sub functions ---------------
|
yuuji@3
|
956
|
yuuji@3
|
957 ;(defun index (string char)
|
yuuji@3
|
958 ; (let ((pos 0)(len (1- (length string)))(index -1))
|
yuuji@3
|
959 ; (while (<= pos len)
|
yuuji@3
|
960 ; (cond
|
yuuji@3
|
961 ; ((= (aref string pos) char)
|
yuuji@3
|
962 ; (setq index pos) (setq pos len))
|
yuuji@3
|
963 ; (t (setq pos (1+ pos))))
|
yuuji@3
|
964 ; )
|
yuuji@3
|
965 ; index)
|
yuuji@3
|
966 ;)
|
yuuji@3
|
967
|
yuuji@3
|
968 (defun rindex (string char)
|
yuuji@3
|
969 (let ((pos (1- (length string)))(index -1))
|
yuuji@3
|
970 (while (>= pos 0)
|
yuuji@3
|
971 (cond
|
yuuji@3
|
972 ((= (aref string pos) char)
|
yuuji@3
|
973 (setq index pos) (setq pos -1))
|
yuuji@3
|
974 (t (setq pos (1- pos))))
|
yuuji@3
|
975 )
|
yuuji@3
|
976 index)
|
yuuji@3
|
977 )
|
yuuji@3
|
978
|
yuuji@3
|
979 (defun point-beginning-of-line ()
|
yuuji@3
|
980 (save-excursion (beginning-of-line)(point))
|
yuuji@3
|
981 )
|
yuuji@3
|
982
|
yuuji@3
|
983 (defun point-end-of-line ()
|
yuuji@3
|
984 (save-excursion (end-of-line)(point))
|
yuuji@3
|
985 )
|
yuuji@3
|
986
|
yuuji@0
|
987 (defun append-to-hook (hook hook-list)
|
yuuji@0
|
988 "Add hook-list to certain emacs's hook correctly.
|
yuuji@0
|
989 Argument hook-list is the list of function int the form to be called
|
yuuji@0
|
990 Call this function with argument as next example,
|
yuuji@0
|
991 (append-to-hook '((ding))) ;If one function to add.
|
yuuji@0
|
992 (append-to-hook '((func1)(func2 arg)))."
|
yuuji@0
|
993 (if (null (eval hook)) ;Not defined
|
yuuji@0
|
994 (set hook
|
yuuji@0
|
995 (append '(lambda ()) hook-list))
|
yuuji@0
|
996 (if (listp (eval hook))
|
yuuji@0
|
997 (if (eq (car (eval hook)) 'lambda) ;'(lambda () ....)
|
yuuji@0
|
998 (set hook
|
yuuji@0
|
999 (append (eval hook) hook-list))
|
yuuji@0
|
1000 (if (eq hook 'kill-emacs-hook) ;'(hook1 hook2 ...)
|
yuuji@0
|
1001 (progn ; this format is not
|
yuuji@0
|
1002 (ding) ; for kill-emacs-hook
|
yuuji@0
|
1003 (message
|
yuuji@0
|
1004 "Caution!! you have wrong format of kill-emacs-hook"))
|
yuuji@0
|
1005 (while (not (null hook-list))
|
yuuji@0
|
1006 (set hook
|
yuuji@0
|
1007 (append (eval hook) (car hook-list)))
|
yuuji@0
|
1008 (setq hook-list (cdr hook-list))))
|
yuuji@0
|
1009 )
|
yuuji@0
|
1010 (set hook ;'hook
|
yuuji@0
|
1011 (append '(lambda ())
|
yuuji@0
|
1012 (cons (list (eval hook)) hook-list)))))
|
yuuji@0
|
1013 )
|
yuuji@0
|
1014 (append-to-hook 'kill-emacs-hook '((YaTeX-save-table)))
|
yuuji@0
|
1015
|
yuuji@0
|
1016 ;--------------------------------- History ---------------------------------
|
yuuji@0
|
1017 ; Rev. | Date | Contents
|
yuuji@0
|
1018 ;------+----------+---------------------------------------------------------
|
yuuji@0
|
1019 ; 1.00 | 91/ 6/13 | Initial version.
|
yuuji@0
|
1020 ; | | Auto compilation & preview.
|
yuuji@0
|
1021 ; | | \section{}-type and \begin{}\end{}-type completion.
|
yuuji@0
|
1022 ; 1.01 | 91/ 6/14 | Add {\large ..} type completion (prefix+l).
|
yuuji@0
|
1023 ; 1.10 | 6/21 | Add learning feature of completion.
|
yuuji@0
|
1024 ; 1.11 | 6/27 | Simplify function begin-document etc. using lambda.
|
yuuji@0
|
1025 ; 1.12 | 7/ 6 | Modify YaTeX-make-section, show section-name.
|
yuuji@0
|
1026 ; 1.13 | 12/ 4 | Delete blank lines in make begin/end environment.
|
yuuji@0
|
1027 ; 1.20 | 12/ 5 | Saving learned completion into user file.
|
yuuji@0
|
1028 ; 1.21 | 12/ 6 | Add \maketitle type completion (prefix+m).
|
yuuji@0
|
1029 ; 1.22 | 12/30 | Port yatex.el to DOS(Demacs).
|
yuuji@0
|
1030 ; 1.23 | 92/ 1/ 8 | Enable latex and preview command on DOS.
|
yuuji@0
|
1031 ; 1.24 | 1/ 9 | Add YaTeX-save-table to kill-emacs-hook automatically.
|
yuuji@0
|
1032 ; 1.25 | 1/16 | YaTeX-do-completion (prefix+SPC) and argument
|
yuuji@3
|
1033 ; | | acceptable YaTeX-make-section works. Put region into
|
yuuji@0
|
1034 ; | | \begin...\end by calling YaTeX-make-begin-end with ARG.
|
yuuji@0
|
1035 ; | | append-kill-emacs-hook was revised to append-to-hook.
|
yuuji@0
|
1036 ; 1.26 | 1/18 | Region mode is added to {\large }. Default fontsize.
|
yuuji@3
|
1037 ; 1.27 | 1/21 | Default name on completing-read.
|
yuuji@1
|
1038 ; 1.28 | 7/ 2 | Add \nonstopmode{} automatically on DOS.
|
yuuji@1
|
1039 ; | 7/20 | %#! usage to specify latex command and its arguments.
|
yuuji@3
|
1040 ; | | Change default fill-prefix from TAB to null string.
|
yuuji@3
|
1041 ; 1.29 | 7/21 | Add YaTeX-end-environment.
|
yuuji@3
|
1042 ; 1.30 | 9/26 | Support project 30 lines(other than 25 lines).
|
yuuji@3
|
1043 ; 1.31 | 10/28 | Variable argument for previewer from %#! usage.
|
yuuji@3
|
1044 ; 1.32 | 10/16 | YaTeX-goto-corresponding-environment.
|
yuuji@0
|
1045 ;------+----------+---------------------------------------------------------
|
yuuji@0
|
1046 ;
|
yuuji@0
|
1047 ;----------------------------- End of yatex.el -----------------------------
|