[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX] Update for TOC parsing
From: |
Vincent Belaïche |
Subject: |
[AUCTeX] Update for TOC parsing |
Date: |
Thu, 22 Nov 2012 07:45:35 +0100 |
Hello,
As agreed previously, I have ported my contribution for Texinfo TOC
parsing to the latest AUCTeX on ACUTEX CVS repo and latest RefTeX on
emacs Bazaar repo.
For RefTeX I can do the commit myself after your feedback as I have
write access.
VBR,
Vincent.
=== modified file 'lisp/textmodes/reftex.el'
--- lisp/textmodes/reftex.el 2012-10-05 05:57:24 +0000
+++ lisp/textmodes/reftex.el 2012-11-22 05:33:11 +0000
@@ -301,7 +301,9 @@
(modify-syntax-entry ?\' "." reftex-syntax-table-for-bib)
(modify-syntax-entry ?\" "." reftex-syntax-table-for-bib)
(modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib)
- (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib))
+ (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib)
+
+ (run-hooks 'reftex-mode-hook))
;; Mode was turned off
(easy-menu-remove reftex-mode-menu)))
@@ -664,6 +666,16 @@
(defvar reftex-find-label-regexp-format nil)
(defvar reftex-find-label-regexp-format2 nil)
+;; Constants for making RefTeX open to Texinfo hooking
+(defvar reftex-section-pre-regexp "\\\\")
+;; Including `\' as a character to be matched at the end of the regexp
+;; will allow stuff like \begin{foo}\label{bar} to be matched. This
+;; will make the parser to advance one char too much. Therefore
+;; `reftex-parse-from-file' will step one char back if a section is
+;; found.
+(defvar reftex-section-post-regexp "\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n\\]")
+(defvar reftex-section-info-function 'reftex-section-info)
+
(defvar reftex-memory nil
"Memorizes old variable values to indicate changes in these variables.")
@@ -1083,16 +1095,10 @@
reftex-include-file-commands "\\|")
"\\)[{ \t]+\\([^} \t\n\r]+\\)"))
(section-re
- ;; Including `\' as a character to be matched at the end
- ;; of the regexp will allow stuff like
- ;; \begin{foo}\label{bar} to be matched. This will make
- ;; the parser to advance one char too much. Therefore
- ;; `reftex-parse-from-file' will step one char back if a
- ;; section is found.
- (concat wbol "\\\\\\("
+ (concat wbol reftex-section-pre-regexp "\\("
(mapconcat (lambda (x) (regexp-quote (car x)))
reftex-section-levels-all "\\|")
- "\\)\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n\\]"))
+ "\\)" reftex-section-post-regexp))
(appendix-re (concat wbol "\\(\\\\appendix\\)"))
(macro-re
(if macros-with-labels
=== modified file 'lisp/textmodes/reftex-toc.el'
--- lisp/textmodes/reftex-toc.el 2012-09-30 20:30:13 +0000
+++ lisp/textmodes/reftex-toc.el 2012-11-22 04:48:45 +0000
@@ -785,7 +785,7 @@
(marker (nth 4 data)))
(with-current-buffer (marker-buffer marker)
(goto-char (marker-position marker))
- (if (looking-at (concat "\\([ \t]*\\\\\\)" (regexp-quote name)))
+ (if (looking-at (concat "\\([ \t]*" reftex-section-pre-regexp "\\)"
(regexp-quote name)))
(replace-match (concat "\\1" newname))
(error "Fatal error during %smotion" pro-or-de)))))
=== modified file 'lisp/textmodes/reftex-parse.el'
--- lisp/textmodes/reftex-parse.el 2012-09-30 20:30:13 +0000
+++ lisp/textmodes/reftex-parse.el 2012-11-22 04:52:27 +0000
@@ -251,7 +251,7 @@
;; the next parsing iteration.
(when (eq (char-before) ?\\) (backward-char))
;; Insert in List
- (setq toc-entry (reftex-section-info file))
+ (setq toc-entry (funcall reftex-section-info-function file))
(when toc-entry
;; It can happen that section info returns nil
(setq level (nth 5 toc-entry))
=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog 2012-11-16 18:18:07 +0000
+++ lisp/ChangeLog 2012-11-22 06:40:30 +0000
@@ -1,3 +1,20 @@
+2012-11-22 Vincent Belaïche <address@hidden>
+
+ * textmodes/reftex-parse.el (reftex-parse-from-file): Use variable
+ reftex-section-info-function in order to be compatible with
+ Texinfo integration.
+
+ * textmodes/reftex-base.el (reftex-section-pre-regexp)
+ (reftex-section-post-regexp, reftex-section-info-function): New
+ variable.
+ (reftex-compile-variables): Use variables
+ reftex-section-pre-regexp, reftex-section-post-regexp, and
+ reftex-section-info-function in order to be compatible with Texinfo
integration.
+
+ * textmodes/reftex-toc.el (reftex-toc-promote-action): use
+ reftex-section-pre-regexp variable in order to be compatible with
+ Texinfo integration.
+
2012-11-16 Jürgen Hötzel <address@hidden> (tiny change)
* eshell/em-unix.el (eshell/mkdir): Handle "--parents" (bug#12897).
Index: tex-info.el
===================================================================
RCS file: /sources/auctex/auctex/tex-info.el,v
retrieving revision 5.162
diff -r5.162 tex-info.el
345a346,395
> (defun Texinfo-reftex-section-info (file)
> ;; Return a section entry for the current match.
> ;; Carefull: This function expects the match-data to be still in place!
> (let* ((marker (set-marker (make-marker) (1- (match-beginning 3))))
> (macro (reftex-match-string 3))
> (level-exp (cdr (assoc macro reftex-section-levels-all)))
> (level (if (symbolp level-exp)
> (save-match-data (funcall level-exp))
> level-exp))
> (unnumbered (< level 0))
> (level (abs level))
> (section-number (reftex-section-number level unnumbered))
> (text1 (save-match-data
> (save-excursion
> (buffer-substring-no-properties (point) (progn
> (end-of-line) (point))))))
> (literal (buffer-substring-no-properties
> (1- (match-beginning 3))
> (min (point-max) (+ (match-end 0) (length text1) 1))))
> ;; Literal can be too short since text1 too short. No big problem.
> (text (reftex-nicify-text text1)))
>
> ;; Add section number and indentation
> (setq text
> (concat
> (make-string (* reftex-level-indent level) ?\ )
> (if (nth 1 reftex-label-menu-flags) ; section number flag
> (concat section-number " "))
> text))
> (list 'toc "toc" text file marker level section-number
> literal (marker-position marker))))
>
> (defun Texinfo-reftex-hook ()
> "Hook function to plug Texinfo into RefTeX."
> ;; force recompilation of variables
> (when (string= TeX-base-mode-name "Texinfo")
> (dolist (v `((reftex-section-pre-regexp . "@")
> ; section post-regexp must contain exactly one group
> (reftex-section-post-regexp . "\\([ \t]+\\)")
> (reftex-section-info-function . Texinfo-reftex-section-info)
> (reftex-section-levels
> . ,(mapcar
> (lambda (x)
> (if (string-match
> "\\(\\`unnumbered\\)\\|\\(heading\\'\\)\\|\\(\\`top\\'\\)"
> (car x))
> (cons (car x) (- (cadr x)))
> (cons (car x) (cadr x))))
> texinfo-section-list))))
> (set (make-local-variable (car v) ) (cdr v)))
> (setq reftex-tables-dirty t)
> (reftex-ensure-compiled-variables)))
683a734,738
> ;; RefTeX plugging
> (add-hook 'reftex-mode-hook 'Texinfo-reftex-hook)
> (if (and (boundp 'reftex-mode) reftex-mode)
> (Texinfo-reftex-hook))
>
Index: ChangeLog
===================================================================
RCS file: /sources/auctex/auctex/ChangeLog,v
retrieving revision 5.1764
diff -r5.1764 ChangeLog
0a1,5
> 2012-07-17 Vincent Belaïche <address@hidden>
>
> * tex-info.el (Texinfo-reftex-hook): Added function.
> (TeX-texinfo-mode): Added RefTeX plugging.
>
- [AUCTeX] Update for TOC parsing,
Vincent Belaïche <=