diff options
Diffstat (limited to 'lisp/textmodes/tex-mode.el')
-rw-r--r-- | lisp/textmodes/tex-mode.el | 137 |
1 files changed, 74 insertions, 63 deletions
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index d5a79ad0ac5..c53acf53e7e 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -28,7 +28,6 @@ ;;; Code: -;; Pacify the byte-compiler (eval-when-compile (require 'compare-w) (require 'cl-lib) @@ -600,11 +599,13 @@ An alternative value is \" . \", if you use a font with a narrow period." ;; Citation args. (list (concat slash citations opt arg) 3 'font-lock-constant-face) ;; - ;; Text between `` quotes ''. - (cons (concat (regexp-opt '("``" "\"<" "\"`" "<<" "«") t) - "[^'\">{]+" ;a bit pessimistic - (regexp-opt '("''" "\">" "\"'" ">>" "»") t)) - 'font-lock-string-face) + ;; Text between `` quotes ''. + (list (concat (regexp-opt '("``" "\"<" "\"`" "<<" "«") t) + "\\(\\(.\\|\n\\)+?\\)" + (regexp-opt `("''" "\">" "\"'" ">>" "»") t)) + '(1 font-lock-keyword-face) + '(2 font-lock-string-face) + '(4 font-lock-keyword-face)) ;; ;; Command names, special and general. (cons (concat slash specials-1) 'font-lock-warning-face) @@ -857,11 +858,11 @@ START is the position of the \\ and DELIM is the delimiter char." (defun tex-define-common-keys (keymap) "Define the keys that we want defined both in TeX mode and in the TeX shell." - (define-key keymap "\C-c\C-k" 'tex-kill-job) - (define-key keymap "\C-c\C-l" 'tex-recenter-output-buffer) - (define-key keymap "\C-c\C-q" 'tex-show-print-queue) - (define-key keymap "\C-c\C-p" 'tex-print) - (define-key keymap "\C-c\C-v" 'tex-view) + (define-key keymap "\C-c\C-k" #'tex-kill-job) + (define-key keymap "\C-c\C-l" #'tex-recenter-output-buffer) + (define-key keymap "\C-c\C-q" #'tex-show-print-queue) + (define-key keymap "\C-c\C-p" #'tex-print) + (define-key keymap "\C-c\C-v" #'tex-view) (define-key keymap [menu-bar tex] (cons "TeX" (make-sparse-keymap "TeX"))) @@ -884,27 +885,27 @@ START is the position of the \\ and DELIM is the delimiter char." (let ((map (make-sparse-keymap))) (set-keymap-parent map text-mode-map) (tex-define-common-keys map) - (define-key map "\"" 'tex-insert-quote) - (define-key map "\n" 'tex-handle-newline) - (define-key map "\M-\r" 'latex-insert-item) - (define-key map "\C-c}" 'up-list) - (define-key map "\C-c{" 'tex-insert-braces) - (define-key map "\C-c\C-r" 'tex-region) - (define-key map "\C-c\C-b" 'tex-buffer) - (define-key map "\C-c\C-f" 'tex-file) - (define-key map "\C-c\C-c" 'tex-compile) - (define-key map "\C-c\C-i" 'tex-bibtex-file) - (define-key map "\C-c\C-o" 'latex-insert-block) + (define-key map "\"" #'tex-insert-quote) + (define-key map "\n" #'tex-handle-newline) + (define-key map "\M-\r" #'latex-insert-item) + (define-key map "\C-c}" #'up-list) + (define-key map "\C-c{" #'tex-insert-braces) + (define-key map "\C-c\C-r" #'tex-region) + (define-key map "\C-c\C-b" #'tex-buffer) + (define-key map "\C-c\C-f" #'tex-file) + (define-key map "\C-c\C-c" #'tex-compile) + (define-key map "\C-c\C-i" #'tex-bibtex-file) + (define-key map "\C-c\C-o" #'latex-insert-block) ;; Redundant keybindings, for consistency with SGML mode. - (define-key map "\C-c\C-t" 'latex-insert-block) - (define-key map "\C-c]" 'latex-close-block) - (define-key map "\C-c/" 'latex-close-block) - - (define-key map "\C-c\C-e" 'latex-close-block) - (define-key map "\C-c\C-u" 'tex-goto-last-unclosed-latex-block) - (define-key map "\C-c\C-m" 'tex-feed-input) - (define-key map [(control return)] 'tex-feed-input) + (define-key map "\C-c\C-t" #'latex-insert-block) + (define-key map "\C-c]" #'latex-close-block) + (define-key map "\C-c/" #'latex-close-block) + + (define-key map "\C-c\C-e" #'latex-close-block) + (define-key map "\C-c\C-u" #'tex-goto-last-unclosed-latex-block) + (define-key map "\C-c\C-m" #'tex-feed-input) + (define-key map [(control return)] #'tex-feed-input) (define-key map [menu-bar tex tex-bibtex-file] '("BibTeX File" . tex-bibtex-file)) (define-key map [menu-bar tex tex-validate-region] @@ -922,7 +923,7 @@ START is the position of the \\ and DELIM is the delimiter char." (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) + (define-key map "\C-c\C-s" #'latex-split-block) map) "Keymap for `latex-mode'. See also `tex-mode-map'.") @@ -1033,11 +1034,11 @@ says which mode to use." ;; received them from someone using AUCTeX). ;;;###autoload -(defalias 'TeX-mode 'tex-mode) +(defalias 'TeX-mode #'tex-mode) ;;;###autoload -(defalias 'plain-TeX-mode 'plain-tex-mode) +(defalias 'plain-TeX-mode #'plain-tex-mode) ;;;###autoload -(defalias 'LaTeX-mode 'latex-mode) +(defalias 'LaTeX-mode #'latex-mode) ;;;###autoload (define-derived-mode plain-tex-mode tex-mode "TeX" @@ -1425,20 +1426,25 @@ on the line for the invalidity you want to see." ;; Skip "Mismatches:" header line. (forward-line 1) (setq num-matches (1+ num-matches)) - (insert-buffer-substring buffer start end) - (let (text-beg (text-end (point-marker))) - (forward-char (- start end)) - (setq text-beg (point-marker)) - (insert (format "%3d: " linenum)) - (add-text-properties - text-beg (- text-end 1) - '(mouse-face highlight - help-echo - "mouse-2: go to this invalidity")) - (put-text-property text-beg (- text-end 1) - 'occur-target tem)))))))) + (let ((inhibit-read-only t)) + (insert-buffer-substring buffer start end) + (let ((text-end (point-marker)) + text-beg) + (forward-char (- start end)) + (setq text-beg (point-marker)) + (insert (format "%3d: " linenum)) + (add-text-properties + text-beg (- text-end 1) + '(mouse-face highlight + help-echo + "mouse-2: go to this invalidity")) + (put-text-property (point) (- text-end 1) + 'occur-match t) + (put-text-property text-beg text-end + 'occur-target tem))))))))) (with-current-buffer standard-output - (let ((no-matches (zerop num-matches))) + (let ((no-matches (zerop num-matches)) + (inhibit-read-only t)) (if no-matches (insert "None!\n")) (if (called-interactively-p 'interactive) @@ -1560,7 +1566,7 @@ the name of the environment and SKEL-ELEM is an element to use in a skeleton (see `skeleton-insert').") ;; Like tex-insert-braces, but for LaTeX. -(defalias 'tex-latex-block 'latex-insert-block) +(defalias 'tex-latex-block #'latex-insert-block) (define-skeleton latex-insert-block "Create a matching pair of lines \\begin{NAME} and \\end{NAME} at point. Puts point on a blank line between them." @@ -1866,7 +1872,7 @@ Mark is left at original location." (with-syntax-table tex-mode-syntax-table (forward-sexp)))))) -(defalias 'tex-close-latex-block 'latex-close-block) +(defalias 'tex-close-latex-block #'latex-close-block) (define-skeleton latex-close-block "Create an \\end{...} to match the last unclosed \\begin{...}." (save-excursion @@ -2008,7 +2014,7 @@ Mark is left at original location." ;; Specify an interactive shell, to make sure it prompts. "-i") (let ((proc (get-process "tex-shell"))) - (set-process-sentinel proc 'tex-shell-sentinel) + (set-process-sentinel proc #'tex-shell-sentinel) (set-process-query-on-exit-flag proc nil) (tex-shell) (while (zerop (buffer-size)) @@ -2063,10 +2069,10 @@ evaluates to a command string. Return the process in which TeX is running." (save-excursion - (let* ((cmd (eval command)) + (let* ((cmd (eval command t)) (proc (tex-shell-proc)) (buf (process-buffer proc)) - (star (string-match "\\*" cmd)) + (star (string-search "*" cmd)) (string (concat (if (null file) @@ -2131,6 +2137,7 @@ If NOT-ALL is non-nil, save the `.dvi' file." (defvar tex-compile-commands `(,@(mapcar (lambda (prefix) `((concat ,prefix tex-command + " " tex-start-options " " (if (< 0 (length tex-start-commands)) (shell-quote-argument tex-start-commands)) " %f") @@ -2313,7 +2320,7 @@ FILE is typically the output DVI or PDF file." executable)))))) (defun tex-command-executable (cmd) - (let ((s (if (stringp cmd) cmd (eval (car cmd))))) + (let ((s (if (stringp cmd) cmd (eval (car cmd) t)))) (substring s 0 (string-match "[ \t]\\|\\'" s)))) (defun tex-command-active-p (cmd fspec) @@ -2400,7 +2407,7 @@ Only applies the FSPEC to the args part of FORMAT." (setq latest (nth 1 cmd) cmds (list cmd))))))) ;; Expand the command spec into the actual text. (dolist (cmd (prog1 cmds (setq cmds nil))) - (push (cons (eval (car cmd)) (cdr cmd)) cmds)) + (push (cons (eval (car cmd) t) (cdr cmd)) cmds)) ;; Select the favorite command from the history. (let ((hist tex-compile-history) re hist-cmd) @@ -2446,7 +2453,7 @@ Only applies the FSPEC to the args part of FORMAT." (completing-read (format "Command [%s]: " (tex-summarize-command default)) (mapcar (lambda (x) - (list (tex-format-cmd (eval (car x)) fspec))) + (list (tex-format-cmd (eval (car x) t) fspec))) tex-compile-commands) nil nil nil 'tex-compile-history default)))) (save-some-buffers (not compilation-ask-about-save) nil) @@ -2467,7 +2474,7 @@ Only applies the FSPEC to the args part of FORMAT." (defun tex-start-tex (command file &optional dir) "Start a TeX run, using COMMAND on FILE." - (let* ((star (string-match "\\*" command)) + (let* ((star (string-search "*" command)) (compile-command (if star (concat (substring command 0 star) @@ -2526,7 +2533,10 @@ The value of `tex-command' specifies the command to use to run TeX." (file-name-as-directory (expand-file-name tex-directory))) (tex-out-file (expand-file-name (concat tex-zap-file ".tex") zap-directory)) - (main-file (expand-file-name (tex-main-file))) + ;; We may be running from an unsaved buffer, in which case + ;; there's no point in guessing for a main file name. + (main-file (and buffer-file-name + (expand-file-name (tex-main-file)))) (ismain (string-equal main-file (buffer-file-name))) already-output) ;; Don't delete temp files if we do the same buffer twice in a row. @@ -2535,9 +2545,11 @@ The value of `tex-command' specifies the command to use to run TeX." (let ((default-directory zap-directory)) ; why? ;; We assume the header is fully contained in tex-main-file. ;; We use f-f-ns so we get prompted about any changes on disk. - (with-current-buffer (find-file-noselect main-file) - (setq already-output (tex-region-header tex-out-file - (and ismain beg)))) + (if (not main-file) + (setq already-output 0) + (with-current-buffer (find-file-noselect main-file) + (setq already-output (tex-region-header tex-out-file + (and ismain beg))))) ;; Write out the specified region (but don't repeat anything ;; already written in the header). (write-region (if ismain @@ -2740,7 +2752,7 @@ because there is no standard value that would generally work." ;; Restart the TeX shell if necessary. (or (tex-shell-running) (tex-start-shell)) - (let ((tex-dvi-print-command (eval tex-dvi-view-command))) + (let ((tex-dvi-print-command (eval tex-dvi-view-command t))) (tex-print))) (defun tex-append (file-name suffix) @@ -2766,7 +2778,7 @@ so normally SUFFIX starts with one." ;; Not found, so split on first period. (concat (file-name-directory file-name) (substring file 0 - (string-match "\\." file)) + (string-search "." file)) suffix))) " ")) @@ -3330,7 +3342,6 @@ There might be text before point." ("\\oplus" . ?⊕) ("\\oslash" . ?⊘) ("\\otimes" . ?⊗) - ("\\par" . ?
) ("\\parallel" . ?∥) ("\\partial" . ?∂) ("\\perp" . ?⊥) |