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