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