diff options
| author | Stefan Monnier | 2000-11-10 10:25:00 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-11-10 10:25:00 +0000 |
| commit | dd459839dab4262241722bb74e68c24429c9faa3 (patch) | |
| tree | 5aeb0a072a0c0ae3463c8f2ad52509d05757506e | |
| parent | 5dd31b135afa7beef777ff6a1f97eb3902b0beb5 (diff) | |
| download | emacs-dd459839dab4262241722bb74e68c24429c9faa3.tar.gz emacs-dd459839dab4262241722bb74e68c24429c9faa3.zip | |
(standard-latex-block-names): Add "math".
(latex-mode): Tweak tex-*-(head|trail)er regexps.
Tweak paragraph regexps to allow a leading [ \t]*.
(tex-latex-block): Insert a newline if necessary.
(latex-insert-item): Only insert a newline if necessary.
(tex-guess-main-file): New function.
(tex-main-file): Use it. Add arg `realfile'. Trim `.tex'.
Set tex-main-file if TeX-master is provided.
(tex-latex-indent-syntax-table): Map ( and ) to punctuation.
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 103 |
1 files changed, 74 insertions, 29 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 1faa2a257f0..8d60f4674d0 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -130,15 +130,15 @@ See the documentation of `tex-command'." | |||
| 130 | :version "20.4") | 130 | :version "20.4") |
| 131 | 131 | ||
| 132 | (defvar standard-latex-block-names | 132 | (defvar standard-latex-block-names |
| 133 | '("abstract" "array" "center" "description" | 133 | '("abstract" "array" "center" "description" |
| 134 | "displaymath" "document" "enumerate" "eqnarray" | 134 | "displaymath" "document" "enumerate" "eqnarray" |
| 135 | "eqnarray*" "equation" "figure" "figure*" | 135 | "eqnarray*" "equation" "figure" "figure*" |
| 136 | "flushleft" "flushright" "itemize" "letter" | 136 | "flushleft" "flushright" "itemize" "letter" |
| 137 | "list" "minipage" "picture" "quotation" | 137 | "list" "minipage" "picture" "quotation" |
| 138 | "quote" "slide" "sloppypar" "tabbing" | 138 | "quote" "slide" "sloppypar" "tabbing" |
| 139 | "table" "table*" "tabular" "tabular*" | 139 | "table" "table*" "tabular" "tabular*" |
| 140 | "thebibliography" "theindex*" "titlepage" "trivlist" | 140 | "thebibliography" "theindex*" "titlepage" "trivlist" |
| 141 | "verbatim" "verbatim*" "verse") | 141 | "verbatim" "verbatim*" "verse" "math") |
| 142 | "Standard LaTeX block names.") | 142 | "Standard LaTeX block names.") |
| 143 | 143 | ||
| 144 | ;;;###autoload | 144 | ;;;###autoload |
| @@ -721,14 +721,14 @@ Entering Latex mode runs the hook `text-mode-hook', then | |||
| 721 | subshell is initiated, `tex-shell-hook' is run." | 721 | subshell is initiated, `tex-shell-hook' is run." |
| 722 | (tex-common-initialization) | 722 | (tex-common-initialization) |
| 723 | (setq tex-command latex-run-command) | 723 | (setq tex-command latex-run-command) |
| 724 | (setq tex-start-of-header "\\\\documentstyle\\|\\\\documentclass") | 724 | (setq tex-start-of-header "\\\\document\\(style\\|class\\)") |
| 725 | (setq tex-end-of-header "\\\\begin{document}") | 725 | (setq tex-end-of-header "\\\\begin\\s-*{document}") |
| 726 | (setq tex-trailer "\\end{document}\n") | 726 | (setq tex-trailer "\\end\\s-*{document}\n") |
| 727 | ;; A line containing just $$ is treated as a paragraph separator. | 727 | ;; A line containing just $$ is treated as a paragraph separator. |
| 728 | ;; A line starting with $$ starts a paragraph, | 728 | ;; A line starting with $$ starts a paragraph, |
| 729 | ;; but does not separate paragraphs if it has more stuff on it. | 729 | ;; but does not separate paragraphs if it has more stuff on it. |
| 730 | (setq paragraph-start | 730 | (setq paragraph-start |
| 731 | (concat "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|" | 731 | (concat "[\f%]\\|[ \t]*\\($\\|\\$\\$\\|" |
| 732 | "\\\\[][]\\|" | 732 | "\\\\[][]\\|" |
| 733 | "\\\\" (regexp-opt (append | 733 | "\\\\" (regexp-opt (append |
| 734 | (mapcar 'car latex-section-alist) | 734 | (mapcar 'car latex-section-alist) |
| @@ -737,9 +737,9 @@ subshell is initiated, `tex-shell-hook' is run." | |||
| 737 | "newpage" "footnote" "marginpar" | 737 | "newpage" "footnote" "marginpar" |
| 738 | "parbox" "caption")) t) | 738 | "parbox" "caption")) t) |
| 739 | "\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t) | 739 | "\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t) |
| 740 | "\\>")) | 740 | "\\>\\)")) |
| 741 | (setq paragraph-separate | 741 | (setq paragraph-separate |
| 742 | (concat "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|" | 742 | (concat "[\f%]\\|[ \t]*\\($\\|" |
| 743 | "\\\\[][]\\|" | 743 | "\\\\[][]\\|" |
| 744 | "\\\\" (regexp-opt (append | 744 | "\\\\" (regexp-opt (append |
| 745 | (mapcar 'car latex-section-alist) | 745 | (mapcar 'car latex-section-alist) |
| @@ -747,14 +747,15 @@ subshell is initiated, `tex-shell-hook' is run." | |||
| 747 | "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline" | 747 | "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline" |
| 748 | "noindent" "newpage" "footnote" | 748 | "noindent" "newpage" "footnote" |
| 749 | "marginpar" "parbox" "caption")) | 749 | "marginpar" "parbox" "caption")) |
| 750 | "\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)" | 750 | "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)" |
| 751 | "\\)[ \t]*\\($\\|%\\)")) | 751 | "\\>\\)[ \t]*\\($\\|%\\)\\)")) |
| 752 | (set (make-local-variable 'imenu-create-index-function) | 752 | (set (make-local-variable 'imenu-create-index-function) |
| 753 | 'latex-imenu-create-index) | 753 | 'latex-imenu-create-index) |
| 754 | (set (make-local-variable 'tex-face-alist) tex-latex-face-alist) | 754 | (set (make-local-variable 'tex-face-alist) tex-latex-face-alist) |
| 755 | (set (make-local-variable 'fill-nobreak-predicate) | 755 | (set (make-local-variable 'fill-nobreak-predicate) |
| 756 | 'latex-fill-nobreak-predicate) | 756 | 'latex-fill-nobreak-predicate) |
| 757 | (set (make-local-variable 'indent-line-function) 'latex-indent) | 757 | (set (make-local-variable 'indent-line-function) 'latex-indent) |
| 758 | (set (make-local-variable 'fill-indent-according-to-mode) t) | ||
| 758 | (set (make-local-variable 'outline-regexp) latex-outline-regexp) | 759 | (set (make-local-variable 'outline-regexp) latex-outline-regexp) |
| 759 | (set (make-local-variable 'outline-level) 'latex-outline-level) | 760 | (set (make-local-variable 'outline-level) 'latex-outline-level) |
| 760 | (set (make-local-variable 'forward-sexp-function) 'latex-forward-sexp) | 761 | (set (make-local-variable 'forward-sexp-function) 'latex-forward-sexp) |
| @@ -1050,15 +1051,17 @@ Puts point on a blank line between them." | |||
| 1050 | ;; Remember new block names for later completion. | 1051 | ;; Remember new block names for later completion. |
| 1051 | (push choice latex-block-names)) | 1052 | (push choice latex-block-names)) |
| 1052 | choice) | 1053 | choice) |
| 1054 | (unless (save-excursion (beginning-of-line) (looking-at "[ \t]*$")) '\n) | ||
| 1053 | "\\begin{" str ?\} | 1055 | "\\begin{" str ?\} |
| 1054 | ?\[ (skeleton-read "[options]: ") & ?\] | -1 | 1056 | ?\[ (skeleton-read "[options]: ") & ?\] | -1 |
| 1055 | \n _ \n | 1057 | > \n _ \n |
| 1056 | "\\end{" str ?\} >) | 1058 | "\\end{" str ?\} >) |
| 1057 | 1059 | ||
| 1058 | (define-skeleton latex-insert-item | 1060 | (define-skeleton latex-insert-item |
| 1059 | "Insert a \item macro." | 1061 | "Insert a \item macro." |
| 1060 | nil | 1062 | nil |
| 1061 | \n "\\item " >) | 1063 | (unless (save-excursion (beginning-of-line) (looking-at "[ \t]*$")) '\n) |
| 1064 | "\\item " >) | ||
| 1062 | 1065 | ||
| 1063 | 1066 | ||
| 1064 | ;;;; | 1067 | ;;;; |
| @@ -1299,16 +1302,56 @@ If NOT-ALL is non-nil, save the `.dvi' file." | |||
| 1299 | (defvar tex-start-tex-marker nil | 1302 | (defvar tex-start-tex-marker nil |
| 1300 | "Marker pointing after last TeX-running command in the TeX shell buffer.") | 1303 | "Marker pointing after last TeX-running command in the TeX shell buffer.") |
| 1301 | 1304 | ||
| 1302 | (defun tex-main-file () | 1305 | (defun tex-guess-main-file (&optional all) |
| 1306 | "Find a likely `tex-main-file'. | ||
| 1307 | Looks for hints in other buffers in the same directory or in | ||
| 1308 | ALL other buffers." | ||
| 1309 | (let ((dir default-directory) | ||
| 1310 | (header-re tex-start-of-header)) | ||
| 1311 | (catch 'found | ||
| 1312 | ;; Look for a buffer with `tex-main-file' set. | ||
| 1313 | (dolist (buf (if (consp all) all (buffer-list))) | ||
| 1314 | (with-current-buffer buf | ||
| 1315 | (when (and (or all (equal dir default-directory)) | ||
| 1316 | (stringp tex-main-file)) | ||
| 1317 | (throw 'found (expand-file-name tex-main-file))))) | ||
| 1318 | ;; Look for a buffer containing the magic `tex-start-of-header'. | ||
| 1319 | (dolist (buf (if (consp all) all (buffer-list))) | ||
| 1320 | (with-current-buffer buf | ||
| 1321 | (when (and (or all (equal dir default-directory)) | ||
| 1322 | buffer-file-name | ||
| 1323 | ;; (or (easy-mmode-derived-mode-p 'latex-mode) | ||
| 1324 | ;; (easy-mmode-derived-mode-p 'plain-tex-mode)) | ||
| 1325 | (save-excursion | ||
| 1326 | (goto-char (point-min)) | ||
| 1327 | (re-search-forward header-re 10000 t))) | ||
| 1328 | (throw 'found (expand-file-name buffer-file-name)))))))) | ||
| 1329 | |||
| 1330 | (defun tex-main-file (&optional realfile) | ||
| 1331 | "Return the name of the main file with the `.tex' extension stripped. | ||
| 1332 | If REALFILE is non-nil, don't strip the extension." | ||
| 1303 | (let ((file (or tex-main-file | 1333 | (let ((file (or tex-main-file |
| 1304 | ;; Compatibility with AUCTeX | 1334 | ;; Compatibility with AUCTeX. |
| 1305 | (and (boundp 'TeX-master) (stringp TeX-master) TeX-master) | 1335 | (and (boundp 'TeX-master) (stringp TeX-master) |
| 1306 | (if (buffer-file-name) | 1336 | (set (make-local-variable 'tex-main-file) TeX-master)) |
| 1307 | (file-relative-name (buffer-file-name)) | 1337 | ;; Try to guess the main file. |
| 1308 | (error "Buffer is not associated with any file"))))) | 1338 | (if (not buffer-file-name) |
| 1309 | (if (string-match "\\.tex\\'" file) | 1339 | (error "Buffer is not associated with any file") |
| 1310 | (substring file 0 (match-beginning 0)) | 1340 | (file-relative-name |
| 1311 | file))) | 1341 | (if (save-excursion |
| 1342 | (goto-char (point-min)) | ||
| 1343 | (re-search-forward tex-start-of-header 10000 t)) | ||
| 1344 | ;; This is the main file. | ||
| 1345 | buffer-file-name | ||
| 1346 | ;; This isn't the main file, let's try to find better, | ||
| 1347 | (or (tex-guess-main-file) | ||
| 1348 | ;; (tex-guess-main-file t) | ||
| 1349 | buffer-file-name))))))) | ||
| 1350 | (cond | ||
| 1351 | (realfile (if (file-exists-p file) file (concat file ".tex"))) | ||
| 1352 | ((string-match "\\.tex\\'" file) (substring file 0 (match-beginning 0))) | ||
| 1353 | (t file)))) | ||
| 1354 | |||
| 1312 | 1355 | ||
| 1313 | (defun tex-start-tex (command file &optional dir) | 1356 | (defun tex-start-tex (command file &optional dir) |
| 1314 | "Start a TeX run, using COMMAND on FILE." | 1357 | "Start a TeX run, using COMMAND on FILE." |
| @@ -1702,7 +1745,9 @@ Runs the shell command defined by `tex-show-queue-command'." | |||
| 1702 | (defvar tex-indent-item-re "\\\\\\(bib\\)?item\\>") | 1745 | (defvar tex-indent-item-re "\\\\\\(bib\\)?item\\>") |
| 1703 | 1746 | ||
| 1704 | (easy-mmode-defsyntax tex-latex-indent-syntax-table | 1747 | (easy-mmode-defsyntax tex-latex-indent-syntax-table |
| 1705 | '((?$ . ".")) | 1748 | '((?$ . ".") |
| 1749 | (?\( . ".") | ||
| 1750 | (?\) . ".")) | ||
| 1706 | "Syntax table used while computing indentation." | 1751 | "Syntax table used while computing indentation." |
| 1707 | :copy tex-mode-syntax-table) | 1752 | :copy tex-mode-syntax-table) |
| 1708 | 1753 | ||