annotate yatexprc.el @ 51:b0371b6ed799

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

yatex.org