auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-devel] RefTeX / Texinfo integration


From: Vincent Belaïche
Subject: [AUCTeX-devel] RefTeX / Texinfo integration
Date: Tue, 17 Jul 2012 20:40:48 +0200

Dear all,

Here is a contribution that makes RefTeX TOC function more or less work
with Texinfo files: it now can grasp the document structuring commands
(like @top, @section, etc...), but labels (@node, @anchor) and @include
are still not yet supported (so forget about documents from multifile
source files).

OK, I acknowledge that this is far from perfect, however this is still
better than the current situation in which Texinfo is not handled at all
by RefTeX, and I personnally find the contribution quite usefull.

VBR,
   Vincent.

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.
> 
Index: lisp/reftex-toc.el
===================================================================
RCS file: /sources/auctex/reftex/lisp/reftex-toc.el,v
retrieving revision 1.41
diff -r1.41 reftex-toc.el
712c712
<       (if (looking-at (concat "\\([ \t]*\\\\\\)" (regexp-quote name)))
---
>       (if (looking-at (concat "\\([ \t]*" reftex-section-pre-regexp "\\)" 
> (regexp-quote name)))
Index: lisp/reftex-base.el
===================================================================
RCS file: /sources/auctex/reftex/lisp/reftex-base.el,v
retrieving revision 1.21
diff -r1.21 reftex-base.el
689a690,694
> ;; Constants for making RefTeX open to Texinfo hooking
> (defvar reftex-section-pre-regexp "\\\\")
> (defvar reftex-section-post-regexp "\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n\\]")
> (defvar reftex-section-info-function 'reftex-section-info)
> 
1107c1112
<             (concat wbol "\\\\\\("
---
>             (concat wbol reftex-section-pre-regexp "\\("
1110c1115
<                     "\\)\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n\\]"))
---
>                     "\\)" reftex-section-post-regexp))
Index: lisp/reftex-parse.el
===================================================================
RCS file: /sources/auctex/reftex/lisp/reftex-parse.el,v
retrieving revision 1.38
diff -r1.38 reftex-parse.el
254c254
<                  (setq toc-entry (reftex-section-info file))
---
>                  (setq toc-entry (funcall reftex-section-info-function file))
Index: ChangeLog
===================================================================
RCS file: /sources/auctex/reftex/ChangeLog,v
retrieving revision 1.89
diff -r1.89 ChangeLog
0a1,17
> 2012-07-17  Vincent Belaïche  <address@hidden>
> 
>       * lisp/reftex-parse.el (reftex-parse-from-file): Use variable
>       reftex-section-info-function in order to be compatible with
>       Texinfo integration.
> 
>       * lisp/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.
> 
>       * lisp/reftex-toc.el (reftex-toc-promote-action): use
>       reftex-section-pre-regexp variable in order to be compatible with
>       Texinfo integration.
> 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]