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