[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex bbb4e2ae23 08/13: Fill \verb-like macros appropr
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex bbb4e2ae23 08/13: Fill \verb-like macros appropriately (bug#61400) |
Date: |
Sun, 5 Mar 2023 03:25:39 -0500 (EST) |
branch: externals/auctex
commit bbb4e2ae23541870de60fa4929b410d6fa2ee769
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
Fill \verb-like macros appropriately (bug#61400)
* latex.el (LaTeX-verbatim-macro-boundaries): Attach an optional
argument so that it can return boundaries of its argument only.
Include *-braces verbatim macros like \url{} as targets. This affects
`LaTeX-current-verbatim-macro' in the same way.
Clean up codes to fix the following bugs.
(1) Inconsistent result when the point is at just before "\verb...".
(2) Going back to the previous line unintentionally in search of
verbatim macros.
Support optional argument of macros such as \Verb from fancyvrb.
Allow one level of nested braces as verb argument.
(LaTeX-verbatim-p): Don't regard the point just before "\verb..." as
verbatim.
Depend only on syntax-table property when syntax propertize is used.
---
latex.el | 91 ++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 63 insertions(+), 28 deletions(-)
diff --git a/latex.el b/latex.el
index fb862b7637..7306fcc4e3 100644
--- a/latex.el
+++ b/latex.el
@@ -3780,46 +3780,72 @@ values of the variable `LaTeX-verbatim-environments' as
well.")
(append LaTeX-verbatim-environments
LaTeX-verbatim-environments-local))
-(defun LaTeX-verbatim-macro-boundaries ()
- "Return boundaries of verbatim macro.
+(defun LaTeX-verbatim-macro-boundaries (&optional arg-only)
+ "Return boundaries of verbatim macro containing point.
Boundaries are returned as a cons cell where the car is the macro
start and the cdr the macro end.
-Only macros which enclose their arguments with special
-non-parenthetical delimiters, like \\verb+foo+, are recognized."
+If optional argument ARG-ONLY is non-nil, return the inner region
+of the macro argument as cons."
(save-excursion
(let ((orig (point))
- (verbatim-regexp (regexp-opt (LaTeX-verbatim-macros-with-delims) t)))
+ (verbatim-regexp (regexp-opt
+ (append (LaTeX-verbatim-macros-with-delims)
+ (LaTeX-verbatim-macros-with-braces))
+ t)))
;; Search backwards for the macro start, unless we are facing one
- (unless (looking-at (concat (regexp-quote TeX-esc) verbatim-regexp))
- (catch 'found
- (while (progn
- (skip-chars-backward (concat "^\n" (regexp-quote TeX-esc))
- (line-beginning-position))
- (when (looking-at verbatim-regexp) (throw 'found nil))
- (or (bobp) (forward-char -1))
- (/= (point) (line-beginning-position))))))
+ (if (looking-at (concat (regexp-quote TeX-esc) verbatim-regexp))
+ (forward-char 1)
+ (while (progn
+ (skip-chars-backward (concat "^" (regexp-quote TeX-esc))
+ (line-beginning-position))
+ (if (or (bolp)
+ (looking-at verbatim-regexp))
+ ;; Terminate the loop.
+ nil
+ (forward-char -1)
+ ;; Continue the loop.
+ t))))
;; Search forward for the macro end, unless we failed to find a start
(unless (bolp)
(let* ((beg (1- (point)))
- (macro-end (match-end 0))
+ (end (match-end 0))
;; XXX: Here we assume we are dealing with \verb which
;; expects the delimiter right behind the command.
;; However, \lstinline can also cope with whitespace as
;; well as an optional argument after the command.
- (delimiter (buffer-substring-no-properties
- macro-end (1+ macro-end))))
+ ;; \Verb (from fancyvrb) also accepts an optional
+ ;; argument which we have to encounter. We assume that
+ ;; users don't write something like this '\Verb[foo['
+ ;; and again the delimiter is directly after the ]
+ ;; closing the optional argument:
+ (delimiter (progn
+ (if (= (char-after end) (aref LaTeX-optop 0))
+ ;; Update `end'.
+ (save-excursion (goto-char end)
+ (forward-list)
+ (setq end (point))))
+ (string (char-after end)))))
;; Heuristic: If an opening brace is encountered, search for
- ;; both the opening and the closing brace as an end marker.
+ ;; a closing brace as an end marker.
;; Like that the function should work for \verb|...| as well
;; as for \url{...}.
- (when (string= delimiter TeX-grop)
- (setq delimiter (concat delimiter TeX-grcl)))
- (goto-char (1+ macro-end))
- (skip-chars-forward (concat "^" delimiter))
+ (if (string= delimiter TeX-grop)
+ (progn
+ (goto-char end)
+ ;; Allow one level of nested braces as verb argument.
+ (re-search-forward "{[^}{]*\\(?:{[^}{]*}[^}{]*\\)*}"
+ (line-end-position) t)
+ (backward-char))
+ (goto-char (1+ end))
+ (skip-chars-forward (concat "^" delimiter) (line-end-position)))
(when (<= orig (point))
- (cons beg (1+ (point)))))))))
+ (if arg-only
+ (cons (1+ end) (point))
+ (cons beg (1+ (point))))))))))
+;; Currently, AUCTeX doesn't use this function at all. We leave it as
+;; a utility function. It was originally used in `LaTeX-verbatim-p'.
(defun LaTeX-current-verbatim-macro ()
"Return name of verbatim macro containing point, nil if none is present."
(let ((macro-boundaries (LaTeX-verbatim-macro-boundaries)))
@@ -3831,16 +3857,25 @@ non-parenthetical delimiters, like \\verb+foo+, are
recognized."
(point) (progn (skip-chars-forward "@A-Za-z*") (point)))))))
(defun LaTeX-verbatim-p (&optional pos)
- "Return non-nil if position POS is in a verbatim-like construct."
+ "Return non-nil if position POS is in a verbatim-like construct.
+The macro body (\"\\verb\") and its delimiters, including
+optional argument if any, aren't considered as component of a
+verbatim-like construct."
(when pos (goto-char pos))
(save-match-data
- (or (progn
+ ;; TODO: Factor out syntax propertize facility from font-latex.el
+ ;; and re-implement as major mode feature. Then we can drop the
+ ;; fallback code below.
+ (if (eq TeX-install-font-lock 'font-latex-setup)
+ (progn
(syntax-propertize (point))
(nth 3 (syntax-ppss)))
- (member (LaTeX-current-verbatim-macro)
- (LaTeX-verbatim-macros-with-delims))
- (member (TeX-current-macro) (LaTeX-verbatim-macros-with-braces))
- (member (LaTeX-current-environment) (LaTeX-verbatim-environments)))))
+ ;; Fallback for users who stay away from font-latex.
+ (or
+ (let ((region (LaTeX-verbatim-macro-boundaries t)))
+ (and region
+ (<= (car region) (point) (cdr region))))
+ (member (LaTeX-current-environment) (LaTeX-verbatim-environments))))))
;;; Formatting
- [elpa] externals/auctex updated (6d4b412b69 -> 658832b8a2), Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 41397e93cb 04/13: ; Improve last change, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 5cf1dd2ae2 01/13: Indent the active region (bug#48518, bug#28382), Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 3564d9467e 10/13: ; Fix typos, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 992410a201 02/13: ; * style/physics.el: Fix trivial typo., Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 9d8bd6b30e 06/13: Update style/ltugboat.el to class version 2.28, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex fbc6399b99 09/13: Add new tests, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex b77907698e 12/13: Merge remote-tracking branch 'origin/master' into externals/auctex, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex bbb4e2ae23 08/13: Fill \verb-like macros appropriately (bug#61400),
Tassilo Horn <=
- [elpa] externals/auctex 658832b8a2 13/13: Release GNU AUCTeX 13.1.10, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 358cc74dda 03/13: Add new style/algpseudocodex.el, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex de6aa05d74 05/13: Make `texmathp' aware of verbatim macros/environments, Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 4c77908707 11/13: Fix \includegraphics key-vals prompt in beamer documents., Tassilo Horn, 2023/03/05
- [elpa] externals/auctex 4959b9d240 07/13: * style/url.el ("url"): Add missing \DeclareUrlCommand macro., Tassilo Horn, 2023/03/05