(describe-function): Fix previous change.
[bpt/emacs.git] / lisp / textmodes / tex-mode.el
index b9c450c..ebf39c2 100644 (file)
@@ -239,7 +239,7 @@ Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].")
   "Keymap for the TeX shell.
 Inherits `comint-mode-map' with a few additions.")
 
-(defvar compare-windows-whitespace nil)        ; Pacify the byte-compiler
+(defvar compare-windows-whitespace)    ; Pacify the byte-compiler
 
 ;;; This would be a lot simpler if we just used a regexp search,
 ;;; but then it would be too slow.
@@ -261,8 +261,9 @@ says which mode to use."
                                    (beginning-of-line)
                                    (search-forward "%" search-end t))))))
       (if (and slash (not comment))
-         (setq mode (if (looking-at "documentstyle")
-                         (if (looking-at "documentstyle{slides}")
+         (setq mode (if (looking-at "documentstyle\\|documentclass")
+                         (if (looking-at
+                             "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
                              'slitex-mode
                            'latex-mode)
                       'plain-tex-mode))))
@@ -381,7 +382,7 @@ subshell is initiated, `tex-shell-hook' is run."
   ;; A line starting with $$ starts a paragraph,
   ;; but does not separate paragraphs if it has more stuff on it.
   (setq paragraph-start "^[ \t]*$\\|^[\f%]\\|^[ \t]*\\$\\$\\|\
-^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|\
+^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|^\\\\\\]\\|\
 ^\\\\chapter\\>\\|^\\\\section\\>\\|\
 ^\\\\subsection\\>\\|^\\\\subsubsection\\>\\|\
 ^\\\\paragraph\\>\\|^\\\\subparagraph\\>\\|\
@@ -389,15 +390,15 @@ subshell is initiated, `tex-shell-hook' is run."
 ^\\\\[a-z]*space\\>\\|^\\\\[a-z]*skip\\>\\|\
 ^\\\\newpage\\>\\|^\\\\[a-z]*page\\|^\\\\footnote\\>\\|\
 ^\\\\marginpar\\>\\|^\\\\parbox\\>\\|^\\\\caption\\>")
-  (setq paragraph-separate "^[ \t]*$\\|^[\f\\\\%]\\|^[ \t]*\\$\\$[ \t]*$\\|\
-^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|\
+  (setq paragraph-separate "^[ \t]*$\\|^[\f%]\\|^[ \t]*\\$\\$[ \t]*$\\|\
+^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|^\\\\\\]\\|\
 ^\\\\chapter\\>\\|^\\\\section\\>\\|\
 ^\\\\subsection\\>\\|^\\\\subsubsection\\>\\|\
 ^\\\\paragraph\\>\\|^\\\\subparagraph\\>\\|\
-^\\\\item[ \t]*$\\|^\\\\bibitem[ \t]*$\\|^\\\\newline[ \t]*$\\|^\\\\noindent[ \t]*$\\|\
-^\\\\[a-z]*space[ \t]*$\\|^\\\\[a-z]*skip[ \t]*$\\|\
-^\\\\newpage[ \t]*$\\|^\\\\[a-z]*page[a-z]*[ \t]*$\\|^\\\\footnote[ \t]*$\\|\
-^\\\\marginpar[ \t]*$\\|^\\\\parbox[ \t]*$\\|^\\\\caption[ \t]*$")
+\\(^\\\\item\\|^\\\\bibitem\\|^\\\\newline\\|^\\\\noindent\\|\
+^\\\\[a-z]*space\\|^\\\\[a-z]*skip\\|\
+^\\\\newpage\\|^\\\\[a-z]*page[a-z]*\\|^\\\\footnote\\|\
+^\\\\marginpar\\|^\\\\parbox\\|^\\\\caption\\)[ \t]*\\($\\|%\\)")
   (run-hooks 'text-mode-hook 'tex-mode-hook 'latex-mode-hook))
 
 ;;;###autoload
@@ -454,7 +455,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
   ;; A line starting with $$ starts a paragraph,
   ;; but does not separate paragraphs if it has more stuff on it.
   (setq paragraph-start "^[ \t]*$\\|^[\f%]\\|^[ \t]*\\$\\$\\|\
-^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|\
+^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|^\\\\\\]\\|\
 ^\\\\chapter\\>\\|^\\\\section\\>\\|\
 ^\\\\subsection\\>\\|^\\\\subsubsection\\>\\|\
 ^\\\\paragraph\\>\\|^\\\\subparagraph\\>\\|\
@@ -462,8 +463,8 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
 ^\\\\[a-z]*space\\>\\|^\\\\[a-z]*skip\\>\\|\
 ^\\\\newpage\\>\\|^\\\\[a-z]*page\\|^\\\\footnote\\>\\|\
 ^\\\\marginpar\\>\\|^\\\\parbox\\>\\|^\\\\caption\\>")
-  (setq paragraph-separate "^[ \t]*$\\|^[\f\\\\%]\\|^[ \t]*\\$\\$[ \t]*$\\|\
-^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|\
+  (setq paragraph-separate "^[ \t]*$\\|^[\f%]\\|^[ \t]*\\$\\$[ \t]*$\\|\
+^\\\\begin\\>\\|^\\\\label\\>\\|^\\\\end\\>\\|^\\\\\\[\\|^\\\\\\]\\|\
 ^\\\\chapter\\>\\|^\\\\section\\>\\|\
 ^\\\\subsection\\>\\|^\\\\subsubsection\\>\\|\
 ^\\\\paragraph\\>\\|^\\\\subparagraph\\>\\|\
@@ -812,6 +813,7 @@ line numbers for the errors."
 
 ;;; The utility functions:
 
+;;;###autoload
 (defun tex-start-shell ()
   (save-excursion
     (set-buffer
@@ -822,7 +824,8 @@ line numbers for the errors."
     (let ((proc (get-process "tex-shell")))
       (set-process-sentinel proc 'tex-shell-sentinel)
       (process-kill-without-query proc)
-      (setq tex-shell-map (copy-keymap shell-mode-map))
+      (setq comint-prompt-regexp shell-prompt-pattern)
+      (setq tex-shell-map (copy-keymap comint-mode-map))
       (tex-define-common-keys tex-shell-map)
       (use-local-map tex-shell-map)
       (run-hooks 'tex-shell-hook)
@@ -884,9 +887,10 @@ evaluates to a command string."
 If NOT-ALL is non-nil, save the `.dvi' file."
   (if tex-last-temp-file
       (let* ((dir (file-name-directory tex-last-temp-file))
-             (list (file-name-all-completions
-                    (file-name-nondirectory tex-last-temp-file) dir)))
-        (while list
+            (list (and (file-directory-p dir)
+                       (file-name-all-completions
+                        (file-name-nondirectory tex-last-temp-file) dir))))
+       (while list
          (if not-all
              (and
               ;; If arg is non-nil, don't delete the .dvi file.
@@ -916,6 +920,7 @@ The value of `tex-command' specifies the command to use to run TeX."
   (if (tex-shell-running)
       (tex-kill-job)
     (tex-start-shell))
+  (display-buffer (process-buffer (get-process "tex-shell")))
   (or tex-zap-file
       (setq tex-zap-file (tex-generate-zap-file-name)))
   (let* ((temp-buffer (get-buffer-create " TeX-Output-Buffer"))
@@ -927,7 +932,9 @@ The value of `tex-command' specifies the command to use to run TeX."
          (zap-directory
           (file-name-as-directory (expand-file-name tex-directory)))
          (tex-out-file (concat zap-directory tex-zap-file)))
-    (tex-delete-last-temp-files t)
+    ;; Don't delete temp files if we do the same buffer twice in a row.
+    (or (eq (current-buffer) tex-last-buffer-texed)
+       (tex-delete-last-temp-files t))
     ;; Write the new temp file.
     (save-excursion
       (save-restriction
@@ -988,6 +995,7 @@ This function is more useful than \\[tex-buffer] when you need the
     (if (tex-shell-running)
         (tex-kill-job)
       (tex-start-shell))
+    (display-buffer (process-buffer (get-process "tex-shell")))
     (tex-send-command tex-shell-cd-command file-dir)
     (tex-send-command tex-command tex-out-file))
   (setq tex-last-buffer-texed (current-buffer))
@@ -1107,6 +1115,7 @@ Runs the shell command defined by `tex-show-queue-command'."
   (if (tex-shell-running)
       (tex-kill-job)
     (tex-start-shell))
+  (display-buffer (process-buffer (get-process "tex-shell")))
   (tex-send-command tex-show-queue-command))
 
 (defun tex-bibtex-file ()
@@ -1115,6 +1124,7 @@ Runs the shell command defined by `tex-show-queue-command'."
   (if (tex-shell-running)
       (tex-kill-job)
     (tex-start-shell))
+  (display-buffer (process-buffer (get-process "tex-shell")))
   (let ((tex-out-file
          (tex-append (file-name-nondirectory (buffer-file-name)) ""))
        (file-dir (file-name-directory (buffer-file-name))))