yatex

annotate yatexprc.el @ 79:0734be649cb8

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