Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexprc.el @ 86:f14ec50103d0
as of 2009/9/28
author | yuuji@gentei.org |
---|---|
date | Mon, 28 Sep 2009 07:56:08 +0900 |
parents | 9b4354af748c |
children | ce2deaceb818 |
rev | line source |
---|---|
51 | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX process handler. | |
3 ;;; yatexprc.el | |
86 | 4 ;;; (c)1993-2007 by HIROSE Yuuji.[yuuji@yatex.org] |
5 ;;; Last modified Thu May 7 13:47:28 2009 on firestorm | |
51 | 6 ;;; $Id$ |
7 | |
64 | 8 ;(require 'yatex) |
9 (require 'yatexlib) | |
51 | 10 |
11 (defvar YaTeX-typeset-process nil | |
69 | 12 "Process identifier for jlatex") |
13 | |
51 | 14 (defvar YaTeX-typeset-buffer "*YaTeX-typesetting*" |
15 "Process buffer for jlatex") | |
16 | |
17 (defvar YaTeX-typeset-buffer-syntax nil | |
18 "*Syntax table for typesetting buffer") | |
19 | |
20 (defvar YaTeX-current-TeX-buffer nil | |
21 "Keeps the buffer on which recently typeset run.") | |
22 | |
23 (defvar YaTeX-shell-command-option | |
24 (or (and (boundp 'shell-command-option) shell-command-option) | |
68 | 25 (and (boundp 'shell-command-switch) shell-command-switch) |
51 | 26 (if YaTeX-dos "/c" "-c")) |
27 "Shell option for command execution.") | |
28 | |
64 | 29 (defvar YaTeX-latex-message-code |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
30 ;; (cond |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
31 ;; (YaTeX-dos (cdr (assq 1 YaTeX-kanji-code-alist))) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
32 ;; ((and YaTeX-emacs-20 (member 'undecided (coding-system-list)) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
33 ;; 'undecided)) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
34 ;; ((featurep 'mule) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
35 ;; (or (and (boundp '*autoconv*) *autoconv*) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
36 ;; (and (fboundp 'coding-system-list) 'automatic-conversion))) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
37 ;; ((boundp 'NEMACS) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
38 ;; (cdr (assq (if YaTeX-dos 1 2) YaTeX-kanji-code-alist)))) |
64 | 39 (cond |
80 | 40 (YaTeX-dos (cdr (assq 1 YaTeX-kanji-code-alist))) |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
41 (YaTeX-emacs-20 |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
42 (cdr (assoc latex-message-kanji-code YaTeX-kanji-code-alist))) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
43 ((boundp 'MULE) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
44 (symbol-value |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
45 (cdr (assoc latex-message-kanji-code YaTeX-kanji-code-alist)))) |
64 | 46 ((boundp 'NEMACS) |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
47 latex-message-kanji-code)) |
64 | 48 "Process coding system for LaTeX.") |
49 | |
51 | 50 (if YaTeX-typeset-buffer-syntax nil |
51 (setq YaTeX-typeset-buffer-syntax | |
52 (make-syntax-table (standard-syntax-table))) | |
53 (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax) | |
54 (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax) | |
55 (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax) | |
69 | 56 (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax)) |
51 | 57 |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
58 (defun YaTeX-typeset (command buffer &optional prcname modename) |
51 | 59 "Execute jlatex (or other) to LaTeX typeset." |
60 (interactive) | |
61 (save-excursion | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
62 (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer)) |
64 | 63 (map YaTeX-typesetting-mode-map) |
64 (outcode | |
65 (cond ((eq major-mode 'yatex-mode) YaTeX-coding-system) | |
69 | 66 ((eq major-mode 'yahtml-mode) yahtml-kanji-code)))) |
51 | 67 (if (and YaTeX-typeset-process |
68 (eq (process-status YaTeX-typeset-process) 'run)) | |
69 ;; if tex command is halting. | |
70 (YaTeX-kill-typeset-process YaTeX-typeset-process)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
71 (YaTeX-put-nonstopmode) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
72 (setq prcname (or prcname "LaTeX") |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
73 modename (or modename "typeset")) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
74 (if (eq major-mode 'yatex-mode) (YaTeX-visit-main t)) ;;execution dir |
51 | 75 (setq execdir default-directory) |
76 ;;Select lower-most window if there are more than 2 windows and | |
77 ;;typeset buffer not seen. | |
78 (YaTeX-showup-buffer | |
79 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
80 (set-buffer (get-buffer-create buffer)) | |
81 (setq default-directory execdir) | |
82 (cd execdir) | |
83 (erase-buffer) | |
84 (cond | |
64 | 85 ((not (fboundp 'start-process)) ;YaTeX-dos;if MS-DOS |
51 | 86 (call-process |
64 | 87 shell-file-name nil buffer nil YaTeX-shell-command-option command)) |
51 | 88 (t ;if UNIX |
89 (set-process-buffer | |
90 (setq YaTeX-typeset-process | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
91 (start-process prcname buffer shell-file-name |
51 | 92 YaTeX-shell-command-option command)) |
93 (get-buffer buffer)) | |
94 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel))) | |
95 (message (format "Calling `%s'..." command)) | |
96 (setq YaTeX-current-TeX-buffer (buffer-name)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
97 (use-local-map map) ;map may be localized |
51 | 98 (set-syntax-table YaTeX-typeset-buffer-syntax) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
99 (setq mode-name modename) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
100 (if YaTeX-typeset-process ;if process is running (maybe on UNIX) |
64 | 101 (cond ((fboundp 'set-current-process-coding-system) |
51 | 102 (set-current-process-coding-system |
64 | 103 YaTeX-latex-message-code outcode)) |
104 ((fboundp 'set-process-coding-system) | |
105 (set-process-coding-system | |
106 YaTeX-typeset-process YaTeX-latex-message-code outcode)) | |
107 (YaTeX-emacs-20 | |
108 (set-buffer-process-coding-system | |
109 YaTeX-latex-message-code outcode)) | |
51 | 110 ((boundp 'NEMACS) |
111 (set-kanji-process-code YaTeX-latex-message-code)))) | |
112 (if YaTeX-dos (message "Done.") | |
113 (insert " ") | |
114 (set-marker (process-mark YaTeX-typeset-process) (1- (point)))) | |
115 (if (bolp) (forward-line -1)) ;what for? | |
116 (if (and YaTeX-emacs-19 window-system) | |
117 (let ((win (get-buffer-window buffer t)) owin) | |
118 (select-frame (window-frame win)) | |
119 (setq owin (selected-window)) | |
120 (select-window win) | |
121 (goto-char (point-max)) | |
122 (recenter -1) | |
123 (select-window owin)) | |
124 (select-window (get-buffer-window buffer)) | |
125 (goto-char (point-max)) | |
126 (recenter -1)) | |
127 (select-window window) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
128 (switch-to-buffer cb) |
69 | 129 (YaTeX-remove-nonstopmode)))) |
51 | 130 |
131 (defun YaTeX-typeset-sentinel (proc mes) | |
132 (cond ((null (buffer-name (process-buffer proc))) | |
133 ;; buffer killed | |
134 (set-process-buffer proc nil)) | |
135 ((memq (process-status proc) '(signal exit)) | |
136 (let* ((obuf (current-buffer)) (pbuf (process-buffer proc)) | |
137 (pwin (get-buffer-window pbuf)) | |
138 (owin (selected-window)) win) | |
139 ;; save-excursion isn't the right thing if | |
140 ;; process-buffer is current-buffer | |
141 (unwind-protect | |
142 (progn | |
143 ;; Write something in *typesetting* and hack its mode line | |
144 (if pwin | |
145 (select-window pwin) | |
146 (set-buffer pbuf)) | |
147 ;;(YaTeX-showup-buffer pbuf nil t) | |
148 (goto-char (point-max)) | |
149 (if pwin (recenter -3)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
150 (insert ?\n mode-name " " mes) |
51 | 151 (forward-char -1) |
152 (insert " at " (substring (current-time-string) 0 -5) "\n") | |
153 (forward-char 1) | |
154 (setq mode-line-process | |
155 (concat ": " | |
156 (symbol-name (process-status proc)))) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
157 (message mode-name " %s." |
51 | 158 (if (eq (process-status proc) 'exit) |
159 "done" "ceased")) | |
160 ;; If buffer and mode line shows that the process | |
161 ;; is dead, we can delete it now. Otherwise it | |
162 ;; will stay around until M-x list-processes. | |
163 (delete-process proc) | |
164 ) | |
165 (setq YaTeX-typeset-process nil) | |
166 ;; Force mode line redisplay soon | |
167 (set-buffer-modified-p (buffer-modified-p)) | |
168 ) | |
169 (select-window owin) | |
69 | 170 (set-buffer obuf))))) |
51 | 171 |
172 (defvar YaTeX-texput-file "texput.tex" | |
69 | 173 "*File name for temporary file of typeset-region.") |
51 | 174 |
175 (defun YaTeX-typeset-region () | |
52 | 176 "Paste the region to the file `texput.tex' and execute typesetter. |
177 The region is specified by the rule: | |
51 | 178 (1)If keyword `%#BEGIN' is found in the upper direction from (point). |
179 (1-1)if the keyword `%#END' is found after `%#BEGIN', | |
180 ->Assume the text between `%#BEGIN' and `%#END' as region. | |
181 (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN', | |
182 ->Assume the text after `%#BEGIN' as region. | |
183 (2)If no `%#BEGIN' usage is found before the (point), | |
184 ->Assume the text between current (point) and (mark) as region. | |
185 DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing | |
186 operation to the region." | |
187 (interactive) | |
188 (save-excursion | |
189 (let* | |
190 ((end "") typeout ;Type out message that tells the method of cutting. | |
191 (texput YaTeX-texput-file) | |
192 (cmd (concat (YaTeX-get-latex-command nil) " " texput)) | |
193 (buffer (current-buffer)) opoint preamble (subpreamble "") main | |
194 (hilit-auto-highlight nil) ;for Emacs19 with hilit19 | |
52 | 195 reg-begin reg-end lineinfo) |
51 | 196 |
197 (save-excursion | |
198 (if (search-backward "%#BEGIN" nil t) | |
199 (progn | |
200 (setq typeout "--- Region from BEGIN to " | |
201 end "the end of the buffer ---" | |
202 reg-begin (match-end 0)) | |
203 (if (search-forward "%#END" nil t) | |
204 (setq reg-end (match-beginning 0) | |
205 end "END ---") | |
206 (setq reg-end (point-max)))) | |
52 | 207 (setq typeout "=== Region from (point) to (mark) ===" |
208 reg-begin (point) reg-end (mark))) | |
209 (goto-char (min reg-begin reg-end)) | |
210 (setq lineinfo (count-lines (point-min) (point-end-of-line))) | |
51 | 211 (goto-char (point-min)) |
212 (while (search-forward "%#REQUIRE" nil t) | |
213 (setq subpreamble | |
214 (concat subpreamble | |
215 (cond | |
216 ((eolp) | |
217 (buffer-substring | |
218 (match-beginning 0) | |
219 (point-beginning-of-line))) | |
220 (t (buffer-substring | |
221 (match-end 0) | |
222 (point-end-of-line)))) | |
223 "\n")) | |
224 (goto-char (match-end 0)))) | |
225 (YaTeX-visit-main t) | |
226 (setq main (current-buffer)) | |
227 (setq opoint (point)) | |
228 (goto-char (point-min)) | |
229 (setq | |
230 preamble | |
231 (if (re-search-forward "^[ ]*\\\\begin.*{document}" nil t) | |
232 (buffer-substring (point-min) (match-end 0)) | |
73 | 233 (concat |
234 (if YaTeX-use-LaTeX2e "\\documentclass{" "\\documentstyle{") | |
235 YaTeX-default-document-style "}\n" | |
236 "\\begin{document}"))) | |
51 | 237 (goto-char opoint) |
238 ;;(set-buffer buffer) ;for clarity | |
52 | 239 (let ((hilit-auto-highlight nil)) |
240 (set-buffer (find-file-noselect texput))) | |
51 | 241 ;;(find-file YaTeX-texput-file) |
242 (erase-buffer) | |
64 | 243 (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop) |
51 | 244 (insert "\\nonstopmode{}\n")) |
245 (insert preamble "\n" subpreamble "\n") | |
52 | 246 (setq lineinfo (list (count-lines 1 (point-end-of-line)) lineinfo)) |
51 | 247 (insert-buffer-substring buffer reg-begin reg-end) |
248 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method. | |
249 (insert "\n\\end{document}\n") | |
250 (basic-save-buffer) | |
251 (kill-buffer (current-buffer)) | |
252 (set-buffer main) ;return to parent file or itself. | |
253 (YaTeX-typeset cmd YaTeX-typeset-buffer) | |
254 (switch-to-buffer buffer) ;for Emacs-19 | |
52 | 255 (put 'dvi2-command 'region t) |
256 (put 'dvi2-command 'file buffer) | |
69 | 257 (put 'dvi2-command 'offset lineinfo)))) |
51 | 258 |
259 (defun YaTeX-typeset-buffer () | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
260 "Typeset whole buffer. |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
261 If %#! usage says other buffer is main text, |
51 | 262 visit main buffer to confirm if its includeonly list contains current |
263 buffer's file. And if it doesn't contain editing text, ask user which | |
264 action wants to be done, A:Add list, R:Replace list, %:comment-out list." | |
265 (interactive) | |
266 (YaTeX-save-buffers) | |
267 (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.))) | |
268 (mydir (file-name-directory (buffer-file-name))) | |
269 (cmd (YaTeX-get-latex-command t)) (cb (current-buffer))) | |
270 (if (YaTeX-main-file-p) nil | |
271 (save-excursion | |
272 (YaTeX-visit-main t) ;search into main buffer | |
273 (save-excursion | |
274 (push-mark (point) t) | |
275 (goto-char (point-min)) | |
276 (if (and (re-search-forward "^[ ]*\\\\begin{document}" nil t) | |
277 (re-search-backward "^[ ]*\\\\includeonly{" nil t)) | |
278 (let* | |
279 ((b (progn (skip-chars-forward "^{") (point))) | |
280 (e (progn (skip-chars-forward "^}") (1+ (point)))) | |
281 (s (buffer-substring b e)) c | |
282 (pardir (file-name-directory (buffer-file-name)))) | |
283 (if (string-match (concat "[{,/]" me "[,}]") s) | |
284 nil ; Nothing to do when it's already in includeonly. | |
285 (ding) | |
286 (switch-to-buffer (current-buffer));Display this buffer. | |
287 (setq | |
288 me ;;Rewrite my name(me) to contain sub directory name. | |
289 (concat | |
290 (if (string-match pardir mydir) ;if mydir is child of main | |
291 (substring mydir (length pardir)) ;cut absolute path | |
292 mydir) ;else concat absolute path name. | |
293 me)) | |
294 (message | |
295 "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? " | |
296 me) | |
297 (setq c (read-char)) | |
298 (cond | |
299 ((= c ?a) | |
300 (goto-char (1+ b)) | |
301 (insert me (if (string= s "{}") "" ","))) | |
302 ((= c ?r) | |
303 (delete-region (1+ b) (1- e)) (insert me)) | |
304 ((= c ?%) | |
305 (beginning-of-line) (insert "%")) | |
306 (t nil)) | |
307 (basic-save-buffer)))) | |
308 (exchange-point-and-mark))) | |
309 (switch-to-buffer cb)) ;for 19 | |
310 (YaTeX-typeset cmd YaTeX-typeset-buffer) | |
69 | 311 (put 'dvi2-command 'region nil))) |
51 | 312 |
313 (defvar YaTeX-call-command-history nil | |
314 "Holds history list of YaTeX-call-command-on-file.") | |
315 (put 'YaTeX-call-command-history 'no-default t) | |
86 | 316 (defun YaTeX-call-command-on-file (base-cmd buffer &optional file) |
317 "Call external command BASE-CMD int the BUFFER. | |
318 By default, pass the basename of current file. Optional 3rd argument | |
319 FILE changes the default file name." | |
51 | 320 (YaTeX-save-buffers) |
321 (YaTeX-typeset | |
322 (read-string-with-history | |
323 "Call command: " | |
80 | 324 (concat base-cmd " " |
86 | 325 (let ((me (file-name-nondirectory (or file buffer-file-name)))) |
80 | 326 (if (string-match "\\.tex" me) |
327 (substring me 0 (match-beginning 0)) | |
328 me))) | |
51 | 329 'YaTeX-call-command-history) |
69 | 330 buffer)) |
51 | 331 |
332 (defun YaTeX-bibtex-buffer (cmd) | |
333 "Pass the bibliography data of editing file to bibtex." | |
334 (interactive) | |
335 (YaTeX-save-buffers) | |
86 | 336 (let ((main (or YaTeX-parent-file |
337 (progn (YaTeX-visit-main t) buffer-file-name)))) | |
338 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" main))) | |
51 | 339 |
340 (defun YaTeX-kill-typeset-process (proc) | |
341 "Kill process PROC after sending signal to PROC. | |
342 PROC should be process identifier." | |
343 (cond | |
68 | 344 ((not (fboundp 'start-process)) |
345 (error "This system can't have concurrent process.")) | |
51 | 346 ((or (null proc) (not (eq (process-status proc) 'run))) |
347 (message "Typesetting process is not running.")) | |
348 (t | |
349 (save-excursion | |
350 (set-buffer (process-buffer proc)) | |
351 (save-excursion | |
352 (goto-char (point-max)) | |
353 (beginning-of-line) | |
354 (if (looking-at "\\? +$") | |
355 (let ((mp (point-max))) | |
356 (process-send-string proc "x\n") | |
357 (while (= mp (point-max)) (sit-for 1)))))) | |
358 (if (eq (process-status proc) 'run) | |
359 (progn | |
360 (interrupt-process proc) | |
69 | 361 (delete-process proc)))))) |
51 | 362 |
363 (defun YaTeX-system (command buffer) | |
364 "Execute some command on buffer. Not a official function." | |
365 (save-excursion | |
366 (YaTeX-showup-buffer | |
367 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
59 | 368 (let ((df default-directory)) ;preserve current buf's pwd |
369 (set-buffer (get-buffer-create buffer)) ;1.61.3 | |
370 (setq default-directory df) | |
371 (cd df)) | |
51 | 372 (erase-buffer) |
64 | 373 (if (not (fboundp 'start-process)) |
51 | 374 (call-process |
375 shell-file-name nil buffer nil YaTeX-shell-command-option command) | |
59 | 376 (if (and (get-buffer-process buffer) |
377 (eq (process-status (get-buffer-process buffer)) 'run) | |
378 (not | |
379 (y-or-n-p (format "Process %s is running. Continue?" buffer)))) | |
380 nil | |
381 (set-process-buffer | |
382 (start-process | |
383 "system" buffer shell-file-name YaTeX-shell-command-option command) | |
69 | 384 (get-buffer buffer)))))) |
51 | 385 |
72 | 386 (defvar YaTeX-default-paper-type "a4" |
387 "*Default paper type.") | |
388 (defconst YaTeX-paper-type-alist | |
389 '(("a4paper" . "a4") | |
390 ("a5paper" . "a5") | |
391 ("b4paper" . "b4") | |
392 ("b5paper" . "b5")) | |
393 "Holds map of options and paper types.") | |
394 (defconst YaTeX-dvips-paper-option-alist | |
395 '(("a4" . "-t a4") | |
396 ("a5" . "-t a5") | |
397 ("b4" . "-t b4") | |
398 ("b5" . "-t b5") | |
399 ("a4r" . "-t landscape"); Can't specify options, `-t a4' and `-t landscape', at the same time. | |
400 ("a5r" . "-t landscape") | |
401 ("b4r" . "-t landscape") | |
402 ("b5r" . "-t landscape")) | |
403 "Holds map of dvips options and paper types.") | |
404 (defun YaTeX-get-paper-type () | |
405 "Search options in header and return a paper type, such as \"a4\", \"a4r\", etc." | |
406 (save-excursion | |
77 | 407 (YaTeX-visit-main t) |
72 | 408 (goto-char (point-min)) |
77 | 409 (let ((opts |
410 (if (re-search-forward | |
411 "^[ \t]*\\\\document\\(style\\|class\\)[ \t]*\\[\\([^]]*\\)\\]" nil t) | |
412 (YaTeX-split-string (YaTeX-match-string 2) "[ \t]*,[ \t]*")))) | |
413 (concat | |
414 (catch 'found-paper | |
415 (mapcar (lambda (pair) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
416 (if (YaTeX-member (car pair) opts) |
77 | 417 (throw 'found-paper (cdr pair)))) |
418 YaTeX-paper-type-alist) | |
419 YaTeX-default-paper-type) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
420 (if (YaTeX-member "landscape" opts) (if YaTeX-dos "L" "r") ""))))) |
72 | 421 |
51 | 422 (defvar YaTeX-preview-command-history nil |
423 "Holds minibuffer history of preview command.") | |
424 (put 'YaTeX-preview-command-history 'no-default t) | |
425 (defvar YaTeX-preview-file-history nil | |
426 "Holds minibuffer history of file to preview.") | |
427 (put 'YaTeX-preview-file-history 'no-default t) | |
428 (defun YaTeX-preview (preview-command preview-file) | |
429 "Execute xdvi (or other) to tex-preview." | |
430 (interactive | |
86 | 431 (let* ((command (read-string-with-history |
432 "Preview command: " | |
433 (YaTeX-replace-format | |
434 (or (YaTeX-get-builtin "PREVIEW") dvi2-command) | |
435 "p" (format (cond | |
436 (YaTeX-dos "-y:%s") | |
437 (t "-paper %s")) | |
438 (YaTeX-get-paper-type))) | |
439 'YaTeX-preview-command-history)) | |
440 (file (read-string-with-history | |
441 "Preview file: " | |
442 (if (get 'dvi2-command 'region) | |
443 (substring YaTeX-texput-file | |
444 0 (rindex YaTeX-texput-file ?.)) | |
445 (YaTeX-get-preview-file-name command)) | |
446 'YaTeX-preview-file-history))) | |
447 (list command file))) | |
51 | 448 (setq dvi2-command preview-command) ;`dvi2command' is buffer local |
449 (save-excursion | |
450 (YaTeX-visit-main t) | |
86 | 451 (if YaTeX-dos (setq preview-file (expand-file-name preview-file))) |
51 | 452 (let ((pbuffer "*dvi-preview*") (dir default-directory)) |
453 (YaTeX-showup-buffer | |
454 pbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
455 (set-buffer (get-buffer-create pbuffer)) | |
456 (erase-buffer) | |
457 (setq default-directory dir) ;for 18 | |
458 (cd dir) ;for 19 | |
459 (cond | |
64 | 460 ((not (fboundp 'start-process)) ;if MS-DOS |
51 | 461 (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor |
462 (call-process shell-file-name "con" "*dvi-preview*" nil | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
463 YaTeX-shell-command-option |
61 | 464 (concat preview-command " " preview-file)) |
51 | 465 (send-string-to-terminal "\e[>5l") ;show cursor |
466 (redraw-display)) | |
69 | 467 ((and (string-match "dviout" preview-command) ;maybe on `kon' |
468 (stringp (getenv "TERM")) | |
469 (string-match "^kon" (getenv "TERM"))) | |
470 (call-process shell-file-name "con" "*dvi-preview*" nil | |
471 YaTeX-shell-command-option | |
472 (concat preview-command " " preview-file))) | |
51 | 473 (t ;if UNIX |
474 (set-process-buffer | |
86 | 475 (let ((process-connection-type nil)) |
476 (start-process "preview" "*dvi-preview*" shell-file-name | |
477 YaTeX-shell-command-option | |
478 (concat preview-command " " preview-file))) | |
51 | 479 (get-buffer pbuffer)) |
480 (message | |
481 (concat "Starting " preview-command | |
69 | 482 " to preview " preview-file))))))) |
51 | 483 |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
484 (defvar YaTeX-xdvi-remote-program "xdvi") |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
485 (defun YaTeX-xdvi-remote-search (&optional region-mode) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
486 "Search string at the point on xdvi -remote window. |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
487 Non-nil for optional argument REGION-MODE specifies the search string |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
488 by region." |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
489 (interactive "P") |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
490 (let ((pb " *xdvi*") str proc) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
491 (save-excursion |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
492 (if region-mode |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
493 (setq str (buffer-substring (region-beginning) (region-end))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
494 (setq str (buffer-substring |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
495 (point) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
496 (progn (skip-chars-forward "^\n\\\\}") (point))))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
497 (message "Searching `%s'..." str) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
498 (if (boundp 'MULE) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
499 (define-program-coding-system |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
500 (regexp-quote pb) (regexp-quote YaTeX-xdvi-remote-program) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
501 *euc-japan*)) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
502 (setq proc |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
503 (start-process |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
504 "xdvi" pb YaTeX-xdvi-remote-program |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
505 "-remote" (format "SloppySearch(%s) " str) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
506 (concat (YaTeX-get-preview-file-name) ".dvi"))) |
69 | 507 (message "Searching `%s'...Done" str)))) |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
508 |
52 | 509 (defun YaTeX-set-virtual-error-position (file-sym line-sym) |
510 "Replace the value of FILE-SYM, LINE-SYM by virtual error position." | |
511 (cond | |
512 ((and (get 'dvi2-command 'region) | |
513 (> (symbol-value line-sym) (car (get 'dvi2-command 'offset)))) | |
514 (set file-sym (get 'dvi2-command 'file)) | |
515 (set line-sym | |
516 (+ (- (apply '- (get 'dvi2-command 'offset))) | |
517 (symbol-value line-sym) | |
518 -1))))) | |
519 | |
51 | 520 (defun YaTeX-prev-error () |
521 "Visit previous typeset error. | |
522 To avoid making confliction of line numbers by editing, jump to | |
523 error or warning lines in reverse order." | |
524 (interactive) | |
525 (let ((cur-buf (buffer-name)) (cur-win (selected-window)) | |
80 | 526 b0 errorp error-line typeset-win error-buffer error-win) |
51 | 527 (if (null (get-buffer YaTeX-typeset-buffer)) |
528 (error "There is no typesetting buffer.")) | |
529 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
530 (setq typeset-win (selected-window)) | |
531 (if (re-search-backward | |
532 (concat "\\(" latex-error-regexp "\\)\\|\\(" | |
533 latex-warning-regexp "\\)") | |
534 nil t) | |
80 | 535 (setq errorp (match-beginning 1)) |
51 | 536 (select-window cur-win) |
68 | 537 (error "No more errors on %s" cur-buf)) |
80 | 538 (goto-char (setq b0 (match-beginning 0))) |
51 | 539 (skip-chars-forward "^0-9" (match-end 0)) |
540 (setq error-line | |
541 (string-to-int | |
542 (buffer-substring | |
543 (point) | |
544 (progn (skip-chars-forward "0-9" (match-end 0)) (point)))) | |
70 | 545 error-buffer (expand-file-name (YaTeX-get-error-file cur-buf))) |
51 | 546 (if (or (null error-line) (equal 0 error-line)) |
547 (error "Can't detect error position.")) | |
52 | 548 (YaTeX-set-virtual-error-position 'error-buffer 'error-line) |
549 (setq error-win (get-buffer-window error-buffer)) | |
51 | 550 (select-window cur-win) |
551 (cond | |
552 (error-win (select-window error-win)) | |
553 ((eq (get-lru-window) typeset-win) | |
554 (YaTeX-switch-to-buffer error-buffer)) | |
555 (t (select-window (get-lru-window)) | |
556 (YaTeX-switch-to-buffer error-buffer))) | |
557 (setq error-win (selected-window)) | |
558 (goto-line error-line) | |
559 (message "LaTeX %s in `%s' on line: %d." | |
80 | 560 (if errorp "error" "warning") |
51 | 561 error-buffer error-line) |
562 (select-window typeset-win) | |
563 (skip-chars-backward "0-9") | |
564 (recenter (/ (window-height) 2)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
565 (sit-for 1) |
80 | 566 (goto-char b0) |
69 | 567 (select-window error-win))) |
51 | 568 |
569 (defun YaTeX-jump-error-line () | |
570 "Jump to corresponding line on latex command's error message." | |
571 (interactive) | |
572 (let (error-line error-file error-buf) | |
573 (save-excursion | |
574 (beginning-of-line) | |
575 (setq error-line (re-search-forward "l[ ines]*\\.?\\([1-9][0-9]*\\)" | |
576 (point-end-of-line) t))) | |
577 (if (null error-line) | |
578 (if (eobp) (insert (this-command-keys)) | |
579 (error "No line number expression.")) | |
580 (goto-char (match-beginning 0)) | |
581 (setq error-line (string-to-int | |
582 (buffer-substring (match-beginning 1) (match-end 1))) | |
70 | 583 error-file (expand-file-name |
584 (YaTeX-get-error-file YaTeX-current-TeX-buffer))) | |
52 | 585 (YaTeX-set-virtual-error-position 'error-file 'error-line) |
586 (setq error-buf (YaTeX-switch-to-buffer error-file t))) | |
51 | 587 (if (null error-buf) |
588 (error "`%s' is not found in this directory." error-file)) | |
589 (YaTeX-showup-buffer error-buf nil t) | |
69 | 590 (goto-line error-line))) |
51 | 591 |
592 (defun YaTeX-send-string () | |
593 "Send string to current typeset process." | |
594 (interactive) | |
595 (if (and (eq (process-status YaTeX-typeset-process) 'run) | |
596 (>= (point) (process-mark YaTeX-typeset-process))) | |
597 (let ((b (process-mark YaTeX-typeset-process)) | |
598 (e (point-end-of-line))) | |
599 (goto-char b) | |
600 (skip-chars-forward " \t" e) | |
601 (setq b (point)) | |
602 (process-send-string | |
603 YaTeX-typeset-process (concat (buffer-substring b e) "\n")) | |
604 (goto-char e) | |
605 (insert "\n") | |
606 (set-marker (process-mark YaTeX-typeset-process) (point)) | |
607 (insert " ")) | |
69 | 608 (ding))) |
51 | 609 |
610 (defun YaTeX-view-error () | |
611 (interactive) | |
612 (if (null (get-buffer YaTeX-typeset-buffer)) | |
613 (message "No typeset buffer found.") | |
614 (let ((win (selected-window))) | |
615 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
616 ;; Next 3 lines are obsolete because YaTeX-typesetting-buffer is | |
617 ;; automatically scrolled up at typesetting. | |
618 ;;(goto-char (point-max)) | |
619 ;;(forward-line -1) | |
620 ;;(recenter -1) | |
69 | 621 (select-window win)))) |
51 | 622 |
623 (defun YaTeX-get-error-file (default) | |
624 "Get current processing file from typesetting log." | |
625 (save-excursion | |
626 (let(s) | |
627 (condition-case () (up-list -1) | |
628 (error | |
629 (let ((list 0) found) | |
630 (while | |
631 (and (<= list 0) (not found) | |
632 (re-search-backward "\\((\\)\\|\\()\\)" nil t)) | |
633 (if (equal (match-beginning 0) (match-beginning 2)) ;close paren. | |
634 (setq list (1- list)) ;open paren | |
635 (setq list (1+ list)) | |
636 (if (= list 1) | |
637 (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty") | |
638 (setq found t) | |
639 (setq list (1- list))))))))) | |
640 (setq s | |
641 (buffer-substring | |
642 (progn (forward-char 1) (point)) | |
643 (progn (skip-chars-forward "^ \n" (point-end-of-line)) | |
644 (point)))) | |
69 | 645 (if (string= "" s) default s)))) |
51 | 646 |
647 (defun YaTeX-put-nonstopmode () | |
64 | 648 (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop) |
51 | 649 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t) |
650 nil ;if already written in text then do nothing | |
651 (save-excursion | |
652 (YaTeX-visit-main t) | |
653 (goto-char (point-min)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
654 (insert "\\nonstopmode{}%_YaTeX_%\n") |
69 | 655 (if (buffer-file-name) (basic-save-buffer)))))) |
51 | 656 |
657 (defun YaTeX-remove-nonstopmode () | |
64 | 658 (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop) ;for speed |
51 | 659 (save-excursion |
660 (YaTeX-visit-main t) | |
661 (goto-char (point-min)) | |
662 (forward-line 1) | |
663 (narrow-to-region (point-min) (point)) | |
664 (goto-char (point-min)) | |
665 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$") | |
69 | 666 (widen)))) |
51 | 667 |
80 | 668 (defvar YaTeX-dvi2-command-ext-alist |
669 '(("[agx]dvi\\|dviout" . ".dvi") | |
670 ("ghostview\\|gv" . ".ps") | |
86 | 671 ("acroread\\|pdf\\|Preview\\|TeXShop\\|Skim" . ".pdf"))) |
80 | 672 |
86 | 673 (defun YaTeX-get-preview-file-name (&optional preview-command) |
51 | 674 "Get file name to preview by inquiring YaTeX-get-latex-command" |
86 | 675 (if (null preview-command) (setq preview-command dvi2-command)) |
51 | 676 (let* ((latex-cmd (YaTeX-get-latex-command t)) |
677 (rin (rindex latex-cmd ? )) | |
678 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) "")) | |
86 | 679 (r (YaTeX-assoc-regexp preview-command YaTeX-dvi2-command-ext-alist)) |
80 | 680 (ext (if r (cdr r) "")) |
51 | 681 (period)) |
80 | 682 (concat |
683 (if (string= fname "") | |
51 | 684 (setq fname (substring (file-name-nondirectory |
685 (buffer-file-name)) | |
686 0 -4)) | |
687 (setq period (rindex fname ?.)) | |
80 | 688 (setq fname (substring fname 0 (if (eq -1 period) nil period)))) |
689 ext))) | |
51 | 690 |
691 (defun YaTeX-get-latex-command (&optional switch) | |
692 "Specify the latex-command name and its argument. | |
693 If there is a line which begins with string: \"%#!\", the following | |
694 strings are assumed to be the latex-command and arguments. The | |
695 default value of latex-command is: | |
696 tex-command FileName | |
697 and if you write \"%#!jlatex\" in the beginning of certain line. | |
698 \"jlatex \" FileName | |
699 will be the latex-command, | |
700 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH | |
701 is non-nil, then | |
702 \"jlatex main.tex\" | |
703 | |
704 will be given to the shell." | |
80 | 705 (let (parent tparent magic) |
51 | 706 (setq parent |
707 (cond | |
80 | 708 (YaTeX-parent-file |
709 (if YaTeX-dos (expand-file-name YaTeX-parent-file) | |
710 YaTeX-parent-file)) | |
51 | 711 (t (save-excursion |
712 (YaTeX-visit-main t) | |
713 (file-name-nondirectory (buffer-file-name))))) | |
80 | 714 magic (YaTeX-get-builtin "!") |
715 tparent (file-name-nondirectory parent)) | |
716 (YaTeX-replace-formats | |
717 (cond | |
718 (magic | |
719 (cond | |
720 (switch (if (string-match "\\s " magic) magic | |
721 (concat magic " " parent))) | |
722 (t (concat (substring magic 0 (string-match "\\s " magic)) " ")))) | |
723 (t (concat tex-command " " (if switch parent)))) | |
724 (list (cons "f" tparent) | |
725 (cons "r" (substring tparent 0 (rindex tparent ?.))))))) | |
51 | 726 |
727 (defvar YaTeX-lpr-command-history nil | |
728 "Holds command line history of YaTeX-lpr.") | |
729 (put 'YaTeX-lpr-command-history 'no-default t) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
730 (defvar YaTeX-lpr-ask-page-range-default t) |
51 | 731 (defun YaTeX-lpr (arg) |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
732 "Print out. |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
733 If prefix arg ARG is non nil, call print driver without |
51 | 734 page range description." |
735 (interactive "P") | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
736 (or YaTeX-lpr-ask-page-range-default (setq arg (not arg))) |
51 | 737 (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)) |
52 | 738 from to (lbuffer "*dvi-printing*") dir) |
51 | 739 (setq |
740 cmd | |
741 (YaTeX-replace-format | |
742 cmd "f" | |
743 (if (or arg (not (string-match "%f" cmd))) | |
744 "" | |
745 (YaTeX-replace-format | |
746 dviprint-from-format | |
747 "b" | |
748 (if (string= | |
749 (setq from (read-string "From page(default 1): ")) "") | |
750 "1" from)))) | |
751 ) | |
752 (setq | |
753 cmd | |
754 (YaTeX-replace-format | |
755 cmd "t" | |
756 (if (or arg (not (string-match "%t" cmd)) | |
757 (string= | |
758 (setq to (read-string "To page(default none): ")) "")) | |
759 "" | |
760 (YaTeX-replace-format dviprint-to-format "e" to))) | |
761 ) | |
72 | 762 (setq |
763 cmd | |
764 (YaTeX-replace-format | |
765 cmd "p" | |
766 (cdr (assoc (YaTeX-get-paper-type) YaTeX-dvips-paper-option-alist)))) | |
51 | 767 (setq cmd |
768 (read-string-with-history | |
769 "Edit command line: " | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
770 (format cmd |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
771 (if (get 'dvi2-command 'region) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
772 (substring YaTeX-texput-file |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
773 0 (rindex YaTeX-texput-file ?.)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
774 (YaTeX-get-preview-file-name))) |
51 | 775 'YaTeX-lpr-command-history)) |
776 (save-excursion | |
777 (YaTeX-visit-main t) ;;change execution directory | |
52 | 778 (setq dir default-directory) |
51 | 779 (YaTeX-showup-buffer |
780 lbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
781 (set-buffer (get-buffer-create lbuffer)) | |
782 (erase-buffer) | |
52 | 783 (cd dir) ;for 19 |
51 | 784 (cond |
64 | 785 ((not (fboundp 'start-process)) |
51 | 786 (call-process shell-file-name "con" "*dvi-printing*" nil |
787 YaTeX-shell-command-option cmd)) | |
788 (t | |
789 (set-process-buffer | |
86 | 790 (let ((process-connection-type nil)) |
791 (start-process "print" "*dvi-printing*" shell-file-name | |
792 YaTeX-shell-command-option cmd)) | |
51 | 793 (get-buffer lbuffer)) |
69 | 794 (message "Starting printing command: %s..." cmd)))))) |
51 | 795 |
796 (defun YaTeX-main-file-p () | |
797 "Return if current buffer is main LaTeX source." | |
798 (cond | |
52 | 799 (YaTeX-parent-file |
800 (eq (get-file-buffer YaTeX-parent-file) (current-buffer))) | |
51 | 801 ((YaTeX-get-builtin "!") |
70 | 802 (string-match |
803 (concat "^" (YaTeX-guess-parent (YaTeX-get-builtin "!"))) | |
804 (buffer-name))) | |
51 | 805 (t |
806 (save-excursion | |
57 | 807 (let ((latex-main-id |
808 (concat "^\\s *" YaTeX-ec-regexp "document\\(style\\|class\\)"))) | |
51 | 809 (or (re-search-backward latex-main-id nil t) |
69 | 810 (re-search-forward latex-main-id nil t))))))) |
51 | 811 |
812 (defun YaTeX-visit-main (&optional setbuf) | |
813 "Switch buffer to main LaTeX source. | |
814 Use set-buffer instead of switch-to-buffer if the optional second argument | |
815 SETBUF is t(Use it only from Emacs-Lisp program)." | |
816 (interactive "P") | |
817 (if (and (interactive-p) setbuf) (setq YaTeX-parent-file nil)) | |
70 | 818 (let ((ff (function (lambda (f) |
819 (if setbuf (set-buffer (find-file-noselect f)) | |
820 (find-file f))))) | |
821 b-in main-file YaTeX-create-file-prefix-g | |
822 (hilit-auto-highlight (not setbuf))) | |
51 | 823 (if (setq b-in (YaTeX-get-builtin "!")) |
824 (setq main-file (YaTeX-guess-parent b-in))) | |
825 (if YaTeX-parent-file | |
826 (setq main-file ;;(get-file-buffer YaTeX-parent-file) | |
827 YaTeX-parent-file)) | |
828 (if (YaTeX-main-file-p) | |
829 (if (interactive-p) (message "I think this is main LaTeX source.") nil) | |
830 (cond | |
70 | 831 ((and ;;(interactive-p) |
832 main-file | |
833 (cond ((get-file-buffer main-file) | |
834 (cond | |
835 (setbuf (set-buffer (get-file-buffer main-file))) | |
836 ((get-buffer-window (get-file-buffer main-file)) | |
837 (select-window | |
838 (get-buffer-window (get-file-buffer main-file)))) | |
839 (t (switch-to-buffer (get-file-buffer main-file))))) | |
840 ((file-exists-p main-file) | |
841 (funcall ff main-file))))) | |
842 ;;((and main-file (YaTeX-switch-to-buffer main-file setbuf))) | |
51 | 843 ((and main-file |
844 (file-exists-p (setq main-file (concat "../" main-file))) | |
80 | 845 (or b-in |
846 (y-or-n-p (concat (expand-file-name main-file) | |
847 " is main file?:")))) | |
51 | 848 (setq YaTeX-parent-file main-file) |
70 | 849 ;(YaTeX-switch-to-buffer main-file setbuf) |
850 (funcall ff main-file) | |
851 ) | |
51 | 852 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1)) |
853 (setq YaTeX-parent-file main-file) | |
70 | 854 ; (YaTeX-switch-to-buffer main-file setbuf)) |
855 (funcall ff main-file)) | |
51 | 856 ))) |
69 | 857 nil) |
51 | 858 |
859 (defun YaTeX-guess-parent (command-line) | |
860 (setq command-line | |
861 (if (string-match ".*\\s " command-line) | |
862 (substring command-line (match-end 0)) | |
863 (file-name-nondirectory (buffer-file-name))) | |
864 command-line | |
865 (concat (if (string-match "\\(.*\\)\\." command-line) | |
866 (substring command-line (match-beginning 1) (match-end 1)) | |
867 command-line) | |
69 | 868 ".tex"))) |
51 | 869 |
870 (defun YaTeX-visit-main-other-window () | |
871 "Switch to buffer main LaTeX source in other window." | |
872 (interactive) | |
873 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.") | |
874 (YaTeX-switch-to-buffer-other-window | |
69 | 875 (concat (YaTeX-get-preview-file-name) ".tex")))) |
51 | 876 |
877 (defun YaTeX-get-builtin (key) | |
878 "Read source built-in command of %# usage." | |
879 (save-excursion | |
880 (goto-char (point-min)) | |
881 (if (and (re-search-forward | |
882 (concat "^" (regexp-quote (concat "%#" key))) nil t) | |
883 (not (eolp))) | |
80 | 884 (YaTeX-buffer-substring |
51 | 885 (progn (skip-chars-forward " " (point-end-of-line))(point)) |
886 (point-end-of-line)) | |
69 | 887 nil))) |
51 | 888 |
889 (defun YaTeX-save-buffers () | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
890 "Save buffers whose major-mode is equal to current major-mode." |
51 | 891 (basic-save-buffer) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
892 (let ((cmm major-mode)) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
893 (save-excursion |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
894 (mapcar '(lambda (buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
895 (set-buffer buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
896 (if (and (buffer-file-name buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
897 (eq major-mode cmm) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
898 (buffer-modified-p buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
899 (y-or-n-p (format "Save %s" (buffer-name buf)))) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
900 (save-buffer buf))) |
69 | 901 (buffer-list))))) |
51 | 902 |
903 (provide 'yatexprc) |