branch: main commit 3c4c78b4309bd807db625bf180e5ce047b0cfb76 Merge: 0383415b 40b9319b Author: Tassilo Horn <t...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Merge remote-tracking branch 'origin/master' into externals/auctex --- font-latex.el | 28 ++++++------ latex.el | 31 +++++++------- tests/latex/latex-comment-filling-in.tex | 35 +++++++++++++++ tests/latex/latex-comment-filling-out.tex | 38 +++++++++++++++++ tests/latex/latex-test.el | 71 +++++++++++++++++++++++++------ 5 files changed, 163 insertions(+), 40 deletions(-) diff --git a/font-latex.el b/font-latex.el index 7ba37924..906afc97 100644 --- a/font-latex.el +++ b/font-latex.el @@ -2141,19 +2141,21 @@ set to french, and >>german<< (and 8-bit) are used if set to german." (defun font-latex-match-script-chars (limit) "Match subscript and superscript chars up to LIMIT." - (and (re-search-forward "[^_^]\\([_^]\\)" limit t) - (let ((pos (match-beginning 1))) - (and (font-latex-faces-present-p 'font-latex-math-face pos) - (not (font-latex-faces-present-p '(font-lock-constant-face - font-lock-builtin-face - font-lock-comment-face - font-latex-verbatim-face) pos)) - ;; Check for backslash quoting - (not (let ((odd nil) - (pos pos)) - (while (eq (char-before pos) ?\\) - (setq pos (1- pos) odd (not odd))) - odd)))))) + (catch 'found + (while (re-search-forward "[^_^]\\([_^]\\)" limit t) + (let ((pos (match-beginning 1))) + (when (and (font-latex-faces-present-p 'font-latex-math-face pos) + (not (font-latex-faces-present-p '(font-lock-constant-face + font-lock-builtin-face + font-lock-comment-face + font-latex-verbatim-face) pos)) + ;; Check for backslash quoting + (not (let ((odd nil) + (pos pos)) + (while (eq (char-before pos) ?\\) + (setq pos (1- pos) odd (not odd))) + odd))) + (throw 'found t)))))) (defun font-latex--get-script-props (pos script-type) (let* ((old-raise (or (plist-get (get-text-property pos 'display) 'raise) 0.0)) diff --git a/latex.el b/latex.el index 83d50caf..1feafd1a 100644 --- a/latex.el +++ b/latex.el @@ -2899,9 +2899,14 @@ Normally bound to keys \(, { and [." (TeX-active-mark) (> (point) (mark))) (exchange-point-and-mark)) - (self-insert-command (prefix-numeric-value arg)) (if auto-p + ;; Should supply corresponding right brace with possible + ;; \right-like macro. (let ((lbrace (char-to-string last-command-event)) lmacro skip-p) + ;; Use `insert' rather than `self-insert-command' so that + ;; unexcpected side effects, e.g. `electric-pair-mode', + ;; won't mess up the following outcomes. (bug#47936) + (insert last-command-event) (save-excursion (backward-char) ;; The brace "{" is exceptional in two aspects. @@ -2930,7 +2935,10 @@ Normally bound to keys \(, { and [." (if (TeX-active-mark) (goto-char (mark))) (LaTeX-insert-corresponding-right-macro-and-brace - lmacro lbrace))))))) + lmacro lbrace)))) + ;; Don't supply right brace and just act as ordinary + ;; `self-insert-command'. + (self-insert-command (prefix-numeric-value arg))))) ;; Cater for `delete-selection-mode' (bug#36385) ;; See the header comment of delsel.el for detail. (put #'LaTeX-insert-left-brace 'delete-selection @@ -2954,7 +2962,7 @@ Normally bound to keys \(, { and [." (funcall f)))))) (defun LaTeX-insert-corresponding-right-macro-and-brace - (lmacro lbrace &optional optional prompt) + (lmacro lbrace &optional optional prompt) "Insert right macro and brace correspoinding to LMACRO and LBRACE. Left-right association is determined through `LaTeX-left-right-macros-association' and `TeX-braces-association'. @@ -2987,7 +2995,7 @@ is nil, consult user which brace should be used." optional prompt (format "Which brace (default %s)" (or rbrace "."))) TeX-left-right-braces - nil nil nil nil (or rbrace "."))))))) + nil nil nil nil (or rbrace "."))))))) (defun LaTeX--find-preceding-left-macro-name () "Return the left macro name just before the point, if any. @@ -3775,7 +3783,7 @@ performed in that case." (if (re-search-forward (concat "\\(" ;; Code comments. - "[^\r\n%\\]\\([ \t]\\|\\\\\\\\\\)*" + "[^ \r\n%\\]\\([ \t]\\|\\\\\\\\\\)*" TeX-comment-start-regexp "\\|" ;; Lines ending with `\par'. @@ -3921,7 +3929,7 @@ space does not end a sentence, so don't break a line there." (goto-char from) (let* (linebeg (code-comment-start (save-excursion - (LaTeX-back-to-indentation) + (LaTeX-back-to-indentation 'inner) (TeX-search-forward-comment-start (line-end-position)))) (end-marker (save-excursion @@ -4032,7 +4040,7 @@ space does not end a sentence, so don't break a line there." (TeX-looking-at-backward (concat (regexp-quote TeX-esc) TeX-token-char "*") (1- (- (point) linebeg))) (not (TeX-escaped-p (match-beginning 0)))) - (goto-char (match-beginning 0))) + (goto-char (match-beginning 0))) ;; Cater for \verb|...| (and similar) contructs which should not be ;; broken. (FIXME: Make it work with shortvrb.sty (also loaded by ;; doc.sty) where |...| is allowed. Arbitrary delimiters may be @@ -4073,7 +4081,7 @@ space does not end a sentence, so don't break a line there." start-point) (save-excursion (beginning-of-line) - (LaTeX-back-to-indentation) + (LaTeX-back-to-indentation 'outer) (setq start-point (point)) ;; Find occurences of [, $, {, }, \(, \), \[, \] or $$. (while (and (= final-breakpoint orig-breakpoint) @@ -6810,13 +6818,6 @@ function would return non-nil and `(match-string 1)' would return (define-key LaTeX-mode-map "\C-xne" #'LaTeX-narrow-to-environment) - ;; AUCTeX's brace pairing feature (`LaTeX-electric-left-right-brace') doesn't - ;; play nice with `electric-pair-mode' which is a global minor mode as of - ;; emacs 24.4. - (when (and LaTeX-electric-left-right-brace - (boundp 'electric-pair-mode)) - (set (make-local-variable 'electric-pair-mode) nil)) - ;; Initialization of `add-log-current-defun-function': (set (make-local-variable 'add-log-current-defun-function) #'TeX-current-defun-name)) diff --git a/tests/latex/latex-comment-filling-in.tex b/tests/latex/latex-comment-filling-in.tex new file mode 100644 index 00000000..1ba1bb83 --- /dev/null +++ b/tests/latex/latex-comment-filling-in.tex @@ -0,0 +1,35 @@ +% This is a very long comment which should be wrapped around after fill-column characters. We'll see if that works. + +% \begin{itemize} +% \item This is a long item text which should be wrapped around after fill-column characters even though it is commented. +% \item This is short. +% This also. +% So all 3 gonna be joined. +% \end{itemize} + +\begin{quote} + % This is a very long comment which should be wrapped around after fill-column characters. We'll see if that works. +\end{quote} + +\begin{quote} + % \begin{itemize} + % \item This is a long item text which should be wrapped around after fill-column characters even though it is commented. This should still work although we're already indented. + % \item This is short. + % This also. + % So all 3 gonna be joined. + % \end{itemize} +\end{quote} + +% This is short.\\ +% But no join because the backslashes. + +% This is short.\par +% But no join because the par. + +% Code comments. + +\foo\bar % This is a code comment. +\baz % This also. +\quux % So lines must not be joined. +\foobar % But very long lines, such as this one, well, you know, they may be wrapped around. TODO: It would be cool if this was indented as much as the previous line. +\bar % This is short. diff --git a/tests/latex/latex-comment-filling-out.tex b/tests/latex/latex-comment-filling-out.tex new file mode 100644 index 00000000..0917d951 --- /dev/null +++ b/tests/latex/latex-comment-filling-out.tex @@ -0,0 +1,38 @@ +% This is a very long comment which should be wrapped around after +% fill-column characters. We'll see if that works. + +% \begin{itemize} +% \item This is a long item text which should be wrapped around after +% fill-column characters even though it is commented. +% \item This is short. This also. So all 3 gonna be joined. +% \end{itemize} + +\begin{quote} + % This is a very long comment which should be wrapped around after + % fill-column characters. We'll see if that works. +\end{quote} + +\begin{quote} + % \begin{itemize} + % \item This is a long item text which should be wrapped around + % after fill-column characters even though it is commented. This + % should still work although we're already indented. + % \item This is short. This also. So all 3 gonna be joined. + % \end{itemize} +\end{quote} + +% This is short.\\ +% But no join because the backslashes. + +% This is short.\par +% But no join because the par. + +% Code comments. + +\foo\bar % This is a code comment. +\baz % This also. +\quux % So lines must not be joined. +\foobar % But very long lines, such as this one, well, you know, they +% may be wrapped around. TODO: It would be cool if this was indented +% as much as the previous line. +\bar % This is short. diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el index 6f70d95a..af6e34f4 100644 --- a/tests/latex/latex-test.el +++ b/tests/latex/latex-test.el @@ -33,6 +33,10 @@ "latex-filling-in.tex" 'LaTeX-filling/out "latex-filling-out.tex" + 'LaTeX-comment-filling/in + "latex-comment-filling-in.tex" + 'LaTeX-comment-filling/out + "latex-comment-filling-out.tex" 'LaTeX-math-indent/in "math-indent-in.tex" 'LaTeX-math-indent/out @@ -96,6 +100,27 @@ (insert-file-contents LaTeX-filling/out) (buffer-string))))) +;; Test for comment filling, especially with +;; `LaTeX-syntactic-comments' which is t by default. +(ert-deftest LaTeX-comment-filling () + (should (string= + (with-temp-buffer + (insert-file-contents LaTeX-comment-filling/in) + (LaTeX-mode) + (let ((fill-column 70) + (code-comment-test nil)) + (fill-paragraph) + (while (= 0 (forward-line 1)) + (when (looking-at "% Code comments.") + (setq code-comment-test t)) + (when code-comment-test + (LaTeX-back-to-indentation 'inner)) + (fill-paragraph))) + (buffer-string)) + (with-temp-buffer + (insert-file-contents LaTeX-comment-filling/out) + (buffer-string))))) + ;; Test for bug#19281 (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19281): ;; make sure AUCTeX is able to insert and modify an environment containing a ;; TeX-esc and braces in its name. @@ -453,9 +478,7 @@ ghi")) (buffer-string) "\\begin{quote} % \\begin{center} - % abc - % def - % ghi + % abc def ghi % \\end{center} \\end{quote} ")) @@ -478,9 +501,7 @@ ghi")) (buffer-string) "\\begin{quote} % \\begin{center} - % abc - % def - % ghi + % abc def ghi % \\end{center} \\end{quote} ")) @@ -504,9 +525,7 @@ ghi")) (buffer-string) "\\begin{quote} % \\begin{center} - % abc - % def - % ghi + % abc def ghi % \\end{center} \\end{quote} ")) @@ -529,11 +548,39 @@ ghi")) (buffer-string) "\\begin{quote} \\begin{center} - % abc - % def - % ghi + % abc def ghi \\end{center} \\end{quote} "))))) +(ert-deftest LaTeX-electric-pair-interaction () + "Whether `LaTeX-insert-left-brace' is compatible with `electric-pair-mode'." + (require 'elec-pair) + (let ((LaTeX-electric-left-right-brace t) + (orig-mode electric-pair-mode)) + (unwind-protect + (with-temp-buffer + ;; Temporally enable electric pair mode, if not enabled + ;; already. + (or orig-mode + (electric-pair-mode 1)) + (latex-mode) + + ;; When `LaTeX-insert-left-brace' supplies right brace, + ;; `electric-pair-mode' shoudn't come into play. + (setq last-command-event ?\() + (LaTeX-insert-left-brace nil) + (should (string= "()" (buffer-string))) + + (erase-buffer) + ;; When there is a prefix argument, `LaTeX-insert-left-brace' + ;; just calls `self-insert-command' and `electric-pair-mode' + ;; should work. + (setq last-command-event ?\() + (LaTeX-insert-left-brace 2) + (should (string= "(()" (buffer-string)))) + ;; Restore electric pair mode. + (or orig-mode + (electric-pair-mode -1))))) + ;;; latex-test.el ends here