home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / texpp.zoo / texpp.1 / tex-mode.el < prev   
Lisp/Scheme  |  1990-04-04  |  20KB  |  549 lines

  1. ;; TeX mode commands.
  2. ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
  3. ;; Rewritten following contributions by William F. Schelter
  4. ;; and Dick King (king@kestrel).
  5. ;; Modified August 1986 by Stephen Gildea <mit-erl!gildea> and
  6. ;; Michael Prange <mit-erl!prange> to add LaTeX support and enhance
  7. ;; TeX-region.
  8. ;; Added TeX-directory and reorganized somewhat  gildea 21 Nov 86
  9. ;; Modified to handle TeX preprocessors by csirmaz@cs.rutgers.edu 21 Nov 89
  10.  
  11. ;; This file is part of GNU Emacs.
  12.  
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  15. ;; accepts responsibility to anyone for the consequences of using it
  16. ;; or for whether it serves any particular purpose or works at all,
  17. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  18. ;; License for full details.
  19.  
  20. ;; Everyone is granted permission to copy, modify and redistribute
  21. ;; GNU Emacs, but only under the conditions described in the
  22. ;; GNU Emacs General Public License.   A copy of this license is
  23. ;; supposed to have been given to you along with GNU Emacs so you
  24. ;; can know your rights and responsibilities.  It should be in a
  25. ;; file named COPYING.  Among other things, the copyright notice
  26. ;; and this notice must be preserved on all copies.
  27.  
  28. ;; Still to do:
  29. ;;  Make TAB indent correctly for TeX code.  Then we can make linefeed
  30. ;;  do something more useful.
  31. ;;
  32. ;;  Have spell understand TeX instead of assuming the entire world
  33. ;;  uses nroff.
  34. ;;
  35. ;;  The code for finding matching $ needs to be fixed.
  36.  
  37. ;;;
  38. ;;; To costumize TeX preprocessing, you can put the following lines
  39. ;;; into the .emacs init file:
  40. ;;;    (defun set-my-TeX-filter-default ()
  41. ;;;      (setq TeX-show-dvi-command "your favorite DVI view program")
  42. ;;;      (setq TeX-filter "...here the filter with full path...")
  43. ;;;      (setq TeX-filter-args '("...first macro file with full path..." 
  44. ;;;                              "...second macro file with full path..."
  45. ;;;                              "-"     ;;;for the buffer
  46. ;;;                              "-a"))  ;;;append the output
  47. ;;;    )
  48. ;;;    (setq TeX-mode-hook (if (boundp 'TeX-mode-hook)
  49. ;;;       (append TeX-mode-hook 'set-my-TeX-filter-default)
  50. ;;;       'set-my-TeX-filter-default)
  51. ;;;    )
  52. ;;; If you want to use 'ispell' to check TeX text, use the following in
  53. ;;; your .emacs init file:
  54. ;;;    (require 'ispell)
  55. ;;;    (set-default 'ispell-filter-hook shell-file-name)
  56. ;;;    (set-default 'ispell-filter-hook-args 
  57. ;;;                 '("-f" "-c" "(detex -iw | tr -cs A-Za-z \\\\012)"))
  58.  
  59.  
  60. ;;;
  61.  
  62. (provide 'tex-mode)
  63.  
  64. (defvar TeX-directory "/tmp/"
  65.   "*Directory in which to run TeX subjob.  Temporary files are
  66. created in this directory.")
  67. (defvar TeX-dvi-print-command "lpr -d"
  68.   "*Command string used by \\[TeX-print] to print a .dvi file.")
  69. (defvar TeX-show-dvi-command "texx"
  70.   "*Command used by \\[TeX-view-dvi] for screen view the dvi file")
  71. (defvar TeX-show-queue-command "lpq"
  72.   "*Command string used by \\[TeX-show-print-queue] to show the print queue
  73. that \\[TeX-print] put your job on.")
  74. (defvar TeX-default-mode 'plain-TeX-mode
  75.   "*Mode to enter for a new file when it can't be determined whether
  76. the file is plain TeX or LaTeX or what.")
  77.  
  78. (defvar TeX-command nil
  79.   "The command to run TeX on a file.  The name of the file will be appended
  80. to this string, separated by a space.")
  81. (defvar TeX-filter ()
  82.   "*Filter to produce a file by \\[TeX-region] on which TeX is called.")
  83. (defvar TeX-filter-args '()
  84.   "*Arguments to the filter TeX-filter")
  85. (defvar TeX-trailer nil
  86.   "String appended after the end of a region send to TeX by \\[TeX-region].")
  87. (defvar TeX-start-of-header nil
  88.   "String used by \\[TeX-region] to delimit the start of the file's header.")
  89. (defvar TeX-end-of-header nil
  90.   "String used by \\[TeX-region] to delimit the end of the file's header.")
  91. (defvar TeX-shell-cd-command "cd"
  92.   "Command to give to shell running TeX to change directory.  The value of
  93. TeX-directory will be appended to this, separated by a space.")
  94. (defvar TeX-zap-file nil
  95.   "Temporary file name used for text being sent as input to TeX.
  96. Should be a simple file name with no extension or directory specification.")
  97.  
  98. (defvar TeX-mode-syntax-table nil
  99.   "Syntax table used while in TeX mode.")
  100.  
  101. (defun TeX-define-common-keys (keymap)
  102.   "Define the keys that we want defined both in TeX-mode
  103. and in the TeX-shell."
  104.   (define-key keymap "\C-c\C-k" 'TeX-kill-job)
  105.   (define-key keymap "\C-c\C-l" 'TeX-recenter-output-buffer)
  106.   (define-key keymap "\C-c\C-q" 'TeX-show-print-queue)
  107.   (define-key keymap "\C-c\C-p" 'TeX-print)
  108.   (define-key keymap "\C-c\C-v" 'TeX-view-dvi)
  109.   )
  110.  
  111. (defvar TeX-mode-map nil "Keymap for TeX mode")
  112.  
  113. (if TeX-mode-map 
  114.     nil
  115.   (setq TeX-mode-map (make-sparse-keymap))
  116.   (TeX-define-common-keys TeX-mode-map)
  117.   (define-key TeX-mode-map "\"" 'TeX-insert-quote)
  118.   (define-key TeX-mode-map "\n" 'TeX-terminate-paragraph)
  119.   (define-key TeX-mode-map "\e}" 'up-list)
  120.   (define-key TeX-mode-map "\e{" 'TeX-insert-braces)
  121.   (define-key TeX-mode-map "\C-c\C-r" 'TeX-region)
  122.   (define-key TeX-mode-map "\C-c\C-b" 'TeX-buffer)
  123.   (define-key TeX-mode-map "\C-c\C-f" 'TeX-close-LaTeX-block)
  124.   )
  125.  
  126. (defvar TeX-shell-map nil
  127.   "Keymap for the TeX shell.  A shell-mode-map with a few additions")
  128.  
  129. ;(fset 'TeX-mode 'tex-mode)         ;in loaddefs.
  130.  
  131. ;;; This would be a lot simpler if we just used a regexp search,
  132. ;;; but then it would be too slow.
  133. (defun tex-mode ()
  134.   "Major mode for editing files of input for TeX or LaTeX.
  135. Trys to intuit whether this file is for plain TeX or LaTeX and
  136. calls plain-tex-mode or latex-mode.  If it cannot be determined
  137. \(e.g., there are no commands in the file), the value of
  138. TeX-default-mode is used."
  139.   (interactive)
  140.   (let (mode slash comment)
  141.     (save-excursion
  142.       (goto-char (point-min))
  143.       (while (and (setq slash (search-forward "\\" nil t))
  144.           (setq comment (let ((search-end (point)))
  145.                   (save-excursion
  146.                     (beginning-of-line)
  147.                     (search-forward "%" search-end t))))))
  148.       (if (and slash (not comment))
  149.       (setq mode (if (looking-at "documentstyle")
  150.              'latex-mode
  151.                'plain-tex-mode))))
  152.     (if mode (funcall mode)
  153.       (funcall TeX-default-mode))))
  154.  
  155. (fset 'plain-TeX-mode 'plain-tex-mode)
  156. (fset 'LaTeX-mode 'latex-mode)
  157.  
  158. (defun plain-tex-mode ()
  159.   "Major mode for editing files of input for plain TeX.
  160. Makes $ and } display the characters they match.
  161. Makes \" insert `` when it seems to be the beginning of a quotation,
  162. and '' when it appears to be the end; it inserts \" only after a \\.
  163.  
  164. Use \\[TeX-region] to run TeX on the current region, plus a \"header\"
  165. copied from the top of the file (containing macro definitions, etc.),
  166. running TeX under a special subshell.  \\[TeX-buffer] does the whole buffer.
  167. \\[TeX-print] prints the .dvi file made by either of these,
  168. \\[TeX-view-dvi] shows a dvi view.
  169.  
  170. Use \\[validate-TeX-buffer] to check buffer for paragraphs containing
  171. mismatched $'s or braces.
  172.  
  173. Special commands:
  174. \\{TeX-mode-map}
  175.  
  176. Mode variables:
  177. TeX-directory
  178.     Directory in which to create temporary files for TeX jobs
  179.     run by \\[TeX-region] or \\[TeX-buffer].
  180. TeX-filter
  181.     program (maybe with full path) to filter the region or buffer
  182.     before calling tex or latex.
  183. TeX-filter-args
  184.     list of arguments to TeX-filter.
  185. TeX-dvi-print-command
  186.     Command string used by \\[TeX-print] to print a .dvi file.
  187. TeX-show-queue-command
  188.     Command string used by \\[TeX-show-print-queue] to show the print
  189.     queue that \\[TeX-print] put your job on.
  190.  
  191. Entering plain-TeX mode calls the value of text-mode-hook,
  192. then the value of TeX-mode-hook, and then the value
  193. of plain-TeX-mode-hook."
  194.   (interactive)
  195.   (TeX-common-initialization)
  196.   (setq mode-name "TeX")
  197.   (setq major-mode 'plain-TeX-mode)
  198.   (setq TeX-command "tex")
  199.   (setq TeX-start-of-header "%**start of header")
  200.   (setq TeX-end-of-header "%**end of header")
  201.   (setq TeX-trailer "\\bye\n")
  202.   (run-hooks 'text-mode-hook 'TeX-mode-hook 'plain-TeX-mode-hook))
  203.  
  204. (defun latex-mode ()
  205.   "Major mode for editing files of input for LaTeX.
  206. Makes $ and } display the characters they match.
  207. Makes \" insert `` when it seems to be the beginning of a quotation,
  208. and '' when it appears to be the end; it inserts \" only after a \\.
  209.  
  210. Use \\[TeX-region] to run LaTeX on the current region, plus the preamble
  211. copied from the top of the file (containing \\documentstyle, etc.),
  212. running LaTeX under a special subshell.  \\[TeX-buffer] does the whole buffer.
  213. \\[TeX-print] prints the .dvi file made by either of these.
  214.  
  215. Use \\[validate-TeX-buffer] to check buffer for paragraphs containing
  216. mismatched $'s or braces.
  217.  
  218. Special commands:
  219. \\{TeX-mode-map}
  220.  
  221. Mode variables:
  222. TeX-directory
  223.     Directory in which to create temporary files for TeX jobs
  224.     run by \\[TeX-region] or \\[TeX-buffer].
  225. TeX-filter
  226.     program (maybe with full path) to filter the region or buffer
  227.     before calling tex or latex.
  228. TeX-filter-args
  229.     list of arguments to TeX-filter.
  230. TeX-dvi-print-command
  231.     Command string used by \\[TeX-print] to print a .dvi file.
  232. TeX-show-queue-command
  233.     Command string used by \\[TeX-show-print-queue] to show the print
  234.     queue that \\[TeX-print] put your job on.
  235.  
  236. Entering LaTeX mode calls the value of text-mode-hook,
  237. then the value of TeX-mode-hook, and then the value
  238. of LaTeX-mode-hook."
  239.   (interactive)
  240.   (TeX-common-initialization)
  241.   (setq mode-name "LaTeX")
  242.   (setq major-mode 'LaTeX-mode)
  243.   (setq TeX-command "latex")
  244.   (setq TeX-start-of-header "\\documentstyle")
  245.   (setq TeX-end-of-header "\\begin{document}")
  246.   (setq TeX-trailer "\\end{document}\n")
  247.   (run-hooks 'text-mode-hook 'TeX-mode-hook 'LaTeX-mode-hook))
  248.  
  249. (defun TeX-common-initialization ()
  250.   (kill-all-local-variables)
  251.   (use-local-map TeX-mode-map)
  252.   (setq local-abbrev-table text-mode-abbrev-table)
  253.   (if (null TeX-mode-syntax-table)
  254.       (progn
  255.     (setq TeX-mode-syntax-table (make-syntax-table))
  256.     (set-syntax-table TeX-mode-syntax-table)
  257.     (modify-syntax-entry ?\\ ".")
  258.     (modify-syntax-entry ?\f ">")
  259.     (modify-syntax-entry ?\n ">")
  260.     (modify-syntax-entry ?$ "$$")
  261.     (modify-syntax-entry ?% "<")
  262.     (modify-syntax-entry ?\" ".")
  263.     (modify-syntax-entry ?& ".")
  264.     (modify-syntax-entry ?_ ".")
  265.     (modify-syntax-entry ?@ "_")
  266.     (modify-syntax-entry ?~ " ")
  267.     (modify-syntax-entry ?' "w"))
  268.     (set-syntax-table TeX-mode-syntax-table))
  269.   (make-local-variable 'paragraph-start)
  270.   (setq paragraph-start "^[ \t]*$\\|^[\f\\\\]")
  271.   (make-local-variable 'paragraph-separate)
  272.   (setq paragraph-separate paragraph-start)
  273.   (make-local-variable 'comment-start)
  274.   (setq comment-start "%")
  275.   (make-local-variable 'comment-start-skip)
  276.   (setq comment-start-skip "[^\\]\\(\\(\\\\\\\\\\)*\\)%+ *")
  277.   (make-local-variable 'comment-indent-hook)
  278.   (setq comment-indent-hook 'TeX-comment-indent)
  279.   (make-local-variable 'TeX-command)
  280.   (make-local-variable 'TeX-trailer))
  281.  
  282. (defun TeX-comment-indent ()
  283.   (if (looking-at "%%%")
  284.       (current-column)
  285.     (skip-chars-backward " \t")
  286.     (max (if (bolp) 0 (1+ (current-column)))
  287.      comment-column)))
  288.  
  289. (defun TeX-insert-quote (arg)
  290.   "Insert ``, '' or \" according to preceding character.
  291. With prefix argument, always insert \" characters."
  292.   (interactive "P")
  293.   (if arg
  294.       (let ((count (prefix-numeric-value arg)))
  295.     (if (listp arg)
  296.         (self-insert-command 1)    ;C-u always inserts just one
  297.       (self-insert-command count)))
  298.     (insert
  299.      (cond
  300.       ((or (bobp)
  301.        (save-excursion
  302.          (forward-char -1)
  303.          (looking-at "[ \t\n]\\|\\s(")))
  304.        "``")
  305.       ((= (preceding-char) ?\\)
  306.        ?\")
  307.       (t "''")))))
  308.  
  309. (defun validate-TeX-buffer ()
  310.   "Check current buffer for paragraphs containing mismatched $'s.
  311. As each such paragraph is found, a mark is pushed at its beginning,
  312. and the location is displayed for a few seconds."
  313.   (interactive)
  314.   (let ((opoint (point)))
  315.     (goto-char (point-max))
  316.     ;; Does not use save-excursion
  317.     ;; because we do not want to save the mark.
  318.     (unwind-protect
  319.     (while (and (not (input-pending-p)) (not (bobp)))
  320.       (let ((end (point)))
  321.         (search-backward "\n\n" nil 'move)
  322.         (or (TeX-validate-paragraph (point) end)
  323.         (progn
  324.           (push-mark (point))
  325.           (message "Mismatch found in pararaph starting here")
  326.           (sit-for 4)))))
  327.       (goto-char opoint))))
  328.  
  329. (defun TeX-validate-paragraph (start end)
  330.   (condition-case ()
  331.       (save-excursion
  332.     (save-restriction
  333.       (narrow-to-region start end)
  334.       (goto-char start)
  335.       (forward-sexp (- end start))
  336.       t))
  337.     (error nil)))
  338.  
  339. (defun TeX-terminate-paragraph (inhibit-validation)
  340.   "Insert two newlines, breaking a paragraph for TeX.
  341. Check for mismatched braces/$'s in paragraph being terminated.
  342. A prefix arg inhibits the checking."
  343.   (interactive "P")
  344.   (or inhibit-validation
  345.       (TeX-validate-paragraph
  346.        (save-excursion
  347.      (search-backward "\n\n" nil 'move)
  348.      (point))
  349.        (point))
  350.       (message "Paragraph being closed appears to contain a mismatch"))
  351.   (insert "\n\n"))
  352.  
  353. (defun TeX-insert-braces ()
  354.   "Make a pair of braces and be poised to type inside of them."
  355.   (interactive)
  356.   (insert ?\{)
  357.   (save-excursion
  358.     (insert ?})))
  359.  
  360. ;;; Like TeX-insert-braces, but for LaTeX.
  361. (defun TeX-close-LaTeX-block ()
  362.   "Creates an \\end{...} to match \\begin{...} on the current line and
  363. puts point on the blank line between them."
  364.   (interactive "*")
  365.   (let ((fail-point (point)))
  366.     (end-of-line)
  367.     (if (re-search-backward "\\\\begin{\\([^}\n]*\\)}"
  368.                 (save-excursion (beginning-of-line) (point)) t)
  369.     (let ((text (buffer-substring (match-beginning 1) (match-end 1)))
  370.           (indentation (current-column)))
  371.       (end-of-line)
  372.       (delete-horizontal-space)
  373.       (insert "\n\n")
  374.       (indent-to indentation)
  375.       (insert "\\end{" text "}")
  376.       (forward-line -1))
  377.       (goto-char fail-point)
  378.       (ding))))
  379.  
  380. ;;; Invoking TeX in an inferior shell.
  381.  
  382. ;;; Why use a shell instead of running TeX directly?  Because if TeX
  383. ;;; gets stuck, the user can switch to the shell window and type at it.
  384.  
  385. ;;; The utility functions:
  386.  
  387. (defun TeX-start-shell ()
  388.   (require 'shell)
  389.   (if (eq (process-status "TeX-shell") 'run) ()
  390.   (save-excursion
  391.     (let ((buffer (make-shell "TeX-shell" shell-file-name nil "-v")))
  392.       (process-kill-without-query (get-buffer-process buffer))
  393.       (set-buffer buffer)
  394.       (setq TeX-shell-map (copy-keymap shell-mode-map))
  395.       (TeX-define-common-keys TeX-shell-map)
  396.       (use-local-map TeX-shell-map)))))
  397.  
  398. (defun set-buffer-directory (buffer directory)
  399.   "Set BUFFER's default directory to be DIRECTORY."
  400.   (setq directory (file-name-as-directory (expand-file-name directory)))
  401.   (if (not (file-directory-p directory))
  402.       (error "%s is not a directory" directory)
  403.     (save-excursion
  404.       (set-buffer buffer)
  405.       (setq default-directory directory))))
  406.  
  407. ;;; It's a kludge that we have to create a special buffer just 
  408. ;;; to write out the TeX-trailer.  It would nice if there were a
  409. ;;; function like write-region that would write literal strings.
  410.  
  411. ;;; write-region complains if the file is also a buffer. To overcome
  412. ;;; this, here is my version
  413. (defun my-write-region (beg end file app)
  414. "The region between BEGIN and END of the current buffer is written or
  415. appended to the FILE depending whether the fourth argument is nil or
  416. non-nil (append in the latter case)."
  417.     (call-process-region beg end shell-file-name nil nil nil
  418.     "-F" "-c" (concat "cat " (if app ">>" ">") "\"" file "\""))
  419. )
  420.  
  421. (defun TeX-region (beg end)
  422.   "Run TeX on the current region.  The region is filtered through the
  423. program given in (TeX-filter) to produce the temporary file (TeX-zap-file)
  424. in directory (TeX-directory). TeX is run in that directory. If the buffer has
  425. a header, it is written to the temporary file before the region. Also, the
  426. value of the TeX-trailer is appended to the file. They are NOT filtered through
  427. (TeX-filter). The buffer's header is all lines between the string defined by
  428. TeX-start-of-header and TeX-end-of-header inclusive."
  429.   (interactive "r")
  430.   (or TeX-zap-file (setq TeX-zap-file (make-temp-name "#tz")))
  431.   (let* ((tex-out-file (concat TeX-zap-file ".tex"))
  432.      (tex-out-buffer (get-file-buffer tex-out-file))
  433.      (temp-buffer (get-buffer-create " TeX-Output-Buffer"))
  434.      (zap-directory (expand-file-name TeX-directory))
  435.          (local-tex-trailer TeX-trailer))
  436.     (unwind-protect (save-excursion (save-restriction
  437.     (widen)
  438.     (goto-char (point-min))
  439.     (forward-line 100)
  440.     (let ((search-end (point))
  441.           (hbeg (point-min)) (hend (point-min))
  442.           (default-directory zap-directory))
  443.       (goto-char (point-min))
  444.       ;; Initialize the temp file with either the header or nothing
  445.       (if (search-forward TeX-start-of-header search-end t)
  446.           (progn
  447.         (forward-line -1)
  448.         (setq hbeg (point))    ;mark beginning of header
  449.         (if (search-forward TeX-end-of-header nil t)
  450.             (progn (forward-line 1)
  451.                (setq hend (min beg (point))));mark end of header
  452.           (setq hbeg (point-min))))) ;no header
  453.       (my-write-region (min hbeg beg) hend tex-out-file nil))
  454.          (message "Preprocessing...")
  455.          (narrow-to-region beg end)
  456.          (sit-for 0)
  457.          (save-excursion  (set-buffer temp-buffer)  (erase-buffer))
  458.          (if TeX-filter
  459.            (apply 'call-process-region
  460.              (append (list beg end TeX-filter nil temp-buffer nil)
  461.                      TeX-filter-args
  462.                      (list (concat zap-directory tex-out-file))))
  463.            (my-write-region beg end (concat zap-directory tex-out-file) t))
  464.          (message "Done...") (sit-for 0)
  465.     )))
  466.     (if (save-excursion (set-buffer temp-buffer)
  467.                 (beginning-of-file) (eobp))
  468.         (progn
  469.            (save-excursion
  470.              (set-buffer temp-buffer)
  471.              (set-buffer-directory temp-buffer zap-directory)
  472.              (insert-string "\n")
  473.              (if local-tex-trailer (insert-string local-tex-trailer))
  474.              (my-write-region (point-min) (point-max) tex-out-file t))
  475.            (pop-to-TeX-shell zap-directory tex-out-file)
  476.          )
  477. ;;; error during preprocessing, show the error messages ...
  478.       (let ((buffer (current-buffer))) 
  479.         (pop-to-buffer temp-buffer)
  480.         (pop-to-buffer buffer))
  481.     )
  482. ))
  483.  
  484. (defun pop-to-TeX-shell (zap-directory tex-out-file)
  485.    (if (get-buffer "*TeX-shell*") (TeX-kill-job))
  486.    (TeX-start-shell)
  487.    (set-buffer-directory "*TeX-shell*" zap-directory)
  488.    (send-string "TeX-shell" (concat TeX-shell-cd-command " "
  489.                      zap-directory "\n"))
  490.    (send-string "TeX-shell" (concat TeX-command " \""
  491.                      tex-out-file "\"\n"))
  492.    (TeX-recenter-output-buffer 0)
  493. )
  494.  
  495. (defun TeX-buffer ()
  496.   "Run TeX on current buffer.  See \\[TeX-region] for more information."
  497.   (interactive)
  498.   (TeX-region (point-min) (point-max)))
  499.  
  500. (defun TeX-kill-job ()
  501.   "Kill the currently running TeX job."
  502.   (interactive)
  503.   (if (process-status "TeX-shell")      ; not nil if the process exists
  504.       (quit-process "TeX-shell" t)))
  505.  
  506. (defun TeX-recenter-output-buffer (linenum)
  507.   "Redisplay buffer of TeX job output so that most recent output can be seen.
  508. The last line of the buffer is displayed on
  509. line LINE of the window, or centered if LINE is nil."
  510.   (interactive "P")
  511.   (let ((tex-shell (get-buffer "*TeX-shell*"))
  512.     (old-buffer (current-buffer)))
  513.     (if (null tex-shell)
  514.     (message "No TeX output buffer")
  515.       (pop-to-buffer tex-shell)
  516.       (bury-buffer tex-shell)
  517.       (goto-char (point-max))
  518.       (recenter (if linenum
  519.             (prefix-numeric-value linenum)
  520.           (/ (window-height) 2)))
  521.       (pop-to-buffer old-buffer)
  522.       )))
  523.  
  524. (defun TeX-print ()
  525.   "Print the .dvi file made by \\[TeX-region] or \\[TeX-buffer].
  526. Runs the shell command defined by TeX-dvi-print-command."
  527.   (interactive)
  528.   (send-string "TeX-shell"
  529.            (concat TeX-dvi-print-command " \"" TeX-zap-file ".dvi\"\n"))
  530.   (TeX-recenter-output-buffer nil))
  531.  
  532. (defun TeX-view-dvi ()
  533.   "Shows the .dvi file on the screen bu the shell command defined 
  534. by TeX-show-dvi-command."
  535.   (interactive)
  536.   (send-string "TeX-shell"
  537.            (concat TeX-show-dvi-command " \"" TeX-zap-file ".dvi\"\n"))
  538.   (TeX-recenter-output-buffer nil))
  539.  
  540. (defun TeX-show-print-queue ()
  541.   "Show the print queue that \\[TeX-print] put your job on.
  542. Runs the shell command defined by TeX-show-queue-command."
  543.   (interactive)
  544.   (if (not (get-buffer "*TeX-shell*"))
  545.       (TeX-start-shell))
  546.   (send-string "TeX-shell" (concat TeX-show-queue-command "\n"))
  547.   (TeX-recenter-output-buffer nil))
  548.  
  549.