/[emacs]/emacs/lisp/textmodes/tex-mode.el
ViewVC logotype

Diff of /emacs/lisp/textmodes/tex-mode.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.124 by sds, Mon Jul 1 19:55:45 2002 UTC revision 1.125 by monnier, Sun Jul 14 20:39:18 2002 UTC
# Line 1  Line 1 
1  ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands  ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands -*- coding: utf-8 -*-
2    
3  ;; Copyright (C) 1985, 86, 89, 92, 94, 95, 96, 97, 98, 1999, 2002  ;; Copyright (C) 1985, 86, 89, 92, 94, 95, 96, 97, 98, 1999, 2002
4  ;;       Free Software Foundation, Inc.  ;;       Free Software Foundation, Inc.
# Line 120  See the documentation of that variable." Line 120  See the documentation of that variable."
120    :group 'tex-run)    :group 'tex-run)
121    
122  ;;;###autoload  ;;;###autoload
123  (defcustom tex-start-options nil  (defcustom tex-start-options ""
124    "*TeX options to use when starting TeX.    "*TeX options to use when starting TeX.
125  These precede the commands in `tex-start-options'  These immediately precede the commands in `tex-start-commands'
126  and the input file name.  If nil, TeX runs with no options.  and the input file name, with no separating space and are not shell-quoted.
127  See the documentation of `tex-command'."  If nil, TeX runs with no options.  See the documentation of `tex-command'."
128    :type '(radio (const :tag "Interactive \(nil\)" nil)    :type 'string
                 (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"  
                        "\\nonstopmode\\input")  
                 (string :tag "String at your choice"))  
129    :group 'tex-run    :group 'tex-run
130    :version "21.4")    :version "21.4")
131    
132  ;;;###autoload  ;;;###autoload
133  (defcustom tex-start-commands "\\nonstopmode\\input"  (defcustom tex-start-commands "\\nonstopmode\\input"
134    "*TeX commands to use when starting TeX.    "*TeX commands to use when starting TeX.
135  These precede the input file name.  If nil, no commands are used.  They are shell-quoted and precede the input file name, with a separating space.
136  See the documentation of `tex-command'."  If nil, no commands are used.  See the documentation of `tex-command'."
137    :type '(radio (const :tag "Interactive \(nil\)" nil)    :type '(radio (const :tag "Interactive \(nil\)" nil)
138                  (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"                  (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"
139                         "\\nonstopmode\\input")                         "\\nonstopmode\\input")
# Line 235  Normally set to either `plain-tex-mode' Line 232  Normally set to either `plain-tex-mode'
232  (defcustom tex-open-quote "``"  (defcustom tex-open-quote "``"
233    "*String inserted by typing \\[tex-insert-quote] to open a quotation."    "*String inserted by typing \\[tex-insert-quote] to open a quotation."
234    :type 'string    :type 'string
235      :options '("``" "\"<" "\"`" "<<" "«")
236    :group 'tex)    :group 'tex)
237    
238  ;;;###autoload  ;;;###autoload
239  (defcustom tex-close-quote "''"  (defcustom tex-close-quote "''"
240    "*String inserted by typing \\[tex-insert-quote] to close a quotation."    "*String inserted by typing \\[tex-insert-quote] to close a quotation."
241    :type 'string    :type 'string
242      :options '("''" "\">" "\"'" ">>" "»")
243    :group 'tex)    :group 'tex)
244    
245  (defvar tex-last-temp-file nil  (defvar tex-last-temp-file nil
# Line 248  Normally set to either `plain-tex-mode' Line 247  Normally set to either `plain-tex-mode'
247  Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the  Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the
248  tex shell terminates.")  tex shell terminates.")
249    
250  (defvar tex-command nil  (defvar tex-command "tex"
251    "*Command to run TeX.    "*Command to run TeX.
252  If this string contains an asterisk \(`*'\), that is replaced by the file name\;  If this string contains an asterisk \(`*'\), that is replaced by the file name;
253  otherwise the value of `tex-start-options', the \(shell-quoted\)  otherwise the value of `tex-start-options', the \(shell-quoted\)
254  value of `tex-start-commands', and the file name are added at the end  value of `tex-start-commands', and the file name are added at the end
255  with blanks as separators.  with blanks as separators.
# Line 465  An alternative value is \" . \", if you Line 464  An alternative value is \" . \", if you
464             ;; (arg "\\(?:{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)\\|\\\\[a-z*]+\\)"))             ;; (arg "\\(?:{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)\\|\\\\[a-z*]+\\)"))
465             (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)"))             (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)"))
466        (list        (list
467           ;; display $$ math $$
468           ;; We only mark the match between $$ and $$ because the $$ delimiters
469           ;; themselves have already been marked (along with $..$) by syntactic
470           ;; fontification.  Also this is done at the very beginning so as to
471           ;; interact with the other keywords in the same way as $...$ does.
472           (list "\\$\\$\\([^$]+\\)\\$\\$" 1 'tex-math-face)
473         ;; Heading args.         ;; Heading args.
474         (list (concat slash headings "\\*?" opt arg)         (list (concat slash headings "\\*?" opt arg)
475               ;; If ARG ends up matching too much (if the {} don't match, f.ex)               ;; If ARG ends up matching too much (if the {} don't match, f.ex)
# Line 529  An alternative value is \" . \", if you Line 534  An alternative value is \" . \", if you
534          (list (concat slash citations opt arg) 3 'font-lock-constant-face)          (list (concat slash citations opt arg) 3 'font-lock-constant-face)
535          ;;          ;;
536          ;; Text between `` quotes ''.          ;; Text between `` quotes ''.
537          (cons (concat (regexp-opt `("``" "\"<" "\"`" "<<" "k") t)          (cons (concat (regexp-opt `("``" "\"<" "\"`" "<<" "«") t)
538                        "[^'\">{]+"       ;a bit pessimistic                        "[^'\">{]+"       ;a bit pessimistic
539                        (regexp-opt `("''" "\">" "\"'" ">>" "{") t))                        (regexp-opt `("''" "\">" "\"'" ">>" "»") t))
540                'font-lock-string-face)                'font-lock-string-face)
541          ;;          ;;
542          ;; Command names, special and general.          ;; Command names, special and general.
# Line 601  An alternative value is \" . \", if you Line 606  An alternative value is \" . \", if you
606      (define-key map "[" 'skeleton-pair-insert-maybe)      (define-key map "[" 'skeleton-pair-insert-maybe)
607      (define-key map "$" 'skeleton-pair-insert-maybe)      (define-key map "$" 'skeleton-pair-insert-maybe)
608      (define-key map "\n" 'tex-terminate-paragraph)      (define-key map "\n" 'tex-terminate-paragraph)
     (define-key map "\t" 'indent-for-tab-command)  
609      (define-key map "\M-\r" 'latex-insert-item)      (define-key map "\M-\r" 'latex-insert-item)
610      (define-key map "\C-c}" 'up-list)      (define-key map "\C-c}" 'up-list)
611      (define-key map "\C-c{" 'tex-insert-braces)      (define-key map "\C-c{" 'tex-insert-braces)
# Line 686  says which mode to use." Line 690  says which mode to use."
690                     (eval-when-compile                     (eval-when-compile
691                       (concat                       (concat
692                        (regexp-opt '("documentstyle" "documentclass"                        (regexp-opt '("documentstyle" "documentclass"
693                                      "begin" "section" "part" "chapter") 'words)                                      "begin" "subsection" "section"
694                                        "part" "chapter" "newcommand") 'words)
695                        "\\|NeedsTeXFormat{LaTeX")))                        "\\|NeedsTeXFormat{LaTeX")))
696                    (if (looking-at                    (if (looking-at
697                         "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")                         "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
# Line 824  subshell is initiated, `tex-shell-hook' Line 829  subshell is initiated, `tex-shell-hook'
829    (set (make-local-variable 'imenu-create-index-function)    (set (make-local-variable 'imenu-create-index-function)
830         'latex-imenu-create-index)         'latex-imenu-create-index)
831    (set (make-local-variable 'tex-face-alist) tex-latex-face-alist)    (set (make-local-variable 'tex-face-alist) tex-latex-face-alist)
832    (set (make-local-variable 'fill-nobreak-predicate)    (add-hook 'fill-nobreak-predicate 'latex-fill-nobreak-predicate nil t)
        'latex-fill-nobreak-predicate)  
833    (set (make-local-variable 'indent-line-function) 'latex-indent)    (set (make-local-variable 'indent-line-function) 'latex-indent)
834    (set (make-local-variable 'fill-indent-according-to-mode) t)    (set (make-local-variable 'fill-indent-according-to-mode) t)
835    (set (make-local-variable 'outline-regexp) latex-outline-regexp)    (set (make-local-variable 'outline-regexp) latex-outline-regexp)
# Line 913  Entering SliTeX mode runs the hook `text Line 917  Entering SliTeX mode runs the hook `text
917           (font-lock-mark-block-function . mark-paragraph)           (font-lock-mark-block-function . mark-paragraph)
918           (font-lock-syntactic-face-function           (font-lock-syntactic-face-function
919            . tex-font-lock-syntactic-face-function)))            . tex-font-lock-syntactic-face-function)))
920      ;; TABs in verbatim environments don't do what you think.
921      (set (make-local-variable 'indent-tabs-mode) nil)
922    (make-local-variable 'tex-command)    (make-local-variable 'tex-command)
923    (make-local-variable 'tex-start-of-header)    (make-local-variable 'tex-start-of-header)
924    (make-local-variable 'tex-end-of-header)    (make-local-variable 'tex-end-of-header)
# Line 954  Inserts the value of `tex-open-quote' (n Line 960  Inserts the value of `tex-open-quote' (n
960  \(normally '') depending on the context.  With prefix argument, always  \(normally '') depending on the context.  With prefix argument, always
961  inserts \" characters."  inserts \" characters."
962    (interactive "*P")    (interactive "*P")
963    (if arg    (if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\))
964              (eq (get-text-property (point) 'face) 'tex-verbatim-face)
965              (save-excursion
966                (backward-char (length tex-open-quote))
967                (when (or (looking-at (regexp-quote tex-open-quote))
968                          (looking-at (regexp-quote tex-close-quote)))
969                  (delete-char (length tex-open-quote))
970                  t)))
971        (self-insert-command (prefix-numeric-value arg))        (self-insert-command (prefix-numeric-value arg))
972      (insert      (insert (if (memq (char-syntax (preceding-char)) '(?\( ?> ?\ ))
973       (cond ((= (preceding-char) ?\\) ?\")                  tex-open-quote tex-close-quote))))
            ((memq (char-syntax (preceding-char)) '(?\( ?> ?\ )) tex-open-quote)  
            (t tex-close-quote)))))  
974    
975  (defun tex-validate-buffer ()  (defun tex-validate-buffer ()
976    "Check current buffer for paragraphs containing mismatched braces or $s.    "Check current buffer for paragraphs containing mismatched braces or $s.
# Line 1090  A prefix arg inhibits the checking." Line 1101  A prefix arg inhibits the checking."
1101    (let ((opoint (point))    (let ((opoint (point))
1102          inside)          inside)
1103      (save-excursion      (save-excursion
1104        (save-restriction        (beginning-of-line)
1105          (beginning-of-line)        (while (re-search-forward "\\\\verb\\(.\\)" opoint t)
1106          (narrow-to-region (point) opoint)          (unless (re-search-forward (regexp-quote (match-string 1)) opoint t)
1107          (while (re-search-forward "\\\\verb\\(.\\)" nil t)            (setq inside t))))
           (unless (re-search-forward (regexp-quote (match-string 1)) nil t)  
             (setq inside t)))))  
1108      inside))      inside))
1109    
1110  (defvar latex-block-default "enumerate")  (defvar latex-block-default "enumerate")
# Line 1106  A prefix arg inhibits the checking." Line 1115  A prefix arg inhibits the checking."
1115  Puts point on a blank line between them."  Puts point on a blank line between them."
1116    (let ((choice (completing-read (format "LaTeX block name [%s]: "    (let ((choice (completing-read (format "LaTeX block name [%s]: "
1117                                           latex-block-default)                                           latex-block-default)
1118                                   (mapcar 'list                                   (append latex-block-names
1119                                           (append standard-latex-block-names                                           standard-latex-block-names)
                                                  latex-block-names))  
1120                                   nil nil nil nil latex-block-default)))                                   nil nil nil nil latex-block-default)))
1121      (setq latex-block-default choice)      (setq latex-block-default choice)
1122      (unless (or (member choice standard-latex-block-names)      (unless (or (member choice standard-latex-block-names)
# Line 1116  Puts point on a blank line between them. Line 1124  Puts point on a blank line between them.
1124        ;; Remember new block names for later completion.        ;; Remember new block names for later completion.
1125        (push choice latex-block-names))        (push choice latex-block-names))
1126      choice)      choice)
1127    \n "\\begin{" str ?\}    \n "\\begin{" str "}"
1128    ?\[ (skeleton-read "[options]: ") & ?\] | -1    ?\[ (skeleton-read "[options]: ") & ?\] | -1
1129    > \n _ \n    > \n _ \n
1130    "\\end{" str ?\} > \n)    "\\end{" str "}" > \n)
1131    
1132  (define-skeleton latex-insert-item  (define-skeleton latex-insert-item
1133    "Insert a \item macro."    "Insert a \item macro."
# Line 1133  Puts point on a blank line between them. Line 1141  Puts point on a blank line between them.
1141    
1142  (defun tex-last-unended-begin ()  (defun tex-last-unended-begin ()
1143    "Leave point at the beginning of the last `\\begin{...}' that is unended."    "Leave point at the beginning of the last `\\begin{...}' that is unended."
1144    (while (and (re-search-backward "\\\\\\(begin\\|end\\)\\s *{")    (condition-case nil
1145                (looking-at "\\\\end"))        (while (and (re-search-backward "\\\\\\(begin\\|end\\)\\s *{")
1146      (tex-last-unended-begin)))                    (looking-at "\\\\end"))
1147            (tex-last-unended-begin))
1148        (search-failed (error "Couldn't find unended \\begin"))))
1149    
1150  (defun tex-next-unmatched-end ()  (defun tex-next-unmatched-end ()
1151    "Leave point at the end of the next `\\end' that is unended."    "Leave point at the end of the next `\\end' that is unended."
# Line 1150  Mark is left at original location." Line 1160  Mark is left at original location."
1160    (interactive)    (interactive)
1161    (let ((spot))    (let ((spot))
1162      (save-excursion      (save-excursion
1163        (condition-case nil        (tex-last-unended-begin)
           (tex-last-unended-begin)  
         (error (error "Couldn't find unended \\begin")))  
1164        (setq spot (point)))        (setq spot (point)))
1165      (push-mark)      (push-mark)
1166      (goto-char spot)))      (goto-char spot)))
# Line 1428  ALL other buffers." Line 1436  ALL other buffers."
1436                         (save-restriction                         (save-restriction
1437                           (widen)                           (widen)
1438                           (goto-char (point-min))                           (goto-char (point-min))
1439                           (re-search-forward header-re 10000 t))))                           (re-search-forward
1440                              header-re (+ (point) 10000) t))))
1441              (throw 'found (expand-file-name buffer-file-name))))))))              (throw 'found (expand-file-name buffer-file-name))))))))
1442    
1443  (defun tex-main-file ()  (defun tex-main-file ()
# Line 1443  ALL other buffers." Line 1452  ALL other buffers."
1452                       (file-relative-name                       (file-relative-name
1453                        (if (save-excursion                        (if (save-excursion
1454                              (goto-char (point-min))                              (goto-char (point-min))
1455                              (re-search-forward tex-start-of-header 10000 t))                              (re-search-forward tex-start-of-header
1456                                                   (+ (point) 10000) t))
1457                            ;; This is the main file.                            ;; This is the main file.
1458                            buffer-file-name                            buffer-file-name
1459                          ;; This isn't the main file, let's try to find better,                          ;; This isn't the main file, let's try to find better,
# Line 1462  ALL other buffers." Line 1472  ALL other buffers."
1472                        (comint-quote-filename file)                        (comint-quote-filename file)
1473                        (substring command (1+ star)))                        (substring command (1+ star)))
1474              (concat command " "              (concat command " "
1475                        tex-start-options
1476                      (if (< 0 (length tex-start-commands))                      (if (< 0 (length tex-start-commands))
1477                          (concat                          (concat
1478                           (shell-quote-argument tex-start-commands) " "))                           (shell-quote-argument tex-start-commands) " "))
                     tex-start-options  
1479                      (comint-quote-filename file)))))                      (comint-quote-filename file)))))
1480      (tex-send-tex-command compile-command dir)))      (tex-send-tex-command compile-command dir)))
1481    

Legend:
Removed from v.1.124  
changed lines
  Added in v.1.125

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26