aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-07-14 20:39:18 +0000
committerStefan Monnier2002-07-14 20:39:18 +0000
commit95a045bd7f62e78b7b211ed80cbd691134c02b6b (patch)
treeb775c71e713092ed53b721ce322efb2e05773d02
parente28e4d206791cc138e87243eca5d44d7dbef5469 (diff)
downloademacs-95a045bd7f62e78b7b211ed80cbd691134c02b6b.tar.gz
emacs-95a045bd7f62e78b7b211ed80cbd691134c02b6b.zip
Set encoding to utf-8.
(tex-start-options): Make it into always-a-string. Remove silly custom options that are covered by the other var. (tex-start-commands): Fix docstring. (tex-open-quote, tex-close-quote): Add options. (tex-command): Provide default. (tex-font-lock-keywords-1): Highlight $$...$$. (tex-font-lock-keywords-2): Fix latin-1 chars. (tex-mode-map): Remove redundant \t binding. (tex-mode): Add `subsection' and `newcommand' to known latex cmds. (latex-mode): Use add-hook for fill-nobreak-predicate. (tex-common-initialization): Set indent-tabs-mode to nil. (tex-insert-quote): Undo magic if invoked twice in a row. (latex-fill-nobreak-predicate): Don't use narrowing. (tex-latex-block): Don't cons uselessly. (tex-last-unended-begin): Signal user-friendlier error. (tex-goto-last-unclosed-latex-block): Don't catch signal. (tex-start-tex): Switch order of tex-start-options and tex-start-commands to make it obey docstrings.
-rw-r--r--lisp/textmodes/tex-mode.el98
1 files changed, 54 insertions, 44 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index b78c50b2ec1..3715a7dd7c8 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -1,4 +1,4 @@
1;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands 1;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands -*- coding: utf-8 -*-
2 2
3;; Copyright (C) 1985, 86, 89, 92, 94, 95, 96, 97, 98, 1999, 2002 3;; Copyright (C) 1985, 86, 89, 92, 94, 95, 96, 97, 98, 1999, 2002
4;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
@@ -120,23 +120,20 @@ See the documentation of that variable."
120 :group 'tex-run) 120 :group 'tex-run)
121 121
122;;;###autoload 122;;;###autoload
123(defcustom tex-start-options nil 123(defcustom tex-start-options ""
124 "*TeX options to use when starting TeX. 124 "*TeX options to use when starting TeX.
125These precede the commands in `tex-start-options' 125These immediately precede the commands in `tex-start-commands'
126and the input file name. If nil, TeX runs with no options. 126and the input file name, with no separating space and are not shell-quoted.
127See the documentation of `tex-command'." 127If nil, TeX runs with no options. See the documentation of `tex-command'."
128 :type '(radio (const :tag "Interactive \(nil\)" nil) 128 :type 'string
129 (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"
130 "\\nonstopmode\\input")
131 (string :tag "String at your choice"))
132 :group 'tex-run 129 :group 'tex-run
133 :version "21.4") 130 :version "21.4")
134 131
135;;;###autoload 132;;;###autoload
136(defcustom tex-start-commands "\\nonstopmode\\input" 133(defcustom tex-start-commands "\\nonstopmode\\input"
137 "*TeX commands to use when starting TeX. 134 "*TeX commands to use when starting TeX.
138These precede the input file name. If nil, no commands are used. 135They are shell-quoted and precede the input file name, with a separating space.
139See the documentation of `tex-command'." 136If nil, no commands are used. See the documentation of `tex-command'."
140 :type '(radio (const :tag "Interactive \(nil\)" nil) 137 :type '(radio (const :tag "Interactive \(nil\)" nil)
141 (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)" 138 (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"
142 "\\nonstopmode\\input") 139 "\\nonstopmode\\input")
@@ -235,12 +232,14 @@ Normally set to either `plain-tex-mode' or `latex-mode'."
235(defcustom tex-open-quote "``" 232(defcustom tex-open-quote "``"
236 "*String inserted by typing \\[tex-insert-quote] to open a quotation." 233 "*String inserted by typing \\[tex-insert-quote] to open a quotation."
237 :type 'string 234 :type 'string
235 :options '("``" "\"<" "\"`" "<<" "«")
238 :group 'tex) 236 :group 'tex)
239 237
240;;;###autoload 238;;;###autoload
241(defcustom tex-close-quote "''" 239(defcustom tex-close-quote "''"
242 "*String inserted by typing \\[tex-insert-quote] to close a quotation." 240 "*String inserted by typing \\[tex-insert-quote] to close a quotation."
243 :type 'string 241 :type 'string
242 :options '("''" "\">" "\"'" ">>" "»")
244 :group 'tex) 243 :group 'tex)
245 244
246(defvar tex-last-temp-file nil 245(defvar tex-last-temp-file nil
@@ -248,9 +247,9 @@ Normally set to either `plain-tex-mode' or `latex-mode'."
248Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the 247Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the
249tex shell terminates.") 248tex shell terminates.")
250 249
251(defvar tex-command nil 250(defvar tex-command "tex"
252 "*Command to run TeX. 251 "*Command to run TeX.
253If this string contains an asterisk \(`*'\), that is replaced by the file name\; 252If this string contains an asterisk \(`*'\), that is replaced by the file name;
254otherwise the value of `tex-start-options', the \(shell-quoted\) 253otherwise the value of `tex-start-options', the \(shell-quoted\)
255value of `tex-start-commands', and the file name are added at the end 254value of `tex-start-commands', and the file name are added at the end
256with blanks as separators. 255with blanks as separators.
@@ -465,6 +464,12 @@ An alternative value is \" . \", if you use a font with a narrow period."
465 ;; (arg "\\(?:{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)\\|\\\\[a-z*]+\\)")) 464 ;; (arg "\\(?:{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)\\|\\\\[a-z*]+\\)"))
466 (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)")) 465 (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)"))
467 (list 466 (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)
468 ;; Heading args. 473 ;; Heading args.
469 (list (concat slash headings "\\*?" opt arg) 474 (list (concat slash headings "\\*?" opt arg)
470 ;; If ARG ends up matching too much (if the {} don't match, f.ex) 475 ;; If ARG ends up matching too much (if the {} don't match, f.ex)
@@ -529,9 +534,9 @@ An alternative value is \" . \", if you use a font with a narrow period."
529 (list (concat slash citations opt arg) 3 'font-lock-constant-face) 534 (list (concat slash citations opt arg) 3 'font-lock-constant-face)
530 ;; 535 ;;
531 ;; Text between `` quotes ''. 536 ;; Text between `` quotes ''.
532 (cons (concat (regexp-opt `("``" "\"<" "\"`" "<<" "k") t) 537 (cons (concat (regexp-opt `("``" "\"<" "\"`" "<<" "«") t)
533 "[^'\">{]+" ;a bit pessimistic 538 "[^'\">{]+" ;a bit pessimistic
534 (regexp-opt `("''" "\">" "\"'" ">>" "{") t)) 539 (regexp-opt `("''" "\">" "\"'" ">>" "»") t))
535 'font-lock-string-face) 540 'font-lock-string-face)
536 ;; 541 ;;
537 ;; Command names, special and general. 542 ;; Command names, special and general.
@@ -601,7 +606,6 @@ An alternative value is \" . \", if you use a font with a narrow period."
601 (define-key map "[" 'skeleton-pair-insert-maybe) 606 (define-key map "[" 'skeleton-pair-insert-maybe)
602 (define-key map "$" 'skeleton-pair-insert-maybe) 607 (define-key map "$" 'skeleton-pair-insert-maybe)
603 (define-key map "\n" 'tex-terminate-paragraph) 608 (define-key map "\n" 'tex-terminate-paragraph)
604 (define-key map "\t" 'indent-for-tab-command)
605 (define-key map "\M-\r" 'latex-insert-item) 609 (define-key map "\M-\r" 'latex-insert-item)
606 (define-key map "\C-c}" 'up-list) 610 (define-key map "\C-c}" 'up-list)
607 (define-key map "\C-c{" 'tex-insert-braces) 611 (define-key map "\C-c{" 'tex-insert-braces)
@@ -686,7 +690,8 @@ says which mode to use."
686 (eval-when-compile 690 (eval-when-compile
687 (concat 691 (concat
688 (regexp-opt '("documentstyle" "documentclass" 692 (regexp-opt '("documentstyle" "documentclass"
689 "begin" "section" "part" "chapter") 'words) 693 "begin" "subsection" "section"
694 "part" "chapter" "newcommand") 'words)
690 "\\|NeedsTeXFormat{LaTeX"))) 695 "\\|NeedsTeXFormat{LaTeX")))
691 (if (looking-at 696 (if (looking-at
692 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}") 697 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
@@ -824,8 +829,7 @@ subshell is initiated, `tex-shell-hook' is run."
824 (set (make-local-variable 'imenu-create-index-function) 829 (set (make-local-variable 'imenu-create-index-function)
825 'latex-imenu-create-index) 830 'latex-imenu-create-index)
826 (set (make-local-variable 'tex-face-alist) tex-latex-face-alist) 831 (set (make-local-variable 'tex-face-alist) tex-latex-face-alist)
827 (set (make-local-variable 'fill-nobreak-predicate) 832 (add-hook 'fill-nobreak-predicate 'latex-fill-nobreak-predicate nil t)
828 'latex-fill-nobreak-predicate)
829 (set (make-local-variable 'indent-line-function) 'latex-indent) 833 (set (make-local-variable 'indent-line-function) 'latex-indent)
830 (set (make-local-variable 'fill-indent-according-to-mode) t) 834 (set (make-local-variable 'fill-indent-according-to-mode) t)
831 (set (make-local-variable 'outline-regexp) latex-outline-regexp) 835 (set (make-local-variable 'outline-regexp) latex-outline-regexp)
@@ -913,6 +917,8 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
913 (font-lock-mark-block-function . mark-paragraph) 917 (font-lock-mark-block-function . mark-paragraph)
914 (font-lock-syntactic-face-function 918 (font-lock-syntactic-face-function
915 . tex-font-lock-syntactic-face-function))) 919 . 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)
916 (make-local-variable 'tex-command) 922 (make-local-variable 'tex-command)
917 (make-local-variable 'tex-start-of-header) 923 (make-local-variable 'tex-start-of-header)
918 (make-local-variable 'tex-end-of-header) 924 (make-local-variable 'tex-end-of-header)
@@ -954,12 +960,17 @@ Inserts the value of `tex-open-quote' (normally ``) or `tex-close-quote'
954\(normally '') depending on the context. With prefix argument, always 960\(normally '') depending on the context. With prefix argument, always
955inserts \" characters." 961inserts \" characters."
956 (interactive "*P") 962 (interactive "*P")
957 (if arg 963 (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)))
958 (self-insert-command (prefix-numeric-value arg)) 971 (self-insert-command (prefix-numeric-value arg))
959 (insert 972 (insert (if (memq (char-syntax (preceding-char)) '(?\( ?> ?\ ))
960 (cond ((= (preceding-char) ?\\) ?\") 973 tex-open-quote tex-close-quote))))
961 ((memq (char-syntax (preceding-char)) '(?\( ?> ?\ )) tex-open-quote)
962 (t tex-close-quote)))))
963 974
964(defun tex-validate-buffer () 975(defun tex-validate-buffer ()
965 "Check current buffer for paragraphs containing mismatched braces or $s. 976 "Check current buffer for paragraphs containing mismatched braces or $s.
@@ -1090,12 +1101,10 @@ A prefix arg inhibits the checking."
1090 (let ((opoint (point)) 1101 (let ((opoint (point))
1091 inside) 1102 inside)
1092 (save-excursion 1103 (save-excursion
1093 (save-restriction 1104 (beginning-of-line)
1094 (beginning-of-line) 1105 (while (re-search-forward "\\\\verb\\(.\\)" opoint t)
1095 (narrow-to-region (point) opoint) 1106 (unless (re-search-forward (regexp-quote (match-string 1)) opoint t)
1096 (while (re-search-forward "\\\\verb\\(.\\)" nil t) 1107 (setq inside t))))
1097 (unless (re-search-forward (regexp-quote (match-string 1)) nil t)
1098 (setq inside t)))))
1099 inside)) 1108 inside))
1100 1109
1101(defvar latex-block-default "enumerate") 1110(defvar latex-block-default "enumerate")
@@ -1106,9 +1115,8 @@ A prefix arg inhibits the checking."
1106Puts point on a blank line between them." 1115Puts point on a blank line between them."
1107 (let ((choice (completing-read (format "LaTeX block name [%s]: " 1116 (let ((choice (completing-read (format "LaTeX block name [%s]: "
1108 latex-block-default) 1117 latex-block-default)
1109 (mapcar 'list 1118 (append latex-block-names
1110 (append standard-latex-block-names 1119 standard-latex-block-names)
1111 latex-block-names))
1112 nil nil nil nil latex-block-default))) 1120 nil nil nil nil latex-block-default)))
1113 (setq latex-block-default choice) 1121 (setq latex-block-default choice)
1114 (unless (or (member choice standard-latex-block-names) 1122 (unless (or (member choice standard-latex-block-names)
@@ -1116,10 +1124,10 @@ Puts point on a blank line between them."
1116 ;; Remember new block names for later completion. 1124 ;; Remember new block names for later completion.
1117 (push choice latex-block-names)) 1125 (push choice latex-block-names))
1118 choice) 1126 choice)
1119 \n "\\begin{" str ?\} 1127 \n "\\begin{" str "}"
1120 ?\[ (skeleton-read "[options]: ") & ?\] | -1 1128 ?\[ (skeleton-read "[options]: ") & ?\] | -1
1121 > \n _ \n 1129 > \n _ \n
1122 "\\end{" str ?\} > \n) 1130 "\\end{" str "}" > \n)
1123 1131
1124(define-skeleton latex-insert-item 1132(define-skeleton latex-insert-item
1125 "Insert a \item macro." 1133 "Insert a \item macro."
@@ -1133,9 +1141,11 @@ Puts point on a blank line between them."
1133 1141
1134(defun tex-last-unended-begin () 1142(defun tex-last-unended-begin ()
1135 "Leave point at the beginning of the last `\\begin{...}' that is unended." 1143 "Leave point at the beginning of the last `\\begin{...}' that is unended."
1136 (while (and (re-search-backward "\\\\\\(begin\\|end\\)\\s *{") 1144 (condition-case nil
1137 (looking-at "\\\\end")) 1145 (while (and (re-search-backward "\\\\\\(begin\\|end\\)\\s *{")
1138 (tex-last-unended-begin))) 1146 (looking-at "\\\\end"))
1147 (tex-last-unended-begin))
1148 (search-failed (error "Couldn't find unended \\begin"))))
1139 1149
1140(defun tex-next-unmatched-end () 1150(defun tex-next-unmatched-end ()
1141 "Leave point at the end of the next `\\end' that is unended." 1151 "Leave point at the end of the next `\\end' that is unended."
@@ -1150,9 +1160,7 @@ Mark is left at original location."
1150 (interactive) 1160 (interactive)
1151 (let ((spot)) 1161 (let ((spot))
1152 (save-excursion 1162 (save-excursion
1153 (condition-case nil 1163 (tex-last-unended-begin)
1154 (tex-last-unended-begin)
1155 (error (error "Couldn't find unended \\begin")))
1156 (setq spot (point))) 1164 (setq spot (point)))
1157 (push-mark) 1165 (push-mark)
1158 (goto-char spot))) 1166 (goto-char spot)))
@@ -1428,7 +1436,8 @@ ALL other buffers."
1428 (save-restriction 1436 (save-restriction
1429 (widen) 1437 (widen)
1430 (goto-char (point-min)) 1438 (goto-char (point-min))
1431 (re-search-forward header-re 10000 t)))) 1439 (re-search-forward
1440 header-re (+ (point) 10000) t))))
1432 (throw 'found (expand-file-name buffer-file-name)))))))) 1441 (throw 'found (expand-file-name buffer-file-name))))))))
1433 1442
1434(defun tex-main-file () 1443(defun tex-main-file ()
@@ -1443,7 +1452,8 @@ ALL other buffers."
1443 (file-relative-name 1452 (file-relative-name
1444 (if (save-excursion 1453 (if (save-excursion
1445 (goto-char (point-min)) 1454 (goto-char (point-min))
1446 (re-search-forward tex-start-of-header 10000 t)) 1455 (re-search-forward tex-start-of-header
1456 (+ (point) 10000) t))
1447 ;; This is the main file. 1457 ;; This is the main file.
1448 buffer-file-name 1458 buffer-file-name
1449 ;; This isn't the main file, let's try to find better, 1459 ;; This isn't the main file, let's try to find better,
@@ -1462,10 +1472,10 @@ ALL other buffers."
1462 (comint-quote-filename file) 1472 (comint-quote-filename file)
1463 (substring command (1+ star))) 1473 (substring command (1+ star)))
1464 (concat command " " 1474 (concat command " "
1475 tex-start-options
1465 (if (< 0 (length tex-start-commands)) 1476 (if (< 0 (length tex-start-commands))
1466 (concat 1477 (concat
1467 (shell-quote-argument tex-start-commands) " ")) 1478 (shell-quote-argument tex-start-commands) " "))
1468 tex-start-options
1469 (comint-quote-filename file))))) 1479 (comint-quote-filename file)))))
1470 (tex-send-tex-command compile-command dir))) 1480 (tex-send-tex-command compile-command dir)))
1471 1481