yatex

annotate yatexprc.el @ 355:6c67a826f266

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