Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexprc.el @ 326:d989511a492a dev
Keep YaTeX-parent-file in absolute-path
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Wed, 05 Nov 2014 09:09:22 +0900 |
parents | 2561570d7194 |
children | d972598d233b |
rev | line source |
---|---|
287 | 1 ;;; yatexprc.el --- YaTeX process handler |
2 ;;; | |
294 | 3 ;;; (c)1993-2013 by HIROSE Yuuji.[yuuji@yatex.org] |
326
d989511a492a
Keep YaTeX-parent-file in absolute-path
HIROSE Yuuji <yuuji@gentei.org>
parents:
325
diff
changeset
|
4 ;;; Last modified Wed Nov 5 09:07:25 2014 on firestorm |
51 | 5 ;;; $Id$ |
6 | |
287 | 7 ;;; Code: |
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 |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
58 (defvar YaTeX-typeset-marker nil) |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
59 (defvar YaTeX-typeset-consumption nil) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
60 (make-variable-buffer-local 'YaTeX-typeset-consumption) |
213 | 61 (defun YaTeX-typeset (command buffer &optional prcname modename ppcmd) |
51 | 62 "Execute jlatex (or other) to LaTeX typeset." |
63 (interactive) | |
64 (save-excursion | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
65 (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer)) |
64 | 66 (map YaTeX-typesetting-mode-map) |
67 (outcode | |
68 (cond ((eq major-mode 'yatex-mode) YaTeX-coding-system) | |
69 | 69 ((eq major-mode 'yahtml-mode) yahtml-kanji-code)))) |
51 | 70 (if (and YaTeX-typeset-process |
71 (eq (process-status YaTeX-typeset-process) 'run)) | |
72 ;; if tex command is halting. | |
73 (YaTeX-kill-typeset-process YaTeX-typeset-process)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
74 (YaTeX-put-nonstopmode) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
75 (setq prcname (or prcname "LaTeX") |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
76 modename (or modename "typeset")) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
77 (if (eq major-mode 'yatex-mode) (YaTeX-visit-main t)) ;;execution dir |
51 | 78 (setq execdir default-directory) |
79 ;;Select lower-most window if there are more than 2 windows and | |
80 ;;typeset buffer not seen. | |
81 (YaTeX-showup-buffer | |
82 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
83 (set-buffer (get-buffer-create buffer)) | |
84 (setq default-directory execdir) | |
85 (cd execdir) | |
213 | 86 (erase-buffer) |
51 | 87 (cond |
64 | 88 ((not (fboundp 'start-process)) ;YaTeX-dos;if MS-DOS |
51 | 89 (call-process |
64 | 90 shell-file-name nil buffer nil YaTeX-shell-command-option command)) |
51 | 91 (t ;if UNIX |
92 (set-process-buffer | |
93 (setq YaTeX-typeset-process | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
94 (start-process prcname buffer shell-file-name |
51 | 95 YaTeX-shell-command-option command)) |
96 (get-buffer buffer)) | |
123 | 97 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel) |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
98 (put 'YaTeX-typeset-process 'thiscmd command) |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
99 (put 'YaTeX-typeset-process 'name prcname) |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
100 (if (fboundp 'current-time) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
101 (setq YaTeX-typeset-consumption |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
102 (cons (cons 'time (current-time)) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
103 (delq 'time YaTeX-typeset-consumption)))) |
123 | 104 (let ((ppprop (get 'YaTeX-typeset-process 'ppcmd))) |
105 (setq ppprop (delq (assq YaTeX-typeset-process ppprop) ppprop)) | |
106 (if ppcmd | |
107 (setq ppprop (cons (cons YaTeX-typeset-process ppcmd) ppprop))) | |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
108 (put 'YaTeX-typeset-process 'ppcmd ppprop)) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
109 (if (and (boundp 'bibcmd) bibcmd) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
110 (let ((bcprop (get 'YaTeX-typeset-process 'bibcmd))) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
111 (setq bcprop (cons |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
112 (cons YaTeX-typeset-process bibcmd) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
113 (delq (assq YaTeX-typeset-process bcprop) bcprop))) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
114 (put 'YaTeX-typeset-process 'bibcmd bcprop))))) |
51 | 115 (message (format "Calling `%s'..." command)) |
116 (setq YaTeX-current-TeX-buffer (buffer-name)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
117 (use-local-map map) ;map may be localized |
51 | 118 (set-syntax-table YaTeX-typeset-buffer-syntax) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
119 (setq mode-name modename) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
120 (if YaTeX-typeset-process ;if process is running (maybe on UNIX) |
64 | 121 (cond ((fboundp 'set-current-process-coding-system) |
51 | 122 (set-current-process-coding-system |
64 | 123 YaTeX-latex-message-code outcode)) |
124 ((fboundp 'set-process-coding-system) | |
125 (set-process-coding-system | |
126 YaTeX-typeset-process YaTeX-latex-message-code outcode)) | |
127 (YaTeX-emacs-20 | |
128 (set-buffer-process-coding-system | |
129 YaTeX-latex-message-code outcode)) | |
51 | 130 ((boundp 'NEMACS) |
131 (set-kanji-process-code YaTeX-latex-message-code)))) | |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
132 (set-marker (or YaTeX-typeset-marker |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
133 (setq YaTeX-typeset-marker (make-marker))) |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
134 (point)) |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
135 (insert (format "Call `%s'\n" command)) |
51 | 136 (if YaTeX-dos (message "Done.") |
137 (insert " ") | |
138 (set-marker (process-mark YaTeX-typeset-process) (1- (point)))) | |
139 (if (bolp) (forward-line -1)) ;what for? | |
140 (if (and YaTeX-emacs-19 window-system) | |
141 (let ((win (get-buffer-window buffer t)) owin) | |
142 (select-frame (window-frame win)) | |
143 (setq owin (selected-window)) | |
144 (select-window win) | |
145 (goto-char (point-max)) | |
146 (recenter -1) | |
147 (select-window owin)) | |
148 (select-window (get-buffer-window buffer)) | |
149 (goto-char (point-max)) | |
150 (recenter -1)) | |
151 (select-window window) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
152 (switch-to-buffer cb) |
69 | 153 (YaTeX-remove-nonstopmode)))) |
51 | 154 |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
155 (defvar YaTeX-typeset-auto-rerun t |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
156 "*Non-nil automatically reruns typesetter when cross-refs update found. |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
157 This is a toy mechanism. DO NOT RELY ON THIS MECHANISM. |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
158 You SHOULD check the integrity of cross-references with your eyes!! |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
159 Supplying an integer to this variable inhibit compulsory call of bibtex, |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
160 thus, it call bibtex only if warning messages about citation are seen.") |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
161 (defvar YaTeX-typeset-rerun-msg "Rerun to get cross-references right.") |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
162 (defvar YaTeX-typeset-citation-msg |
261
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
163 "Warning: Citation \`") |
51 | 164 (defun YaTeX-typeset-sentinel (proc mes) |
165 (cond ((null (buffer-name (process-buffer proc))) | |
166 ;; buffer killed | |
167 (set-process-buffer proc nil)) | |
168 ((memq (process-status proc) '(signal exit)) | |
169 (let* ((obuf (current-buffer)) (pbuf (process-buffer proc)) | |
170 (pwin (get-buffer-window pbuf)) | |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
171 (owin (selected-window)) win |
261
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
172 tobecalled shortname |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
173 (thiscmd (get 'YaTeX-typeset-process 'thiscmd)) |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
174 (ppprop (get 'YaTeX-typeset-process 'ppcmd)) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
175 (ppcmd (cdr (assq proc ppprop))) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
176 (bcprop (get 'YaTeX-typeset-process 'bibcmd)) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
177 (bibcmd (cdr (assq proc bcprop)))) |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
178 (put 'YaTeX-typeset-process 'ppcmd ;erase ppcmd |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
179 (delq (assq proc ppprop) ppprop)) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
180 (put 'YaTeX-typeset-process 'bibcmd ;erase bibcmd |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
181 (delq (assq proc bcprop) bcprop)) |
51 | 182 ;; save-excursion isn't the right thing if |
183 ;; process-buffer is current-buffer | |
184 (unwind-protect | |
185 (progn | |
186 ;; Write something in *typesetting* and hack its mode line | |
187 (if pwin | |
188 (select-window pwin) | |
189 (set-buffer pbuf)) | |
190 ;;(YaTeX-showup-buffer pbuf nil t) | |
191 (goto-char (point-max)) | |
192 (if pwin (recenter -3)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
193 (insert ?\n mode-name " " mes) |
51 | 194 (forward-char -1) |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
195 (insert |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
196 (format " at %s%s\n" |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
197 (substring (current-time-string) 0 -5) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
198 (if (and (fboundp 'current-time) (fboundp 'float) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
199 (assq 'time YaTeX-typeset-consumption)) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
200 (format |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
201 " (%.2f secs)" |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
202 (YaTeX-elapsed-time |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
203 (cdr (assq 'time YaTeX-typeset-consumption)) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
204 (current-time)))))) |
51 | 205 (setq mode-line-process |
206 (concat ": " | |
207 (symbol-name (process-status proc)))) | |
256
b1e70dc23208
Clarify messages for typesetting process.
HIROSE Yuuji <yuuji@gentei.org>
parents:
230
diff
changeset
|
208 (message "%s %s" mode-name |
51 | 209 (if (eq (process-status proc) 'exit) |
210 "done" "ceased")) | |
211 ;; If buffer and mode line shows that the process | |
212 ;; is dead, we can delete it now. Otherwise it | |
213 ;; will stay around until M-x list-processes. | |
214 (delete-process proc) | |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
215 (if (cond |
263
808f532d68d3
Inhibit auto-rerun of bibtex when using latexmk.
HIROSE Yuuji <yuuji@gentei.org>
parents:
262
diff
changeset
|
216 ((or (not YaTeX-typeset-auto-rerun) |
808f532d68d3
Inhibit auto-rerun of bibtex when using latexmk.
HIROSE Yuuji <yuuji@gentei.org>
parents:
262
diff
changeset
|
217 (string-match "latexmk" thiscmd)) |
808f532d68d3
Inhibit auto-rerun of bibtex when using latexmk.
HIROSE Yuuji <yuuji@gentei.org>
parents:
262
diff
changeset
|
218 nil) |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
219 ((and bibcmd ;Call bibtex if bibcmd defined && |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
220 (or ; (1st call || warning found) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
221 (and (not (numberp YaTeX-typeset-auto-rerun)) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
222 ; cancel call at 1st, if value is a number. |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
223 (not (string-match "bibtex" mode-name))) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
224 (re-search-backward |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
225 YaTeX-typeset-citation-msg |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
226 YaTeX-typeset-marker t)) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
227 (save-excursion ; && using .bbl files. |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
228 (search-backward |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
229 ".bbl" YaTeX-typeset-marker t))) |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
230 ;; Always call bibtex after the first typesetting, |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
231 ;; because bibtex doesn't warn disappeared \cite. |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
232 ;; (Suggested by ryseto. 2012) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
233 ;; It is more efficient to call bibtex directly than |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
234 ;; to call it after deep inspection on the balance |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
235 ;; of \cite vs. \bib*'s referring all *.aux files. |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
236 (insert "\n" YaTeX-typeset-rerun-msg "\n") |
261
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
237 (setq tobecalled bibcmd shortname "+bibtex")) |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
238 ((or |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
239 (save-excursion |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
240 (search-backward |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
241 YaTeX-typeset-rerun-msg YaTeX-typeset-marker t)) |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
242 (save-excursion |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
243 (re-search-backward |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
244 "natbib.*Rerun to get citations correct" |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
245 YaTeX-typeset-marker t))) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
246 (if bibcmd |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
247 (put 'YaTeX-typeset-process 'bibcmd |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
248 (cons (cons (get-buffer-process pbuf) bibcmd) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
249 bcprop))) |
261
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
250 (setq tobecalled thiscmd shortname "+typeset")) |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
251 (t |
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
252 nil)) ;no need to call any process |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
253 (progn |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
254 (insert |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
255 (format |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
256 "===!!! %s !!!===\n" |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
257 (message "Rerun `%s' to get cross-references right" |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
258 tobecalled))) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
259 (if (equal tobecalled thiscmd) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
260 (set-marker YaTeX-typeset-marker (point))) |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
261 (set-process-sentinel |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
262 (start-process |
261
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
263 (setq mode-name (concat mode-name shortname)) |
256
b1e70dc23208
Clarify messages for typesetting process.
HIROSE Yuuji <yuuji@gentei.org>
parents:
230
diff
changeset
|
264 pbuf |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
265 shell-file-name YaTeX-shell-command-option tobecalled) |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
266 'YaTeX-typeset-sentinel) |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
267 (if ppcmd |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
268 (put 'YaTeX-typeset-process 'ppcmd |
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
269 (cons (cons (get-buffer-process pbuf) ppcmd) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
270 ppprop))) |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
271 (if thiscmd |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
272 (put 'YaTeX-typeset-process 'thiscmd thiscmd))) |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
273 ;; If ppcmd is active, call it. |
123 | 274 (cond |
275 ((and ppcmd (string-match "finish" mes)) | |
276 (insert (format "=======> Success! Calling %s\n" ppcmd)) | |
277 (setq mode-name ; set process name | |
256
b1e70dc23208
Clarify messages for typesetting process.
HIROSE Yuuji <yuuji@gentei.org>
parents:
230
diff
changeset
|
278 (concat |
b1e70dc23208
Clarify messages for typesetting process.
HIROSE Yuuji <yuuji@gentei.org>
parents:
230
diff
changeset
|
279 mode-name "+" |
b1e70dc23208
Clarify messages for typesetting process.
HIROSE Yuuji <yuuji@gentei.org>
parents:
230
diff
changeset
|
280 (substring ppcmd 0 (string-match " " ppcmd)))) |
212
c63a4ec6a492
Rerun typesetter when cross-reference warning seen.
yuuji@gentei.org
parents:
195
diff
changeset
|
281 ; to reach here, 'start-process exists on this emacsen |
123 | 282 (set-process-sentinel |
283 (start-process | |
284 mode-name | |
285 pbuf ; Use this buffer twice. | |
286 shell-file-name YaTeX-shell-command-option | |
287 ppcmd) | |
261
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
288 'YaTeX-typeset-sentinel)) |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
289 (t ;pull back original mode-name |
261
8c555014f933
Auto-rerun supports natbib.
HIROSE Yuuji <yuuji@gentei.org>
parents:
260
diff
changeset
|
290 (setq mode-name "typeset")))) |
123 | 291 (forward-char 1)) |
292 (setq YaTeX-typeset-process nil) | |
51 | 293 ;; Force mode line redisplay soon |
294 (set-buffer-modified-p (buffer-modified-p)) | |
295 ) | |
296 (select-window owin) | |
69 | 297 (set-buffer obuf))))) |
51 | 298 |
299 (defvar YaTeX-texput-file "texput.tex" | |
69 | 300 "*File name for temporary file of typeset-region.") |
51 | 301 |
302 (defun YaTeX-typeset-region () | |
52 | 303 "Paste the region to the file `texput.tex' and execute typesetter. |
304 The region is specified by the rule: | |
51 | 305 (1)If keyword `%#BEGIN' is found in the upper direction from (point). |
306 (1-1)if the keyword `%#END' is found after `%#BEGIN', | |
307 ->Assume the text between `%#BEGIN' and `%#END' as region. | |
308 (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN', | |
309 ->Assume the text after `%#BEGIN' as region. | |
310 (2)If no `%#BEGIN' usage is found before the (point), | |
311 ->Assume the text between current (point) and (mark) as region. | |
312 DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing | |
313 operation to the region." | |
314 (interactive) | |
315 (save-excursion | |
316 (let* | |
317 ((end "") typeout ;Type out message that tells the method of cutting. | |
318 (texput YaTeX-texput-file) | |
319 (cmd (concat (YaTeX-get-latex-command nil) " " texput)) | |
320 (buffer (current-buffer)) opoint preamble (subpreamble "") main | |
321 (hilit-auto-highlight nil) ;for Emacs19 with hilit19 | |
52 | 322 reg-begin reg-end lineinfo) |
51 | 323 |
324 (save-excursion | |
325 (if (search-backward "%#BEGIN" nil t) | |
326 (progn | |
327 (setq typeout "--- Region from BEGIN to " | |
328 end "the end of the buffer ---" | |
329 reg-begin (match-end 0)) | |
330 (if (search-forward "%#END" nil t) | |
331 (setq reg-end (match-beginning 0) | |
332 end "END ---") | |
333 (setq reg-end (point-max)))) | |
52 | 334 (setq typeout "=== Region from (point) to (mark) ===" |
335 reg-begin (point) reg-end (mark))) | |
336 (goto-char (min reg-begin reg-end)) | |
337 (setq lineinfo (count-lines (point-min) (point-end-of-line))) | |
51 | 338 (goto-char (point-min)) |
339 (while (search-forward "%#REQUIRE" nil t) | |
340 (setq subpreamble | |
341 (concat subpreamble | |
342 (cond | |
343 ((eolp) | |
344 (buffer-substring | |
345 (match-beginning 0) | |
346 (point-beginning-of-line))) | |
347 (t (buffer-substring | |
348 (match-end 0) | |
349 (point-end-of-line)))) | |
350 "\n")) | |
351 (goto-char (match-end 0)))) | |
352 (YaTeX-visit-main t) | |
353 (setq main (current-buffer)) | |
354 (setq opoint (point)) | |
355 (goto-char (point-min)) | |
356 (setq | |
357 preamble | |
358 (if (re-search-forward "^[ ]*\\\\begin.*{document}" nil t) | |
359 (buffer-substring (point-min) (match-end 0)) | |
73 | 360 (concat |
361 (if YaTeX-use-LaTeX2e "\\documentclass{" "\\documentstyle{") | |
362 YaTeX-default-document-style "}\n" | |
363 "\\begin{document}"))) | |
51 | 364 (goto-char opoint) |
365 ;;(set-buffer buffer) ;for clarity | |
133
e117bfc8ce66
Do not activate any major-mode for texput.tex at typeset-region.
yuuji@gentei.org
parents:
130
diff
changeset
|
366 (let ((hilit-auto-highlight nil) (auto-mode-alist nil) |
e117bfc8ce66
Do not activate any major-mode for texput.tex at typeset-region.
yuuji@gentei.org
parents:
130
diff
changeset
|
367 (magic-mode-alist nil)) ;Do not activate yatex-mode here |
52 | 368 (set-buffer (find-file-noselect texput))) |
51 | 369 ;;(find-file YaTeX-texput-file) |
370 (erase-buffer) | |
64 | 371 (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop) |
51 | 372 (insert "\\nonstopmode{}\n")) |
373 (insert preamble "\n" subpreamble "\n") | |
52 | 374 (setq lineinfo (list (count-lines 1 (point-end-of-line)) lineinfo)) |
51 | 375 (insert-buffer-substring buffer reg-begin reg-end) |
376 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method. | |
377 (insert "\n\\end{document}\n") | |
378 (basic-save-buffer) | |
379 (kill-buffer (current-buffer)) | |
380 (set-buffer main) ;return to parent file or itself. | |
381 (YaTeX-typeset cmd YaTeX-typeset-buffer) | |
382 (switch-to-buffer buffer) ;for Emacs-19 | |
52 | 383 (put 'dvi2-command 'region t) |
384 (put 'dvi2-command 'file buffer) | |
69 | 385 (put 'dvi2-command 'offset lineinfo)))) |
51 | 386 |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
125
diff
changeset
|
387 (defun YaTeX-typeset-environment () |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
125
diff
changeset
|
388 "Typeset current math environment" |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
125
diff
changeset
|
389 (interactive) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
125
diff
changeset
|
390 (save-excursion |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
125
diff
changeset
|
391 (YaTeX-mark-environment) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
125
diff
changeset
|
392 (YaTeX-typeset-region))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
125
diff
changeset
|
393 |
123 | 394 (defun YaTeX-typeset-buffer (&optional pp) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
395 "Typeset whole buffer. |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
396 If %#! usage says other buffer is main text, |
51 | 397 visit main buffer to confirm if its includeonly list contains current |
398 buffer's file. And if it doesn't contain editing text, ask user which | |
123 | 399 action wants to be done, A:Add list, R:Replace list, %:comment-out list. |
400 If optional argument PP given as string, PP is considered as post-process | |
401 command and call it with the same command argument as typesetter without | |
402 last extension. | |
403 eg. if PP is \"dvipdfmx\", called commands as follows. | |
404 platex foo.tex | |
405 dvipdfmx foo | |
406 PP command will be called iff typeset command exit successfully" | |
51 | 407 (interactive) |
408 (YaTeX-save-buffers) | |
409 (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.))) | |
410 (mydir (file-name-directory (buffer-file-name))) | |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
411 (cmd (YaTeX-get-latex-command t)) pparg ppcmd bibcmd |
123 | 412 (cb (current-buffer))) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
413 (setq pparg (substring cmd 0 (string-match "[;&]" cmd)) ;rm multistmt |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
414 pparg (substring pparg (rindex pparg ? )) ;get last arg |
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
415 pparg (substring pparg 0 (rindex pparg ?.)) ;rm ext |
262
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
416 bibcmd (or (YaTeX-get-builtin "BIBTEX") bibtex-command)) |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
417 (or (string-match "\\s " bibcmd) ;if bibcmd has no spaces, |
15ec86ff549c
Call always bibtex after first typesetting when document needs bibtex.
HIROSE Yuuji <yuuji@gentei.org>
parents:
261
diff
changeset
|
418 (setq bibcmd (concat bibcmd pparg))) ;append argument(== %#!) |
123 | 419 (and pp |
420 (stringp pp) | |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
421 (setq ppcmd (concat pp pparg))) |
51 | 422 (if (YaTeX-main-file-p) nil |
423 (save-excursion | |
424 (YaTeX-visit-main t) ;search into main buffer | |
425 (save-excursion | |
426 (push-mark (point) t) | |
427 (goto-char (point-min)) | |
428 (if (and (re-search-forward "^[ ]*\\\\begin{document}" nil t) | |
429 (re-search-backward "^[ ]*\\\\includeonly{" nil t)) | |
430 (let* | |
431 ((b (progn (skip-chars-forward "^{") (point))) | |
432 (e (progn (skip-chars-forward "^}") (1+ (point)))) | |
433 (s (buffer-substring b e)) c | |
434 (pardir (file-name-directory (buffer-file-name)))) | |
435 (if (string-match (concat "[{,/]" me "[,}]") s) | |
436 nil ; Nothing to do when it's already in includeonly. | |
437 (ding) | |
438 (switch-to-buffer (current-buffer));Display this buffer. | |
439 (setq | |
440 me ;;Rewrite my name(me) to contain sub directory name. | |
441 (concat | |
442 (if (string-match pardir mydir) ;if mydir is child of main | |
443 (substring mydir (length pardir)) ;cut absolute path | |
444 mydir) ;else concat absolute path name. | |
445 me)) | |
446 (message | |
447 "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? " | |
448 me) | |
449 (setq c (read-char)) | |
450 (cond | |
451 ((= c ?a) | |
452 (goto-char (1+ b)) | |
453 (insert me (if (string= s "{}") "" ","))) | |
454 ((= c ?r) | |
455 (delete-region (1+ b) (1- e)) (insert me)) | |
456 ((= c ?%) | |
457 (beginning-of-line) (insert "%")) | |
458 (t nil)) | |
459 (basic-save-buffer)))) | |
460 (exchange-point-and-mark))) | |
461 (switch-to-buffer cb)) ;for 19 | |
123 | 462 (YaTeX-typeset cmd YaTeX-typeset-buffer nil nil ppcmd) |
69 | 463 (put 'dvi2-command 'region nil))) |
51 | 464 |
465 (defvar YaTeX-call-command-history nil | |
466 "Holds history list of YaTeX-call-command-on-file.") | |
467 (put 'YaTeX-call-command-history 'no-default t) | |
86 | 468 (defun YaTeX-call-command-on-file (base-cmd buffer &optional file) |
171
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
469 "Call external command BASE-CMD in the BUFFER. |
86 | 470 By default, pass the basename of current file. Optional 3rd argument |
471 FILE changes the default file name." | |
51 | 472 (YaTeX-save-buffers) |
171
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
473 (let ((default (concat base-cmd " " |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
474 (let ((me (file-name-nondirectory |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
475 (or file buffer-file-name)))) |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
476 (if (string-match "\\.tex" me) |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
477 (substring me 0 (match-beginning 0)) |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
478 me))))) |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
479 (or YaTeX-call-command-history |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
480 (setq YaTeX-call-command-history (list default))) |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
481 (YaTeX-typeset |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
482 (read-string-with-history |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
483 "Call command: " |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
484 (car YaTeX-call-command-history) |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
485 'YaTeX-call-command-history) |
670549efa5c2
YaTeX-call-command-on-file: Use last input command line as default.
yuuji@gentei.org
parents:
152
diff
changeset
|
486 buffer))) |
51 | 487 |
227
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
488 (defvar YaTeX-call-builtin-on-file) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
489 (make-variable-buffer-local 'YaTeX-call-builtin-on-file) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
490 (defun YaTeX-call-builtin-on-file (builtin-type &optional default update) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
491 "Call command on file specified by BUILTIN-TYPE." |
51 | 492 (YaTeX-save-buffers) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
493 (let*((main (or YaTeX-parent-file |
227
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
494 (save-excursion (YaTeX-visit-main t) buffer-file-name))) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
495 (mainroot (file-name-nondirectory (substring main 0 (rindex main ?.)))) |
227
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
496 (alist YaTeX-call-builtin-on-file) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
497 (b-in (or (YaTeX-get-builtin builtin-type) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
498 (cdr (assoc builtin-type alist)))) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
499 (command b-in)) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
500 (if (or update (null b-in)) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
501 (progn |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
502 (setq command (read-string-with-history |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
503 (format "%s command: " builtin-type) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
504 (or b-in |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
505 (format "%s %s" default mainroot)) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
506 'YaTeX-call-command-history)) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
507 (if (or update (null b-in)) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
508 (if (y-or-n-p "Use this command line in the future? ") |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
509 (YaTeX-getset-builtin builtin-type command) ;keep in a file |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
510 (setq YaTeX-call-builtin-on-file ;keep in memory |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
511 (cons (cons builtin-type command) |
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
512 (delete (assoc builtin-type alist) alist))))))) |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
513 (YaTeX-typeset |
227
3b2ac4652810
Handling of built-in is changed to use YaTeX-getset-builtin.
yuuji@gentei.org
parents:
224
diff
changeset
|
514 command |
224
9705855793ca
YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
yuuji@gentei.org
parents:
213
diff
changeset
|
515 (format " *YaTeX-%s*" (downcase builtin-type))))) |
51 | 516 |
517 (defun YaTeX-kill-typeset-process (proc) | |
518 "Kill process PROC after sending signal to PROC. | |
519 PROC should be process identifier." | |
520 (cond | |
68 | 521 ((not (fboundp 'start-process)) |
522 (error "This system can't have concurrent process.")) | |
51 | 523 ((or (null proc) (not (eq (process-status proc) 'run))) |
524 (message "Typesetting process is not running.")) | |
525 (t | |
526 (save-excursion | |
527 (set-buffer (process-buffer proc)) | |
528 (save-excursion | |
529 (goto-char (point-max)) | |
530 (beginning-of-line) | |
531 (if (looking-at "\\? +$") | |
532 (let ((mp (point-max))) | |
533 (process-send-string proc "x\n") | |
534 (while (= mp (point-max)) (sit-for 1)))))) | |
535 (if (eq (process-status proc) 'run) | |
536 (progn | |
537 (interrupt-process proc) | |
69 | 538 (delete-process proc)))))) |
51 | 539 |
540 (defun YaTeX-system (command buffer) | |
541 "Execute some command on buffer. Not a official function." | |
542 (save-excursion | |
543 (YaTeX-showup-buffer | |
544 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
59 | 545 (let ((df default-directory)) ;preserve current buf's pwd |
546 (set-buffer (get-buffer-create buffer)) ;1.61.3 | |
547 (setq default-directory df) | |
548 (cd df)) | |
51 | 549 (erase-buffer) |
64 | 550 (if (not (fboundp 'start-process)) |
51 | 551 (call-process |
552 shell-file-name nil buffer nil YaTeX-shell-command-option command) | |
59 | 553 (if (and (get-buffer-process buffer) |
554 (eq (process-status (get-buffer-process buffer)) 'run) | |
555 (not | |
556 (y-or-n-p (format "Process %s is running. Continue?" buffer)))) | |
557 nil | |
558 (set-process-buffer | |
559 (start-process | |
560 "system" buffer shell-file-name YaTeX-shell-command-option command) | |
69 | 561 (get-buffer buffer)))))) |
51 | 562 |
72 | 563 (defvar YaTeX-default-paper-type "a4" |
564 "*Default paper type.") | |
565 (defconst YaTeX-paper-type-alist | |
566 '(("a4paper" . "a4") | |
567 ("a5paper" . "a5") | |
568 ("b4paper" . "b4") | |
569 ("b5paper" . "b5")) | |
570 "Holds map of options and paper types.") | |
571 (defconst YaTeX-dvips-paper-option-alist | |
572 '(("a4" . "-t a4") | |
573 ("a5" . "-t a5") | |
574 ("b4" . "-t b4") | |
575 ("b5" . "-t b5") | |
576 ("a4r" . "-t landscape"); Can't specify options, `-t a4' and `-t landscape', at the same time. | |
577 ("a5r" . "-t landscape") | |
578 ("b4r" . "-t landscape") | |
579 ("b5r" . "-t landscape")) | |
580 "Holds map of dvips options and paper types.") | |
581 (defun YaTeX-get-paper-type () | |
582 "Search options in header and return a paper type, such as \"a4\", \"a4r\", etc." | |
583 (save-excursion | |
77 | 584 (YaTeX-visit-main t) |
72 | 585 (goto-char (point-min)) |
77 | 586 (let ((opts |
587 (if (re-search-forward | |
588 "^[ \t]*\\\\document\\(style\\|class\\)[ \t]*\\[\\([^]]*\\)\\]" nil t) | |
589 (YaTeX-split-string (YaTeX-match-string 2) "[ \t]*,[ \t]*")))) | |
590 (concat | |
591 (catch 'found-paper | |
592 (mapcar (lambda (pair) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
593 (if (YaTeX-member (car pair) opts) |
77 | 594 (throw 'found-paper (cdr pair)))) |
595 YaTeX-paper-type-alist) | |
596 YaTeX-default-paper-type) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
597 (if (YaTeX-member "landscape" opts) (if YaTeX-dos "L" "r") ""))))) |
72 | 598 |
51 | 599 (defvar YaTeX-preview-command-history nil |
600 "Holds minibuffer history of preview command.") | |
601 (put 'YaTeX-preview-command-history 'no-default t) | |
602 (defvar YaTeX-preview-file-history nil | |
603 "Holds minibuffer history of file to preview.") | |
604 (put 'YaTeX-preview-file-history 'no-default t) | |
605 (defun YaTeX-preview (preview-command preview-file) | |
606 "Execute xdvi (or other) to tex-preview." | |
607 (interactive | |
86 | 608 (let* ((command (read-string-with-history |
609 "Preview command: " | |
610 (YaTeX-replace-format | |
325
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
611 (or (YaTeX-get-builtin "PREVIEW") |
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
612 (if (eq (get 'dvi2-command 'format) 'pdf) |
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
613 tex-pdfview-command |
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
614 dvi2-command)) |
86 | 615 "p" (format (cond |
616 (YaTeX-dos "-y:%s") | |
617 (t "-paper %s")) | |
618 (YaTeX-get-paper-type))) | |
619 'YaTeX-preview-command-history)) | |
620 (file (read-string-with-history | |
621 "Preview file: " | |
622 (if (get 'dvi2-command 'region) | |
623 (substring YaTeX-texput-file | |
624 0 (rindex YaTeX-texput-file ?.)) | |
625 (YaTeX-get-preview-file-name command)) | |
626 'YaTeX-preview-file-history))) | |
627 (list command file))) | |
51 | 628 (setq dvi2-command preview-command) ;`dvi2command' is buffer local |
629 (save-excursion | |
630 (YaTeX-visit-main t) | |
86 | 631 (if YaTeX-dos (setq preview-file (expand-file-name preview-file))) |
51 | 632 (let ((pbuffer "*dvi-preview*") (dir default-directory)) |
633 (YaTeX-showup-buffer | |
634 pbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
635 (set-buffer (get-buffer-create pbuffer)) | |
636 (erase-buffer) | |
637 (setq default-directory dir) ;for 18 | |
638 (cd dir) ;for 19 | |
639 (cond | |
64 | 640 ((not (fboundp 'start-process)) ;if MS-DOS |
51 | 641 (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor |
642 (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
|
643 YaTeX-shell-command-option |
61 | 644 (concat preview-command " " preview-file)) |
51 | 645 (send-string-to-terminal "\e[>5l") ;show cursor |
646 (redraw-display)) | |
69 | 647 ((and (string-match "dviout" preview-command) ;maybe on `kon' |
648 (stringp (getenv "TERM")) | |
649 (string-match "^kon" (getenv "TERM"))) | |
650 (call-process shell-file-name "con" "*dvi-preview*" nil | |
651 YaTeX-shell-command-option | |
652 (concat preview-command " " preview-file))) | |
51 | 653 (t ;if UNIX |
654 (set-process-buffer | |
86 | 655 (let ((process-connection-type nil)) |
656 (start-process "preview" "*dvi-preview*" shell-file-name | |
657 YaTeX-shell-command-option | |
658 (concat preview-command " " preview-file))) | |
51 | 659 (get-buffer pbuffer)) |
660 (message | |
661 (concat "Starting " preview-command | |
69 | 662 " to preview " preview-file))))))) |
51 | 663 |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
664 (defvar YaTeX-xdvi-remote-program "xdvi") |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
665 (defun YaTeX-xdvi-remote-search (&optional region-mode) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
666 "Search string at the point on xdvi -remote window. |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
667 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
|
668 by region." |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
669 (interactive "P") |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
670 (let ((pb " *xdvi*") str proc) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
671 (save-excursion |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
672 (if region-mode |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
673 (setq str (buffer-substring (region-beginning) (region-end))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
674 (setq str (buffer-substring |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
675 (point) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
676 (progn (skip-chars-forward "^\n\\\\}") (point))))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
677 (message "Searching `%s'..." str) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
678 (if (boundp 'MULE) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
679 (define-program-coding-system |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
680 (regexp-quote pb) (regexp-quote YaTeX-xdvi-remote-program) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
681 *euc-japan*)) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
682 (setq proc |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
683 (start-process |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
684 "xdvi" pb YaTeX-xdvi-remote-program |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
685 "-remote" (format "SloppySearch(%s) " str) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
686 (concat (YaTeX-get-preview-file-name) ".dvi"))) |
69 | 687 (message "Searching `%s'...Done" str)))) |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
57
diff
changeset
|
688 |
52 | 689 (defun YaTeX-set-virtual-error-position (file-sym line-sym) |
690 "Replace the value of FILE-SYM, LINE-SYM by virtual error position." | |
691 (cond | |
692 ((and (get 'dvi2-command 'region) | |
693 (> (symbol-value line-sym) (car (get 'dvi2-command 'offset)))) | |
694 (set file-sym (get 'dvi2-command 'file)) | |
695 (set line-sym | |
696 (+ (- (apply '- (get 'dvi2-command 'offset))) | |
697 (symbol-value line-sym) | |
698 -1))))) | |
699 | |
51 | 700 (defun YaTeX-prev-error () |
230
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
701 "Visit position of previous typeset error or warning. |
51 | 702 To avoid making confliction of line numbers by editing, jump to |
703 error or warning lines in reverse order." | |
704 (interactive) | |
230
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
705 (let ((cur-buf (save-excursion (YaTeX-visit-main t) (buffer-name))) |
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
706 (cur-win (selected-window)) |
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
707 b0 bound errorp error-line typeset-win error-buffer error-win) |
51 | 708 (if (null (get-buffer YaTeX-typeset-buffer)) |
709 (error "There is no typesetting buffer.")) | |
710 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
230
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
711 (if (and (markerp YaTeX-typeset-marker) |
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
712 (eq (marker-buffer YaTeX-typeset-marker) (current-buffer))) |
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
713 (setq bound YaTeX-typeset-marker)) |
51 | 714 (setq typeset-win (selected-window)) |
715 (if (re-search-backward | |
716 (concat "\\(" latex-error-regexp "\\)\\|\\(" | |
717 latex-warning-regexp "\\)") | |
230
7f4a5db88fbb
Don't pause at re-run. YaTeX-prev-error supports re-run.
yuuji@gentei.org
parents:
227
diff
changeset
|
718 bound t) |
80 | 719 (setq errorp (match-beginning 1)) |
51 | 720 (select-window cur-win) |
68 | 721 (error "No more errors on %s" cur-buf)) |
80 | 722 (goto-char (setq b0 (match-beginning 0))) |
51 | 723 (skip-chars-forward "^0-9" (match-end 0)) |
724 (setq error-line | |
725 (string-to-int | |
726 (buffer-substring | |
727 (point) | |
728 (progn (skip-chars-forward "0-9" (match-end 0)) (point)))) | |
70 | 729 error-buffer (expand-file-name (YaTeX-get-error-file cur-buf))) |
51 | 730 (if (or (null error-line) (equal 0 error-line)) |
731 (error "Can't detect error position.")) | |
52 | 732 (YaTeX-set-virtual-error-position 'error-buffer 'error-line) |
733 (setq error-win (get-buffer-window error-buffer)) | |
51 | 734 (select-window cur-win) |
735 (cond | |
736 (error-win (select-window error-win)) | |
737 ((eq (get-lru-window) typeset-win) | |
738 (YaTeX-switch-to-buffer error-buffer)) | |
739 (t (select-window (get-lru-window)) | |
740 (YaTeX-switch-to-buffer error-buffer))) | |
741 (setq error-win (selected-window)) | |
742 (goto-line error-line) | |
743 (message "LaTeX %s in `%s' on line: %d." | |
80 | 744 (if errorp "error" "warning") |
51 | 745 error-buffer error-line) |
746 (select-window typeset-win) | |
747 (skip-chars-backward "0-9") | |
748 (recenter (/ (window-height) 2)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
749 (sit-for 1) |
80 | 750 (goto-char b0) |
69 | 751 (select-window error-win))) |
51 | 752 |
753 (defun YaTeX-jump-error-line () | |
754 "Jump to corresponding line on latex command's error message." | |
755 (interactive) | |
756 (let (error-line error-file error-buf) | |
757 (save-excursion | |
758 (beginning-of-line) | |
759 (setq error-line (re-search-forward "l[ ines]*\\.?\\([1-9][0-9]*\\)" | |
760 (point-end-of-line) t))) | |
761 (if (null error-line) | |
762 (if (eobp) (insert (this-command-keys)) | |
763 (error "No line number expression.")) | |
764 (goto-char (match-beginning 0)) | |
765 (setq error-line (string-to-int | |
766 (buffer-substring (match-beginning 1) (match-end 1))) | |
70 | 767 error-file (expand-file-name |
768 (YaTeX-get-error-file YaTeX-current-TeX-buffer))) | |
52 | 769 (YaTeX-set-virtual-error-position 'error-file 'error-line) |
770 (setq error-buf (YaTeX-switch-to-buffer error-file t))) | |
51 | 771 (if (null error-buf) |
772 (error "`%s' is not found in this directory." error-file)) | |
773 (YaTeX-showup-buffer error-buf nil t) | |
69 | 774 (goto-line error-line))) |
51 | 775 |
776 (defun YaTeX-send-string () | |
777 "Send string to current typeset process." | |
778 (interactive) | |
779 (if (and (eq (process-status YaTeX-typeset-process) 'run) | |
780 (>= (point) (process-mark YaTeX-typeset-process))) | |
781 (let ((b (process-mark YaTeX-typeset-process)) | |
782 (e (point-end-of-line))) | |
783 (goto-char b) | |
784 (skip-chars-forward " \t" e) | |
785 (setq b (point)) | |
786 (process-send-string | |
787 YaTeX-typeset-process (concat (buffer-substring b e) "\n")) | |
788 (goto-char e) | |
789 (insert "\n") | |
790 (set-marker (process-mark YaTeX-typeset-process) (point)) | |
791 (insert " ")) | |
69 | 792 (ding))) |
51 | 793 |
794 (defun YaTeX-view-error () | |
795 (interactive) | |
796 (if (null (get-buffer YaTeX-typeset-buffer)) | |
797 (message "No typeset buffer found.") | |
798 (let ((win (selected-window))) | |
799 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
800 ;; Next 3 lines are obsolete because YaTeX-typesetting-buffer is | |
801 ;; automatically scrolled up at typesetting. | |
802 ;;(goto-char (point-max)) | |
803 ;;(forward-line -1) | |
804 ;;(recenter -1) | |
69 | 805 (select-window win)))) |
51 | 806 |
807 (defun YaTeX-get-error-file (default) | |
808 "Get current processing file from typesetting log." | |
809 (save-excursion | |
810 (let(s) | |
811 (condition-case () (up-list -1) | |
812 (error | |
813 (let ((list 0) found) | |
814 (while | |
815 (and (<= list 0) (not found) | |
816 (re-search-backward "\\((\\)\\|\\()\\)" nil t)) | |
817 (if (equal (match-beginning 0) (match-beginning 2)) ;close paren. | |
818 (setq list (1- list)) ;open paren | |
819 (setq list (1+ list)) | |
820 (if (= list 1) | |
821 (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty") | |
822 (setq found t) | |
823 (setq list (1- list))))))))) | |
824 (setq s | |
825 (buffer-substring | |
826 (progn (forward-char 1) (point)) | |
827 (progn (skip-chars-forward "^ \n" (point-end-of-line)) | |
828 (point)))) | |
69 | 829 (if (string= "" s) default s)))) |
51 | 830 |
831 (defun YaTeX-put-nonstopmode () | |
64 | 832 (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop) |
51 | 833 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t) |
834 nil ;if already written in text then do nothing | |
835 (save-excursion | |
836 (YaTeX-visit-main t) | |
837 (goto-char (point-min)) | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
838 (insert "\\nonstopmode{}%_YaTeX_%\n") |
69 | 839 (if (buffer-file-name) (basic-save-buffer)))))) |
51 | 840 |
841 (defun YaTeX-remove-nonstopmode () | |
64 | 842 (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop) ;for speed |
51 | 843 (save-excursion |
844 (YaTeX-visit-main t) | |
845 (goto-char (point-min)) | |
846 (forward-line 1) | |
847 (narrow-to-region (point-min) (point)) | |
848 (goto-char (point-min)) | |
849 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$") | |
69 | 850 (widen)))) |
51 | 851 |
80 | 852 (defvar YaTeX-dvi2-command-ext-alist |
853 '(("[agx]dvi\\|dviout" . ".dvi") | |
854 ("ghostview\\|gv" . ".ps") | |
289
9f3a86e5d216
Add some pdf readers to YaTeX-dvi2-command-ext-alist.
HIROSE Yuuji <yuuji@gentei.org>
parents:
287
diff
changeset
|
855 ("acroread\\|xpdf\\|pdfopen\\|Preview\\|TeXShop\\|Skim\\|evince\\|mupdf\\|zathura\\|okular" . ".pdf"))) |
80 | 856 |
86 | 857 (defun YaTeX-get-preview-file-name (&optional preview-command) |
51 | 858 "Get file name to preview by inquiring YaTeX-get-latex-command" |
86 | 859 (if (null preview-command) (setq preview-command dvi2-command)) |
51 | 860 (let* ((latex-cmd (YaTeX-get-latex-command t)) |
861 (rin (rindex latex-cmd ? )) | |
172
429d10a0d5b2
YaTeX-typeset-buffer: Change the method of constructing ppcmd.
yuuji@gentei.org
parents:
171
diff
changeset
|
862 (fname (if rin (substring latex-cmd (1+ rin)) "")) |
86 | 863 (r (YaTeX-assoc-regexp preview-command YaTeX-dvi2-command-ext-alist)) |
172
429d10a0d5b2
YaTeX-typeset-buffer: Change the method of constructing ppcmd.
yuuji@gentei.org
parents:
171
diff
changeset
|
864 (ext (if r (cdr r) ""))) |
325
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
865 (and (null r) |
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
866 (eq (get 'dvi2-command 'format) 'pdf) |
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
867 (setq ext "pdf")) |
80 | 868 (concat |
869 (if (string= fname "") | |
172
429d10a0d5b2
YaTeX-typeset-buffer: Change the method of constructing ppcmd.
yuuji@gentei.org
parents:
171
diff
changeset
|
870 (setq fname (substring (file-name-nondirectory |
429d10a0d5b2
YaTeX-typeset-buffer: Change the method of constructing ppcmd.
yuuji@gentei.org
parents:
171
diff
changeset
|
871 (buffer-file-name)) |
429d10a0d5b2
YaTeX-typeset-buffer: Change the method of constructing ppcmd.
yuuji@gentei.org
parents:
171
diff
changeset
|
872 0 -4)) |
429d10a0d5b2
YaTeX-typeset-buffer: Change the method of constructing ppcmd.
yuuji@gentei.org
parents:
171
diff
changeset
|
873 (setq fname (substring fname 0 (rindex fname ?.)))) |
80 | 874 ext))) |
51 | 875 |
876 (defun YaTeX-get-latex-command (&optional switch) | |
877 "Specify the latex-command name and its argument. | |
878 If there is a line which begins with string: \"%#!\", the following | |
879 strings are assumed to be the latex-command and arguments. The | |
880 default value of latex-command is: | |
881 tex-command FileName | |
882 and if you write \"%#!jlatex\" in the beginning of certain line. | |
883 \"jlatex \" FileName | |
884 will be the latex-command, | |
885 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH | |
886 is non-nil, then | |
887 \"jlatex main.tex\" | |
888 | |
889 will be given to the shell." | |
80 | 890 (let (parent tparent magic) |
51 | 891 (setq parent |
892 (cond | |
80 | 893 (YaTeX-parent-file |
894 (if YaTeX-dos (expand-file-name YaTeX-parent-file) | |
895 YaTeX-parent-file)) | |
51 | 896 (t (save-excursion |
897 (YaTeX-visit-main t) | |
898 (file-name-nondirectory (buffer-file-name))))) | |
80 | 899 magic (YaTeX-get-builtin "!") |
900 tparent (file-name-nondirectory parent)) | |
901 (YaTeX-replace-formats | |
902 (cond | |
903 (magic | |
904 (cond | |
905 (switch (if (string-match "\\s " magic) magic | |
906 (concat magic " " parent))) | |
907 (t (concat (substring magic 0 (string-match "\\s " magic)) " ")))) | |
908 (t (concat tex-command " " (if switch parent)))) | |
909 (list (cons "f" tparent) | |
910 (cons "r" (substring tparent 0 (rindex tparent ?.))))))) | |
51 | 911 |
912 (defvar YaTeX-lpr-command-history nil | |
913 "Holds command line history of YaTeX-lpr.") | |
914 (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
|
915 (defvar YaTeX-lpr-ask-page-range-default t) |
51 | 916 (defun YaTeX-lpr (arg) |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
917 "Print out. |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
918 If prefix arg ARG is non nil, call print driver without |
51 | 919 page range description." |
920 (interactive "P") | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
921 (or YaTeX-lpr-ask-page-range-default (setq arg (not arg))) |
51 | 922 (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)) |
52 | 923 from to (lbuffer "*dvi-printing*") dir) |
51 | 924 (setq |
925 cmd | |
926 (YaTeX-replace-format | |
927 cmd "f" | |
928 (if (or arg (not (string-match "%f" cmd))) | |
929 "" | |
930 (YaTeX-replace-format | |
931 dviprint-from-format | |
932 "b" | |
933 (if (string= | |
934 (setq from (read-string "From page(default 1): ")) "") | |
935 "1" from)))) | |
936 ) | |
937 (setq | |
938 cmd | |
939 (YaTeX-replace-format | |
940 cmd "t" | |
941 (if (or arg (not (string-match "%t" cmd)) | |
942 (string= | |
943 (setq to (read-string "To page(default none): ")) "")) | |
944 "" | |
945 (YaTeX-replace-format dviprint-to-format "e" to))) | |
946 ) | |
72 | 947 (setq |
948 cmd | |
949 (YaTeX-replace-format | |
950 cmd "p" | |
951 (cdr (assoc (YaTeX-get-paper-type) YaTeX-dvips-paper-option-alist)))) | |
51 | 952 (setq cmd |
953 (read-string-with-history | |
954 "Edit command line: " | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
955 (format cmd |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
956 (if (get 'dvi2-command 'region) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
957 (substring YaTeX-texput-file |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
958 0 (rindex YaTeX-texput-file ?.)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
959 (YaTeX-get-preview-file-name))) |
51 | 960 'YaTeX-lpr-command-history)) |
961 (save-excursion | |
962 (YaTeX-visit-main t) ;;change execution directory | |
52 | 963 (setq dir default-directory) |
51 | 964 (YaTeX-showup-buffer |
965 lbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
966 (set-buffer (get-buffer-create lbuffer)) | |
967 (erase-buffer) | |
52 | 968 (cd dir) ;for 19 |
51 | 969 (cond |
64 | 970 ((not (fboundp 'start-process)) |
51 | 971 (call-process shell-file-name "con" "*dvi-printing*" nil |
972 YaTeX-shell-command-option cmd)) | |
973 (t | |
974 (set-process-buffer | |
86 | 975 (let ((process-connection-type nil)) |
976 (start-process "print" "*dvi-printing*" shell-file-name | |
977 YaTeX-shell-command-option cmd)) | |
51 | 978 (get-buffer lbuffer)) |
69 | 979 (message "Starting printing command: %s..." cmd)))))) |
51 | 980 |
981 (defun YaTeX-main-file-p () | |
982 "Return if current buffer is main LaTeX source." | |
983 (cond | |
52 | 984 (YaTeX-parent-file |
985 (eq (get-file-buffer YaTeX-parent-file) (current-buffer))) | |
51 | 986 ((YaTeX-get-builtin "!") |
70 | 987 (string-match |
988 (concat "^" (YaTeX-guess-parent (YaTeX-get-builtin "!"))) | |
989 (buffer-name))) | |
51 | 990 (t |
991 (save-excursion | |
57 | 992 (let ((latex-main-id |
993 (concat "^\\s *" YaTeX-ec-regexp "document\\(style\\|class\\)"))) | |
51 | 994 (or (re-search-backward latex-main-id nil t) |
69 | 995 (re-search-forward latex-main-id nil t))))))) |
51 | 996 |
997 (defun YaTeX-visit-main (&optional setbuf) | |
998 "Switch buffer to main LaTeX source. | |
122
57d3d9abd661
Search %# built-in value for parent if not found in current buffer.
yuuji@gentei.org
parents:
88
diff
changeset
|
999 Use set-buffer instead of switch-to-buffer if the optional argument |
51 | 1000 SETBUF is t(Use it only from Emacs-Lisp program)." |
1001 (interactive "P") | |
1002 (if (and (interactive-p) setbuf) (setq YaTeX-parent-file nil)) | |
70 | 1003 (let ((ff (function (lambda (f) |
1004 (if setbuf (set-buffer (find-file-noselect f)) | |
1005 (find-file f))))) | |
325
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
1006 b-in main-file mfa YaTeX-create-file-prefix-g |
70 | 1007 (hilit-auto-highlight (not setbuf))) |
51 | 1008 (if (setq b-in (YaTeX-get-builtin "!")) |
1009 (setq main-file (YaTeX-guess-parent b-in))) | |
1010 (if YaTeX-parent-file | |
1011 (setq main-file ;;(get-file-buffer YaTeX-parent-file) | |
1012 YaTeX-parent-file)) | |
1013 (if (YaTeX-main-file-p) | |
1014 (if (interactive-p) (message "I think this is main LaTeX source.") nil) | |
1015 (cond | |
70 | 1016 ((and ;;(interactive-p) |
1017 main-file | |
1018 (cond ((get-file-buffer main-file) | |
1019 (cond | |
1020 (setbuf (set-buffer (get-file-buffer main-file))) | |
1021 ((get-buffer-window (get-file-buffer main-file)) | |
1022 (select-window | |
1023 (get-buffer-window (get-file-buffer main-file)))) | |
1024 (t (switch-to-buffer (get-file-buffer main-file))))) | |
1025 ((file-exists-p main-file) | |
1026 (funcall ff main-file))))) | |
1027 ;;((and main-file (YaTeX-switch-to-buffer main-file setbuf))) | |
51 | 1028 ((and main-file |
1029 (file-exists-p (setq main-file (concat "../" main-file))) | |
80 | 1030 (or b-in |
325
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
1031 (y-or-n-p (concat (setq mfa (expand-file-name main-file)) |
80 | 1032 " is main file?:")))) |
325
2561570d7194
evince usage; YaTeX-parent-file handling:
HIROSE Yuuji <yuuji@gentei.org>
parents:
294
diff
changeset
|
1033 (setq YaTeX-parent-file mfa) |
70 | 1034 ;(YaTeX-switch-to-buffer main-file setbuf) |
1035 (funcall ff main-file) | |
1036 ) | |
51 | 1037 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1)) |
326
d989511a492a
Keep YaTeX-parent-file in absolute-path
HIROSE Yuuji <yuuji@gentei.org>
parents:
325
diff
changeset
|
1038 (setq YaTeX-parent-file (expand-file-name main-file)) |
70 | 1039 ; (YaTeX-switch-to-buffer main-file setbuf)) |
1040 (funcall ff main-file)) | |
51 | 1041 ))) |
69 | 1042 nil) |
51 | 1043 |
1044 (defun YaTeX-guess-parent (command-line) | |
1045 (setq command-line | |
1046 (if (string-match ".*\\s " command-line) | |
1047 (substring command-line (match-end 0)) | |
1048 (file-name-nondirectory (buffer-file-name))) | |
1049 command-line | |
1050 (concat (if (string-match "\\(.*\\)\\." command-line) | |
1051 (substring command-line (match-beginning 1) (match-end 1)) | |
1052 command-line) | |
69 | 1053 ".tex"))) |
51 | 1054 |
1055 (defun YaTeX-visit-main-other-window () | |
1056 "Switch to buffer main LaTeX source in other window." | |
1057 (interactive) | |
1058 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.") | |
1059 (YaTeX-switch-to-buffer-other-window | |
69 | 1060 (concat (YaTeX-get-preview-file-name) ".tex")))) |
51 | 1061 |
1062 (defun YaTeX-save-buffers () | |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1063 "Save buffers whose major-mode is equal to current major-mode." |
51 | 1064 (basic-save-buffer) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1065 (let ((cmm major-mode)) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1066 (save-excursion |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1067 (mapcar '(lambda (buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1068 (set-buffer buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1069 (if (and (buffer-file-name buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1070 (eq major-mode cmm) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1071 (buffer-modified-p buf) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
1072 (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
|
1073 (save-buffer buf))) |
69 | 1074 (buffer-list))))) |
51 | 1075 |
1076 (provide 'yatexprc) |