[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lisp/textmodes/reftex-parse.el [lexbind]
From: |
Miles Bader |
Subject: |
[Emacs-diffs] Changes to emacs/lisp/textmodes/reftex-parse.el [lexbind] |
Date: |
Tue, 14 Oct 2003 19:30:36 -0400 |
Index: emacs/lisp/textmodes/reftex-parse.el
diff -c emacs/lisp/textmodes/reftex-parse.el:1.10.8.1
emacs/lisp/textmodes/reftex-parse.el:1.10.8.2
*** emacs/lisp/textmodes/reftex-parse.el:1.10.8.1 Fri Apr 4 01:20:40 2003
--- emacs/lisp/textmodes/reftex-parse.el Tue Oct 14 19:30:22 2003
***************
*** 1,8 ****
;;; reftex-parse.el --- parser functions for RefTeX
! ;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
;; Author: Carsten Dominik <address@hidden>
! ;; Version: 4.18
;;
;; This file is part of GNU Emacs.
--- 1,8 ----
;;; reftex-parse.el --- parser functions for RefTeX
! ;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
;; Author: Carsten Dominik <address@hidden>
! ;; Version: 4.21
;;
;; This file is part of GNU Emacs.
***************
*** 33,42 ****
(defmacro reftex-with-special-syntax (&rest body)
`(let ((saved-syntax (syntax-table)))
(unwind-protect
! (progn
! (set-syntax-table reftex-syntax-table)
! (let ((case-fold-search nil))
! ,@body))
(set-syntax-table saved-syntax))))
(defun reftex-parse-one ()
--- 33,42 ----
(defmacro reftex-with-special-syntax (&rest body)
`(let ((saved-syntax (syntax-table)))
(unwind-protect
! (progn
! (set-syntax-table reftex-syntax-table)
! (let ((case-fold-search nil))
! ,@body))
(set-syntax-table saved-syntax))))
(defun reftex-parse-one ()
***************
*** 68,79 ****
(let* ((old-list (symbol-value reftex-docstruct-symbol))
(master (reftex-TeX-master-file))
! (true-master (file-truename master))
! (master-dir (file-name-as-directory (file-name-directory master)))
(file (or file (buffer-file-name)))
! (true-file (file-truename file))
! (bibview-cache (assq 'bibview-cache old-list))
! (index-tags (cdr (assq 'index-tags old-list)))
from-file appendix docstruct tmp)
;; Make sure replacement is really an option here
--- 68,79 ----
(let* ((old-list (symbol-value reftex-docstruct-symbol))
(master (reftex-TeX-master-file))
! (true-master (file-truename master))
! (master-dir (file-name-as-directory (file-name-directory master)))
(file (or file (buffer-file-name)))
! (true-file (file-truename file))
! (bibview-cache (assq 'bibview-cache old-list))
! (index-tags (cdr (assq 'index-tags old-list)))
from-file appendix docstruct tmp)
;; Make sure replacement is really an option here
***************
*** 97,105 ****
;; Find active toc entry and initialize section-numbers
(setq reftex-active-toc (reftex-last-assoc-before-elt
! 'toc (list 'bof from-file) old-list)
! appendix (reftex-last-assoc-before-elt
! 'appendix (list 'bof from-file) old-list))
(reftex-init-section-numbers reftex-active-toc appendix)
--- 97,105 ----
;; Find active toc entry and initialize section-numbers
(setq reftex-active-toc (reftex-last-assoc-before-elt
! 'toc (list 'bof from-file) old-list)
! appendix (reftex-last-assoc-before-elt
! 'appendix (list 'bof from-file) old-list))
(reftex-init-section-numbers reftex-active-toc appendix)
***************
*** 110,120 ****
(reftex-with-special-syntax
(save-window-excursion
(save-excursion
! (unwind-protect
! (setq docstruct
! (reftex-parse-from-file
! from-file docstruct master-dir))
! (reftex-kill-temporary-buffers)))))
(message "Scanning document... done")
--- 110,120 ----
(reftex-with-special-syntax
(save-window-excursion
(save-excursion
! (unwind-protect
! (setq docstruct
! (reftex-parse-from-file
! from-file docstruct master-dir))
! (reftex-kill-temporary-buffers)))))
(message "Scanning document... done")
***************
*** 141,167 ****
(and index-tags (setq index-tags (sort index-tags 'string<)))
(let ((index-tag-cell (assq 'index-tags docstruct)))
(if index-tag-cell
! (setcdr index-tag-cell index-tags)
! (push (cons 'index-tags index-tags) docstruct)))
(unless (assq 'xr docstruct)
(let* ((allxr (reftex-all-assq 'xr-doc docstruct))
! (alist (mapcar
! (lambda (x)
! (if (setq tmp (reftex-locate-file (nth 2 x) "tex"
! master-dir))
! (cons (nth 1 x) tmp)
! (message "Can't find external document %s"
! (nth 2 x))
! nil))
! allxr))
! (alist (delq nil alist))
! (allprefix (delq nil (mapcar 'car alist)))
! (regexp (if allprefix
! (concat "\\`\\("
! (mapconcat 'identity allprefix "\\|")
! "\\)")
! "\\\\\\\\\\\\"))) ; this will never match
! (push (list 'xr alist regexp) docstruct)))
(set reftex-docstruct-symbol docstruct)
(put reftex-docstruct-symbol 'modified t)))
--- 141,167 ----
(and index-tags (setq index-tags (sort index-tags 'string<)))
(let ((index-tag-cell (assq 'index-tags docstruct)))
(if index-tag-cell
! (setcdr index-tag-cell index-tags)
! (push (cons 'index-tags index-tags) docstruct)))
(unless (assq 'xr docstruct)
(let* ((allxr (reftex-all-assq 'xr-doc docstruct))
! (alist (mapcar
! (lambda (x)
! (if (setq tmp (reftex-locate-file (nth 2 x) "tex"
! master-dir))
! (cons (nth 1 x) tmp)
! (message "Can't find external document %s"
! (nth 2 x))
! nil))
! allxr))
! (alist (delq nil alist))
! (allprefix (delq nil (mapcar 'car alist)))
! (regexp (if allprefix
! (concat "\\`\\("
! (mapconcat 'identity allprefix "\\|")
! "\\)")
! "\\\\\\\\\\\\"))) ; this will never match
! (push (list 'xr alist regexp) docstruct)))
(set reftex-docstruct-symbol docstruct)
(put reftex-docstruct-symbol 'modified t)))
***************
*** 171,176 ****
--- 171,177 ----
reftex-everything-regexp
reftex-everything-regexp-no-index))
+ ;;;###autoload
(defun reftex-all-document-files (&optional relative)
"Return a list of all files belonging to the current document.
When RELATIVE is non-nil, give file names relative to directory
***************
*** 200,207 ****
(catch 'exit
(setq file-found (reftex-locate-file file "tex" master-dir))
(if (and (not file-found)
! (setq buf (reftex-get-buffer-visiting file)))
! (setq file-found (buffer-file-name buf)))
(unless file-found
(push (list 'file-error file) docstruct)
--- 201,208 ----
(catch 'exit
(setq file-found (reftex-locate-file file "tex" master-dir))
(if (and (not file-found)
! (setq buf (reftex-get-buffer-visiting file)))
! (setq file-found (buffer-file-name buf)))
(unless file-found
(push (list 'file-error file) docstruct)
***************
*** 220,325 ****
(setq file (buffer-file-name))
(push (list 'bof file) docstruct)
! (reftex-with-special-syntax
! (save-excursion
! (save-restriction
! (widen)
! (goto-char 1)
!
! (while (re-search-forward regexp nil t)
!
! (cond
!
! ((match-end 1)
! ;; It is a label
! (push (reftex-label-info (reftex-match-string 1) file bound)
! docstruct))
!
! ((match-end 3)
! ;; It is a section
! (setq bound (point))
!
! ;; Insert in List
! (setq toc-entry (reftex-section-info file))
! (when toc-entry
! ;; It can happen that section info returns nil
! (setq level (nth 5 toc-entry))
! (setq highest-level (min highest-level level))
! (if (= level highest-level)
! (message
! "Scanning %s %s ..."
! (car (rassoc level reftex-section-levels-all))
! (nth 6 toc-entry)))
!
! (push toc-entry docstruct)
! (setq reftex-active-toc toc-entry)))
!
! ((match-end 7)
! ;; It's an include or input
! (setq include-file (reftex-match-string 7))
! ;; Test if this file should be ignored
! (unless (delq nil (mapcar
! (lambda (x) (string-match x include-file))
! reftex-no-include-regexps))
! ;; Parse it
! (setq docstruct
! (reftex-parse-from-file
! include-file
! docstruct master-dir))))
!
! ((match-end 9)
! ;; Appendix starts here
! (reftex-init-section-numbers nil t)
! (push (cons 'appendix t) docstruct))
!
! ((match-end 10)
! ;; Index entry
! (when reftex-support-index
! (setq index-entry (reftex-index-info file))
! (when index-entry
! (add-to-list 'index-tags (nth 1 index-entry))
! (push index-entry docstruct))))
!
! ((match-end 11)
! ;; A macro with label
! (save-excursion
! (let* ((mac (reftex-match-string 11))
! (label (progn (goto-char (match-end 11))
! (save-match-data
! (reftex-no-props
! (reftex-nth-arg-wrapper
! mac)))))
! (typekey (nth 1 (assoc mac reftex-env-or-mac-alist)))
! (entry (progn (if typekey
! ;; A typing macro
! (goto-char (match-end 0))
! ;; A neutral macro
! (goto-char (match-end 11))
! (reftex-move-over-touching-args))
! (reftex-label-info
! label file bound nil nil))))
! (push entry docstruct))))
! (t (error "This should not happen (reftex-parse-from-file)")))
! )
!
! ;; Find bibliography statement
! (when (setq tmp (reftex-locate-bibliography-files master-dir))
! (push (cons 'bib tmp) docstruct))
!
! (goto-char 1)
! (when (re-search-forward
! "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t)
! (push (cons 'thebib file) docstruct))
!
! ;; Find external document specifications
! (goto-char 1)
! (while (re-search-forward "[\n\r][
\t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t)
! (push (list 'xr-doc (reftex-match-string 2)
! (reftex-match-string 3))
! docstruct))
! ;; End of file mark
! (push (list 'eof file) docstruct)))))
;; Kill the scanned buffer
(reftex-kill-temporary-buffers next-buf))
--- 221,326 ----
(setq file (buffer-file-name))
(push (list 'bof file) docstruct)
! (reftex-with-special-syntax
! (save-excursion
! (save-restriction
! (widen)
! (goto-char 1)
!
! (while (re-search-forward regexp nil t)
!
! (cond
!
! ((match-end 1)
! ;; It is a label
! (push (reftex-label-info (reftex-match-string 1) file bound)
! docstruct))
!
! ((match-end 3)
! ;; It is a section
! (setq bound (point))
!
! ;; Insert in List
! (setq toc-entry (reftex-section-info file))
! (when toc-entry
! ;; It can happen that section info returns nil
! (setq level (nth 5 toc-entry))
! (setq highest-level (min highest-level level))
! (if (= level highest-level)
! (message
! "Scanning %s %s ..."
! (car (rassoc level reftex-section-levels-all))
! (nth 6 toc-entry)))
!
! (push toc-entry docstruct)
! (setq reftex-active-toc toc-entry)))
!
! ((match-end 7)
! ;; It's an include or input
! (setq include-file (reftex-match-string 7))
! ;; Test if this file should be ignored
! (unless (delq nil (mapcar
! (lambda (x) (string-match x include-file))
! reftex-no-include-regexps))
! ;; Parse it
! (setq docstruct
! (reftex-parse-from-file
! include-file
! docstruct master-dir))))
!
! ((match-end 9)
! ;; Appendix starts here
! (reftex-init-section-numbers nil t)
! (push (cons 'appendix t) docstruct))
!
! ((match-end 10)
! ;; Index entry
! (when reftex-support-index
! (setq index-entry (reftex-index-info file))
! (when index-entry
! (add-to-list 'index-tags (nth 1 index-entry))
! (push index-entry docstruct))))
!
! ((match-end 11)
! ;; A macro with label
! (save-excursion
! (let* ((mac (reftex-match-string 11))
! (label (progn (goto-char (match-end 11))
! (save-match-data
! (reftex-no-props
! (reftex-nth-arg-wrapper
! mac)))))
! (typekey (nth 1 (assoc mac
reftex-env-or-mac-alist)))
! (entry (progn (if typekey
! ;; A typing macro
! (goto-char (match-end 0))
! ;; A neutral macro
! (goto-char (match-end 11))
! (reftex-move-over-touching-args))
! (reftex-label-info
! label file bound nil nil))))
! (push entry docstruct))))
! (t (error "This should not happen (reftex-parse-from-file)")))
! )
!
! ;; Find bibliography statement
! (when (setq tmp (reftex-locate-bibliography-files master-dir))
! (push (cons 'bib tmp) docstruct))
!
! (goto-char 1)
! (when (re-search-forward
! "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil
t)
! (push (cons 'thebib file) docstruct))
!
! ;; Find external document specifications
! (goto-char 1)
! (while (re-search-forward "[\n\r][
\t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t)
! (push (list 'xr-doc (reftex-match-string 2)
! (reftex-match-string 3))
! docstruct))
! ;; End of file mark
! (push (list 'eof file) docstruct)))))
;; Kill the scanned buffer
(reftex-kill-temporary-buffers next-buf))
***************
*** 329,359 ****
(defun reftex-locate-bibliography-files (master-dir &optional files)
;; Scan buffer for bibliography macro and return file list.
!
(unless files
(save-excursion
(goto-char (point-min))
(if (re-search-forward
! (concat
! ; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
! "\\(^\\)[^%]*\\\\\\("
! (mapconcat 'identity reftex-bibliography-commands "\\|")
! "\\){[ \t]*\\([^}]+\\)") nil t)
! (setq files
! (split-string (reftex-match-string 3)
! "[ \t\n\r]*,[ \t\n\r]*")))))
(when files
! (setq files
! (mapcar
! (lambda (x)
! (if (or (member x reftex-bibfile-ignore-list)
! (delq nil (mapcar (lambda (re) (string-match re x))
! reftex-bibfile-ignore-regexps)))
! ;; excluded file
! nil
! ;; find the file
! (reftex-locate-file x "bib" master-dir)))
! files))
(delq nil files)))
(defun reftex-replace-label-list-segment (old insert &optional entirely)
--- 330,360 ----
(defun reftex-locate-bibliography-files (master-dir &optional files)
;; Scan buffer for bibliography macro and return file list.
!
(unless files
(save-excursion
(goto-char (point-min))
(if (re-search-forward
! (concat
! ; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
! "\\(^\\)[^%\n\r]*\\\\\\("
! (mapconcat 'identity reftex-bibliography-commands "\\|")
! "\\){[ \t]*\\([^}]+\\)") nil t)
! (setq files
! (split-string (reftex-match-string 3)
! "[ \t\n\r]*,[ \t\n\r]*")))))
(when files
! (setq files
! (mapcar
! (lambda (x)
! (if (or (member x reftex-bibfile-ignore-list)
! (delq nil (mapcar (lambda (re) (string-match re x))
! reftex-bibfile-ignore-regexps)))
! ;; excluded file
! nil
! ;; find the file
! (reftex-locate-file x "bib" master-dir)))
! files))
(delq nil files)))
(defun reftex-replace-label-list-segment (old insert &optional entirely)
***************
*** 386,409 ****
;; 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))
! (prefix (save-match-data
! (if (string-match "begin{\\([^}]+\\)}" macro)
! (match-string 1 macro))))
! (level-exp (cdr (assoc macro reftex-section-levels-all)))
(level (if (symbolp level-exp)
! (save-match-data (funcall level-exp))
! level-exp))
! (star (= ?* (char-after (match-end 3))))
! (unnumbered (or star (< level 0)))
! (level (abs level))
(section-number (reftex-section-number level unnumbered))
! (text1 (save-match-data
! (save-excursion
! (reftex-context-substring prefix))))
(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
--- 387,410 ----
;; 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))
! (prefix (save-match-data
! (if (string-match "begin{\\([^}]+\\)}" macro)
! (match-string 1 macro))))
! (level-exp (cdr (assoc macro reftex-section-levels-all)))
(level (if (symbolp level-exp)
! (save-match-data (funcall level-exp))
! level-exp))
! (star (= ?* (char-after (match-end 3))))
! (unnumbered (or star (< level 0)))
! (level (abs level))
(section-number (reftex-section-number level unnumbered))
! (text1 (save-match-data
! (save-excursion
! (reftex-context-substring prefix))))
(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
***************
*** 412,418 ****
(make-string (* reftex-level-indent level) ?\ )
(if (nth 1 reftex-label-menu-flags) ; section number flag
(concat section-number " "))
! (if prefix (concat (capitalize prefix) ": ") "")
text))
(list 'toc "toc" text file marker level section-number
literal (marker-position marker))))
--- 413,419 ----
(make-string (* reftex-level-indent level) ?\ )
(if (nth 1 reftex-label-menu-flags) ; section number flag
(concat section-number " "))
! (if prefix (concat (capitalize prefix) ": ") "")
text))
(list 'toc "toc" text file marker level section-number
literal (marker-position marker))))
***************
*** 425,436 ****
(reftex-support-index t)
((y-or-n-p "Turn on index support and rescan entire document? ")
(setq reftex-support-index 'demanded
! current-prefix-arg '(16)))
(t (if abort
! (error "No index support")
! (message "No index support")
! (ding)
! (sit-for 1)))))
(defun reftex-index-info-safe (file)
(reftex-with-special-syntax
--- 426,437 ----
(reftex-support-index t)
((y-or-n-p "Turn on index support and rescan entire document? ")
(setq reftex-support-index 'demanded
! current-prefix-arg '(16)))
(t (if abort
! (error "No index support")
! (message "No index support")
! (ding)
! (sit-for 1)))))
(defun reftex-index-info-safe (file)
(reftex-with-special-syntax
***************
*** 442,490 ****
;; Carefull: This function expects the match-data to be still in place!
(catch 'exit
(let* ((macro (reftex-match-string 10))
! (bom (match-beginning 10))
! (boa (match-end 10))
! (entry (or (assoc macro reftex-index-macro-alist)
! (throw 'exit nil)))
! (exclude (nth 3 entry))
! ;; The following is a test if this match should be excluded
! (test-dummy (and (fboundp exclude)
! (funcall exclude)
! (throw 'exit nil)))
! (itag (nth 1 entry))
! (prefix (nth 2 entry))
! (index-tag
! (cond ((stringp itag) itag)
! ((integerp itag)
! (progn (goto-char boa)
! (or (reftex-nth-arg itag (nth 6 entry)) "idx")))
! (t "idx")))
! (arg (or (progn (goto-char boa)
! (reftex-nth-arg (nth 5 entry) (nth 6 entry)))
! ""))
! (end-of-args (progn (goto-char boa)
! (reftex-move-over-touching-args)
! (point)))
! (end-of-context (progn (skip-chars-forward "^ \t\n\r") (point)))
! (begin-of-context
! (progn (goto-char bom)
! (skip-chars-backward "^ \t\r\n")
! (point)))
! (context (buffer-substring-no-properties
! begin-of-context end-of-context))
! (key-end (if (string-match reftex-index-key-end-re arg)
! (1+ (match-beginning 0))))
! (rawkey (substring arg 0 key-end))
!
! (key (if prefix (concat prefix rawkey) rawkey))
! (sortkey (downcase key))
! (showkey (mapconcat 'identity
! (split-string key reftex-index-level-re)
! " ! ")))
(goto-char end-of-args)
;; 0 1 2 3 4 5 6 7 8 9
(list 'index index-tag context file bom arg key showkey sortkey
key-end))))
!
(defun reftex-short-context (env parse &optional bound derive)
;; Get about one line of useful context for the label definition at point.
--- 443,491 ----
;; Carefull: This function expects the match-data to be still in place!
(catch 'exit
(let* ((macro (reftex-match-string 10))
! (bom (match-beginning 10))
! (boa (match-end 10))
! (entry (or (assoc macro reftex-index-macro-alist)
! (throw 'exit nil)))
! (exclude (nth 3 entry))
! ;; The following is a test if this match should be excluded
! (test-dummy (and (fboundp exclude)
! (funcall exclude)
! (throw 'exit nil)))
! (itag (nth 1 entry))
! (prefix (nth 2 entry))
! (index-tag
! (cond ((stringp itag) itag)
! ((integerp itag)
! (progn (goto-char boa)
! (or (reftex-nth-arg itag (nth 6 entry)) "idx")))
! (t "idx")))
! (arg (or (progn (goto-char boa)
! (reftex-nth-arg (nth 5 entry) (nth 6 entry)))
! ""))
! (end-of-args (progn (goto-char boa)
! (reftex-move-over-touching-args)
! (point)))
! (end-of-context (progn (skip-chars-forward "^ \t\n\r") (point)))
! (begin-of-context
! (progn (goto-char bom)
! (skip-chars-backward "^ \t\r\n")
! (point)))
! (context (buffer-substring-no-properties
! begin-of-context end-of-context))
! (key-end (if (string-match reftex-index-key-end-re arg)
! (1+ (match-beginning 0))))
! (rawkey (substring arg 0 key-end))
!
! (key (if prefix (concat prefix rawkey) rawkey))
! (sortkey (downcase key))
! (showkey (mapconcat 'identity
! (split-string key reftex-index-level-re)
! " ! ")))
(goto-char end-of-args)
;; 0 1 2 3 4 5 6 7 8 9
(list 'index index-tag context file bom arg key showkey sortkey
key-end))))
!
(defun reftex-short-context (env parse &optional bound derive)
;; Get about one line of useful context for the label definition at point.
***************
*** 515,523 ****
(match-string 1 (nth 7 reftex-active-toc)))
"SECTION HEADING NOT FOUND")))
(save-excursion
! (goto-char reftex-default-context-position)
! (unless (eq (string-to-char env) ?\\)
! (reftex-move-over-touching-args))
(reftex-context-substring))))
((stringp parse)
--- 516,524 ----
(match-string 1 (nth 7 reftex-active-toc)))
"SECTION HEADING NOT FOUND")))
(save-excursion
! (goto-char reftex-default-context-position)
! (unless (eq (string-to-char env) ?\\)
! (reftex-move-over-touching-args))
(reftex-context-substring))))
((stringp parse)
***************
*** 592,598 ****
((looking-at (reftex-make-regexp-allow-for-ctrl-m
(nth 7 (car list))))
;; Same title: remember, but keep looking
! (setq rtn-if-no-other (car list)))))
(pop list))
rtn1))
((match-end 7)
--- 593,599 ----
((looking-at (reftex-make-regexp-allow-for-ctrl-m
(nth 7 (car list))))
;; Same title: remember, but keep looking
! (setq rtn-if-no-other (car list)))))
(pop list))
rtn1))
((match-end 7)
***************
*** 600,634 ****
(car
(member (list 'eof (reftex-locate-file
(reftex-match-string 7) "tex"
! (cdr (assq 'master-dir docstruct))))
docstruct)))
! ((match-end 9)
! (assq 'appendix (symbol-value reftex-docstruct-symbol)))
! ((match-end 10)
! ;; Index entry
! (when reftex-support-index
! (let* ((index-info (save-excursion
! (reftex-index-info-safe nil)))
! (list (member (list 'bof (buffer-file-name))
! docstruct))
! (endelt (car (member (list 'eof (buffer-file-name))
! list)))
! dist last-dist last (n 0))
! ;; Check all index entries with equal text
! (while (and list (not (eq endelt (car list))))
! (when (and (eq (car (car list)) 'index)
! (string= (nth 2 index-info)
! (nth 2 (car list))))
! (incf n)
! (setq dist (abs (- (point) (nth 4 (car list)))))
! (if (or (not last-dist) (< dist last-dist))
! (setq last-dist dist last (car list))))
! (setq list (cdr list)))
! ;; We are sure if we have only one, or a zero distance
! (cond ((or (= n 1) (= dist 0)) last)
! ((> n 1) (setq cnt 2) last)
! (t nil)))))
! ((match-end 11)
(save-excursion
(goto-char (match-end 11))
(assoc (reftex-no-props
--- 601,635 ----
(car
(member (list 'eof (reftex-locate-file
(reftex-match-string 7) "tex"
! (cdr (assq 'master-dir docstruct))))
docstruct)))
! ((match-end 9)
! (assq 'appendix (symbol-value reftex-docstruct-symbol)))
! ((match-end 10)
! ;; Index entry
! (when reftex-support-index
! (let* ((index-info (save-excursion
! (reftex-index-info-safe nil)))
! (list (member (list 'bof (buffer-file-name))
! docstruct))
! (endelt (car (member (list 'eof (buffer-file-name))
! list)))
! dist last-dist last (n 0))
! ;; Check all index entries with equal text
! (while (and list (not (eq endelt (car list))))
! (when (and (eq (car (car list)) 'index)
! (string= (nth 2 index-info)
! (nth 2 (car list))))
! (incf n)
! (setq dist (abs (- (point) (nth 4 (car list)))))
! (if (or (not last-dist) (< dist last-dist))
! (setq last-dist dist last (car list))))
! (setq list (cdr list)))
! ;; We are sure if we have only one, or a zero distance
! (cond ((or (= n 1) (equal dist 0)) last)
! ((> n 1) (setq cnt 2) last)
! (t nil)))))
! ((match-end 11)
(save-excursion
(goto-char (match-end 11))
(assoc (reftex-no-props
***************
*** 640,727 ****
;; Check if there was only a by-name match for the section.
(when (and (not rtn) rtn-if-no-other)
(setq rtn rtn-if-no-other
! cnt 2))
(cons rtn (eq cnt 1))))
(defun reftex-notice-new (&optional n force)
"Hook to handshake with RefTeX after something new has been inserted."
;; Add a new entry to the docstruct list. If it is a section, renumber
;; the following sections.
! ;; FIXME: Put in a WHAT parameter
;; When N is given, go back that many matches of reftex-everything-regexp
;; When FORCE is non-nil, also insert if `reftex-where-am-I' was uncertain.
(condition-case nil
(catch 'exit
! (unless reftex-mode (throw 'exit nil))
! (reftex-access-scan-info)
! (let* ((docstruct (symbol-value reftex-docstruct-symbol))
! here-I-am appendix tail entry star level
! section-number context)
(save-excursion
(when (re-search-backward (reftex-everything-regexp) nil t (or n 1))
! ;; Find where we are
! (setq here-I-am (reftex-where-am-I))
! (or here-I-am (throw 'exit nil))
! (unless (or force (cdr here-I-am)) (throw 'exit nil))
! (setq tail (memq (car here-I-am) docstruct))
! (or tail (throw 'exit nil))
! (setq reftex-active-toc (reftex-last-assoc-before-elt
! 'toc (car here-I-am) docstruct)
! appendix (reftex-last-assoc-before-elt
! 'appendix (car here-I-am) docstruct))
!
! ;; Initialize section numbers
! (if (eq (car (car here-I-am)) 'appendix)
! (reftex-init-section-numbers nil t)
! (reftex-init-section-numbers reftex-active-toc appendix))
!
! ;; Match the section command
! (when (re-search-forward (reftex-everything-regexp) nil t)
! (cond
! ((match-end 1)
! (push (reftex-label-info (reftex-match-string 1) buffer-file-name)
! (cdr tail)))
!
! ((match-end 3)
! (setq star (= ?* (char-after (match-end 3)))
! entry (reftex-section-info (buffer-file-name))
! level (nth 5 entry))
! ;; Insert the section info
! (push entry (cdr tail))
!
! ;; We are done unless we use section numbers
! (unless (nth 1 reftex-label-menu-flags) (throw 'exit nil))
!
! ;; Update the remaining toc items
! (setq tail (cdr tail))
! (while (and (setq tail (memq (assq 'toc (cdr tail)) tail))
! (setq entry (car tail))
! (>= (nth 5 entry) level))
! (setq star (string-match "\\*" (nth 6 entry))
! context (nth 2 entry)
! section-number
! (reftex-section-number (nth 5 entry) star))
! (when (string-match "\\`\\([ \t]*\\)\\([.0-9A-Z]+\\)\\(.*\\)"
! context)
! (when (and (not appendix)
! (>= (string-to-char (match-string 2)) ?A))
! ;; Just entered the appendex. Get out.
! (throw 'exit nil))
!
! ;; Change the section number.
! (setf (nth 2 entry)
! (concat (match-string 1 context)
! section-number
! (match-string 3 context))))))
! ((match-end 10)
! ;; Index entry
! (and reftex-support-index
! (setq entry (reftex-index-info-safe buffer-file-name))
! ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry))
! (push entry (cdr tail))))))))))
!
(error nil))
)
--- 641,728 ----
;; Check if there was only a by-name match for the section.
(when (and (not rtn) rtn-if-no-other)
(setq rtn rtn-if-no-other
! cnt 2))
(cons rtn (eq cnt 1))))
(defun reftex-notice-new (&optional n force)
"Hook to handshake with RefTeX after something new has been inserted."
;; Add a new entry to the docstruct list. If it is a section, renumber
;; the following sections.
! ;; FIXME: Put in a WHAT parameter and search backward until one is found.
;; When N is given, go back that many matches of reftex-everything-regexp
;; When FORCE is non-nil, also insert if `reftex-where-am-I' was uncertain.
(condition-case nil
(catch 'exit
! (unless reftex-mode (throw 'exit nil))
! (reftex-access-scan-info)
! (let* ((docstruct (symbol-value reftex-docstruct-symbol))
! here-I-am appendix tail entry star level
! section-number context)
(save-excursion
(when (re-search-backward (reftex-everything-regexp) nil t (or n 1))
! ;; Find where we are
! (setq here-I-am (reftex-where-am-I))
! (or here-I-am (throw 'exit nil))
! (unless (or force (cdr here-I-am)) (throw 'exit nil))
! (setq tail (memq (car here-I-am) docstruct))
! (or tail (throw 'exit nil))
! (setq reftex-active-toc (reftex-last-assoc-before-elt
! 'toc (car here-I-am) docstruct)
! appendix (reftex-last-assoc-before-elt
! 'appendix (car here-I-am) docstruct))
!
! ;; Initialize section numbers
! (if (eq (car (car here-I-am)) 'appendix)
! (reftex-init-section-numbers nil t)
! (reftex-init-section-numbers reftex-active-toc appendix))
!
! ;; Match the section command
! (when (re-search-forward (reftex-everything-regexp) nil t)
! (cond
! ((match-end 1)
! (push (reftex-label-info (reftex-match-string 1)
buffer-file-name)
! (cdr tail)))
!
! ((match-end 3)
! (setq star (= ?* (char-after (match-end 3)))
! entry (reftex-section-info (buffer-file-name))
! level (nth 5 entry))
! ;; Insert the section info
! (push entry (cdr tail))
!
! ;; We are done unless we use section numbers
! (unless (nth 1 reftex-label-menu-flags) (throw 'exit nil))
!
! ;; Update the remaining toc items
! (setq tail (cdr tail))
! (while (and (setq tail (memq (assq 'toc (cdr tail)) tail))
! (setq entry (car tail))
! (>= (nth 5 entry) level))
! (setq star (string-match "\\*" (nth 6 entry))
! context (nth 2 entry)
! section-number
! (reftex-section-number (nth 5 entry) star))
! (when (string-match "\\`\\([ \t]*\\)\\([.0-9A-Z]+\\)\\(.*\\)"
! context)
! (when (and (not appendix)
! (>= (string-to-char (match-string 2)) ?A))
! ;; Just entered the appendex. Get out.
! (throw 'exit nil))
!
! ;; Change the section number.
! (setf (nth 2 entry)
! (concat (match-string 1 context)
! section-number
! (match-string 3 context))))))
! ((match-end 10)
! ;; Index entry
! (and reftex-support-index
! (setq entry (reftex-index-info-safe buffer-file-name))
! ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry))
! (push entry (cdr tail))))))))))
!
(error nil))
)
***************
*** 735,742 ****
((memq (preceding-char) '(?\] ?\})))
;; Do a search
((and reftex-allow-detached-macro-args
! (re-search-backward
! "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t))
(goto-char (1+ (match-beginning 0)))
t)
(t nil)))
--- 736,743 ----
((memq (preceding-char) '(?\] ?\})))
;; Do a search
((and reftex-allow-detached-macro-args
! (re-search-backward
! "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t))
(goto-char (1+ (match-beginning 0)))
t)
(t nil)))
***************
*** 781,809 ****
(setq cnt 1 cnt-opt 0)
;; move back over any touching sexps
(while (and (reftex-move-to-previous-arg bound)
! (condition-case nil
! (progn (backward-sexp) t)
! (error nil)))
! (if (eq (following-char) ?\[) (incf cnt-opt))
(incf cnt))
(setq pos (point))
(when (and (or (= (following-char) ?\[)
(= (following-char) ?\{))
(re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
(setq cmd (reftex-match-string 0))
! (when (looking-at "\\\\begin{[^}]*}")
! (setq cmd (reftex-match-string 0)
! cnt (1- cnt)))
! ;; This does ignore optional arguments. Very hard to fix.
! (when (setq entry (assoc cmd reftex-env-or-mac-alist))
! (if (> cnt (or (nth 4 entry) 100))
! (setq cmd nil)))
(cond
! ((null cmd))
! ((eq t which)
! (push (cons cmd (point)) cmd-list))
! ((or (eq 1 which) (member cmd which))
! (throw 'exit (cons cmd (point))))))
(goto-char pos)))
(nreverse cmd-list)))))
--- 782,810 ----
(setq cnt 1 cnt-opt 0)
;; move back over any touching sexps
(while (and (reftex-move-to-previous-arg bound)
! (condition-case nil
! (progn (backward-sexp) t)
! (error nil)))
! (if (eq (following-char) ?\[) (incf cnt-opt))
(incf cnt))
(setq pos (point))
(when (and (or (= (following-char) ?\[)
(= (following-char) ?\{))
(re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
(setq cmd (reftex-match-string 0))
! (when (looking-at "\\\\begin{[^}]*}")
! (setq cmd (reftex-match-string 0)
! cnt (1- cnt)))
! ;; This does ignore optional arguments. Very hard to fix.
! (when (setq entry (assoc cmd reftex-env-or-mac-alist))
! (if (> cnt (or (nth 4 entry) 100))
! (setq cmd nil)))
(cond
! ((null cmd))
! ((eq t which)
! (push (cons cmd (point)) cmd-list))
! ((or (eq 1 which) (member cmd which))
! (throw 'exit (cons cmd (point))))))
(goto-char pos)))
(nreverse cmd-list)))))
***************
*** 836,842 ****
(match-beginning 2) (match-end 2)))
(cond
((string= (match-string 1) "end")
! (push env end-list))
((equal env (car end-list))
(setq end-list (cdr end-list)))
((eq t which)
--- 837,843 ----
(match-beginning 2) (match-end 2)))
(cond
((string= (match-string 1) "end")
! (push env end-list))
((equal env (car end-list))
(setq end-list (cdr end-list)))
((eq t which)
***************
*** 866,890 ****
(let ((bound (or bound (save-excursion (re-search-backward
reftex-section-regexp nil 1)
(point))))
! (fun-list (if (listp which)
! (mapcar (lambda (x) (if (memq x which) x nil))
! reftex-special-env-parsers)
! reftex-special-env-parsers))
specials rtn)
! ;; Call all functions
! (setq specials (mapcar
! (lambda (fun)
! (save-excursion
! (setq rtn (and fun (funcall fun bound)))
! (if rtn (cons (symbol-name fun) rtn) nil)))
! fun-list))
! ;; Delete the non-matches
! (setq specials (delq nil specials))
! ;; Sort
! (setq specials (sort specials (lambda (a b) (> (cdr a) (cdr b)))))
! (if (eq which t)
! specials
! (car specials))))))
(defsubst reftex-move-to-next-arg (&optional ignore)
;; Assuming that we are at the end of a macro name or a macro argument,
--- 867,891 ----
(let ((bound (or bound (save-excursion (re-search-backward
reftex-section-regexp nil 1)
(point))))
! (fun-list (if (listp which)
! (mapcar (lambda (x) (if (memq x which) x nil))
! reftex-special-env-parsers)
! reftex-special-env-parsers))
specials rtn)
! ;; Call all functions
! (setq specials (mapcar
! (lambda (fun)
! (save-excursion
! (setq rtn (and fun (funcall fun bound)))
! (if rtn (cons (symbol-name fun) rtn) nil)))
! fun-list))
! ;; Delete the non-matches
! (setq specials (delq nil specials))
! ;; Sort
! (setq specials (sort specials (lambda (a b) (> (cdr a) (cdr b)))))
! (if (eq which t)
! specials
! (car specials))))))
(defsubst reftex-move-to-next-arg (&optional ignore)
;; Assuming that we are at the end of a macro name or a macro argument,
***************
*** 896,902 ****
((memq (following-char) '(?\[ ?\{)))
;; Do a search
((and reftex-allow-detached-macro-args
! (looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]"))
(goto-char (1- (match-end 0)))
t)
(t nil)))
--- 897,903 ----
((memq (following-char) '(?\[ ?\{)))
;; Do a search
((and reftex-allow-detached-macro-args
! (looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]"))
(goto-char (1- (match-end 0)))
t)
(t nil)))
***************
*** 915,953 ****
(if (= n 1000)
;; Special case: Skip all touching arguments
(progn
! (reftex-move-over-touching-args)
! (reftex-context-substring))
;; Do the real thing.
(let ((cnt 1))
!
(when (reftex-move-to-next-arg)
!
! (while (< cnt n)
! (while (and (member cnt opt-args)
! (eq (following-char) ?\{))
! (incf cnt))
! (when (< cnt n)
! (unless (and (condition-case nil
! (or (forward-list 1) t)
! (error nil))
! (reftex-move-to-next-arg)
! (incf cnt))
! (setq cnt 1000))))
!
! (while (and (memq cnt opt-args)
! (eq (following-char) ?\{))
! (incf cnt)))
(if (and (= n cnt)
! (> (skip-chars-forward "{\\[") 0))
! (reftex-context-substring)
! nil))))
(defun reftex-move-over-touching-args ()
(condition-case nil
(while (memq (following-char) '(?\[ ?\{))
! (forward-list 1))
! (error nil)))
(defun reftex-context-substring (&optional to-end)
;; Return up to 150 chars from point
--- 916,954 ----
(if (= n 1000)
;; Special case: Skip all touching arguments
(progn
! (reftex-move-over-touching-args)
! (reftex-context-substring))
;; Do the real thing.
(let ((cnt 1))
!
(when (reftex-move-to-next-arg)
!
! (while (< cnt n)
! (while (and (member cnt opt-args)
! (eq (following-char) ?\{))
! (incf cnt))
! (when (< cnt n)
! (unless (and (condition-case nil
! (or (forward-list 1) t)
! (error nil))
! (reftex-move-to-next-arg)
! (incf cnt))
! (setq cnt 1000))))
!
! (while (and (memq cnt opt-args)
! (eq (following-char) ?\{))
! (incf cnt)))
(if (and (= n cnt)
! (> (skip-chars-forward "{\\[") 0))
! (reftex-context-substring)
! nil))))
(defun reftex-move-over-touching-args ()
(condition-case nil
(while (memq (following-char) '(?\[ ?\{))
! (forward-list 1))
! (error nil)))
(defun reftex-context-substring (&optional to-end)
;; Return up to 150 chars from point
***************
*** 958,968 ****
(buffer-substring-no-properties
(point)
(min (+ (point) 150)
! (save-match-data
! ;; FIXME: THis is not perfect
! (if (re-search-forward "\\\\end{" nil t)
! (match-beginning 0)
! (point-max))))))
((or (= (preceding-char) ?\{)
(= (preceding-char) ?\[))
;; Inside a list - get only the list.
--- 959,969 ----
(buffer-substring-no-properties
(point)
(min (+ (point) 150)
! (save-match-data
! ;; FIXME: This is not perfect
! (if (re-search-forward "\\\\end{" nil t)
! (match-beginning 0)
! (point-max))))))
((or (= (preceding-char) ?\{)
(= (preceding-char) ?\[))
;; Inside a list - get only the list.
***************
*** 977,984 ****
(error (point-max))))))
(t
;; no list - just grab 150 characters
! (buffer-substring-no-properties (point)
! (min (+ (point) 150) (point-max))))))
;; Variable holding the vector with section numbers
(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0))
--- 978,985 ----
(error (point-max))))))
(t
;; no list - just grab 150 characters
! (buffer-substring-no-properties (point)
! (min (+ (point) 150) (point-max))))))
;; Variable holding the vector with section numbers
(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0))
***************
*** 993,1003 ****
(while (>= i 0)
(if (> i level)
(aset reftex-section-numbers i 0)
! (setq number-string (or (car numbers) "0"))
! (if (string-match "\\`[A-Z]\\'" number-string)
! (aset reftex-section-numbers i
! (- (string-to-char number-string) ?A -1))
! (aset reftex-section-numbers i (string-to-int number-string)))
(pop numbers))
(decf i)))
(put 'reftex-section-numbers 'appendix appendix))
--- 994,1004 ----
(while (>= i 0)
(if (> i level)
(aset reftex-section-numbers i 0)
! (setq number-string (or (car numbers) "0"))
! (if (string-match "\\`[A-Z]\\'" number-string)
! (aset reftex-section-numbers i
! (- (string-to-char number-string) ?A -1))
! (aset reftex-section-numbers i (string-to-int number-string)))
(pop numbers))
(decf i)))
(put 'reftex-section-numbers 'appendix appendix))
***************
*** 1006,1070 ****
;; Return a string with the current section number.
;; When LEVEL is non-nil, increase section numbers on that level.
(let* ((depth (1- (length reftex-section-numbers))) idx n (string "")
! (appendix (get 'reftex-section-numbers 'appendix))
! (partspecial (and (not reftex-part-resets-chapter)
! (equal level 0))))
;; partspecial means, this is a part statement.
;; Parts do not reset the chapter counter, and the part number is
;; not included in the numbering of other sectioning levels.
(when level
(when (and (> level -1) (not star))
! (aset reftex-section-numbers
! level (1+ (aref reftex-section-numbers level))))
(setq idx (1+ level))
(when (not star)
! (while (<= idx depth)
! (if (or (not partspecial)
! (not (= idx 1)))
! (aset reftex-section-numbers idx 0))
! (incf idx))))
(if partspecial
! (setq string (concat "Part " (reftex-roman-number
! (aref reftex-section-numbers 0))))
(setq idx (if reftex-part-resets-chapter 0 1))
(while (<= idx depth)
! (setq n (aref reftex-section-numbers idx))
! (if (not (and partspecial (not (equal string ""))))
! (setq string (concat string (if (not (string= string "")) "." "")
! (int-to-string n))))
! (incf idx))
(save-match-data
! (if (string-match "\\`\\(address@hidden)+" string)
! (setq string (replace-match "" nil nil string)))
! (if (string-match "\\(\\.0\\)+\\'" string)
! (setq string (replace-match "" nil nil string)))
! (if (and appendix
! (string-match "\\`[0-9]+" string))
! (setq string
! (concat
! (char-to-string
! (1- (+ ?A (string-to-int (match-string 0 string)))))
! (substring string (match-end 0))))))
(if star
! (concat (make-string (1- (length string)) ?\ ) "*")
! string))))
(defun reftex-roman-number (n)
;; Return as a string the roman number equal to N.
(let ((nrest n)
! (string "")
! (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD")
! ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
! ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
! ( 1 . "I")))
! listel i s)
(while (>= nrest 1)
(setq listel (pop list)
! i (car listel)
! s (cdr listel))
(while (>= nrest i)
! (setq string (concat string s)
! nrest (- nrest i))))
string))
;;; reftex-parse.el ends here
--- 1007,1072 ----
;; Return a string with the current section number.
;; When LEVEL is non-nil, increase section numbers on that level.
(let* ((depth (1- (length reftex-section-numbers))) idx n (string "")
! (appendix (get 'reftex-section-numbers 'appendix))
! (partspecial (and (not reftex-part-resets-chapter)
! (equal level 0))))
;; partspecial means, this is a part statement.
;; Parts do not reset the chapter counter, and the part number is
;; not included in the numbering of other sectioning levels.
(when level
(when (and (> level -1) (not star))
! (aset reftex-section-numbers
! level (1+ (aref reftex-section-numbers level))))
(setq idx (1+ level))
(when (not star)
! (while (<= idx depth)
! (if (or (not partspecial)
! (not (= idx 1)))
! (aset reftex-section-numbers idx 0))
! (incf idx))))
(if partspecial
! (setq string (concat "Part " (reftex-roman-number
! (aref reftex-section-numbers 0))))
(setq idx (if reftex-part-resets-chapter 0 1))
(while (<= idx depth)
! (setq n (aref reftex-section-numbers idx))
! (if (not (and partspecial (not (equal string ""))))
! (setq string (concat string (if (not (string= string "")) "." "")
! (int-to-string n))))
! (incf idx))
(save-match-data
! (if (string-match "\\`\\(address@hidden)+" string)
! (setq string (replace-match "" nil nil string)))
! (if (string-match "\\(\\.0\\)+\\'" string)
! (setq string (replace-match "" nil nil string)))
! (if (and appendix
! (string-match "\\`[0-9]+" string))
! (setq string
! (concat
! (char-to-string
! (1- (+ ?A (string-to-int (match-string 0 string)))))
! (substring string (match-end 0))))))
(if star
! (concat (make-string (1- (length string)) ?\ ) "*")
! string))))
(defun reftex-roman-number (n)
;; Return as a string the roman number equal to N.
(let ((nrest n)
! (string "")
! (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD")
! ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
! ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
! ( 1 . "I")))
! listel i s)
(while (>= nrest 1)
(setq listel (pop list)
! i (car listel)
! s (cdr listel))
(while (>= nrest i)
! (setq string (concat string s)
! nrest (- nrest i))))
string))
+ ;;; arch-tag: 6a8168f7-abb9-4576-99dc-fcbc7ba901a3
;;; reftex-parse.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] Changes to emacs/lisp/textmodes/reftex-parse.el [lexbind],
Miles Bader <=