[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex 22ba857c53 06/39: Improve fontification within s
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex 22ba857c53 06/39: Improve fontification within shortvrb delimiters |
Date: |
Thu, 20 Jul 2023 04:21:48 -0400 (EDT) |
branch: externals/auctex
commit 22ba857c53ca633f93b543328a17e01825961817
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>
Improve fontification within shortvrb delimiters
* style/shortvrb.el ("shortvrb"): Use
`font-latex-syntactic-keywords-extra' for fontification instead of
`font-latex-add-to-syntax-alist' in order to catch a backslash as
last character inside the shortvrb delimiters.
* tests/latex/font-latex-test.el (font-latex-shortvrb-chars): Add
new test.
---
style/shortvrb.el | 45 +++++++++++++++++-----------------
tests/latex/font-latex-test.el | 55 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 22 deletions(-)
diff --git a/style/shortvrb.el b/style/shortvrb.el
index e6de06080c..405ab6f240 100644
--- a/style/shortvrb.el
+++ b/style/shortvrb.el
@@ -1,6 +1,6 @@
;;; shortvrb.el --- AUCTeX style for `shortvrb.sty' -*- lexical-binding: t;
-*-
-;; Copyright (C) 2009--2022 Free Software Foundation, Inc.
+;; Copyright (C) 2009--2023 Free Software Foundation, Inc.
;; Author: Ralf Angeli <angeli@caeruleus.net>
;; Maintainer: auctex-devel@gnu.org
@@ -45,12 +45,11 @@
(require 'tex-style)
;; Silence the compiler:
-(declare-function font-latex-add-to-syntax-alist
- "font-latex"
- (list))
+(declare-function font-latex-set-syntactic-keywords
+ "font-latex" ())
(declare-function font-latex-add-keywords
- "font-latex"
- (keywords class))
+ "font-latex" (keywords class))
+(defvar font-latex-syntactic-keywords-extra)
(TeX-add-style-hook
"shortvrb"
@@ -69,26 +68,28 @@
(cons str str)))
LaTeX-shortvrb-chars)))
- ;; Syntax
- ;; N.B. This doesn't handle backslash just before the closing
- ;; delimiter like |xyz\| correctly. We hope we can live with that.
- (when LaTeX-shortvrb-chars
- (let ((st (make-syntax-table (syntax-table))))
- (dolist (c LaTeX-shortvrb-chars)
- (modify-syntax-entry c "\"" st))
- (set-syntax-table st)))
-
;; Fontification
- (when (and LaTeX-shortvrb-chars
- (featurep 'font-latex)
+ (when (and (featurep 'font-latex)
(eq TeX-install-font-lock 'font-latex-setup))
- (font-latex-add-to-syntax-alist
- (mapcar (lambda (char) (cons char "\""))
- LaTeX-shortvrb-chars))
-
(font-latex-add-keywords '(("MakeShortVerb" "*{")
("DeleteShortVerb" "{"))
- 'function)))
+ 'function)
+
+ ;; Use `font-latex-syntactic-keywords-extra' instead of
+ ;; `font-latex-add-to-syntax-alist' so we can catch a backslash
+ ;; within the shortvrb delimiters and make things like |xyz\|
+ ;; work correctly:
+ (when LaTeX-shortvrb-chars
+ (dolist (c LaTeX-shortvrb-chars)
+ (let ((s (char-to-string c)))
+ (add-to-list 'font-latex-syntactic-keywords-extra
+ `(,(concat "\\(" s "\\)"
+ ".*?"
+ "\\(" (regexp-quote TeX-esc) "*\\)"
+ "\\(" s "\\)")
+ (1 "\"") (2 ".") (3 "\"")))))
+ ;; Tell font-lock about the update
+ (font-latex-set-syntactic-keywords))))
TeX-dialect)
;;; shortvrb.el ends here
diff --git a/tests/latex/font-latex-test.el b/tests/latex/font-latex-test.el
index 0c81392add..7ec3d6df51 100644
--- a/tests/latex/font-latex-test.el
+++ b/tests/latex/font-latex-test.el
@@ -350,4 +350,59 @@ x
(should (font-latex-faces-present-p 'font-lock-function-name-face
(match-end 0))) )))
+(ert-deftest font-latex-shortvrb-chars ()
+ "Test fontification within delimiters defined by `LaTeX-shortvrb-chars'."
+ (with-temp-buffer
+ (let ((TeX-install-font-lock #'font-latex-setup)
+ (LaTeX-shortvrb-chars '(?| ?\"))
+ (TeX-parse-self t))
+ (insert "\
+\\documentclass{article}
+\\usepackage{shortvrb}
+\\begin{document}
+foo |xyz\\| bar
+foo \"xyz\\\" bar
+\\end{document}")
+ (LaTeX-mode)
+ (TeX-update-style t)
+ ;; See
https://lists.gnu.org/archive/html/auctex-devel/2023-04/msg00011.html
+ (syntax-ppss-flush-cache (point-min))
+ (font-lock-ensure)
+ (goto-char (point-min))
+ (re-search-forward "^f" nil t)
+ (should-not (get-text-property (point) 'face))
+ (search-forward "|" nil t)
+ ;; This is the `|' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face
+ (1- (point))))
+ ;; This is the `x' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face))
+ (search-forward "|" nil t)
+ ;; This is the `\' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face
+ (- (point) 2)))
+ ;; This is the `|' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face
+ (1- (point))))
+ (search-forward "ba" nil t)
+ (should-not (get-text-property (point) 'face))
+
+ (re-search-forward "^f" nil t)
+ (should-not (get-text-property (point) 'face))
+ (search-forward "\"" nil t)
+ ;; This is the `"' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face
+ (1- (point))))
+ ;; This is the `x' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face))
+ (search-forward "\"" nil t)
+ ;; This is the `\' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face
+ (- (point) 2)))
+ ;; This is the `"' char:
+ (should (font-latex-faces-present-p 'font-latex-verbatim-face
+ (1- (point))))
+ (search-forward "ba" nil t)
+ (should-not (get-text-property (point) 'face)))))
+
;;; font-latex-test.el ends here
- [elpa] externals/auctex updated (9d47b0a1bd -> 1c3360b162), Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 11e9dbfdf3 30/39: Track last change for \newtheorem macro in styles, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex d6fb3c58ce 01/39: Be more resilient when parsing arguments, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 22ba857c53 06/39: Improve fontification within shortvrb delimiters,
Tassilo Horn <=
- [elpa] externals/auctex 4bcad4772d 15/39: Simplify handling of package options, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex b4c27dd36b 02/39: Lift required GNU Emacs version to 26.1, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex e0bc78a500 23/39: Support in-buffer completion for class/package names/options, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex b55368f75f 38/39: Merge remote-tracking branch 'origin/master' into externals/auctex, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 2017d97b0e 09/39: Rewrite *-unload-hook to *-unload-function, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex c67f5d75b2 14/39: ; * Makefile.in (STYLESRC): Fix last change., Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 1c3360b162 39/39: Release GNU AUCTeX 13.2.1, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex cdd0cbf33a 03/39: Add new style/soul.el, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex 6d34e1f1ae 34/39: Simplify implementation of style/paralist.el, Tassilo Horn, 2023/07/20
- [elpa] externals/auctex fe42de7cf6 26/39: Obey buffer-local value of TeX-error-overview-open-after-TeX-run, Tassilo Horn, 2023/07/20