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