diff options
| author | Richard M. Stallman | 1992-07-04 16:51:02 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-07-04 16:51:02 +0000 |
| commit | 528415e7be2b96158f32a02766c0644338fe5a14 (patch) | |
| tree | ff3312c2ac68ec66d5f9e8ec0abb340e316d3452 | |
| parent | ad6023b323c8378c5f112e0fa5ceda3a61fb4bf4 (diff) | |
| download | emacs-528415e7be2b96158f32a02766c0644338fe5a14.tar.gz emacs-528415e7be2b96158f32a02766c0644338fe5a14.zip | |
*** empty log message ***
| -rw-r--r-- | lisp/files.el | 2 | ||||
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 347 | ||||
| -rw-r--r-- | src/buffer.c | 4 |
3 files changed, 208 insertions, 145 deletions
diff --git a/lisp/files.el b/lisp/files.el index 42607ff5e79..aa597d642eb 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1365,7 +1365,7 @@ With prefix arg, silently save all file-visiting buffers, then kill." | |||
| 1365 | (let ((processes (process-list)) | 1365 | (let ((processes (process-list)) |
| 1366 | active) | 1366 | active) |
| 1367 | (while processes | 1367 | (while processes |
| 1368 | (and (memq (process-status (car processes)) '(run stop)) | 1368 | (and (memq (process-status (car processes)) '(run stop open)) |
| 1369 | (let ((val (process-kill-without-query (car processes)))) | 1369 | (let ((val (process-kill-without-query (car processes)))) |
| 1370 | (process-kill-without-query (car processes) val) | 1370 | (process-kill-without-query (car processes) val) |
| 1371 | val) | 1371 | val) |
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index bc92872d951..00415ed3b0f 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -1,12 +1,10 @@ | |||
| 1 | ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands. | 1 | ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands. |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985, 1986, 1989 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985-1992 Free Software Foundation, Inc. |
| 4 | ;; Rewritten following contributions by William F. Schelter | 4 | ;; Contributions over the years by William F. Schelter, Dick King, |
| 5 | ;; and Dick King (king@kestrel). | 5 | ;; Stephen Gildea, Michael Prange, and Edward M. Reingold. |
| 6 | ;; Supported since 1986 by Stephen Gildea <gildea@erl.mit.edu> | 6 | |
| 7 | ;; and Michael Prange <prange@erl.mit.edu>. | 7 | ;; Latest revision (1992) by Edward M. Reingold <reingold@cs.uiuc.edu>. |
| 8 | ;; Various improvements and corrections in Fall, 1989 by | ||
| 9 | ;; Edward M. Reingold <reingold@cs.uiuc.edu>. | ||
| 10 | 8 | ||
| 11 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| 12 | 10 | ||
| @@ -24,44 +22,100 @@ | |||
| 24 | ;; along with GNU Emacs; see the file COPYING. If not, write to | 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to |
| 25 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 23 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | 24 | ||
| 27 | ;; Still to do: | 25 | (require 'comint) |
| 28 | ;; Make TAB indent correctly for TeX code. Then we can make Linefeed | 26 | |
| 29 | ;; do something more useful. | 27 | (defvar tex-shell-file-name nil |
| 30 | ;; | 28 | "*If non-nil, is file name to use for the subshell in which TeX is run.") |
| 31 | ;; Have spell understand TeX instead of assuming the entire world | 29 | |
| 32 | ;; uses nroff. | 30 | (defvar tex-directory "." |
| 33 | ;; | 31 | "*Directory in which temporary files are left. |
| 34 | ;; The code for finding matching $ needs to be fixed. | 32 | You can make this /tmp if your TEXINPUTS has no relative directories in it |
| 33 | and you don't try to apply \\[tex-region] or \\[tex-buffer] when there are | ||
| 34 | \\input commands with relative directories.") | ||
| 35 | 35 | ||
| 36 | (require 'oshell) | 36 | (defvar tex-offer-save t |
| 37 | (defvar tex-directory "./" | 37 | "*If non-nil, ask about saving modified buffers before \\[tex-file] is run.") |
| 38 | "*Directory in which to run TeX subjob. Temporary files are created here.") | ||
| 39 | 38 | ||
| 40 | (defvar tex-run-command "tex" | 39 | (defvar tex-run-command "tex" |
| 41 | "*Command used to run TeX subjob. | 40 | "*Command used to run TeX subjob. |
| 42 | The name of the file will be appended to this string, separated by a space.") | 41 | If this string contains an asterisk (*), it will be replaced by the |
| 42 | filename; if not, the name of the file, preceded by blank, will be added to | ||
| 43 | this string.") | ||
| 43 | 44 | ||
| 44 | (defvar latex-run-command "latex" | 45 | (defvar latex-run-command "latex" |
| 45 | "*Command used to run LaTeX subjob. | 46 | "*Command used to run LaTeX subjob. |
| 46 | The name of the file will be appended to this string, separated by a space.") | 47 | If this string contains an asterisk (*), it will be replaced by the |
| 48 | filename; if not, the name of the file, preceded by blank, will be added to | ||
| 49 | this string.") | ||
| 50 | |||
| 51 | (defvar standard-latex-block-names | ||
| 52 | '("abstract" "array" "center" "description" | ||
| 53 | "displaymath" "document" "enumerate" "eqnarray" | ||
| 54 | "eqnarray*" "equation" "figure" "figure*" | ||
| 55 | "flushleft" "flushright" "itemize" "letter" | ||
| 56 | "list" "minipage" "picture" "quotation" | ||
| 57 | "quote" "slide" "sloppypar" "tabbing" | ||
| 58 | "table" "table*" "tabular" "tabular*" | ||
| 59 | "thebibliography" "theindex*" "titlepage" "trivlist" | ||
| 60 | "verbatim" "verbatim*" "verse") | ||
| 61 | "Standard LaTeX block names.") | ||
| 62 | |||
| 63 | (defvar latex-block-names nil | ||
| 64 | "*User defined LaTeX block names. | ||
| 65 | Combined with `standard-latex-block-names' for minibuffer completion.") | ||
| 47 | 66 | ||
| 48 | (defvar slitex-run-command "slitex" | 67 | (defvar slitex-run-command "slitex" |
| 49 | "*Command used to run SliTeX subjob. | 68 | "*Command used to run SliTeX subjob. |
| 50 | The name of the file will be appended to this string, separated by a space.") | 69 | If this string contains an asterisk (*), it will be replaced by the |
| 70 | filename; if not, the name of the file, preceded by blank, will be added to | ||
| 71 | this string.") | ||
| 51 | 72 | ||
| 52 | (defvar tex-bibtex-command "bibtex" | 73 | (defvar tex-bibtex-command "bibtex" |
| 53 | "*Command string used by `tex-bibtex-file' to gather bibliographic data. | 74 | "*Command used by `tex-bibtex-file' to gather bibliographic data. |
| 54 | The name of the file will be appended to this string, separated by a space.") | 75 | If this string contains an asterisk (*), it will be replaced by the |
| 76 | filename; if not, the name of the file, preceded by blank, will be added to | ||
| 77 | this string.") | ||
| 55 | 78 | ||
| 56 | (defvar tex-dvi-print-command "lpr -d" | 79 | (defvar tex-dvi-print-command "lpr -d" |
| 57 | "*Command string used by \\[tex-print] to print a .dvi file.") | 80 | "*Command used by \\[tex-print] to print a .dvi file. |
| 81 | If this string contains an asterisk (*), it will be replaced by the | ||
| 82 | filename; if not, the name of the file, preceded by blank, will be added to | ||
| 83 | this string.") | ||
| 84 | |||
| 85 | (defvar tex-alt-dvi-print-command "lpr -d" | ||
| 86 | "*Command used by \\[tex-print] with a prefix arg to print a .dvi file. | ||
| 87 | If this string contains an asterisk (*), it will be replaced by the | ||
| 88 | filename; if not, the name of the file, preceded by blank, will be added to | ||
| 89 | this string. | ||
| 90 | |||
| 91 | If two printers are not enough of a choice, you can define the value | ||
| 92 | of tex-alt-dvi-print-command to be an expression that asks what you want; | ||
| 93 | for example, | ||
| 94 | |||
| 95 | (setq tex-alt-dvi-print-command | ||
| 96 | '(format \"lpr -P%s\" (read-string \"Use printer: \"))) | ||
| 97 | |||
| 98 | would tell \\[tex-print] with a prefix argument to ask you which printer to | ||
| 99 | use.") | ||
| 58 | 100 | ||
| 59 | (defvar tex-dvi-view-command nil | 101 | (defvar tex-dvi-view-command nil |
| 60 | "*Command string used by \\[tex-view] to display a .dvi file.") | 102 | "*Command used by \\[tex-view] to display a .dvi file. |
| 103 | If this string contains an asterisk (*), it will be replaced by the | ||
| 104 | filename; if not, the name of the file, preceded by blank, will be added to | ||
| 105 | this string. | ||
| 106 | |||
| 107 | This can be set conditionally so that the previewer used is suitable for the | ||
| 108 | window system being used. For example, | ||
| 109 | |||
| 110 | (setq tex-dvi-view-command | ||
| 111 | (if (eq window-system 'x) \"xdvi\" \"dvi2tty * | cat -s\")) | ||
| 112 | |||
| 113 | would tell \\[tex-view] use xdvi under X windows and to use dvi2tty | ||
| 114 | otherwise.") | ||
| 61 | 115 | ||
| 62 | (defvar tex-show-queue-command "lpq" | 116 | (defvar tex-show-queue-command "lpq" |
| 63 | "*Command string used by \\[tex-show-print-queue] to show the print queue. | 117 | "*Command used by \\[tex-show-print-queue] to show the print queue. |
| 64 | Should show the queue that \\[tex-print] puts jobs on.") | 118 | Should show the queue(s) that \\[tex-print] puts jobs on.") |
| 65 | 119 | ||
| 66 | (defvar tex-default-mode 'plain-tex-mode | 120 | (defvar tex-default-mode 'plain-tex-mode |
| 67 | "*Mode to enter for a new file that might be either TeX or LaTeX. | 121 | "*Mode to enter for a new file that might be either TeX or LaTeX. |
| @@ -75,9 +129,14 @@ Normally set to either 'plain-tex-mode or 'latex-mode.") | |||
| 75 | (defvar tex-close-quote "''" | 129 | (defvar tex-close-quote "''" |
| 76 | "*String inserted by typing \\[tex-insert-quote] to close a quotation.") | 130 | "*String inserted by typing \\[tex-insert-quote] to close a quotation.") |
| 77 | 131 | ||
| 132 | (defvar tex-last-temp-file nil | ||
| 133 | "Latest temporary file generated by \\[tex-region] and \\[tex-buffer]. | ||
| 134 | Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the | ||
| 135 | tex-shell goes away.") | ||
| 136 | |||
| 78 | (defvar tex-command nil | 137 | (defvar tex-command nil |
| 79 | "Command to run TeX. | 138 | "Command to run TeX. |
| 80 | The name of the file will be appended to this string, separated by a space.") | 139 | The name of the file, preceded by a blank, will be added to this string.") |
| 81 | 140 | ||
| 82 | (defvar tex-trailer nil | 141 | (defvar tex-trailer nil |
| 83 | "String appended after the end of a region sent to TeX by \\[tex-region].") | 142 | "String appended after the end of a region sent to TeX by \\[tex-region].") |
| @@ -133,7 +192,7 @@ Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].") | |||
| 133 | (define-key tex-mode-map "\C-c\C-e" 'tex-close-latex-block)) | 192 | (define-key tex-mode-map "\C-c\C-e" 'tex-close-latex-block)) |
| 134 | 193 | ||
| 135 | (defvar tex-shell-map nil | 194 | (defvar tex-shell-map nil |
| 136 | "Keymap for the tex-shell. A shell-mode-map with a few additions.") | 195 | "Keymap for the tex-shell. A comint-mode-map with a few additions.") |
| 137 | 196 | ||
| 138 | ;(fset 'TeX-mode 'tex-mode) ;in loaddefs. | 197 | ;(fset 'TeX-mode 'tex-mode) ;in loaddefs. |
| 139 | 198 | ||
| @@ -198,6 +257,9 @@ tex-directory | |||
| 198 | run by \\[tex-region] or \\[tex-buffer]. | 257 | run by \\[tex-region] or \\[tex-buffer]. |
| 199 | tex-dvi-print-command | 258 | tex-dvi-print-command |
| 200 | Command string used by \\[tex-print] to print a .dvi file. | 259 | Command string used by \\[tex-print] to print a .dvi file. |
| 260 | tex-alt-dvi-print-command | ||
| 261 | Alternative command string used by \\[tex-print] (when given a prefix | ||
| 262 | argument) to print a .dvi file. | ||
| 201 | tex-dvi-view-command | 263 | tex-dvi-view-command |
| 202 | Command string used by \\[tex-view] to preview a .dvi file. | 264 | Command string used by \\[tex-view] to preview a .dvi file. |
| 203 | tex-show-queue-command | 265 | tex-show-queue-command |
| @@ -248,6 +310,9 @@ tex-directory | |||
| 248 | run by \\[tex-region] or \\[tex-buffer]. | 310 | run by \\[tex-region] or \\[tex-buffer]. |
| 249 | tex-dvi-print-command | 311 | tex-dvi-print-command |
| 250 | Command string used by \\[tex-print] to print a .dvi file. | 312 | Command string used by \\[tex-print] to print a .dvi file. |
| 313 | tex-alt-dvi-print-command | ||
| 314 | Alternative command string used by \\[tex-print] (when given a prefix | ||
| 315 | argument) to print a .dvi file. | ||
| 251 | tex-dvi-view-command | 316 | tex-dvi-view-command |
| 252 | Command string used by \\[tex-view] to preview a .dvi file. | 317 | Command string used by \\[tex-view] to preview a .dvi file. |
| 253 | tex-show-queue-command | 318 | tex-show-queue-command |
| @@ -295,13 +360,16 @@ tex-directory | |||
| 295 | run by \\[tex-region] or \\[tex-buffer]. | 360 | run by \\[tex-region] or \\[tex-buffer]. |
| 296 | tex-dvi-print-command | 361 | tex-dvi-print-command |
| 297 | Command string used by \\[tex-print] to print a .dvi file. | 362 | Command string used by \\[tex-print] to print a .dvi file. |
| 363 | tex-alt-dvi-print-command | ||
| 364 | Alternative command string used by \\[tex-print] (when given a prefix | ||
| 365 | argument) to print a .dvi file. | ||
| 298 | tex-dvi-view-command | 366 | tex-dvi-view-command |
| 299 | Command string used by \\[tex-view] to preview a .dvi file. | 367 | Command string used by \\[tex-view] to preview a .dvi file. |
| 300 | tex-show-queue-command | 368 | tex-show-queue-command |
| 301 | Command string used by \\[tex-show-print-queue] to show the print | 369 | Command string used by \\[tex-show-print-queue] to show the print |
| 302 | queue that \\[tex-print] put your job on. | 370 | queue that \\[tex-print] put your job on. |
| 303 | 371 | ||
| 304 | Entering SliTex mode calls the value of text-mode-hook, then the value of | 372 | Entering SliTeX mode calls the value of text-mode-hook, then the value of |
| 305 | tex-mode-hook, then the value of latex-mode-hook, and then the value of | 373 | tex-mode-hook, then the value of latex-mode-hook, and then the value of |
| 306 | slitex-mode-hook. When the special subshell is initiated, the value of | 374 | slitex-mode-hook. When the special subshell is initiated, the value of |
| 307 | tex-shell-hook is called." | 375 | tex-shell-hook is called." |
| @@ -400,7 +468,7 @@ tex-shell-hook is called." | |||
| 400 | Inserts the value of tex-open-quote (normally ``) or tex-close-quote | 468 | Inserts the value of tex-open-quote (normally ``) or tex-close-quote |
| 401 | (normally '') depending on the context. With prefix argument, always | 469 | (normally '') depending on the context. With prefix argument, always |
| 402 | inserts \" characters." | 470 | inserts \" characters." |
| 403 | (interactive "P") | 471 | (interactive "*P") |
| 404 | (if arg | 472 | (if arg |
| 405 | (self-insert-command (prefix-numeric-value arg)) | 473 | (self-insert-command (prefix-numeric-value arg)) |
| 406 | (insert | 474 | (insert |
| @@ -459,7 +527,7 @@ area if a mismatch is found." | |||
| 459 | "Insert two newlines, breaking a paragraph for TeX. | 527 | "Insert two newlines, breaking a paragraph for TeX. |
| 460 | Check for mismatched braces/$'s in paragraph being terminated. | 528 | Check for mismatched braces/$'s in paragraph being terminated. |
| 461 | A prefix arg inhibits the checking." | 529 | A prefix arg inhibits the checking." |
| 462 | (interactive "P") | 530 | (interactive "*P") |
| 463 | (or inhibit-validation | 531 | (or inhibit-validation |
| 464 | (save-excursion | 532 | (save-excursion |
| 465 | (tex-validate-region | 533 | (tex-validate-region |
| @@ -472,7 +540,7 @@ A prefix arg inhibits the checking." | |||
| 472 | 540 | ||
| 473 | (defun tex-insert-braces () | 541 | (defun tex-insert-braces () |
| 474 | "Make a pair of braces and be poised to type inside of them." | 542 | "Make a pair of braces and be poised to type inside of them." |
| 475 | (interactive) | 543 | (interactive "*") |
| 476 | (insert ?\{) | 544 | (insert ?\{) |
| 477 | (save-excursion | 545 | (save-excursion |
| 478 | (insert ?}))) | 546 | (insert ?}))) |
| @@ -481,7 +549,14 @@ A prefix arg inhibits the checking." | |||
| 481 | (defun tex-latex-block (name) | 549 | (defun tex-latex-block (name) |
| 482 | "Creates a matching pair of lines \\begin{NAME} and \\end{NAME} at point. | 550 | "Creates a matching pair of lines \\begin{NAME} and \\end{NAME} at point. |
| 483 | Puts point on a blank line between them." | 551 | Puts point on a blank line between them." |
| 484 | (interactive "*sLaTeX block name: ") | 552 | (interactive |
| 553 | (prog2 | ||
| 554 | (barf-if-buffer-read-only) | ||
| 555 | (list | ||
| 556 | (completing-read "LaTeX block name: " | ||
| 557 | (mapcar 'list | ||
| 558 | (append standard-latex-block-names | ||
| 559 | latex-block-names)))))) | ||
| 485 | (let ((col (current-column))) | 560 | (let ((col (current-column))) |
| 486 | (insert (format "\\begin{%s}\n" name)) | 561 | (insert (format "\\begin{%s}\n" name)) |
| 487 | (indent-to col) | 562 | (indent-to col) |
| @@ -503,7 +578,7 @@ Puts point on a blank line between them." | |||
| 503 | (let ((new-line-needed (bolp)) | 578 | (let ((new-line-needed (bolp)) |
| 504 | text indentation) | 579 | text indentation) |
| 505 | (save-excursion | 580 | (save-excursion |
| 506 | (condition-case ERR | 581 | (condition-case nil |
| 507 | (tex-last-unended-begin) | 582 | (tex-last-unended-begin) |
| 508 | (error (error "Couldn't find unended \\begin"))) | 583 | (error (error "Couldn't find unended \\begin"))) |
| 509 | (setq indentation (current-column)) | 584 | (setq indentation (current-column)) |
| @@ -522,15 +597,30 @@ Puts point on a blank line between them." | |||
| 522 | 597 | ||
| 523 | (defun tex-start-shell () | 598 | (defun tex-start-shell () |
| 524 | (save-excursion | 599 | (save-excursion |
| 525 | (set-buffer (make-shell "tex-shell" nil nil "-v")) | 600 | (set-buffer |
| 526 | (setq tex-shell-map (copy-keymap shell-mode-map)) | 601 | (make-comint |
| 527 | (tex-define-common-keys tex-shell-map) | 602 | "tex-shell" |
| 528 | (use-local-map tex-shell-map) | 603 | (or tex-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh") |
| 529 | (run-hooks 'tex-shell-hook) | 604 | nil "-v")) |
| 530 | (if (zerop (buffer-size)) | 605 | (let ((proc (get-process "tex-shell"))) |
| 531 | (sleep-for 1)))) | 606 | (set-process-sentinel proc 'tex-shell-sentinel) |
| 532 | 607 | (process-kill-without-query proc) | |
| 533 | (defun set-buffer-directory (buffer directory) | 608 | (setq tex-shell-map (copy-keymap comint-mode-map)) |
| 609 | (tex-define-common-keys tex-shell-map) | ||
| 610 | (use-local-map tex-shell-map) | ||
| 611 | (run-hooks 'tex-shell-hook) | ||
| 612 | (while (zerop (buffer-size)) | ||
| 613 | (sleep-for 1))))) | ||
| 614 | |||
| 615 | (defun tex-shell-sentinel (proc msg) | ||
| 616 | (cond ((null (buffer-name (process-buffer proc))) | ||
| 617 | ;; buffer killed | ||
| 618 | (set-process-buffer proc nil) | ||
| 619 | (tex-delete-last-temp-files)) | ||
| 620 | ((memq (process-status proc) '(signal exit)) | ||
| 621 | (tex-delete-last-temp-files)))) | ||
| 622 | |||
| 623 | (defun tex-set-buffer-directory (buffer directory) | ||
| 534 | "Set BUFFER's default directory to be DIRECTORY." | 624 | "Set BUFFER's default directory to be DIRECTORY." |
| 535 | (setq directory (file-name-as-directory (expand-file-name directory))) | 625 | (setq directory (file-name-as-directory (expand-file-name directory))) |
| 536 | (if (not (file-directory-p directory)) | 626 | (if (not (file-directory-p directory)) |
| @@ -539,11 +629,33 @@ Puts point on a blank line between them." | |||
| 539 | (set-buffer buffer) | 629 | (set-buffer buffer) |
| 540 | (setq default-directory directory)))) | 630 | (setq default-directory directory)))) |
| 541 | 631 | ||
| 542 | ;;; The commands: | 632 | (defun tex-send-command (command &optional file background) |
| 633 | "Send COMMAND to tex-shell, substituting optional FILE for *; in background | ||
| 634 | if optional BACKGROUND is t. If COMMAND has no *, FILE will be appended, | ||
| 635 | preceded by a blank, to COMMAND. If FILE is nil, no substitution will be made | ||
| 636 | in COMMAND. COMMAND can be any expression that evaluates to a command string." | ||
| 637 | (save-excursion | ||
| 638 | (let* ((cmd (eval command)) | ||
| 639 | (star (string-match "\\*" cmd))) | ||
| 640 | (comint-proc-query (get-process "tex-shell") | ||
| 641 | (concat (substring cmd 0 star) | ||
| 642 | (if file (concat " " file) "") | ||
| 643 | (if star (substring cmd (1+ star) nil) "") | ||
| 644 | (if background "&\n" "\n")))))) | ||
| 645 | |||
| 646 | (defun tex-delete-last-temp-files () | ||
| 647 | "Delete any junk files from last temp file." | ||
| 648 | (if tex-last-temp-file | ||
| 649 | (let* ((dir (file-name-directory tex-last-temp-file)) | ||
| 650 | (list (file-name-all-completions | ||
| 651 | (file-name-nondirectory tex-last-temp-file) dir))) | ||
| 652 | (while list | ||
| 653 | (delete-file (concat dir (car list))) | ||
| 654 | (setq list (cdr list)))))) | ||
| 655 | |||
| 656 | (setq kill-emacs-hook 'tex-delete-last-temp-files) | ||
| 543 | 657 | ||
| 544 | ;;; It's a kludge that we have to create a special buffer just | 658 | ;;; The commands: |
| 545 | ;;; to write out the tex-trailer. It would nice if there were a | ||
| 546 | ;;; function like write-region that would write literal strings. | ||
| 547 | 659 | ||
| 548 | (defun tex-region (beg end) | 660 | (defun tex-region (beg end) |
| 549 | "Run TeX on the current region, via a temporary file. | 661 | "Run TeX on the current region, via a temporary file. |
| @@ -564,21 +676,16 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 564 | (tex-start-shell)) | 676 | (tex-start-shell)) |
| 565 | (or tex-zap-file | 677 | (or tex-zap-file |
| 566 | (setq tex-zap-file (tex-generate-zap-file-name))) | 678 | (setq tex-zap-file (tex-generate-zap-file-name))) |
| 567 | (let ((tex-out-file (concat tex-zap-file ".tex")) | 679 | (let* ((temp-buffer (get-buffer-create " TeX-Output-Buffer")) |
| 568 | (temp-buffer (get-buffer-create " TeX-Output-Buffer")) | 680 | ; Temp file will be written and TeX will be run in zap-directory. |
| 569 | (file-dir (if (buffer-file-name) | 681 | ; If the TEXINPUTS file has relative directories or if the region has |
| 570 | (file-name-directory (buffer-file-name)) | 682 | ; \input of files, this must be the same directory as the file for |
| 571 | default-directory)) | 683 | ; TeX to access the correct inputs. That's why it's safest if |
| 572 | (zap-directory | 684 | ; tex-directory is ".". |
| 573 | (file-name-as-directory (expand-file-name tex-directory)))) | 685 | (zap-directory |
| 574 | ;; Delete any junk files or memory files from this temp file, | 686 | (file-name-as-directory (expand-file-name tex-directory))) |
| 575 | ;; since the contents were probably different last time anyway. | 687 | (tex-out-file (concat zap-directory tex-zap-file))) |
| 576 | ;; This may also delete the old temp file if any. | 688 | (tex-delete-last-temp-files) |
| 577 | (let ((list (file-name-all-completions (tex-append tex-out-file ".") | ||
| 578 | zap-directory))) | ||
| 579 | (while list | ||
| 580 | (delete-file (expand-file-name (car list) zap-directory)) | ||
| 581 | (setq list (cdr list)))) | ||
| 582 | ;; Write the new temp file. | 689 | ;; Write the new temp file. |
| 583 | (save-excursion | 690 | (save-excursion |
| 584 | (save-restriction | 691 | (save-restriction |
| @@ -598,70 +705,29 @@ The value of `tex-command' specifies the command to use to run TeX." | |||
| 598 | (progn (forward-line 1) | 705 | (progn (forward-line 1) |
| 599 | (setq hend (point))) ;mark end of header | 706 | (setq hend (point))) ;mark end of header |
| 600 | (setq hbeg (point-min))))) ;no header | 707 | (setq hbeg (point-min))))) ;no header |
| 601 | (write-region (min hbeg beg) hend tex-out-file nil nil) | 708 | (write-region (min hbeg beg) hend |
| 602 | (write-region (max beg hend) end tex-out-file t nil)) | 709 | (concat tex-out-file ".tex") nil nil) |
| 710 | (write-region (max beg hend) end (concat tex-out-file ".tex") t nil)) | ||
| 603 | (let ((local-tex-trailer tex-trailer)) | 711 | (let ((local-tex-trailer tex-trailer)) |
| 604 | (set-buffer temp-buffer) | 712 | (set-buffer temp-buffer) |
| 605 | (erase-buffer) | 713 | (erase-buffer) |
| 606 | ;; make sure trailer isn't hidden by a comment | 714 | ;; make sure trailer isn't hidden by a comment |
| 607 | (insert-string "\n") | 715 | (insert-string "\n") |
| 608 | (if local-tex-trailer (insert-string local-tex-trailer)) | 716 | (if local-tex-trailer (insert-string local-tex-trailer)) |
| 609 | (set-buffer-directory temp-buffer zap-directory) | 717 | (tex-set-buffer-directory temp-buffer zap-directory) |
| 610 | (write-region (point-min) (point-max) tex-out-file t nil)))) | 718 | (write-region (point-min) (point-max) |
| 611 | ;; Record in the shell buffer the file name to delete afterward. | 719 | (concat tex-out-file ".tex") t nil)))) |
| 612 | (save-excursion | 720 | ;; Record the file name to be deleted afterward. |
| 613 | (set-buffer (get-buffer "*tex-shell*")) | 721 | (setq tex-last-temp-file tex-out-file) |
| 614 | (make-local-variable 'tex-last-temp-file) | 722 | (tex-send-command tex-shell-cd-command zap-directory) |
| 615 | (setq tex-last-temp-file tex-out-file)) | 723 | (tex-send-command tex-command tex-out-file) |
| 616 | (set-process-filter "tex-shell" 'tex-filter) | 724 | (setq tex-print-file tex-out-file) |
| 617 | (set-buffer-directory "*tex-shell*" zap-directory) | 725 | (setq tex-last-buffer-texed (current-buffer)))) |
| 618 | ;; Run TeX in source file's dir, in case TEXINPUTS uses current dir. | ||
| 619 | (send-string "tex-shell" (concat tex-shell-cd-command " " file-dir "\n")) | ||
| 620 | (send-string "tex-shell" (concat tex-command " \"" | ||
| 621 | zap-directory | ||
| 622 | tex-out-file "\"\n"))) | ||
| 623 | (setq tex-last-buffer-texed (current-buffer)) | ||
| 624 | (setq tex-print-file | ||
| 625 | (concat (file-name-as-directory (expand-file-name tex-directory)) | ||
| 626 | tex-zap-file)) | ||
| 627 | (tex-recenter-output-buffer 0)) | ||
| 628 | |||
| 629 | ;; This filter is used in the TeX shell buffer | ||
| 630 | ;; while TeX is running for a tex-region command. | ||
| 631 | (defun tex-filter (process string) | ||
| 632 | (let ((old (current-buffer))) | ||
| 633 | (set-buffer (process-buffer proc)) | ||
| 634 | (unwind-protect | ||
| 635 | (progn (if (= (process-mark proc) (point-max)) | ||
| 636 | (insert string) | ||
| 637 | (save-excursion | ||
| 638 | (goto-char (process-mark proc)) | ||
| 639 | (insert string))) | ||
| 640 | (set-marker (process-mark proc) (point)) | ||
| 641 | ;; Delete the temporary file | ||
| 642 | ;; when TeX finishes. | ||
| 643 | ;; And stop using this filter. | ||
| 644 | (save-excursion | ||
| 645 | (forward-line -1) | ||
| 646 | (if (looking-at "^Output written on ") | ||
| 647 | (progn | ||
| 648 | (set-process-filter process nil) | ||
| 649 | ;; Delete the temp file just processed | ||
| 650 | ;; and any related junk files made by TeX. | ||
| 651 | (let ((list (file-name-all-completions | ||
| 652 | (tex-append tex-last-temp-file ".") | ||
| 653 | zap-directory))) | ||
| 654 | (while list | ||
| 655 | (delete-file (expand-file-name | ||
| 656 | (car list) zap-directory)) | ||
| 657 | (setq list (cdr list)))))))) | ||
| 658 | (or (eq old (current-buffer)) | ||
| 659 | (set-buffer old))))) | ||
| 660 | 726 | ||
| 661 | (defun tex-buffer () | 727 | (defun tex-buffer () |
| 662 | "Run TeX on current buffer. See \\[tex-region] for more information. | 728 | "Run TeX on current buffer. See \\[tex-region] for more information. |
| 663 | Does not save the buffer, so it's useful for trying | 729 | Does not save the buffer, so it's useful for trying experimental versions. |
| 664 | experimental versions. See \\[tex-file] for an alternative." | 730 | See \\[tex-file] for an alternative." |
| 665 | (interactive) | 731 | (interactive) |
| 666 | (tex-region (point-min) (point-max))) | 732 | (tex-region (point-min) (point-max))) |
| 667 | 733 | ||
| @@ -679,13 +745,10 @@ This function is more useful than \\[tex-buffer] when you need the | |||
| 679 | (if (tex-shell-running) | 745 | (if (tex-shell-running) |
| 680 | (tex-kill-job) | 746 | (tex-kill-job) |
| 681 | (tex-start-shell)) | 747 | (tex-start-shell)) |
| 682 | (set-buffer-directory "*tex-shell*" file-dir) | 748 | (tex-send-command tex-shell-cd-command file-dir) |
| 683 | (send-string "tex-shell" (concat tex-shell-cd-command " " file-dir "\n")) | 749 | (tex-send-command tex-command tex-out-file)) |
| 684 | (send-string "tex-shell" | ||
| 685 | (concat tex-command " \"" tex-out-file "\"\n"))) | ||
| 686 | (setq tex-last-buffer-texed (current-buffer)) | 750 | (setq tex-last-buffer-texed (current-buffer)) |
| 687 | (setq tex-print-file (buffer-file-name)) | 751 | (setq tex-print-file (buffer-file-name))) |
| 688 | (tex-recenter-output-buffer 0)) | ||
| 689 | 752 | ||
| 690 | (defun tex-generate-zap-file-name () | 753 | (defun tex-generate-zap-file-name () |
| 691 | "Generate a unique name suitable for use as a file name." | 754 | "Generate a unique name suitable for use as a file name." |
| @@ -719,8 +782,7 @@ This function is more useful than \\[tex-buffer] when you need the | |||
| 719 | (defun tex-kill-job () | 782 | (defun tex-kill-job () |
| 720 | "Kill the currently running TeX job." | 783 | "Kill the currently running TeX job." |
| 721 | (interactive) | 784 | (interactive) |
| 722 | (if (get-process "tex-shell") | 785 | (quit-process (get-process "tex-shell") t)) |
| 723 | (quit-process "tex-shell" t))) | ||
| 724 | 786 | ||
| 725 | (defun tex-recenter-output-buffer (linenum) | 787 | (defun tex-recenter-output-buffer (linenum) |
| 726 | "Redisplay buffer of TeX job output so that most recent output can be seen. | 788 | "Redisplay buffer of TeX job output so that most recent output can be seen. |
| @@ -737,24 +799,25 @@ line LINE of the window, or centered if LINE is nil." | |||
| 737 | (recenter (if linenum | 799 | (recenter (if linenum |
| 738 | (prefix-numeric-value linenum) | 800 | (prefix-numeric-value linenum) |
| 739 | (/ (window-height) 2))) | 801 | (/ (window-height) 2))) |
| 740 | (pop-to-buffer old-buffer) | 802 | (pop-to-buffer old-buffer)))) |
| 741 | ))) | ||
| 742 | 803 | ||
| 743 | (defun tex-print () | 804 | (defun tex-print (&optional alt) |
| 744 | "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file]. | 805 | "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file]. |
| 745 | Runs the shell command defined by tex-dvi-print-command." | 806 | Runs the shell command defined by tex-dvi-print-command. If prefix argument |
| 746 | (interactive) | 807 | is provided, use the alternative command, tex-alt-dvi-print-command." |
| 808 | (interactive "P") | ||
| 747 | (let ((print-file-name-dvi (tex-append tex-print-file ".dvi")) | 809 | (let ((print-file-name-dvi (tex-append tex-print-file ".dvi")) |
| 748 | test-name) | 810 | test-name) |
| 749 | (if (and (not (equal (current-buffer) tex-last-buffer-texed)) | 811 | (if (and (not (equal (current-buffer) tex-last-buffer-texed)) |
| 750 | (file-newer-than-file-p | 812 | (file-newer-than-file-p |
| 751 | (setq test-name (tex-append (buffer-file-name) ".dvi")) | 813 | (setq test-name (tex-append (buffer-file-name) ".dvi")) |
| 752 | (tex-append tex-print-file ".dvi"))) | 814 | print-file-name-dvi)) |
| 753 | (setq print-file-name-dvi test-name)) | 815 | (setq print-file-name-dvi test-name)) |
| 754 | (if (file-exists-p print-file-name-dvi) | 816 | (if (not (file-exists-p print-file-name-dvi)) |
| 755 | (shell-command | 817 | (error "No appropriate `.dvi' file could be found") |
| 756 | (concat tex-dvi-print-command " \"" print-file-name-dvi "&\"\n")) | 818 | (tex-send-command |
| 757 | (error "No appropriate `.dvi' file could be found")))) | 819 | (if alt tex-alt-dvi-print-command tex-dvi-print-command) |
| 820 | print-file-name-dvi t)))) | ||
| 758 | 821 | ||
| 759 | (defun tex-view () | 822 | (defun tex-view () |
| 760 | "Preview the last `.dvi' file made by running TeX under Emacs. | 823 | "Preview the last `.dvi' file made by running TeX under Emacs. |
| @@ -784,8 +847,7 @@ Runs the shell command defined by tex-show-queue-command." | |||
| 784 | (if (tex-shell-running) | 847 | (if (tex-shell-running) |
| 785 | (tex-kill-job) | 848 | (tex-kill-job) |
| 786 | (tex-start-shell)) | 849 | (tex-start-shell)) |
| 787 | (send-string "tex-shell" (concat tex-show-queue-command "\n")) | 850 | (tex-send-command tex-show-queue-command)) |
| 788 | (tex-recenter-output-buffer nil)) | ||
| 789 | 851 | ||
| 790 | (defun tex-bibtex-file () | 852 | (defun tex-bibtex-file () |
| 791 | "Run BibTeX on the current buffer's file." | 853 | "Run BibTeX on the current buffer's file." |
| @@ -796,11 +858,10 @@ Runs the shell command defined by tex-show-queue-command." | |||
| 796 | (let ((tex-out-file | 858 | (let ((tex-out-file |
| 797 | (tex-append (file-name-nondirectory (buffer-file-name)) "")) | 859 | (tex-append (file-name-nondirectory (buffer-file-name)) "")) |
| 798 | (file-dir (file-name-directory (buffer-file-name)))) | 860 | (file-dir (file-name-directory (buffer-file-name)))) |
| 799 | (set-buffer-directory "*tex-shell*" file-dir) | 861 | (tex-send-command tex-shell-cd-command file-dir) |
| 800 | (send-string "tex-shell" (concat tex-shell-cd-command " " file-dir "\n")) | 862 | (tex-send-command bibtex-command tex-out-file))) |
| 801 | (send-string "tex-shell" | 863 | |
| 802 | (concat tex-bibtex-command " \"" tex-out-file "\"\n"))) | 864 | (run-hooks 'tex-mode-load-hook) |
| 803 | (tex-recenter-output-buffer 0)) | ||
| 804 | 865 | ||
| 805 | (provide 'tex-mode) | 866 | (provide 'tex-mode) |
| 806 | 867 | ||
diff --git a/src/buffer.c b/src/buffer.c index de9e4246f80..ad70801e812 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -902,7 +902,9 @@ DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, | |||
| 902 | DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "", | 902 | DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "", |
| 903 | "Put BUFFER at the end of the list of all buffers.\n\ | 903 | "Put BUFFER at the end of the list of all buffers.\n\ |
| 904 | There it is the least likely candidate for `other-buffer' to return;\n\ | 904 | There it is the least likely candidate for `other-buffer' to return;\n\ |
| 905 | thus, the least likely buffer for \\[switch-to-buffer] to select by default.") | 905 | thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\ |
| 906 | If the argument is nil, bury the current buffer\n\ | ||
| 907 | and switch to some other buffer in the selected window.") | ||
| 906 | (buf) | 908 | (buf) |
| 907 | register Lisp_Object buf; | 909 | register Lisp_Object buf; |
| 908 | { | 910 | { |