[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-diffs] [elpa] externals/auctex 9d0ccc1 13/62: Update style/fancy
From: |
Tassilo Horn |
Subject: |
[AUCTeX-diffs] [elpa] externals/auctex 9d0ccc1 13/62: Update style/fancyvrb.el to package version 3.6 |
Date: |
Sun, 20 Dec 2020 10:39:53 -0500 (EST) |
branch: externals/auctex
commit 9d0ccc18f3d1a18380af6dfa042d9a1259bf336a
Author: Arash Esbati <arash@gnu.org>
Commit: Tassilo Horn <tsdh@gnu.org>
Update style/fancyvrb.el to package version 3.6
* style/fancyvrb.el (LaTeX-fancyvrb-key-val-options): Add the
"reflabel" key.
(LaTeX-fancyvrb-env-reflabel-key-val)
(LaTeX-fancyvrb-reftex-label-context-function): New functions.
(LaTeX-fancyvrb-arg-define-environment): Use
`LaTeX-fancyvrb-env-reflabel-key-val'.
(LaTeX-fancyvrb-key-val-label-regexp): New variable added to
AUCTeX parser.
("fancyvrb"): Run `font-latex-set-syntactic-keywords' in the hook
if fontification is enabled.
---
style/fancyvrb.el | 213 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 195 insertions(+), 18 deletions(-)
diff --git a/style/fancyvrb.el b/style/fancyvrb.el
index ec34dc2..8cadec5 100644
--- a/style/fancyvrb.el
+++ b/style/fancyvrb.el
@@ -1,4 +1,4 @@
-;;; fancyvrb.el --- AUCTeX style for `fancyvrb.sty' version 3.0. -*-
lexical-binding: t; -*-
+;;; fancyvrb.el --- AUCTeX style for `fancyvrb.sty' version 3.6. -*-
lexical-binding: t; -*-
;; Copyright (C) 2013, 2014, 2016-2018, 2020 Free Software Foundation, Inc.
@@ -25,7 +25,7 @@
;;; Commentary:
-;; This file adds support for `fancyvrb.sty' version 3.0.
+;; This file adds support for `fancyvrb.sty' version 3.6.
;; This style has some capabilities to parse user defined macros,
;; environments and saved blocks with `SaveVerbatim' environments and
@@ -41,6 +41,18 @@
;; The entries in `LaTeX-fancyvrb-key-val-options' cover also some
;; keys which are not mentioned in the manual of the package.
+;; Starting with version 3.6, fancyvrb.sty provides a `reflabel' key
+;; in the optional arguments which acts like a `\label' macro. This
+;; key makes mostly sense for `\pageref'; referencing number of
+;; missing \caption's with `\ref' in a fancyvrb environment isn't
+;; useful. This style provides support for AUCTeX and RefTeX in order
+;; to add and reference these labels. When inserting an environment
+;; with `C-c C-e', choose `reflabel' key during the completion. If
+;; you're using RefTeX and want to pass the label insertion job to it,
+;; simply leave the key value-less and proceed. Otherwise enter the
+;; label value by yourself. AUCTeX and RefTeX will parse the value
+;; and offer it for completion once a referencing macros is used.
+
;;; Code:
;; Needed for auto-parsing:
@@ -59,8 +71,7 @@
`(("commentchar" ("none"))
("gobble")
("formatcom")
- ;; Undocumented key
- ("formatcom*")
+ ("formatcom*") ; Undocumented key
("fontfamily" ("tt" "courier" "helvetica"))
("fontsize" ("auto" "\\tiny" "\\scriptsize"
"\\footnotesize" "\\small" "\\normalsize"
@@ -93,11 +104,10 @@
("hfuzz")
("samepage" ("true" "false"))
("codes")
- ;; Undocumented key
- ("codes*")
+ ("codes*") ; Undocumented key
("defineactive")
- ;; Undocumented key
- ("defineactive*")
+ ("defineactive*") ; Undocumented key
+ ("reflabel")
;; Undocumented key and introduced in version 2.81 2011/04/06
("vspace" ,(mapcar (lambda (x)
(concat TeX-esc (car x)))
@@ -355,16 +365,61 @@ update only various AUCTeX variables for verbatim
environments."
;; (cond ...):
(LaTeX-add-environments
`(,env LaTeX-env-args
- [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]))
+ [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
+ LaTeX-fancyvrb-env-reflabel-key-val))
(LaTeX-add-environments
`(,(concat env "*") LaTeX-env-args
- [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]))
+ [ TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local ]
+ LaTeX-fancyvrb-env-reflabel-key-val))
(add-to-list 'LaTeX-verbatim-environments-local (concat env "*"))
(add-to-list 'LaTeX-indent-environment-list
- `(,(concat env "*") current-indentation) t)))
+ `(,(concat env "*") current-indentation) t)
+ ;; Tell AUCTeX about label values to reflabel key:
+ (add-to-list 'LaTeX-label-alist
+ (cons env 'LaTeX-listing-label) t)
+ (add-to-list 'LaTeX-label-alist
+ (cons (concat env "*") 'LaTeX-listing-label) t)
+ (TeX-auto-add-regexp
+ `(,(concat (regexp-quote TeX-esc)
+ "begin[[:space:]]*"
+ (regexp-quote TeX-grop)
+ env
+ "\\*?"
+ (regexp-quote TeX-grcl)
+ "[[:space:]]*"
+ (LaTeX-extract-key-value-label "reflabel"))
+ 1 LaTeX-auto-label))
+ ;; Tell RefTeX:
+ (when (and (fboundp 'reftex-add-label-environments)
+ (boundp 'reftex-label-regexps))
+ (reftex-add-label-environments
+ `((,env
+ ?l ,LaTeX-listing-label "~\\pageref{%s}"
+ LaTeX-fancyvrb-reftex-label-context-function
+ (regexp "[Ll]isting" "[Vv]erbatim"
+ "[Cc]ode" "Quell\\(code\\|text\\)"))
+
+ (,(concat env "*")
+ ?l ,LaTeX-listing-label "~\\pageref{%s}"
+ LaTeX-fancyvrb-reftex-label-context-function
+ (regexp "[Ll]isting" "[Vv]erbatim"
+ "[Cc]ode" "Quell\\(code\\|text\\)"))))
+ (add-to-list 'reftex-label-regexps
+ (concat
+ (regexp-quote TeX-esc)
+ "begin[[:space:]]*"
+ (regexp-quote TeX-grop)
+ (concat env "\\*?")
+ (regexp-quote TeX-grcl)
+ "[[:space:]]*"
+ (LaTeX-extract-key-value-label "reflabel" 1))
+ t))))
;; These apply for all environments defined:
(add-to-list 'LaTeX-verbatim-environments-local env)
(add-to-list 'LaTeX-indent-environment-list `(,env current-indentation)
t)))
+ ;; Update RefTeX:
+ (when (fboundp 'reftex-compile-variables)
+ (reftex-compile-variables))
;; Update font-lock:
(when (and (fboundp 'font-latex-set-syntactic-keywords)
(eq TeX-install-font-lock 'font-latex-setup))
@@ -379,6 +434,84 @@ If OPTIONAL is non-nil, insert the file name in brackets."
(TeX-master-directory))
optional))
+(defun LaTeX-fancyvrb-env-reflabel-key-val (_optional)
+ "Add a label value to reflabel key.
+This function checks if the reflabel key is given in the optional
+argument of a fancyvrb environment and then adds a label as value
+to that key. The label value is inserted only if the key is
+value-less; user entered label values are recognized and
+respected. OPTIONAL is ignored."
+ (let ((p (point-marker))
+ (s (make-marker)))
+ (set-marker s (save-excursion
+ (LaTeX-find-matching-begin)
+ (re-search-forward (regexp-quote LaTeX-optop)
+ (line-end-position)
+ t)))
+ ;; Search for the reflabel and a potential value:
+ (when (marker-position s)
+ (re-search-backward
+ (concat
+ "\\(\\<reflabel\\>\\)"
+ ;; Check if the key already has a label value:
+ "\\("
+ "[[:space:]]*=[[:space:]]*"
+ (regexp-quote TeX-grop)
+ "?"
+ "[[:alnum:]:._-]"
+ "\\)?")
+ s t)
+ ;; Insert a label value only if the key is value-less:
+ (when (and (not (match-string 2))
+ (match-string 1))
+ (goto-char (match-end 1))
+ (insert "="
+ TeX-grop
+ (format "%s" (LaTeX-label (LaTeX-current-environment)
+ 'environment
+ t))
+ TeX-grcl)))
+ ;; At any rate, go to where we started and clean up:
+ (goto-char p)
+ (set-marker p nil)
+ (set-marker s nil)))
+
+(defun LaTeX-fancyvrb-reftex-label-context-function (env)
+ "Extract and return a context string for RefTeX.
+The context string is the first line of the verbatim environment.
+If no reflabel key is found, an error is issued.
+ENV is the name of current environment as a string."
+ (let* ((envstart (save-excursion
+ (re-search-backward (concat "\\\\begin[[:space:]]*{"
+ env
+ "}")
+ nil t)))
+ (label-key (save-excursion
+ (re-search-backward "\\<reflabel[ \t\n\r%]*=[ \t\n\r%]*"
+ envstart t))))
+ (if label-key
+ (save-excursion
+ (goto-char envstart)
+ (re-search-forward (regexp-quote LaTeX-optop) label-key t)
+ (up-list)
+ (forward-line)
+ ;; Return the first line of verbatim env:
+ (buffer-substring-no-properties (point)
+ (line-end-position)))
+ (error "No label found"))))
+
+(defvar LaTeX-fancyvrb-key-val-label-regexp
+ `(,(concat
+ (regexp-quote TeX-esc)
+ "begin[[:space:]]*"
+ (regexp-quote TeX-grop)
+ "[BL]?Verbatim\\*?"
+ (regexp-quote TeX-grcl)
+ "[[:space:]]*"
+ (LaTeX-extract-key-value-label "reflabel"))
+ 1 LaTeX-auto-label)
+ "Matches the label inside an optional argument of fancyvrb environments.")
+
(TeX-add-style-hook
"fancyvrb"
(lambda ()
@@ -386,6 +519,7 @@ If OPTIONAL is non-nil, insert the file name in brackets."
(TeX-auto-add-regexp LaTeX-fancyvrb-environment-regexp)
(TeX-auto-add-regexp LaTeX-fancyvrb-saveverb-regexp)
(TeX-auto-add-regexp LaTeX-fancyvrb-saveverbatim-regexp)
+ (TeX-auto-add-regexp LaTeX-fancyvrb-key-val-label-regexp)
(TeX-run-style-hooks
"keyval")
@@ -469,17 +603,23 @@ If OPTIONAL is non-nil, insert the file name in brackets."
(LaTeX-add-environments
'("Verbatim" LaTeX-env-args
- [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+ [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+ LaTeX-fancyvrb-env-reflabel-key-val)
'("Verbatim*" LaTeX-env-args
- [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+ [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+ LaTeX-fancyvrb-env-reflabel-key-val)
'("BVerbatim" LaTeX-env-args
- [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+ [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+ LaTeX-fancyvrb-env-reflabel-key-val)
'("BVerbatim*" LaTeX-env-args
- [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+ [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+ LaTeX-fancyvrb-env-reflabel-key-val)
'("LVerbatim" LaTeX-env-args
- [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+ [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+ LaTeX-fancyvrb-env-reflabel-key-val)
'("LVerbatim*" LaTeX-env-args
- [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local])
+ [TeX-arg-key-val LaTeX-fancyvrb-key-val-options-local]
+ LaTeX-fancyvrb-env-reflabel-key-val)
'("SaveVerbatim"
(lambda (env)
(let ((options (TeX-read-key-val t
LaTeX-fancyvrb-key-val-options-local))
@@ -501,6 +641,41 @@ If OPTIONAL is non-nil, insert the file name in brackets."
(concat LaTeX-optop options LaTeX-optcl))
(concat TeX-grop file TeX-grcl)))))))
+ (let ((envs '("BVerbatim" "BVerbatim*"
+ "LVerbatim" "LVerbatim*"
+ "Verbatim" "Verbatim*")))
+ ;; Add pre-defined environments to `LaTeX-label-alist':
+ (dolist (env envs)
+ (add-to-list 'LaTeX-label-alist (cons env 'LaTeX-listing-label) t))
+
+ ;; Tell RefTeX
+ (when (and (fboundp 'reftex-add-label-environments)
+ (fboundp 'reftex-compile-variables)
+ (boundp 'reftex-label-regexps))
+ (dolist (env envs)
+ (reftex-add-label-environments
+ `((,env ?l ,LaTeX-listing-label "~\\pageref{%s}"
+ LaTeX-fancyvrb-reftex-label-context-function
+ (regexp "[Ll]isting" "[Vv]erbatim"
+ "[Cc]ode" "Quell\\(code\\|text\\)")))))
+
+ (unless (string-match "\\<reflabel"
+ (mapconcat #'identity
+ reftex-label-regexps
+ "|"))
+ (make-local-variable 'reftex-label-regexps)
+ (add-to-list 'reftex-label-regexps
+ (concat
+ (regexp-quote TeX-esc)
+ "begin[[:space:]]*"
+ (regexp-quote TeX-grop)
+ "[BL]?Verbatim\\*?"
+ (regexp-quote TeX-grcl)
+ "[[:space:]]*"
+ (LaTeX-extract-key-value-label "reflabel" 1))
+ t)
+ (reftex-compile-variables))))
+
(LaTeX-add-counters
"FancyVerbLine")
@@ -527,6 +702,7 @@ If OPTIONAL is non-nil, insert the file name in brackets."
;; Fontification
(when (and (fboundp 'font-latex-add-keywords)
+ (fboundp 'font-latex-set-syntactic-keywords)
(eq TeX-install-font-lock 'font-latex-setup))
(font-latex-add-keywords '(("CustomVerbatimCommand" "|{\\{{")
("RecustomVerbatimCommand" "|{\\{{")
@@ -546,7 +722,8 @@ If OPTIONAL is non-nil, insert the file name in brackets."
("UseVerbatim" "{")
("LUseVerbatim" "{")
("BUseVerbatim" "{"))
- 'textual)))
+ 'textual)
+ (font-latex-set-syntactic-keywords)))
LaTeX-dialect)
(defvar LaTeX-fancyvrb-package-options nil
- [AUCTeX-diffs] [elpa] externals/auctex f7c0c73 01/62: Enable lexical-binding for AUCTeX core files, (continued)
- [AUCTeX-diffs] [elpa] externals/auctex f7c0c73 01/62: Enable lexical-binding for AUCTeX core files, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 8951549 04/62: ; Trivial cleanups, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 2e196d2 07/62: ; Silence the compiler, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 717e5f0 06/62: Simplify nested `let's, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 96c945a 11/62: Remove `TeX-arg-none', Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex c3b76ca 18/62: * tex-ispell.el: Enable lexical-binding., Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 42f061a 17/62: Improve style/amsthm.el, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 00b2d73 12/62: Add missing argument to function body, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 19cdfe0 22/62: Put point after the graphic file argrument, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex dabe30c 02/62: Arrange test condition, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 9d0ccc1 13/62: Update style/fancyvrb.el to package version 3.6,
Tassilo Horn <=
- [AUCTeX-diffs] [elpa] externals/auctex 5bffc24 24/62: ; * font-latex.el (font-latex-update-math-env): Fix docstring., Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 384c1d2 08/62: Use declared dynamic variable in tex-jp, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 237f409 26/62: ; Suppress warning about obsolete inactivate-input-method, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 08d01c1 19/62: ; * style/changelog.el: Silence the compiler for `reftex-label-alist'., Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex c4583f0 15/62: ; * tests/tex/command-expansion.el: Update copyright year., Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 5c28751 33/62: ; Fix some byte-compiler warnings, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex b42e932 23/62: ; * style/graphicx.el: Fix Ataka-san's name and email., Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 7288b93 31/62: Merge branch 'my-fix' into master, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex f9387c6 27/62: ; use with-no-warnings instead of with-suppressed-warnings for compat, Tassilo Horn, 2020/12/20
- [AUCTeX-diffs] [elpa] externals/auctex 072cfc7 28/62: ; Convert suffix to pattern rule, Tassilo Horn, 2020/12/20