emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/textmodes/tex-mode.el


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/lisp/textmodes/tex-mode.el
Date: Mon, 14 Apr 2003 15:58:05 -0400

Index: emacs/lisp/textmodes/tex-mode.el
diff -c emacs/lisp/textmodes/tex-mode.el:1.129 
emacs/lisp/textmodes/tex-mode.el:1.130
*** emacs/lisp/textmodes/tex-mode.el:1.129      Sun Dec 22 17:03:22 2002
--- emacs/lisp/textmodes/tex-mode.el    Mon Apr 14 15:58:05 2003
***************
*** 499,505 ****
            (bold (regexp-opt '("textbf" "textsc" "textup"
                                "boldsymbol" "pmb") t))
            (italic (regexp-opt '("textit" "textsl" "emph") t))
!           (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t))
            ;;
            ;; Names of commands whose arg should be fontified as a citation.
            (citations (regexp-opt
--- 499,506 ----
            (bold (regexp-opt '("textbf" "textsc" "textup"
                                "boldsymbol" "pmb") t))
            (italic (regexp-opt '("textit" "textsl" "emph") 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,718 ****
--- 714,720 ----
  (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,759 ****
  
  ;; 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)
    (let ((mode tex-default-mode) slash comment)
      (save-excursion
        (goto-char (point-min))
--- 747,753 ----
  
  ;; This would be a lot simpler if we just used a regexp search,
  ;; but then it would be too slow.
! (defun tex-guess-mode ()
    (let ((mode tex-default-mode) slash comment)
      (save-excursion
        (goto-char (point-min))
***************
*** 778,783 ****
--- 772,798 ----
                '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,792 ****
  (defalias 'LaTeX-mode 'latex-mode)
  
  ;;;###autoload
! (define-derived-mode plain-tex-mode text-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,
--- 801,807 ----
  (defalias 'LaTeX-mode 'latex-mode)
  
  ;;;###autoload
! (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,840 ****
  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))
  
  ;;;###autoload
! (define-derived-mode latex-mode text-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,
--- 841,853 ----
  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."
!   (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 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,889 ****
  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")
    ;; 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]*\\($\\|\\$\\$\\|"
                "\\\\[][]\\|"
                "\\\\" (regexp-opt (append
                                    (mapcar 'car latex-section-alist)
--- 887,902 ----
  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."
!   (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 "[ \t]*\\(\\$\\$\\|"
                "\\\\[][]\\|"
                "\\\\" (regexp-opt (append
                                    (mapcar 'car latex-section-alist)
***************
*** 913,920 ****
    (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))
  
  ;;;###autoload
  (define-derived-mode slitex-mode latex-mode "SliTeX"
--- 926,932 ----
    (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))
  
  ;;;###autoload
  (define-derived-mode slitex-mode latex-mode "SliTeX"
***************
*** 962,968 ****
    (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.
--- 974,979 ----
***************
*** 1069,1076 ****
        (num-matches 0))
      (with-output-to-temp-buffer "*Occur*"
        (princ "Mismatches:\n")
!       (save-excursion
!       (set-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.
--- 1080,1086 ----
        (num-matches 0))
      (with-output-to-temp-buffer "*Occur*"
        (princ "Mismatches:\n")
!       (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,1094 ****
                  (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)))
                       start tem)
                  (beginning-of-line)
                  (setq start (point))
--- 1097,1103 ----
                  (forward-char 2))
              (goto-char (setq prev-end (point-min))))
            (or (tex-validate-region (point) end)
!               (let* ((end (line-beginning-position 2))
                       start tem)
                  (beginning-of-line)
                  (setq start (point))
***************
*** 1844,1850 ****
  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")
--- 1853,1858 ----
***************
*** 1971,1977 ****
  (defun latex-indent (&optional arg)
    (if (and (eq (get-text-property (line-beginning-position) 'face)
               tex-verbatim-face))
!       (indent-relative)
      (with-syntax-table tex-latex-indent-syntax-table
        ;; TODO: Rather than ignore $, we should try to be more clever about it.
        (let ((indent
--- 1979,1985 ----
  (defun latex-indent (&optional arg)
    (if (and (eq (get-text-property (line-beginning-position) 'face)
               tex-verbatim-face))
!       '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,2063 ****
--- 2066,2128 ----
                 (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)
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]