branch: externals/auctex commit ebd04735e78eea2d7961225d132107f6d5511836 Merge: 994079d8cd 454f02a588 Author: Ikumi Keita <ik...@ikumi.que.jp> Commit: Ikumi Keita <ik...@ikumi.que.jp>
Merge branch 'master' into feature/fix-mode-names-overlap --- .gitignore | 1 + auctex.el.in | 2 + context.el | 51 +++++++++++++++++++------ doc/auctex.texi | 4 +- doc/changes.texi | 2 +- doc/faq.texi | 2 +- font-latex.el | 18 +++++++-- latex.el | 85 ++++++++++++++++++++++++++++++++++-------- preview.el.in | 15 ++++---- tests/context/context-test.el | 6 --- tests/latex/font-latex-test.el | 6 --- tests/latex/latex-test.el | 12 +----- tests/latex/tabular-out.tex | 8 ++-- tests/latex/texmathp-test.el | 2 - tex-fold.el | 63 ++++++++++++++++++------------- tex-info.el | 64 +++++++++++++++++++++++-------- tex-jp.el | 9 ++++- tex.el | 62 ++++++++++++++++++++---------- 18 files changed, 282 insertions(+), 130 deletions(-) diff --git a/.gitignore b/.gitignore index f242adaf29..4733ddc0fc 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ PROBLEMS.preview tests/*/auto/* *.dynvars auctex-dynvars +.DS_Store diff --git a/auctex.el.in b/auctex.el.in index 390c0e3c32..fab355f0b1 100644 --- a/auctex.el.in +++ b/auctex.el.in @@ -42,4 +42,6 @@ @lisptexsite@) (TeX-load-hack) +(provide 'auctex) + ;;; auctex.el ends here diff --git a/context.el b/context.el index 1c5ac8ef5d..237ba32693 100644 --- a/context.el +++ b/context.el @@ -1833,8 +1833,8 @@ that is, you do _not_ have to cater for this yourself by adding \\\\\\=' or $." (set symbol (symbol-value (intern (concat (symbol-name symbol) "-" ConTeXt-current-interface))))) - ;; Create certain regular expressions based on language - (setq ConTeXt-indent-item-re (concat "\\\\\\(" (mapconcat #'identity ConTeXt-item-list "\\|") "\\)\\>")) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (setq ConTeXt-indent-item-re (concat "\\\\\\(" (mapconcat #'identity ConTeXt-item-list "\\|") "\\)\\>")) ;; What's the deepest level at we can collapse a document? ;; set only if user has not set it. Need to be set before menu is created. @@ -1848,17 +1848,19 @@ that is, you do _not_ have to cater for this yourself by adding \\\\\\=' or $." ;; Paragraph formatting (set (make-local-variable 'LaTeX-syntactic-comments) nil) - (set (make-local-variable 'LaTeX-paragraph-commands-regexp) - (ConTeXt-paragraph-commands-regexp)) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (set (make-local-variable 'LaTeX-paragraph-commands-regexp) + ;; (ConTeXt-paragraph-commands-regexp)) (set (make-local-variable 'paragraph-ignore-fill-prefix) t) (set (make-local-variable 'fill-paragraph-function) #'LaTeX-fill-paragraph) (set (make-local-variable 'adaptive-fill-mode) nil) - (setq paragraph-start - (concat - "[ \t]*\\(" - (ConTeXt-paragraph-commands-regexp) "\\|" - "\\$\\$\\|" ; Plain TeX display math - "$\\)")) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (setq paragraph-start + ;; (concat + ;; "[ \t]*\\(" + ;; (ConTeXt-paragraph-commands-regexp) "\\|" + ;; "\\$\\$\\|" ; Plain TeX display math + ;; "$\\)")) (setq paragraph-separate (concat "[ \t]*\\(" @@ -1877,7 +1879,8 @@ that is, you do _not_ have to cater for this yourself by adding \\\\\\=' or $." ;; Outline support (require 'outline) (set (make-local-variable 'outline-level) #'ConTeXt-outline-level) - (set (make-local-variable 'outline-regexp) (ConTeXt-outline-regexp t)) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (set (make-local-variable 'outline-regexp) (ConTeXt-outline-regexp t)) ;;(make-local-variable 'outline-heading-end-regexp) (setq TeX-header-end (ConTeXt-header-end) TeX-trailer-start (ConTeXt-trailer-start)) @@ -1892,6 +1895,31 @@ that is, you do _not_ have to cater for this yourself by adding \\\\\\=' or $." (setq TeX-command-default "ConTeXt") (setq TeX-sentinel-default-function #'TeX-ConTeXt-sentinel)) +(defun ConTeXt-mode-cleanup () + ;; Create certain regular expressions based on language. + ;; Don't overwrite the value the user set by hooks or file + ;; (directory) variables. + (or (local-variable-p 'ConTeXt-indent-item-re) + (setq-local ConTeXt-indent-item-re + (concat + "\\\\\\(" + (mapconcat #'identity ConTeXt-item-list "\\|") + "\\)\\>"))) + + ;; Don't do locally-bound test for `LaTeX-paragraph-commands-regexp' + ;; and `paragraph-start'. See comments in similar part in latex.el. + (setq-local LaTeX-paragraph-commands-regexp + (ConTeXt-paragraph-commands-regexp)) + (setq paragraph-start + (concat + "[ \t]*\\(" + (ConTeXt-paragraph-commands-regexp) "\\|" + "\\$\\$\\|" ; Plain TeX display math + "$\\)")) + + (or (local-variable-p 'outline-regexp) + (setq-local outline-regexp (ConTeXt-outline-regexp t)))) + (defun context-guess-current-interface () "Guess what ConTeXt interface the current buffer is using." (interactive) @@ -1919,6 +1947,7 @@ that is, you do _not_ have to cater for this yourself by adding \\\\\\=' or $." Entering `ConTeXt-mode' calls the value of `text-mode-hook', then the value of `TeX-mode-hook', and then the value of `ConTeXt-mode-hook'." + :after-hook (ConTeXt-mode-cleanup) (context-guess-current-interface) (require (intern (concat "context-" ConTeXt-current-interface))) (funcall (intern (concat "ConTeXt--mode-" ConTeXt-current-interface))) diff --git a/doc/auctex.texi b/doc/auctex.texi index 8d5b282f66..087d1405f9 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -2747,6 +2747,8 @@ placeholder. If the first element is a function symbol, the function will be called with all mandatory arguments of the macro and the result of the function call will be used as a replacement for the macro. +Such functions typically return a string, but may also return the +symbol @code{abort} to indicate that the macro should not be folded. The placeholder is made by copying the text from the buffer together with its properties, i.e.@: its face as well. If fontification has not @@ -4577,7 +4579,7 @@ Parse all @TeX{} and @LaTeX{} commands that @AUCTeX{} can use. @cindex @acronym{CJK}-@LaTeX{} @TeX{} and Emacs are usable for European (Latin, Cyrillic, Greek) based -languages. Some @LaTeX{} and EmacsLisp packages are available for easy +languages. Some @LaTeX{} and Emacs Lisp packages are available for easy typesetting and editing documents in European languages. @c Some Texinfo macros are not used because they require quite recent diff --git a/doc/changes.texi b/doc/changes.texi index f9e7ee58f4..cbb341c62e 100644 --- a/doc/changes.texi +++ b/doc/changes.texi @@ -15,7 +15,7 @@ @AUCTeX{} now requires GNU Emacs 26.1 or higher. @item -Now @LaTeX{} abbreves are available in doc@TeX{} mode buffers. +Now @LaTeX{} abbrevs are available in doc@TeX{} mode buffers. @end itemize @heading News in 13.2 diff --git a/doc/faq.texi b/doc/faq.texi index 547cb01f0f..a2d2aec0d2 100644 --- a/doc/faq.texi +++ b/doc/faq.texi @@ -51,7 +51,7 @@ command line, depending on the installation scheme of @AUCTeX{} and your If you installed @AUCTeX{} from @acronym{ELPA}, use @samp{emacs -q -no-site-file --eval "(progn (setq package-load-list '((auctex t))) (package-initialize))"}. The @option{--eval} option activates only -@AUCTeX{} among all installed @acronym{EPLA} packages. +@AUCTeX{} among all installed @acronym{ELPA} packages. @item If you installed @AUCTeX{} via traditional @command{configure}--@command{make} scheme, use @samp{emacs -q diff --git a/font-latex.el b/font-latex.el index 61309433bf..472ed4dd44 100644 --- a/font-latex.el +++ b/font-latex.el @@ -1083,8 +1083,10 @@ have changed." "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?" ;; An opening curly brace as delimiter is valid, but ;; allowing it might screw up fontification of stuff - ;; like "\url{...} foo \textbf{<--!...}". - "\\([^a-z@*\n\f{]\\).*?" + ;; like "\url{...} foo \textbf{<--!...}". Also + ;; disallow an opening square bracket which produces + ;; confusion in "\Verb[key-val]{foo[<--!}" + "\\([^a-z@*\n\f{[]\\).*?" ;; Give an escape char at the end of the verbatim ;; construct punctuation syntax. Prevents wrong ;; fontification of stuff like "\verb|foo\|". @@ -1351,7 +1353,17 @@ triggers Font Lock to recognize the change." ;; Make sure fontification will be refreshed if a user sets variables ;; influencing fontification in her file-local variables section. - (add-hook 'hack-local-variables-hook #'font-latex-after-hacking-local-variables t t)) + (add-hook 'hack-local-variables-hook #'font-latex-after-hacking-local-variables t t) + + ;; We may be using the mode programmatically to extract data, and we + ;; then need this to be set up first so that a command like + ;; `xref-find-references' doesn't bug out when matching hits in + ;; files that Emacs isn't visiting. (bug#65912) + ;; We need this treatment because the current syntax propertize + ;; facility depends on font lock machinery. We can remove this + ;; when syntax propertization decouples font lock. + (unless buffer-file-truename + (font-lock-set-defaults))) (defun font-latex-update-font-lock (&optional _syntactic-kws) "Tell font-lock about updates of fontification rules. diff --git a/latex.el b/latex.el index 1bcc66baea..0750d74985 100644 --- a/latex.el +++ b/latex.el @@ -7974,9 +7974,7 @@ See info under AUCTeX for full documentation. Entering LaTeX mode calls the value of `text-mode-hook', then the value of `TeX-mode-hook', and then the value of `LaTeX-mode-hook'." - :after-hook ;; Defeat filladapt - (if (bound-and-true-p filladapt-mode) - (turn-off-filladapt-mode)) + :after-hook (LaTeX-mode-cleanup) (LaTeX-common-initialization) (setq TeX-base-mode-name mode-name) @@ -8005,11 +8003,46 @@ of `LaTeX-mode-hook'." (apply #'append (mapcar #'cdr LaTeX-provided-class-options))))) nil t) + (when (fboundp 'LaTeX-preview-setup) (LaTeX-preview-setup)) ;; Set up flymake backend, see latex-flymake.el (add-hook 'flymake-diagnostic-functions #'LaTeX-flymake nil t)) +(defun LaTeX-mode-cleanup () + ;; Defeat filladapt + (if (bound-and-true-p filladapt-mode) + (turn-off-filladapt-mode)) + + ;; Don't overwrite the value the user set by hooks or file + ;; (directory) local variables. + (or (local-variable-p 'outline-regexp) + (setq-local outline-regexp (LaTeX-outline-regexp t))) + (or (local-variable-p 'outline-heading-alist) + (setq outline-heading-alist + (mapcar (lambda (x) + (cons (concat "\\" (nth 0 x)) (nth 1 x))) + LaTeX-section-list))) + + ;; Keep `LaTeX-paragraph-commands-regexp' in sync with + ;; `LaTeX-paragraph-commands' in case the latter is updated by + ;; hooks or file (directory) local variables. + (and (local-variable-p 'LaTeX-paragraph-commands) + (setq-local LaTeX-paragraph-commands-regexp + (LaTeX-paragraph-commands-regexp-make))) + ;; Don't do locally-bound test for `paragraph-start' because it + ;; makes little sense; Style files casually call this function and + ;; overwrite it unconditionally. Users who need per-file + ;; customization of `paragraph-start' should set + ;; `LaTeX-paragraph-commands' instead. + (LaTeX-set-paragraph-start) + + ;; Don't do locally-bound test for similar reason as above. Users + ;; who need per-file customization of + ;; `LaTeX-indent-begin-regexp-local' etc. should set + ;; `LaTeX-indent-begin-list' and so on instead. + (LaTeX-indent-commands-regexp-make)) + ;; COMPATIBILITY for Emacs<29 ;;;###autoload (put 'LaTeX-mode 'auctex-function-definition (symbol-function 'LaTeX-mode)) @@ -8029,6 +8062,10 @@ runs the hooks in `docTeX-mode-hook'." paragraph-separate (concat paragraph-separate "\\|%<") TeX-comment-start-regexp "\\(?:%\\(?:<[^>]+>\\)?\\)") (setq TeX-base-mode-name mode-name) + ;; We can remove the next `setq' when syntax propertization + ;; decouples font lock and `font-latex-setup' stops calling + ;; `font-lock-set-defaults'. + (setq font-lock-set-defaults nil) (funcall TeX-install-font-lock)) ;; Enable LaTeX abbrevs in docTeX mode buffer. @@ -8102,11 +8139,13 @@ function would return non-nil and `(match-string 1)' would return (require 'outline) (set (make-local-variable 'outline-level) #'LaTeX-outline-level) - (set (make-local-variable 'outline-regexp) (LaTeX-outline-regexp t)) - (setq outline-heading-alist - (mapcar (lambda (x) - (cons (concat "\\" (nth 0 x)) (nth 1 x))) - LaTeX-section-list)) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (set (make-local-variable 'outline-regexp) (LaTeX-outline-regexp t)) + ;; (when (boundp 'outline-heading-alist) + ;; (setq outline-heading-alist + ;; (mapcar (lambda (x) + ;; (cons (concat "\\" (nth 0 x)) (nth 1 x))) + ;; LaTeX-section-list))) (setq-local TeX-auto-full-regexp-list (delete-dups (append LaTeX-auto-regexp-list @@ -8115,7 +8154,8 @@ function would return non-nil and `(match-string 1)' would return (copy-sequence plain-TeX-auto-regexp-list)))) - (LaTeX-set-paragraph-start) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (LaTeX-set-paragraph-start) (setq paragraph-separate (concat "[ \t]*%*[ \t]*\\(" @@ -8131,7 +8171,8 @@ function would return non-nil and `(match-string 1)' would return (setq-local beginning-of-defun-function #'LaTeX-find-matching-begin) (setq-local end-of-defun-function #'LaTeX-find-matching-end) - (LaTeX-indent-commands-regexp-make) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (LaTeX-indent-commands-regexp-make) ;; Standard Emacs completion-at-point support. We append the entry ;; in order to let `TeX--completion-at-point' be first in the list: @@ -8850,22 +8891,36 @@ function would return non-nil and `(match-string 1)' would return (replace-match "\\\\input{" nil nil))))) (TeX-normal-mode nil)) +;; This function is no longer used; We leave it for compatibility. (defun LaTeX-env-beginning-pos-col () "Return a cons: (POINT . COLUMN) for current environment's beginning." (save-excursion (LaTeX-find-matching-begin) (cons (point) (current-column)))) +;; This makes difference from `LaTeX-env-beginning-pos-col' when +;; something non-whitespace sits before the \begin{foo}. (bug#65648) +(defun LaTeX-env-beginning-pos-indent () + "Return a cons: (POINT . INDENT) for current environment's beginning. +INDENT is the indent of the line containing POINT." + (save-excursion + ;; FIXME: There should be some fallback mechanism in case that the + ;; next `backward-up' fails. (Such fail can occur in document + ;; with temporarily broken structure due to in-progress editing + ;; process.) + (LaTeX-backward-up-environment) + (cons (point) (LaTeX-current-indentation)))) + (defun LaTeX-hanging-ampersand-position (&optional pos col) "Return indent column for a hanging ampersand (that is, ^\\s-*&). -When you know the position and column of the beginning of the -current environment, supply them as optional arguments POS and -COL for efficiency." +When you know the position of the beginning of the current +environment and indent of its line, supply them as optional +arguments POS and COL for efficiency." (cl-destructuring-bind (beg-pos . beg-col) (if pos (cons pos col) - (LaTeX-env-beginning-pos-col)) + (LaTeX-env-beginning-pos-indent)) (let ((cur-pos (point))) (save-excursion (if (and (search-backward "\\\\" beg-pos t) @@ -8896,7 +8951,7 @@ COL for efficiency." "Return indent column for the current tabular-like line." (cl-destructuring-bind (beg-pos . beg-col) - (LaTeX-env-beginning-pos-col) + (LaTeX-env-beginning-pos-indent) (let ((tabular-like-end-regex (format "\\\\end{%s}" (regexp-opt diff --git a/preview.el.in b/preview.el.in index 1c5351dae4..4e113baaff 100644 --- a/preview.el.in +++ b/preview.el.in @@ -2290,13 +2290,14 @@ all previews." (defun preview-kill-buffer-cleanup (&optional buf) "This is a cleanup function just for use in hooks. Cleans BUF or current buffer. The difference to -`preview-clearout-buffer' is that previews -associated with the last buffer modification time are -kept." - (with-current-buffer (or buf (current-buffer)) - (save-restriction - (widen) - (preview-clearout (point-min) (point-max) (visited-file-modtime))))) +`preview-clearout-buffer' is that previews associated with the +last buffer modification time are kept." + ;; Do nothing for indirect buffers. (bug#65462) + (unless (buffer-base-buffer (or buf (setq buf (current-buffer)))) + (with-current-buffer buf + (save-restriction + (widen) + (preview-clearout (point-min) (point-max) (visited-file-modtime)))))) (add-hook 'kill-buffer-hook #'preview-kill-buffer-cleanup) (add-hook 'before-revert-hook #'preview-kill-buffer-cleanup) diff --git a/tests/context/context-test.el b/tests/context/context-test.el index cc7c8d549f..4eeab4b67a 100644 --- a/tests/context/context-test.el +++ b/tests/context/context-test.el @@ -24,12 +24,6 @@ (require 'ert) (require 'context) -;; We need to ensure that font-lock has put the syntax properties -;; already which won't happen in batch mode. So trigger font-lock -;; immediately. -(define-advice ConTeXt-mode-common-initialization (:after ()) - (font-lock-ensure)) - (AUCTeX-set-ert-path 'ConTeXt-indent-test/in "context-indentation-in.tex" diff --git a/tests/latex/font-latex-test.el b/tests/latex/font-latex-test.el index 40f9633a1a..94150ac04d 100644 --- a/tests/latex/font-latex-test.el +++ b/tests/latex/font-latex-test.el @@ -27,12 +27,6 @@ (defvar font-lock-beg) (defvar font-lock-end) -;; We need to ensure that font-lock has put the syntax properties -;; already which won't happen in batch mode. So trigger font-lock -;; immediately. -(define-advice LaTeX-common-initialization (:after ()) - (font-lock-ensure)) - (ert-deftest font-latex-three-dollars () "Test three consecutive dollar is ignored." ;; When the function `font-latex-match-dollar-math' encounters three diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el index 767ae4bd12..5b947331e7 100644 --- a/tests/latex/latex-test.el +++ b/tests/latex/latex-test.el @@ -24,12 +24,6 @@ (require 'ert) (require 'latex) -;; We need to ensure that font-lock has put the syntax properties -;; already which won't happen in batch mode. So trigger font-lock -;; immediately. -(define-advice LaTeX-common-initialization (:after ()) - (font-lock-ensure)) - (AUCTeX-set-ert-path 'LaTeX-indent-tabular-test/in "tabular-in.tex" @@ -174,11 +168,10 @@ (should (string= (with-temp-buffer (insert-file-contents LaTeX-filling/in) - (LaTeX-mode) (let ((fill-column 70) (LaTeX-shortvrb-chars '(?\")) (TeX-parse-self t)) - (TeX-update-style t) + (LaTeX-mode) (search-forward "Lorem") (fill-paragraph) @@ -416,9 +409,8 @@ backend=biber % here is a comment ;; dvipdfmx option should not trigger `TeX-PDF-from-DVI' for ;; XeLaTeX document - (LaTeX-mode) (let ((TeX-engine 'xetex)) - (TeX-update-style)) + (LaTeX-mode)) (should TeX-PDF-mode) (should (not (TeX-PDF-from-DVI))) (should (not (member "dvipdfmx" TeX-active-styles))) diff --git a/tests/latex/tabular-out.tex b/tests/latex/tabular-out.tex index 66de0641fa..113c1d1299 100644 --- a/tests/latex/tabular-out.tex +++ b/tests/latex/tabular-out.tex @@ -45,11 +45,11 @@ \begin{equation} \begin{aligned} &n u m=\left[\begin{array}{ll} - 2 & 25 - \end{array}\right] \\ + 2 & 25 + \end{array}\right] \\ &d e n=\left[\begin{array}{lll} - 1 & 4 & 25 - \end{array}\right] + 1 & 4 & 25 + \end{array}\right] \end{aligned} \end{equation} diff --git a/tests/latex/texmathp-test.el b/tests/latex/texmathp-test.el index 121af22c7f..a18df63acd 100644 --- a/tests/latex/texmathp-test.el +++ b/tests/latex/texmathp-test.el @@ -55,7 +55,6 @@ (should-not (with-temp-buffer (insert "a $b$ \\verb|$| c ") (LaTeX-mode) - (font-lock-ensure) (texmathp))) (should-not (with-temp-buffer @@ -67,7 +66,6 @@ $ \\end{verbatim} c") (LaTeX-mode) - (font-lock-ensure) (texmathp))))) ;;; texmathp-test.el ends here diff --git a/tex-fold.el b/tex-fold.el index 21c74f4764..1bbbf969c7 100644 --- a/tex-fold.el +++ b/tex-fold.el @@ -1,6 +1,6 @@ ;;; tex-fold.el --- Fold TeX macros. -*- lexical-binding: t; -*- -;; Copyright (C) 2004-2022 Free Software Foundation, Inc. +;; Copyright (C) 2004-2023 Free Software Foundation, Inc. ;; Author: Ralf Angeli <ang...@caeruleus.net> ;; Maintainer: auctex-de...@gnu.org @@ -111,6 +111,8 @@ the respective macro argument. If the first element is a function symbol, the function will be called with all mandatory arguments of the macro and the result of the function call will be used as a replacement for the macro. +Such functions typically return a string, but may also return the +symbol `abort' to indicate that the macro should not be folded. Setting this variable does not take effect immediately. Use Customize or reset the mode." @@ -796,31 +798,40 @@ That means, put respective properties onto overlay OV." (display-string (if (listp computed) (car computed) computed)) ;; (face (when (listp computed) (cadr computed))) ) - ;; Do nothing if the overlay is empty. - (when (and ov-start ov-end) - ;; Cater for zero-length display strings. - (when (string= display-string "") (setq display-string TeX-fold-ellipsis)) - ;; Add a linebreak to the display string and adjust the overlay end - ;; in case of an overfull line. - (when (TeX-fold-overfull-p ov-start ov-end display-string) - (setq display-string (concat display-string "\n")) - (move-overlay ov ov-start (save-excursion - (goto-char ov-end) - (skip-chars-forward " \t") - (point)))) - (overlay-put ov 'mouse-face 'highlight) - (when font-lock-mode - ;; Add raise adjustment for superscript and subscript. - ;; (bug#42209) - (setq display-string - (propertize display-string - 'display (get-text-property ov-start 'display)))) - (overlay-put ov 'display display-string) - (when font-lock-mode - (overlay-put ov 'face TeX-fold-folded-face)) - (unless (zerop TeX-fold-help-echo-max-length) - (overlay-put ov 'help-echo (TeX-fold-make-help-echo - (overlay-start ov) (overlay-end ov))))))) + + (if (eq computed 'abort) + ;; Abort folding if computed result is the symbol `abort'. + ;; This allows programmatic customization. + ;; Suggested by Paul Nelson <ultr...@gmail.com>. + ;; <URL:https://lists.gnu.org/r/auctex/2023-08/msg00026.html> + (progn (delete-overlay ov) + t ; so that `TeX-fold-dwim' "gives up" + ) + ;; Do nothing if the overlay is empty. + (when (and ov-start ov-end) + ;; Cater for zero-length display strings. + (when (string= display-string "") (setq display-string TeX-fold-ellipsis)) + ;; Add a linebreak to the display string and adjust the overlay end + ;; in case of an overfull line. + (when (TeX-fold-overfull-p ov-start ov-end display-string) + (setq display-string (concat display-string "\n")) + (move-overlay ov ov-start (save-excursion + (goto-char ov-end) + (skip-chars-forward " \t") + (point)))) + (overlay-put ov 'mouse-face 'highlight) + (when font-lock-mode + ;; Add raise adjustment for superscript and subscript. + ;; (bug#42209) + (setq display-string + (propertize display-string + 'display (get-text-property ov-start 'display)))) + (overlay-put ov 'display display-string) + (when font-lock-mode + (overlay-put ov 'face TeX-fold-folded-face)) + (unless (zerop TeX-fold-help-echo-max-length) + (overlay-put ov 'help-echo (TeX-fold-make-help-echo + (overlay-start ov) (overlay-end ov)))))))) (defun TeX-fold-show-item (ov) "Show a single LaTeX macro or environment. diff --git a/tex-info.el b/tex-info.el index 4bc034ef3e..912ffc6619 100644 --- a/tex-info.el +++ b/tex-info.el @@ -31,6 +31,9 @@ (require 'texinfo) +;; Silence the compiler for variables: +(defvar outline-heading-alist) + ;;; Environments: (defvar Texinfo-environment-list '(("cartouche") ("command") ("copying") ("defcv") ("deffn") ("defivar") @@ -635,7 +638,7 @@ is assumed by default." Entering Texinfo mode calls the value of `text-mode-hook' and then the value of `Texinfo-mode-hook'." :syntax-table texinfo-mode-syntax-table - :after-hook (TeX-set-mode-name) + :after-hook (Texinfo-mode-cleanup) (setq TeX-mode-p t) (setq TeX-output-extension (if TeX-PDF-mode "pdf" "dvi")) @@ -643,11 +646,12 @@ value of `Texinfo-mode-hook'." ;; Mostly stolen from texinfo.el (setq TeX-base-mode-name mode-name) - (set (make-local-variable 'page-delimiter) - (concat - "^@node [ \t]*[Tt]op\\|^@\\(" - texinfo-chapter-level-regexp - "\\)")) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (set (make-local-variable 'page-delimiter) + ;; (concat + ;; "^@node [ \t]*[Tt]op\\|^@\\(" + ;; texinfo-chapter-level-regexp + ;; "\\)")) (set (make-local-variable 'require-final-newline) mode-require-final-newline) (set (make-local-variable 'indent-tabs-mode) nil) (set (make-local-variable 'paragraph-separate) @@ -669,13 +673,13 @@ value of `Texinfo-mode-hook'." (set (make-local-variable 'syntax-propertize-function) texinfo-syntax-propertize-function) - ;; Outline settings. - (setq-local outline-heading-alist - (mapcar (lambda (x) (cons (concat "@" (car x)) (cadr x))) - texinfo-section-list)) - (setq-local outline-regexp - (concat (regexp-opt (mapcar #'car outline-heading-alist) t) - "\\>")) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (setq-local outline-heading-alist + ;; (mapcar (lambda (x) (cons (concat "@" (car x)) (cadr x))) + ;; texinfo-section-list)) + ;; (setq-local outline-regexp + ;; (concat (regexp-opt (mapcar #'car outline-heading-alist) t) + ;; "\\>")) ;; Mostly AUCTeX stuff (set (make-local-variable 'TeX-command-current) #'TeX-command-master) @@ -690,9 +694,10 @@ value of `Texinfo-mode-hook'." (setq TeX-trailer-start (format "^%s$" (regexp-quote (concat TeX-esc "bye")))) - (set (make-local-variable 'TeX-complete-list) - (list (list "@\\([a-zA-Z]*\\)" 1 #'TeX-symbol-list-filtered nil) - (list "" TeX-complete-word))) + ;; Moved after `run-mode-hooks'. (bug#65750) + ;; (set (make-local-variable 'TeX-complete-list) + ;; (list (list "@\\([a-zA-Z]*\\)" 1 #'TeX-symbol-list-filtered nil) + ;; (list "" TeX-complete-word))) (set (make-local-variable 'TeX-font-list) Texinfo-font-list) (set (make-local-variable 'TeX-font-replace-function) @@ -857,6 +862,33 @@ value of `Texinfo-mode-hook'." (if (and (boundp 'reftex-mode) reftex-mode) (Texinfo-reftex-hook))) +(defun Texinfo-mode-cleanup () + ;; Don't overwrite the value the user set by hooks or file + ;; (directory) variables. + (or (local-variable-p 'page-delimiter) + (setq-local page-delimiter + (concat + "^@node [ \t]*[Tt]op\\|^@\\(" + texinfo-chapter-level-regexp + "\\)"))) + + ;; Outline settings. + (or (local-variable-p 'outline-heading-alist) + (setq-local outline-heading-alist + (mapcar (lambda (x) (cons (concat "@" (car x)) (cadr x))) + texinfo-section-list))) + (or (local-variable-p 'outline-regexp) + (setq-local outline-regexp + (concat (regexp-opt (mapcar #'car outline-heading-alist) t) + "\\>"))) + + (or (local-variable-p 'TeX-complete-list) + (setq-local TeX-complete-list + (list (list "@\\([a-zA-Z]*\\)" 1 #'TeX-symbol-list-filtered nil) + (list "" TeX-complete-word)))) + + (TeX-set-mode-name)) + (defcustom Texinfo-clean-intermediate-suffixes '("\\.cps?" "\\.vrs?" "\\.fns?" "\\.tps?" "\\.pgs?" "\\.kys?") "List of regexps matching suffixes of files to be deleted. diff --git a/tex-jp.el b/tex-jp.el index f519781f53..1d41175044 100644 --- a/tex-jp.el +++ b/tex-jp.el @@ -1,6 +1,6 @@ ;;; tex-jp.el --- Support for Japanese TeX. -*- lexical-binding: t; -*- -;; Copyright (C) 1999, 2001-2008, 2012-2013, 2016-2018, 2020-2022 +;; Copyright (C) 1999, 2001-2008, 2012-2013, 2016-2018, 2020-2023 ;; Free Software Foundation, Inc. ;; Author: KOBAYASHI Shinji <k...@flab.fujitsu.co.jp>, @@ -493,6 +493,9 @@ overwrite the value already set locally." ;;; Support for various self-insert-command (defalias 'japanese-TeX-self-insert-command + ;; FIXME: `can-n-egg-self-insert-command' and + ;; `egg-self-insert-command' must be much obsolete because + ;; can-n-egg.el and egg.el are no longer available. (cond ((fboundp 'can-n-egg-self-insert-command) #'can-n-egg-self-insert-command) ((fboundp 'egg-self-insert-command) @@ -502,13 +505,15 @@ overwrite the value already set locally." (t #'self-insert-command))) -(defun TeX-insert-punctuation () +(defun japanese-TeX-insert-punctuation () "Insert point or comma, cleaning up preceding space." (interactive) (expand-abbrev) (if (TeX-looking-at-backward "\\\\/\\(}+\\)" 50) (replace-match "\\1" t)) (call-interactively #'japanese-TeX-self-insert-command)) +(advice-add 'TeX-insert-punctuation :override + #'japanese-TeX-insert-punctuation) ;;; Error Messages diff --git a/tex.el b/tex.el index ced88a816e..7ce968d84e 100644 --- a/tex.el +++ b/tex.el @@ -3756,7 +3756,7 @@ other entries will enter `plain-TeX-mode'." Not intended for direct use for user." :abbrev-table nil - :after-hook (TeX-set-mode-name) + :after-hook (TeX-mode-cleanup) :interactive nil (setq TeX-mode-p t) @@ -3797,6 +3797,9 @@ Not intended for direct use for user." ;; (aset buffer-display-table ?\t (apply 'vector (append "<TAB>" nil))) ;; Symbol & length completion. + ;; We have to move the setup of `TeX-complete-list' after + ;; `run-mode-hooks' in order to reflect the file local customization + ;; of `TeX-insert-braces' and `TeX-complete-word'. (setq-local TeX-complete-list (list (list "\\\\\\([a-zA-Z]*\\)" 1 @@ -3853,11 +3856,20 @@ Not intended for direct use for user." (TeX-master-file nil nil t)) (TeX-update-style t)) nil t)) +(defun TeX-mode-cleanup () + ;; Complete style initialization in buffers which don't visit files + ;; and which are therefore missed by the setting of above + ;; `find-file-hook'. This is necessary for `xref-find-references', + ;; for example. (bug#65912) + (unless buffer-file-truename + (TeX-update-style)) + + (TeX-set-mode-name)) + ;; COMPATIBILITY for Emacs<29 ;;;###autoload (put 'TeX-mode 'auctex-function-definition (symbol-function 'TeX-mode)) - ;;; Hilighting ;; FIXME: It's likely that `hilit-patterns-alist' is much obsolete. @@ -5255,8 +5267,16 @@ Brace insertion is only done if point is in a math construct and (progn (easy-menu-add-item nil - ;; Ugly hack because docTeX mode uses the LaTeX menu. - (list (if (eq major-mode 'docTeX-mode) "LaTeX" TeX-base-mode-name)) + ;; Ugly hack because docTeX mode uses the LaTeX menu and + ;; ConTeXt mode uses "ConTeXt-en" or "ConTeXt-nl" for the + ;; value of `TeX-base-mode-name'. + ;; XXX: Perhaps we should have a new variable holding the + ;; mode-specific menu title? + (list + (cond + ((eq major-mode 'docTeX-mode) "LaTeX") + ((eq major-mode 'ConTeXt-mode) "ConTeXt") + (t TeX-base-mode-name))) (or TeX-customization-menu (setq TeX-customization-menu (customize-menu-create 'AUCTeX "Customize AUCTeX"))))) @@ -5499,21 +5519,25 @@ additional characters." '(?\{ ?\} ?\\)) (TeX-in-comment)))) (forward-char) - (cond ((memq char (append - TeX-indent-open-delimiters - '(?\{))) - (setq count (+ count TeX-brace-indent-level))) - ((memq char (append - TeX-indent-close-delimiters - '(?\}))) - (setq count (- count TeX-brace-indent-level))) - ((eq char ?\\) - (when (< (point) limit) - ;; ?\\ in verbatim constructs doesn't escape - ;; the next char - (unless (TeX-verbatim-p) - (forward-char)) - t)))))) + ;; If inside a verbatim construct, just return t and + ;; proceed, otherwise start counting: + (if (TeX-verbatim-p) + t + (cond ((memq char (append + TeX-indent-open-delimiters + '(?\{))) + (setq count (+ count TeX-brace-indent-level))) + ((memq char (append + TeX-indent-close-delimiters + '(?\}))) + (setq count (- count TeX-brace-indent-level))) + ((eq char ?\\) + (when (< (point) limit) + ;; ?\\ in verbatim constructs doesn't escape + ;; the next char + (unless (TeX-verbatim-p) + (forward-char)) + t))))))) count))) ;;; Navigation