Mercurial > emacs
changeset 50592:73473fb92184
(latex-mode-map): Bind latex-split-block to C-c C-s.
(tex-font-lock-keywords-2): Comment out unused var `type'.
(tex-guess-mode): New name for old `tex-mode'.
(tex-mode): Make it a derived mode of text-mode.
(plain-tex-mode, latex-mode): Change parent from text-mode to tex-mode.
(tex-common-initialization): Don't setup syntax-table any more.
(tex-validate-buffer): Remove unused var `oend'.
Use with-current-buffer and line-beginning-position.
(tex-recenter-output-buffer): Remove unused var `old-buffer'.
(latex-indent): Return `noindent' if no indentation can happen.
(doctex-font-lock-^^A, doctex-font-lock-syntactic-face-function)
(doctex-font-lock-syntactic-keywords, doctex-font-lock-keywords)
(doctex-mode): New funs for DocTeX mode, derived from LaTeX mode.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 14 Apr 2003 19:58:05 +0000 |
parents | 12b66952af3a |
children | 9ede3f237c05 |
files | lisp/textmodes/tex-mode.el |
diffstat | 1 files changed, 98 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/textmodes/tex-mode.el Mon Apr 14 17:12:17 2003 +0000 +++ b/lisp/textmodes/tex-mode.el Mon Apr 14 19:58:05 2003 +0000 @@ -499,7 +499,8 @@ (bold (regexp-opt '("textbf" "textsc" "textup" "boldsymbol" "pmb") t)) (italic (regexp-opt '("textit" "textsl" "emph") t)) - (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t)) + ;; FIXME: unimplemented yet. + ;; (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t)) ;; ;; Names of commands whose arg should be fontified as a citation. (citations (regexp-opt @@ -713,6 +714,7 @@ (defvar latex-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map tex-mode-map) + (define-key map "\C-c\C-s" 'latex-split-block) map) "Keymap for `latex-mode'. See also `tex-mode-map'.") @@ -745,15 +747,7 @@ ;; This would be a lot simpler if we just used a regexp search, ;; but then it would be too slow. -;;;###autoload -(defun tex-mode () - "Major mode for editing files of input for TeX, LaTeX, or SliTeX. -Tries to determine (by looking at the beginning of the file) whether -this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode', -`latex-mode', or `slitex-mode', respectively. If it cannot be determined, -such as if there are no commands in the file, the value of `tex-default-mode' -says which mode to use." - (interactive) +(defun tex-guess-mode () (let ((mode tex-default-mode) slash comment) (save-excursion (goto-char (point-min)) @@ -778,6 +772,27 @@ 'plain-tex-mode)))) (funcall mode))) +;; `tex-mode' plays two roles: it's the parent of several sub-modes +;; but it's also the function that chooses between those submodes. +;; To tell the difference between those two cases where the function +;; might be called, we check `delay-mode-hooks'. +;;;###autoload +(define-derived-mode tex-mode text-mode "generic-TeX" + (tex-common-initialization)) +(fset 'tex-mode + `(lambda () + "Major mode for editing files of input for TeX, LaTeX, or SliTeX. +Tries to determine (by looking at the beginning of the file) whether +this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode', +`latex-mode', or `slitex-mode', respectively. If it cannot be determined, +such as if there are no commands in the file, the value of `tex-default-mode' +says which mode to use." + (interactive) + (if delay-mode-hooks + ;; We're called from one of the children already. + (funcall ,(symbol-function 'tex-mode)) + (tex-guess-mode)))) + ;;;###autoload (defalias 'TeX-mode 'tex-mode) ;;;###autoload @@ -786,7 +801,7 @@ (defalias 'LaTeX-mode 'latex-mode) ;;;###autoload -(define-derived-mode plain-tex-mode text-mode "TeX" +(define-derived-mode plain-tex-mode tex-mode "TeX" "Major mode for editing files of input for plain TeX. Makes $ and } display the characters they match. Makes \" insert `` when it seems to be the beginning of a quotation, @@ -826,15 +841,13 @@ Entering Plain-tex mode runs the hook `text-mode-hook', then the hook `tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the special subshell is initiated, the hook `tex-shell-hook' is run." - (tex-common-initialization) - (setq tex-command tex-run-command) - (setq tex-start-of-header "%\\*\\*start of header") - (setq tex-end-of-header "%\\*\\*end of header") - (setq tex-trailer "\\bye\n") - (run-hooks 'tex-mode-hook)) + (set (make-local-variable 'tex-command) tex-run-command) + (set (make-local-variable 'tex-start-of-header) "%\\*\\*start of header") + (set (make-local-variable 'tex-end-of-header) "%\\*\\*end of header") + (set (make-local-variable 'tex-trailer) "\\bye\n")) ;;;###autoload -(define-derived-mode latex-mode text-mode "LaTeX" +(define-derived-mode latex-mode tex-mode "LaTeX" "Major mode for editing files of input for LaTeX. Makes $ and } display the characters they match. Makes \" insert `` when it seems to be the beginning of a quotation, @@ -874,16 +887,16 @@ Entering Latex mode runs the hook `text-mode-hook', then `tex-mode-hook', and finally `latex-mode-hook'. When the special subshell is initiated, `tex-shell-hook' is run." - (tex-common-initialization) - (setq tex-command latex-run-command) - (setq tex-start-of-header "\\\\document\\(style\\|class\\)") - (setq tex-end-of-header "\\\\begin\\s-*{document}") - (setq tex-trailer "\\end\\s-*{document}\n") + (set (make-local-variable 'tex-command) latex-run-command) + (set (make-local-variable 'tex-start-of-header) + "\\\\document\\(style\\|class\\)") + (set (make-local-variable 'tex-end-of-header) "\\\\begin\\s-*{document}") + (set (make-local-variable 'tex-trailer) "\\end\\s-*{document}\n") ;; A line containing just $$ is treated as a paragraph separator. ;; A line starting with $$ starts a paragraph, ;; but does not separate paragraphs if it has more stuff on it. (setq paragraph-start - (concat "[\f%]\\|[ \t]*\\($\\|\\$\\$\\|" + (concat "[ \t]*\\(\\$\\$\\|" "\\\\[][]\\|" "\\\\" (regexp-opt (append (mapcar 'car latex-section-alist) @@ -913,8 +926,7 @@ (set (make-local-variable 'outline-regexp) latex-outline-regexp) (set (make-local-variable 'outline-level) 'latex-outline-level) (set (make-local-variable 'forward-sexp-function) 'latex-forward-sexp) - (set (make-local-variable 'skeleton-end-hook) nil) - (run-hooks 'tex-mode-hook)) + (set (make-local-variable 'skeleton-end-hook) nil)) ;;;###autoload (define-derived-mode slitex-mode latex-mode "SliTeX" @@ -962,7 +974,6 @@ (setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")) (defun tex-common-initialization () - (set-syntax-table tex-mode-syntax-table) ;; Regexp isearch should accept newline and formfeed as whitespace. (set (make-local-variable 'search-whitespace-regexp) "[ \t\r\n\f]+") ;; A line containing just $$ is treated as a paragraph separator. @@ -1069,8 +1080,7 @@ (num-matches 0)) (with-output-to-temp-buffer "*Occur*" (princ "Mismatches:\n") - (save-excursion - (set-buffer standard-output) + (with-current-buffer standard-output (occur-mode) ;; This won't actually work...Really, this whole thing should ;; be rewritten instead of being a hack on top of occur. @@ -1087,8 +1097,7 @@ (forward-char 2)) (goto-char (setq prev-end (point-min)))) (or (tex-validate-region (point) end) - (let* ((oend end) - (end (save-excursion (forward-line 1) (point))) + (let* ((end (line-beginning-position 2)) start tem) (beginning-of-line) (setq start (point)) @@ -1844,7 +1853,6 @@ line LINE of the window, or centered if LINE is nil." (interactive "P") (let ((tex-shell (get-buffer "*tex-shell*")) - (old-buffer (current-buffer)) (window)) (if (null tex-shell) (message "No TeX output buffer") @@ -1971,7 +1979,7 @@ (defun latex-indent (&optional arg) (if (and (eq (get-text-property (line-beginning-position) 'face) tex-verbatim-face)) - (indent-relative) + 'noindent (with-syntax-table tex-latex-indent-syntax-table ;; TODO: Rather than ignore $, we should try to be more clever about it. (let ((indent @@ -2058,6 +2066,63 @@ (min (current-column) (+ tex-indent-arg col)) (skip-syntax-forward " ") (current-column)))))))))) +;;; DocTeX support + +(defun doctex-font-lock-^^A () + (if (eq (char-after (line-beginning-position)) ?\%) + (progn + (put-text-property + (1- (match-beginning 1)) (match-beginning 1) + 'syntax-table + (if (= (1+ (line-beginning-position)) (match-beginning 1)) + ;; The `%' is a single-char comment, which Emacs + ;; syntax-table can't deal with. We could turn it + ;; into a non-comment, or use `\n%' or `%^' as the comment. + ;; Instead, we include it in the ^^A comment. + (eval-when-compile (string-to-syntax "< b")) + (eval-when-compile (string-to-syntax ">")))) + (let ((end (line-end-position))) + (if (< end (point-max)) + (put-text-property + end (1+ end) + 'syntax-table + (eval-when-compile (string-to-syntax "> b"))))) + (eval-when-compile (string-to-syntax "< b"))))) + +(defun doctex-font-lock-syntactic-face-function (state) + ;; Mark DocTeX documentation, which is parsed as a style A comment + ;; starting in column 0. + (if (or (nth 3 state) (nth 7 state) + (not (memq (char-before (nth 8 state)) + '(?\n nil)))) + ;; Anything else is just as for LaTeX. + (tex-font-lock-syntactic-face-function state) + font-lock-doc-face)) + +(defvar doctex-font-lock-syntactic-keywords + (append + tex-font-lock-syntactic-keywords + ;; For DocTeX comment-in-doc. + `(("\\(\\^\\)\\^A" (1 (doctex-font-lock-^^A)))))) + +(defvar doctex-font-lock-keywords + (append tex-font-lock-keywords + '(("^%<[^>]*>" (0 font-lock-preprocessor-face t))))) + +;;;###autoload +(define-derived-mode doctex-mode latex-mode "DocTeX" + "Major mode to edit DocTeX files." + (setq font-lock-defaults + (cons (append (car font-lock-defaults) '(doctex-font-lock-keywords)) + (mapcar + (lambda (x) + (case (car-safe x) + (font-lock-syntactic-keywords + (cons (car x) 'doctex-font-lock-syntactic-keywords)) + (font-lock-syntactic-face-function + (cons (car x) 'doctex-font-lock-syntactic-face-function)) + (t x))) + (cdr font-lock-defaults))))) (run-hooks 'tex-mode-load-hook)