]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/tex-mode.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / textmodes / tex-mode.el
index 8f68c71fd17daa848504d7df234d8982bb9c2991..19aefc29b9639c20cd79702aee7380a551d54f67 100644 (file)
@@ -1,6 +1,6 @@
-;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands -*- coding: utf-8 -*-
+;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1985-1986, 1989, 1992, 1994-1999, 2001-2015 Free
+;; Copyright (C) 1985-1986, 1989, 1992, 1994-1999, 2001-2016 Free
 ;; Software Foundation, Inc.
 
 ;; Maintainer: emacs-devel@gnu.org
@@ -135,8 +135,8 @@ If nil, TeX runs with no options.  See the documentation of `tex-command'."
   "TeX commands to use when starting TeX.
 They are shell-quoted and precede the input file name, with a separating space.
 If nil, no commands are used.  See the documentation of `tex-command'."
-  :type '(radio (const :tag "Interactive \(nil\)" nil)
-               (const :tag "Nonstop \(\"\\nonstopmode\\input\"\)"
+  :type '(radio (const :tag "Interactive (nil)" nil)
+               (const :tag "Nonstop (\"\\nonstopmode\\input\")"
                       "\\nonstopmode\\input")
                (string :tag "String at your choice"))
   :group 'tex-run
@@ -188,7 +188,7 @@ If two printers are not enough of a choice, you can set the variable
 for example,
 
     (setq tex-alt-dvi-print-command
-         '(format \"lpr -P%s\" (read-string \"Use printer: \")))
+         \\='(format \"lpr -P%s\" (read-string \"Use printer: \")))
 
 would tell \\[tex-print] with a prefix argument to ask you which printer to
 use."
@@ -266,8 +266,8 @@ tex shell terminates.")
 
 (defvar tex-command "tex"
   "Command to run TeX.
-If this string contains an asterisk \(`*'\), that is replaced by the file name;
-otherwise the value of `tex-start-options', the \(shell-quoted\)
+If this string contains an asterisk \(`*'), that is replaced by the file name;
+otherwise the value of `tex-start-options', the \(shell-quoted)
 value of `tex-start-commands', and the file name are added at the end
 with blanks as separators.
 
@@ -368,7 +368,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
                              (match-end 1))
                             latex-section-alist))))
          (backward-char 1)
-         (condition-case err
+         (condition-case nil
              (progn
                ;; Using sexps allows some use of matching {...} inside
                ;; titles.
@@ -387,7 +387,7 @@ An alternative value is \" . \", if you use a font with a narrow period."
       (goto-char (point-min))
       (while (search-forward-regexp
              "\\\\\\(include\\|input\\|verbatiminput\\|bibliography\\)\
-\[ \t]*{\\([^}\n]+\\)}"
+[ \t]*{\\([^}\n]+\\)}"
              nil t)
        (push (cons (concat "<<" (buffer-substring-no-properties
                                  (match-beginning 2)
@@ -937,7 +937,7 @@ Inherits `shell-mode-map' with a few additions.")
     ,@tex-face-alist)
   "Alist of face and LaTeX font name for facemenu.")
 
-(defun tex-facemenu-add-face-function (face end)
+(defun tex-facemenu-add-face-function (face _end)
   (or (cdr (assq face tex-face-alist))
       (or (and (consp face)
               (consp (car face))
@@ -1035,7 +1035,7 @@ says which mode to use."
   "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,
-and '' when it appears to be the end; it inserts \" only after a \\.
+and \\='\\=' when it appears to be the end; it inserts \" only after a \\.
 
 Use \\[tex-region] to run TeX on the current region, plus a \"header\"
 copied from the top of the file (containing macro definitions, etc.),
@@ -1081,7 +1081,7 @@ special subshell is initiated, the hook `tex-shell-hook' is run."
   "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,
-and '' when it appears to be the end; it inserts \" only after a \\.
+and \\='\\=' when it appears to be the end; it inserts \" only after a \\.
 
 Use \\[tex-region] to run LaTeX on the current region, plus the preamble
 copied from the top of the file (containing \\documentstyle, etc.),
@@ -1163,7 +1163,7 @@ subshell is initiated, `tex-shell-hook' is run."
   "Major mode for editing files of input for SliTeX.
 Makes $ and } display the characters they match.
 Makes \" insert \\=`\\=` when it seems to be the beginning of a quotation,
-and '' when it appears to be the end; it inserts \" only after a \\.
+and \\='\\=' when it appears to be the end; it inserts \" only after a \\.
 
 Use \\[tex-region] to run SliTeX on the current region, plus the preamble
 copied from the top of the file (containing \\documentstyle, etc.),
@@ -1256,7 +1256,8 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
                (font-lock-unfontify-region-function
                 . tex-font-lock-unfontify-region)))
   (setq-local prettify-symbols-alist tex--prettify-symbols-alist)
-  (setq-local prettify-symbols-compose-predicate #'tex--prettify-symbols-compose-p)
+  (add-function :override (local 'prettify-symbols-compose-predicate)
+                #'tex--prettify-symbols-compose-p)
   (setq-local syntax-propertize-function
              (syntax-propertize-rules latex-syntax-propertize-rules))
   ;; TABs in verbatim environments don't do what you think.
@@ -1300,7 +1301,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook
 (defun tex-insert-quote (arg)
   "Insert the appropriate quote marks for TeX.
 Inserts the value of `tex-open-quote' (normally \\=`\\=`) or `tex-close-quote'
-\(normally '') depending on the context.  With prefix argument, always
+\(normally \\='\\=') depending on the context.  With prefix argument, always
 inserts \" characters."
   (interactive "*P")
   ;; Discover if we'll be inserting normal double quotes.
@@ -1549,7 +1550,7 @@ Puts point on a blank line between them."
   "\\end{" str "}" > \n)
 
 (define-skeleton latex-insert-item
-  "Insert a \item macro."
+  "Insert an \\item macro."
   nil
   \n "\\item " >)
 
@@ -1981,7 +1982,7 @@ In the tex shell buffer this command behaves like `comint-send-input'."
   (display-buffer (tex-shell-buf))
   (tex-recenter-output-buffer nil))
 
-(defun tex-shell-sentinel (proc msg)
+(defun tex-shell-sentinel (proc _msg)
   (cond ((null (buffer-name (process-buffer proc)))
         ;; buffer killed
         (set-process-buffer proc nil)
@@ -2761,10 +2762,11 @@ Runs the shell command defined by `tex-show-queue-command'."
     st)
   "Syntax table used while computing indentation.")
 
-(defun latex-indent (&optional arg)
+(defun latex-indent (&optional _arg)
   (if (and (eq (get-text-property (if (and (eobp) (bolp))
                                       (max (point-min) (1- (point)))
-                                    (line-beginning-position)) 'face)
+                                    (line-beginning-position))
+                                  'face)
               'tex-verbatim))
       'noindent
     (with-syntax-table tex-latex-indent-syntax-table
@@ -2954,7 +2956,7 @@ There might be text before point."
     ("\\beta" . ?β)
     ("\\gamma" . ?γ)
     ("\\delta" . ?δ)
-    ("\\epsilon" . ?ε)
+    ("\\epsilon" . ?ϵ)
     ("\\zeta" . ?ζ)
     ("\\eta" . ?η)
     ("\\theta" . ?θ)
@@ -2964,7 +2966,7 @@ There might be text before point."
     ("\\mu" . ?μ)
     ("\\nu" . ?ν)
     ("\\xi" . ?ξ)
-    ;; There is no \omicron becase it looks like a latin o.
+    ;; There is no \omicron because it looks like a latin o.
     ("\\pi" . ?π)
     ("\\rho" . ?ρ)
     ("\\sigma" . ?σ)
@@ -3271,7 +3273,8 @@ There might be text before point."
     ("\\prod" . ?∏)
     ("\\propto" . ?∝)
     ("\\qed" . ?∎)
-    ("\\quad" . ? )
+    ("\\qquad" . ?⧢)
+    ("\\quad" . ?␣)
     ("\\rangle" . 10217)            ; Literal ?⟩ breaks indentation.
     ("\\rbrace" . ?})
     ("\\rbrack" . ?\])
@@ -3288,6 +3291,7 @@ There might be text before point."
     ("\\rightthreetimes" . ?⋌)
     ("\\risingdotseq" . ?≓)
     ("\\rtimes" . ?⋊)
+    ("\\times" . ?×)
     ("\\sbs" . ?﹨)
     ("\\searrow" . ?↘)
     ("\\setminus" . ?∖)
@@ -3356,8 +3360,10 @@ There might be text before point."
     ("\\urcorner" . ?⌝)
     ("\\u{i}" . ?ĭ)
     ("\\vDash" . ?⊨)
+    ("\\varepsilon" . ?ε)
     ("\\varprime" . ?′)
     ("\\varpropto" . ?∝)
+    ("\\varrho" . ?ϱ)
     ;; ("\\varsigma" ?ς)              ;FIXME: Looks reversed with the non\var.
     ("\\vartriangleleft" . ?⊲)
     ("\\vartriangleright" . ?⊳)
@@ -3371,6 +3377,7 @@ There might be text before point."
     ("\\wr" . ?≀)
     ("\\Bbb{N}" . ?ℕ)                        ; AMS commands for blackboard bold
     ("\\Bbb{P}" . ?ℙ)                        ; Also sometimes \mathbb.
+    ("\\Bbb{Q}" . ?ℚ)
     ("\\Bbb{R}" . ?ℝ)
     ("\\Bbb{Z}" . ?ℤ)
     ("--" . ?–)
@@ -3403,16 +3410,25 @@ There might be text before point."
     ("\\textreferencemark" . ?※))
   "A `prettify-symbols-alist' usable for (La)TeX modes.")
 
-(defun tex--prettify-symbols-compose-p (start end _match)
-  (let* ((after-char (char-after end))
-         (after-syntax  (char-syntax after-char)))
-    (not (or
-          ;; Don't compose \alpha@foo.
-          (eq after-syntax ?_)
-          ;; The \alpha in \alpha2 may be composed but of course \alphax may not.
-          (and (eq after-syntax ?w)
-               (or (< after-char ?0)
-                   (> after-char ?9)))))))
+(defun tex--prettify-symbols-compose-p (_start end _match)
+  (or
+   ;; If the matched symbol doesn't end in a word character, then we
+   ;; simply allow composition.  The symbol is probably something like
+   ;; \|, \(, etc.
+   (not (eq ?w (char-syntax (char-before end))))
+   ;; Else we look at what follows the match in order to decide.
+   (let* ((after-char (char-after end))
+          (after-syntax (char-syntax after-char)))
+     (not (or
+           ;; Don't compose \alpha@foo.
+           (eq after-char ?@)
+           ;; The \alpha in \alpha2 or \alpha-\beta may be composed but
+           ;; of course \alphax may not.
+           (and (eq after-syntax ?w)
+                (not (memq after-char
+                           '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?+ ?- ?' ?\"))))
+           ;; Don't compose inside verbatim blocks.
+           (eq 2 (nth 7 (syntax-ppss))))))))
 
 (run-hooks 'tex-mode-load-hook)