[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex 1ea64ff 01/67: Extract caption for RefTeX's labe
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex 1ea64ff 01/67: Extract caption for RefTeX's label context |
Date: |
Fri, 8 Feb 2019 11:40:27 -0500 (EST) |
branch: externals/auctex
commit 1ea64fffc1429db6b5b8712bb68499c48cf2124b
Author: Arash Esbati <address@hidden>
Commit: Arash Esbati <address@hidden>
Extract caption for RefTeX's label context
* style/listings.el (LaTeX-listings-reftex-label-context-function):
New function. Extract the caption in the optional argrument of
the lstlisting environment and return it as a string for the
context of a label.
---
style/listings.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 50 insertions(+), 3 deletions(-)
diff --git a/style/listings.el b/style/listings.el
index 44c7e6e..4ba5493 100644
--- a/style/listings.el
+++ b/style/listings.el
@@ -36,6 +36,8 @@
;;
;; January 2017: Put label in opt. argument of environment.
;;
+;; October 2018: Extract label context for RefTeX.
+;;
;; FIXME: Please make me more sophisticated!
;;; Code:
@@ -264,7 +266,7 @@ from `listings' package.")
"\\(?:\\[[^][]*"
"\\(?:{[^}{]*"
"\\(?:{[^}{]*"
- "\\(?:{[^}{]*}[^}{]*\\)*"
+ "\\(?:{[^}{]*}[^}{]*\\)*"
"}[^}{]*\\)*"
"}[^][]*\\)*"
"label[ \t]*=[ \t]*{\\([^}]+\\)}"
@@ -287,7 +289,7 @@ with user-defined values via the \"lstdefinestyle\" macro."
(opts (assq-delete-all (car (assoc key temp)) temp)))
(cl-pushnew (list key (TeX-delete-duplicate-strings
(mapcar #'car (LaTeX-listings-lstdefinestyle-list))))
- opts :test #'equal)
+ opts :test #'equal)
(setq LaTeX-listings-key-val-options-local
(copy-alist opts))))
@@ -329,7 +331,9 @@ with user-defined values via the \"lstdefinestyle\" macro."
;; Tell RefTeX
(when (fboundp 'reftex-add-label-environments)
(reftex-add-label-environments
- `((,env ?l "lst:" "~\\ref{%s}" nil (regexp "[Ll]isting")))))
+ `((,env ?l "lst:" "~\\ref{%s}"
+ LaTeX-listings-reftex-label-context-function
+ (regexp "[Ll]isting")))))
;; Fontification
(when (and (fboundp 'font-latex-add-keywords)
(fboundp 'font-latex-update-font-lock)
@@ -345,6 +349,39 @@ with user-defined values via the \"lstdefinestyle\" macro."
(add-hook 'TeX-auto-cleanup-hook #'LaTeX-listings-auto-cleanup t)
(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
+(defun LaTeX-listings-reftex-label-context-function (env)
+ "Extract and return a context string for RefTeX.
+The context string is the value given to the caption key. If no
+caption key is found, an error is issued."
+ (let* ((envstart (save-excursion
+ (re-search-backward (concat "\\\\begin{" env "}")
+ nil t)))
+ (capt-key (save-excursion
+ (re-search-backward "caption[ \t\n\r%]*=[ \t\n\r%]*"
+ envstart t)))
+ capt-start capt-end)
+ (if capt-key
+ (save-excursion
+ (goto-char capt-key)
+ (re-search-forward
+ "caption[ \t\n\r%]*=[ \t\n\r%]*" nil t)
+ (cond (;; Short caption inside [] is available, extract it only
+ (looking-at-p (regexp-quote (concat TeX-grop LaTeX-optop)))
+ (forward-char)
+ (setq capt-start (1+ (point)))
+ (setq capt-end (1- (progn (forward-sexp) (point)))))
+ ;; Extract the entire caption which is enclosed in braces
+ ((looking-at-p TeX-grop)
+ (setq capt-start (1+ (point)))
+ (setq capt-end (1- (progn (forward-sexp) (point)))))
+ ;; Extract everything to next comma ,
+ (t
+ (setq capt-start (point))
+ (setq capt-end (progn (skip-chars-forward "^,") (point)))))
+ ;; Return the extracted string
+ (buffer-substring-no-properties capt-start capt-end))
+ (error "No caption found"))))
+
(TeX-add-style-hook
"listings"
(lambda ()
@@ -400,6 +437,16 @@ with user-defined values via the \"lstdefinestyle\" macro."
(add-to-list 'LaTeX-verbatim-environments-local "lstlisting")
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "lstinline")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "lstinline")
+
+ ;; RefTeX support lstlistings environment via
+ ;; `reftex-label-alist-builtin'. We add the same thing here only
+ ;; with our function as 5th element:
+ (when (fboundp 'reftex-add-label-environments)
+ (reftex-add-label-environments
+ '(("lstlisting" ?l "lst:" "~\\ref{%s}"
+ LaTeX-listings-reftex-label-context-function
+ (regexp "[Ll]isting")))))
+
;; Fontification
(when (and (fboundp 'font-latex-add-keywords)
(fboundp 'font-latex-update-font-lock)
- [elpa] externals/auctex updated (eca4ffe -> f34ce5a), Tassilo Horn, 2019/02/08
- [elpa] externals/auctex 2152678 04/67: Change regexp for clarity, Tassilo Horn, 2019/02/08
- [elpa] externals/auctex 1ea64ff 01/67: Extract caption for RefTeX's label context,
Tassilo Horn <=
- [elpa] externals/auctex 0970844 02/67: Deal with partial ^^-quoting in preview-latex, Tassilo Horn, 2019/02/08
- [elpa] externals/auctex 3694373 05/67: Deal with space in path of MikTeX gs executable (Bug#32251), Tassilo Horn, 2019/02/08
- [elpa] externals/auctex 10047fb 07/67: * style/fancyvrb.el (LaTeX-fancyvrb-key-val-options): Add vspace key., Tassilo Horn, 2019/02/08
- [elpa] externals/auctex c8a8d47 08/67: Don't block emacs during viewing document, Tassilo Horn, 2019/02/08
- [elpa] externals/auctex f213b1b 10/67: Set `TeX-command-buffer' always (bug#33377), Tassilo Horn, 2019/02/08
- [elpa] externals/auctex 06226ea 09/67: Adjust preview-latex in case sub file isn't in master directory, Tassilo Horn, 2019/02/08
- [elpa] externals/auctex d8c6f94 06/67: Improve style/fancyvrb.el, Tassilo Horn, 2019/02/08
- [elpa] externals/auctex 7ede3be 03/67: Make style hooks associated with class options valid again, Tassilo Horn, 2019/02/08
- [elpa] externals/auctex dad0c60 11/67: Surround both \langle and \rangle with math delimiter, Tassilo Horn, 2019/02/08
- [elpa] externals/auctex 8d0e9cd 13/67: style/enumitem.el ("enumitem"): Use `TeX-argument-prompt' for query., Tassilo Horn, 2019/02/08