mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 14:30:50 -08:00
* lisp/allout-widgets.el (allout-widgets-auto-activation) (allout-current-decorated-p): * lisp/auth-source.el (auth-source-protocols): * lisp/autorevert.el (auto-revert-set-timer): * lisp/battery.el (battery-mode-line-limit): * lisp/calc/calcalg3.el (math-map-binop): * lisp/calendar/cal-dst.el (calendar-dst-find-startend): * lisp/calendar/cal-mayan.el (calendar-mayan-long-count-to-absolute): * lisp/calendar/calendar.el (calendar-date-echo-text) (calendar-generate-month, calendar-string-spread) (calendar-cursor-to-date, calendar-read, calendar-read-date) (calendar-mark-visible-date, calendar-dayname-on-or-before): * lisp/calendar/diary-lib.el (diary-ordinal-suffix): * lisp/cedet/ede/autoconf-edit.el (autoconf-new-program) (autoconf-find-last-macro, autoconf-parameter-strip): * lisp/cedet/ede/config.el (ede-target-with-config-build): * lisp/cedet/ede/linux.el (ede-linux--detect-architecture) (ede-linux--get-architecture): * lisp/cedet/semantic/complete.el (semantic-collector-calculate-cache) (semantic-displayer-abstract, semantic-displayer-point-position): * lisp/cedet/semantic/format.el (semantic-format-face-alist) (semantic-format-tag-short-doc): * lisp/cedet/semantic/fw.el (semantic-find-file-noselect): * lisp/cedet/semantic/idle.el (semantic-idle-scheduler-work-idle-time) (semantic-idle-breadcrumbs-display-function) (semantic-idle-breadcrumbs-format-tag-list-function): * lisp/cedet/semantic/lex.el (semantic-lex-map-types) (define-lex, define-lex-block-type-analyzer): * lisp/cedet/semantic/senator.el (senator-search-default-tag-filter): * lisp/cedet/semantic/symref.el (semantic-symref-result) (semantic-symref-hit-to-tag-via-db): * lisp/cedet/semantic/symref.el (semantic-symref-tool-baseclass): * lisp/cedet/semantic/tag.el (semantic-tag-new-variable) (semantic-tag-new-include, semantic-tag-new-package) (semantic-tag-set-faux, semantic-create-tag-proxy) (semantic-tag-function-parent) (semantic-tag-components-with-overlays): * lisp/cedet/srecode/cpp.el (srecode-cpp-namespaces) (srecode-semantic-handle-:c, srecode-semantic-apply-tag-to-dict): * lisp/cedet/srecode/dictionary.el (srecode-create-dictionary) (srecode-dictionary-add-entries, srecode-dictionary-lookup-name) (srecode-create-dictionaries-from-tags): * lisp/cmuscheme.el (scheme-compile-region): * lisp/color.el (color-lab-to-lch): * lisp/doc-view.el (doc-view-image-width) (doc-view-set-up-single-converter): * lisp/dynamic-setting.el (font-setting-change-default-font) (dynamic-setting-handle-config-changed-event): * lisp/elec-pair.el (electric-pair-text-pairs) (electric-pair-skip-whitespace-function) (electric-pair-string-bound-function): * lisp/emacs-lisp/avl-tree.el (avl-tree--del-balance) (avl-tree-member, avl-tree-mapcar, avl-tree-iter): * lisp/emacs-lisp/bytecomp.el (byte-compile-generate-call-tree): * lisp/emacs-lisp/checkdoc.el (checkdoc-autofix-flag) (checkdoc-spellcheck-documentation-flag, checkdoc-ispell) (checkdoc-ispell-current-buffer, checkdoc-ispell-interactive) (checkdoc-ispell-message-interactive) (checkdoc-ispell-message-text, checkdoc-ispell-start) (checkdoc-ispell-continue, checkdoc-ispell-comments) (checkdoc-ispell-defun): * lisp/emacs-lisp/cl-generic.el (cl--generic-search-method): * lisp/emacs-lisp/eieio-custom.el (eieio-read-customization-group): * lisp/emacs-lisp/lisp.el (forward-sexp, up-list): * lisp/emacs-lisp/package-x.el (package--archive-contents-from-file): * lisp/emacs-lisp/package.el (package-desc) (package--make-autoloads-and-stuff, package-hidden-regexps): * lisp/emacs-lisp/tcover-ses.el (ses-exercise-startup): * lisp/emacs-lisp/testcover.el (testcover-nohits) (testcover-1value): * lisp/epg.el (epg-receive-keys, epg-start-edit-key): * lisp/erc/erc-backend.el (erc-server-processing-p) (erc-split-line-length, erc-server-coding-system) (erc-server-send, erc-message): * lisp/erc/erc-button.el (erc-button-face, erc-button-alist) (erc-browse-emacswiki): * lisp/erc/erc-ezbounce.el (erc-ezbounce, erc-ezb-get-login): * lisp/erc/erc-fill.el (erc-fill-variable-maximum-indentation): * lisp/erc/erc-log.el (erc-current-logfile): * lisp/erc/erc-match.el (erc-log-match-format) (erc-text-matched-hook): * lisp/erc/erc-netsplit.el (erc-netsplit, erc-netsplit-debug): * lisp/erc/erc-networks.el (erc-server-alist) (erc-networks-alist, erc-current-network): * lisp/erc/erc-ring.el (erc-input-ring-index): * lisp/erc/erc-speedbar.el (erc-speedbar) (erc-speedbar-update-channel): * lisp/erc/erc-stamp.el (erc-timestamp-only-if-changed-flag): * lisp/erc/erc-track.el (erc-track-position-in-mode-line) (erc-track-remove-from-mode-line, erc-modified-channels-update) (erc-track-last-non-erc-buffer, erc-track-sort-by-importance) (erc-track-get-active-buffer): * lisp/erc/erc.el (erc-get-channel-user-list) (erc-echo-notice-hook, erc-echo-notice-always-hook) (erc-wash-quit-reason, erc-format-@nick): * lisp/ffap.el (ffap-latex-mode): * lisp/files.el (abort-if-file-too-large) (dir-locals--get-sort-score, buffer-stale--default-function): * lisp/filesets.el (filesets-tree-max-level, filesets-data) (filesets-update-pre010505): * lisp/gnus/gnus-agent.el (gnus-agent-flush-cache): * lisp/gnus/gnus-art.el (gnus-article-encrypt-protocol) (gnus-button-prefer-mid-or-mail): * lisp/gnus/gnus-cus.el (gnus-group-parameters): * lisp/gnus/gnus-demon.el (gnus-demon-handlers) (gnus-demon-run-callback): * lisp/gnus/gnus-dired.el (gnus-dired-print): * lisp/gnus/gnus-icalendar.el (gnus-icalendar-event-from-buffer): * lisp/gnus/gnus-range.el (gnus-range-normalize): * lisp/gnus/gnus-spec.el (gnus-pad-form): * lisp/gnus/gnus-srvr.el (gnus-server-agent, gnus-server-cloud) (gnus-server-opened, gnus-server-closed, gnus-server-denied) (gnus-server-offline): * lisp/gnus/gnus-sum.el (gnus-refer-thread-use-nnir) (gnus-refer-thread-limit-to-thread) (gnus-summary-limit-include-thread, gnus-summary-refer-thread) (gnus-summary-find-matching): * lisp/gnus/gnus-util.el (gnus-rescale-image): * lisp/gnus/gnus.el (gnus-summary-line-format, gnus-no-server): * lisp/gnus/mail-source.el (mail-source-incoming-file-prefix): * lisp/gnus/message.el (message-cite-reply-position) (message-cite-style-outlook, message-cite-style-thunderbird) (message-cite-style-gmail, message--send-mail-maybe-partially): * lisp/gnus/mm-extern.el (mm-inline-external-body): * lisp/gnus/mm-partial.el (mm-inline-partial): * lisp/gnus/mml-sec.el (mml-secure-message-sign) (mml-secure-message-sign-encrypt, mml-secure-message-encrypt): * lisp/gnus/mml2015.el (mml2015-epg-key-image) (mml2015-epg-key-image-to-string): * lisp/gnus/nndiary.el (nndiary-reminders, nndiary-get-new-mail): * lisp/gnus/nnheader.el (nnheader-directory-files-is-safe): * lisp/gnus/nnir.el (nnir-search-history) (nnir-imap-search-other, nnir-artlist-length) (nnir-artlist-article, nnir-artitem-group, nnir-artitem-number) (nnir-artitem-rsv, nnir-article-group, nnir-article-number) (nnir-article-rsv, nnir-article-ids, nnir-categorize) (nnir-retrieve-headers-override-function) (nnir-imap-default-search-key, nnir-hyrex-additional-switches) (gnus-group-make-nnir-group, nnir-run-namazu, nnir-read-parms) (nnir-read-parm, nnir-read-server-parm, nnir-search-thread): * lisp/gnus/nnmairix.el (nnmairix-default-group) (nnmairix-propagate-marks): * lisp/gnus/smime.el (smime-keys, smime-crl-check) (smime-verify-buffer, smime-noverify-buffer): * lisp/gnus/spam-report.el (spam-report-url-ping-mm-url): * lisp/gnus/spam.el (spam-spamassassin-positive-spam-flag-header) (spam-spamassassin-spam-status-header, spam-sa-learn-rebuild) (spam-classifications, spam-check-stat, spam-spamassassin-score): * lisp/help.el (describe-minor-mode-from-symbol): * lisp/hippie-exp.el (hippie-expand-ignore-buffers): * lisp/htmlfontify.el (hfy-optimizations, hfy-face-resolve-face) (hfy-begin-span): * lisp/ibuf-ext.el (ibuffer-update-saved-filters-format) (ibuffer-saved-filters, ibuffer-old-saved-filters-warning) (ibuffer-filtering-qualifiers, ibuffer-repair-saved-filters) (eval, ibuffer-unary-operand, file-extension, directory): * lisp/image-dired.el (image-dired-cmd-pngcrush-options): * lisp/image-mode.el (image-toggle-display): * lisp/international/ccl.el (ccl-compile-read-multibyte-character) (ccl-compile-write-multibyte-character): * lisp/international/kkc.el (kkc-save-init-file): * lisp/international/latin1-disp.el (latin1-display): * lisp/international/ogonek.el (ogonek-name-encoding-alist) (ogonek-information, ogonek-lookup-encoding) (ogonek-deprefixify-region): * lisp/isearch.el (isearch-filter-predicate) (isearch--momentary-message): * lisp/jsonrpc.el (jsonrpc-connection-send) (jsonrpc-process-connection, jsonrpc-shutdown) (jsonrpc--async-request-1): * lisp/language/tibet-util.el (tibetan-char-p): * lisp/mail/feedmail.el (feedmail-queue-use-send-time-for-date) (feedmail-last-chance-hook, feedmail-before-fcc-hook) (feedmail-send-it-immediately-wrapper, feedmail-find-eoh): * lisp/mail/hashcash.el (hashcash-generate-payment) (hashcash-generate-payment-async, hashcash-insert-payment) (hashcash-verify-payment): * lisp/mail/rmail.el (rmail-movemail-variant-in-use) (rmail-get-attr-value): * lisp/mail/rmailmm.el (rmail-mime-prefer-html, rmail-mime): * lisp/mail/rmailsum.el (rmail-summary-show-message): * lisp/mail/supercite.el (sc-raw-mode-toggle): * lisp/man.el (Man-start-calling): * lisp/mh-e/mh-acros.el (mh-do-at-event-location) (mh-iterate-on-messages-in-region, mh-iterate-on-range): * lisp/mh-e/mh-alias.el (mh-alias-system-aliases) (mh-alias-reload, mh-alias-ali) (mh-alias-canonicalize-suggestion, mh-alias-add-alias-to-file) (mh-alias-add-alias): * lisp/mouse.el (mouse-save-then-kill): * lisp/net/browse-url.el (browse-url-default-macosx-browser): * lisp/net/eudc.el (eudc-set, eudc-variable-protocol-value) (eudc-variable-server-value, eudc-update-variable) (eudc-expand-inline): * lisp/net/eudcb-bbdb.el (eudc-bbdb-format-record-as-result): * lisp/net/eudcb-ldap.el (eudc-ldap-get-field-list): * lisp/net/pop3.el (pop3-list): * lisp/net/soap-client.el (soap-namespace-put) (soap-xs-parse-sequence, soap-parse-envelope): * lisp/net/soap-inspect.el (soap-inspect-xs-complex-type): * lisp/nxml/rng-xsd.el (rng-xsd-date-to-days): * lisp/org/ob-C.el (org-babel-prep-session:C) (org-babel-load-session:C): * lisp/org/ob-J.el (org-babel-execute:J): * lisp/org/ob-asymptote.el (org-babel-prep-session:asymptote): * lisp/org/ob-awk.el (org-babel-execute:awk): * lisp/org/ob-core.el (org-babel-process-file-name): * lisp/org/ob-ebnf.el (org-babel-execute:ebnf): * lisp/org/ob-forth.el (org-babel-execute:forth): * lisp/org/ob-fortran.el (org-babel-execute:fortran) (org-babel-prep-session:fortran, org-babel-load-session:fortran): * lisp/org/ob-groovy.el (org-babel-execute:groovy): * lisp/org/ob-io.el (org-babel-execute:io): * lisp/org/ob-js.el (org-babel-execute:js): * lisp/org/ob-lilypond.el (org-babel-default-header-args:lilypond) (org-babel-lilypond-compile-post-tangle) (org-babel-lilypond-display-pdf-post-tangle) (org-babel-lilypond-tangle) (org-babel-lilypond-execute-tangled-ly) (org-babel-lilypond-compile-lilyfile) (org-babel-lilypond-check-for-compile-error) (org-babel-lilypond-process-compile-error) (org-babel-lilypond-mark-error-line) (org-babel-lilypond-parse-error-line) (org-babel-lilypond-attempt-to-open-pdf) (org-babel-lilypond-attempt-to-play-midi) (org-babel-lilypond-switch-extension) (org-babel-lilypond-set-header-args): * lisp/org/ob-lua.el (org-babel-prep-session:lua): * lisp/org/ob-picolisp.el (org-babel-execute:picolisp): * lisp/org/ob-processing.el (org-babel-prep-session:processing): * lisp/org/ob-python.el (org-babel-prep-session:python): * lisp/org/ob-scheme.el (org-babel-scheme-capture-current-message) (org-babel-scheme-execute-with-geiser, org-babel-execute:scheme): * lisp/org/ob-shen.el (org-babel-execute:shen): * lisp/org/org-agenda.el (org-agenda-entry-types) (org-agenda-move-date-from-past-immediately-to-today) (org-agenda-time-grid, org-agenda-sorting-strategy) (org-agenda-filter-by-category, org-agenda-forward-block): * lisp/org/org-colview.el (org-columns--overlay-text): * lisp/org/org-faces.el (org-verbatim, org-cycle-level-faces): * lisp/org/org-indent.el (org-indent-set-line-properties): * lisp/org/org-macs.el (org-get-limited-outline-regexp): * lisp/org/org-mobile.el (org-mobile-files): * lisp/org/org.el (org-use-fast-todo-selection) (org-extend-today-until, org-use-property-inheritance) (org-refresh-effort-properties, org-open-at-point-global) (org-track-ordered-property-with-tag, org-shiftright): * lisp/org/ox-html.el (org-html-checkbox-type): * lisp/org/ox-man.el (org-man-source-highlight) (org-man-verse-block): * lisp/org/ox-publish.el (org-publish-sitemap-default): * lisp/outline.el (outline-head-from-level): * lisp/progmodes/dcl-mode.el (dcl-back-to-indentation-1) (dcl-calc-command-indent, dcl-indent-to): * lisp/progmodes/flymake.el (flymake-make-diagnostic) (flymake--overlays, flymake-diagnostic-functions) (flymake-diagnostic-types-alist, flymake--backend-state) (flymake-is-running, flymake--collect, flymake-mode): * lisp/progmodes/gdb-mi.el (gdb-threads-list, gdb, gdb-non-stop) (gdb-buffers, gdb-gud-context-call, gdb-jsonify-buffer): * lisp/progmodes/grep.el (grep-error-screen-columns): * lisp/progmodes/gud.el (gud-prev-expr): * lisp/progmodes/ps-mode.el (ps-mode, ps-mode-target-column) (ps-run-goto-error): * lisp/progmodes/python.el (python-eldoc-get-doc) (python-eldoc-function-timeout-permanent, python-eldoc-function): * lisp/shadowfile.el (shadow-make-group): * lisp/speedbar.el (speedbar-obj-do-check): * lisp/textmodes/flyspell.el (flyspell-auto-correct-previous-hook): * lisp/textmodes/reftex-cite.el (reftex-bib-or-thebib): * lisp/textmodes/reftex-index.el (reftex-index-goto-entry) (reftex-index-kill, reftex-index-undo): * lisp/textmodes/reftex-parse.el (reftex-context-substring): * lisp/textmodes/reftex.el (reftex-TeX-master-file): * lisp/textmodes/rst.el (rst-next-hdr, rst-toc) (rst-uncomment-region, rst-font-lock-extend-region-internal): * lisp/thumbs.el (thumbs-mode): * lisp/vc/ediff-util.el (ediff-restore-diff): * lisp/vc/pcvs-defs.el (cvs-cvsroot, cvs-force-dir-tag): * lisp/vc/vc-hg.el (vc-hg--ignore-patterns-valid-p): * lisp/wid-edit.el (widget-field-value-set, string): * lisp/x-dnd.el (x-dnd-version-from-flags) (x-dnd-more-than-3-from-flags): Assorted docfixes.
1138 lines
44 KiB
EmacsLisp
1138 lines
44 KiB
EmacsLisp
;;; reftex-parse.el --- parser functions for RefTeX
|
|
|
|
;; Copyright (C) 1997-2019 Free Software Foundation, Inc.
|
|
|
|
;; Author: Carsten Dominik <dominik@science.uva.nl>
|
|
;; Maintainer: auctex-devel@gnu.org
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
|
|
|
(require 'reftex)
|
|
|
|
(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))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-parse-one ()
|
|
"Re-parse this file."
|
|
(interactive)
|
|
(let ((reftex-enable-partial-scans t))
|
|
(reftex-access-scan-info '(4))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-parse-all ()
|
|
"Re-parse entire document."
|
|
(interactive)
|
|
(reftex-access-scan-info '(16)))
|
|
|
|
(defvar reftex--index-tags)
|
|
|
|
;;;###autoload
|
|
(defun reftex-do-parse (rescan &optional file)
|
|
"Do a document rescan.
|
|
When allowed, do only a partial scan from FILE."
|
|
|
|
;; Normalize the rescan argument
|
|
(setq rescan (cond ((eq rescan t) t)
|
|
((eq rescan 1) 1)
|
|
((equal rescan '(4)) t)
|
|
((equal rescan '(16)) 1)
|
|
(t 1)))
|
|
|
|
;; Partial scans only when allowed
|
|
(unless reftex-enable-partial-scans
|
|
(setq rescan 1))
|
|
|
|
;; Do the scanning.
|
|
|
|
(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))
|
|
(reftex--index-tags (cdr (assq 'index-tags old-list)))
|
|
from-file appendix docstruct tmp)
|
|
|
|
;; Make sure replacement is really an option here
|
|
(when (and (eq rescan t)
|
|
(not (and (member (list 'bof file) old-list)
|
|
(member (list 'eof file) old-list))))
|
|
;; Scan whole document because no such file section exists
|
|
(setq rescan 1))
|
|
(when (string= true-file true-master)
|
|
;; Scan whole document because this file is the master
|
|
(setq rescan 1))
|
|
|
|
;; From which file do we start?
|
|
(setq from-file
|
|
(cond ((eq rescan t) (or file master))
|
|
((eq rescan 1) master)
|
|
(t (error "This should not happen (reftex-do-parse)"))))
|
|
|
|
;; Reset index-tags if we scan everything
|
|
(if (equal rescan 1) (setq reftex--index-tags nil))
|
|
|
|
;; 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)
|
|
|
|
(if (eq rescan 1)
|
|
(message "Scanning entire document...")
|
|
(message "Scanning document from %s..." from-file))
|
|
|
|
(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")
|
|
|
|
;; Turn the list around.
|
|
(setq docstruct (nreverse docstruct))
|
|
|
|
;; Set or insert
|
|
(setq docstruct (reftex-replace-label-list-segment
|
|
old-list docstruct (eq rescan 1)))
|
|
|
|
;; Add all missing information
|
|
(unless (assq 'label-numbers docstruct)
|
|
(push (cons 'label-numbers nil) docstruct))
|
|
(unless (assq 'master-dir docstruct)
|
|
(push (cons 'master-dir master-dir) docstruct))
|
|
(unless (assq 'bibview-cache docstruct)
|
|
(push (cons 'bibview-cache (cdr bibview-cache)) docstruct))
|
|
(let* ((bof1 (memq (assq 'bof docstruct) docstruct))
|
|
(bof2 (assq 'bof (cdr bof1)))
|
|
(is-multi (not (not (and bof1 bof2))))
|
|
(entry (or (assq 'is-multi docstruct)
|
|
(car (push (list 'is-multi is-multi) docstruct)))))
|
|
(setcdr entry (cons is-multi nil)))
|
|
(and reftex--index-tags
|
|
(setq reftex--index-tags (sort reftex--index-tags 'string<)))
|
|
(let ((index-tag-cell (assq 'index-tags docstruct)))
|
|
(if index-tag-cell
|
|
(setcdr index-tag-cell reftex--index-tags)
|
|
(push (cons 'index-tags reftex--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)))
|
|
|
|
;;;###autoload
|
|
(defun reftex-everything-regexp ()
|
|
(if reftex-support-index
|
|
reftex-everything-regexp
|
|
reftex-everything-regexp-no-index))
|
|
|
|
;; NB this is a global autoload - see reftex.el.
|
|
;;;###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
|
|
of master file."
|
|
(let* ((all (symbol-value reftex-docstruct-symbol))
|
|
(master-dir (file-name-directory (reftex-TeX-master-file)))
|
|
(re (concat "\\`" (regexp-quote master-dir)))
|
|
file-list tmp file)
|
|
(while (setq tmp (assoc 'bof all))
|
|
(setq file (nth 1 tmp)
|
|
all (cdr (memq tmp all)))
|
|
(and relative
|
|
(string-match re file)
|
|
(setq file (substring file (match-end 0))))
|
|
(push file file-list))
|
|
(nreverse file-list)))
|
|
|
|
;; Bound in the caller, reftex-do-parse.
|
|
(defun reftex-parse-from-file (file docstruct master-dir)
|
|
"Scan the buffer for labels and save them in a list."
|
|
(let ((regexp (reftex-everything-regexp))
|
|
(bound 0)
|
|
file-found tmp include-file
|
|
(level 1)
|
|
(highest-level 100)
|
|
toc-entry index-entry next-buf buf)
|
|
|
|
(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)
|
|
(throw 'exit nil))
|
|
|
|
(save-excursion
|
|
|
|
(message "Scanning file %s" file)
|
|
(set-buffer
|
|
(setq next-buf
|
|
(reftex-get-file-buffer-force
|
|
file-found
|
|
(not (eq t reftex-keep-temporary-buffers)))))
|
|
|
|
;; Begin of file mark
|
|
(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
|
|
(when (or (null reftex-label-ignored-macros-and-environments)
|
|
;; \label{} defs should always be honored,
|
|
;; just no keyval style [label=foo] defs.
|
|
(string-equal "\\label{" (substring (reftex-match-string 0) 0 7))
|
|
(if (and (fboundp 'TeX-current-macro)
|
|
(fboundp 'LaTeX-current-environment))
|
|
(not (or (member (save-match-data (TeX-current-macro))
|
|
reftex-label-ignored-macros-and-environments)
|
|
(member (save-match-data (LaTeX-current-environment))
|
|
reftex-label-ignored-macros-and-environments)))
|
|
t))
|
|
(push (reftex-label-info (reftex-match-string 1) file bound)
|
|
docstruct)))
|
|
|
|
((match-end 3)
|
|
;; It is a section
|
|
|
|
;; Use the beginning as bound and not the end
|
|
;; (i.e. (point)) because the section command might
|
|
;; be the start of the current environment to be
|
|
;; found by `reftex-label-info'.
|
|
(setq bound (match-beginning 0))
|
|
;; The section regexp matches a character at the end
|
|
;; we are not interested in. Especially if it is the
|
|
;; backslash of a following macro we want to find in
|
|
;; the next parsing iteration.
|
|
(when (eq (char-before) ?\\) (backward-char))
|
|
;; Insert in List
|
|
(setq toc-entry (funcall reftex-section-info-function file))
|
|
(when (and toc-entry
|
|
(eq ;; Either both are t or both are nil.
|
|
(= (char-after bound) ?%)
|
|
(string-suffix-p ".dtx" file)))
|
|
;; 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
|
|
(cl-pushnew (nth 1 index-entry) reftex--index-tags :test #'equal)
|
|
(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))
|
|
|
|
;; Return the list
|
|
docstruct))
|
|
|
|
(defun reftex-using-biblatex-p ()
|
|
"Return non-nil if we are using biblatex rather than bibtex."
|
|
(if (boundp 'TeX-active-styles)
|
|
;; the sophisticated AUCTeX way
|
|
(member "biblatex" TeX-active-styles)
|
|
;; poor-man's check...
|
|
(save-excursion
|
|
(re-search-forward "^[^%\n]*?\\\\usepackage.*{biblatex}" nil t))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-locate-bibliography-files (master-dir &optional files)
|
|
"Scan buffer for bibliography macros and return file list."
|
|
(unless files
|
|
(save-excursion
|
|
(goto-char (point-min))
|
|
;; when biblatex is used, multiple \bibliography or
|
|
;; \addbibresource macros are allowed. With plain bibtex, only
|
|
;; the first is used.
|
|
(let ((using-biblatex (reftex-using-biblatex-p))
|
|
(again t))
|
|
(while (and again
|
|
(re-search-forward
|
|
(concat
|
|
;; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
|
|
"\\(^\\)[^%\n\r]*\\\\\\("
|
|
(mapconcat 'identity reftex-bibliography-commands "\\|")
|
|
"\\)\\(\\[.+?\\]\\)?{[ \t]*\\([^}]+\\)") nil t))
|
|
(setq files
|
|
(append files
|
|
(split-string (reftex-match-string 4)
|
|
"[ \t\n\r]*,[ \t\n\r]*")))
|
|
(unless using-biblatex
|
|
(setq again nil))))))
|
|
(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)
|
|
"Replace the segment in OLD which corresponds to INSERT.
|
|
Works with side effects, directly changes old.
|
|
If ENTIRELY is t, just return INSERT.
|
|
This function also makes sure the old toc markers do not point anywhere."
|
|
|
|
(cond
|
|
(entirely
|
|
(reftex-silence-toc-markers old (length old))
|
|
insert)
|
|
(t (let* ((new old)
|
|
(file (nth 1 (car insert)))
|
|
(eof-list (member (list 'eof file) old))
|
|
(bof-list (member (list 'bof file) old))
|
|
n)
|
|
(if (not (and bof-list eof-list))
|
|
(error "Cannot splice")
|
|
;; Splice
|
|
(reftex-silence-toc-markers bof-list (- (length bof-list)
|
|
(length eof-list)))
|
|
(setq n (- (length old) (length bof-list)))
|
|
(setcdr (nthcdr n new) (cdr insert))
|
|
(setcdr (nthcdr (1- (length new)) new) (cdr eof-list)))
|
|
new))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-section-info (file)
|
|
"Return a section entry for the current match.
|
|
Careful: 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
|
|
(setq text
|
|
(concat
|
|
(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))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-ensure-index-support (&optional abort)
|
|
"When index support is turned off, ask to turn it on and
|
|
set the current prefix argument so that `reftex-access-scan-info'
|
|
will rescan the entire document."
|
|
(cond
|
|
(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)))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-index-info-safe (file)
|
|
(reftex-with-special-syntax
|
|
(reftex-index-info file)))
|
|
|
|
(defvar test-dummy)
|
|
;;;###autoload
|
|
(defun reftex-index-info (file)
|
|
"Return an index entry for the current match.
|
|
Careful: 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))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-short-context (env parse &optional bound derive)
|
|
"Get about one line of useful context for the label definition at point."
|
|
|
|
(if (consp parse)
|
|
(setq parse (if derive (cdr parse) (car parse))))
|
|
|
|
(reftex-nicify-text
|
|
|
|
(cond
|
|
|
|
((null parse)
|
|
(save-excursion
|
|
(reftex-context-substring)))
|
|
|
|
((eq parse t)
|
|
(if (string= env "section")
|
|
;; special treatment for section labels
|
|
(save-excursion
|
|
(if (and (re-search-backward reftex-section-or-include-regexp
|
|
(point-min) t)
|
|
(match-end 2))
|
|
(progn
|
|
(goto-char (match-end 0))
|
|
(reftex-context-substring))
|
|
(if reftex-active-toc
|
|
(progn
|
|
(string-match "{\\([^}]*\\)" (nth 7 reftex-active-toc))
|
|
(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)
|
|
(save-excursion
|
|
(if (re-search-backward parse bound t)
|
|
(progn
|
|
(goto-char (match-end 0))
|
|
(reftex-context-substring))
|
|
"NO MATCH FOR CONTEXT REGEXP")))
|
|
|
|
((integerp parse)
|
|
(or (save-excursion
|
|
(goto-char reftex-default-context-position)
|
|
(reftex-nth-arg
|
|
parse
|
|
(nth 6 (assoc env reftex-env-or-mac-alist))))
|
|
""))
|
|
|
|
((fboundp parse)
|
|
;; A hook function. Call it.
|
|
(save-excursion
|
|
(condition-case error-var
|
|
(funcall parse env)
|
|
(error (format "HOOK ERROR: %s" (cdr error-var))))))
|
|
(t
|
|
"INVALID VALUE OF PARSE"))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-where-am-I ()
|
|
"Return the docstruct entry above point.
|
|
Actually returns a cons cell in which the cdr is a flag indicating
|
|
if the information is exact (t) or approximate (nil)."
|
|
|
|
(let ((docstruct (symbol-value reftex-docstruct-symbol))
|
|
(cnt 0) rtn rtn-if-no-other
|
|
found)
|
|
(save-excursion
|
|
(while (not rtn)
|
|
(cl-incf cnt)
|
|
(setq found (re-search-backward (reftex-everything-regexp) nil t))
|
|
(setq rtn
|
|
(cond
|
|
((not found)
|
|
;; no match
|
|
(or
|
|
(car (member (list 'bof (buffer-file-name)) docstruct))
|
|
(not (setq cnt 2))
|
|
(assq 'bof docstruct) ;; for safety reasons
|
|
'corrupted))
|
|
((match-end 1)
|
|
;; Label
|
|
(assoc (reftex-match-string 1)
|
|
(symbol-value reftex-docstruct-symbol)))
|
|
((match-end 3)
|
|
;; Section
|
|
(goto-char (1- (match-beginning 3)))
|
|
(let* ((list (member (list 'bof (buffer-file-name))
|
|
docstruct))
|
|
(endelt (car (member (list 'eof (buffer-file-name))
|
|
list)))
|
|
rtn1)
|
|
(while (and list (not (eq endelt (car list))))
|
|
(if (and (eq (car (car list)) 'toc)
|
|
(string= (buffer-file-name)
|
|
(nth 3 (car list))))
|
|
(cond
|
|
((equal (point)
|
|
(or (and (markerp (nth 4 (car list)))
|
|
(marker-position (nth 4 (car list))))
|
|
(nth 8 (car list))))
|
|
;; Fits with marker position or recorded position
|
|
(setq rtn1 (car list) list nil))
|
|
((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)
|
|
;; Input or include...
|
|
(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))))
|
|
(cl-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
|
|
(reftex-nth-arg-wrapper
|
|
(reftex-match-string 11)))
|
|
(symbol-value reftex-docstruct-symbol))))
|
|
(t
|
|
(error "This should not happen (reftex-where-am-I)"))))))
|
|
;; 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))))
|
|
|
|
;;;###autoload
|
|
(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 appendix. 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 'reftex--index-tags (nth 1 index-entry))
|
|
(push entry (cdr tail))))))))))
|
|
|
|
(error nil))
|
|
)
|
|
|
|
(defsubst reftex-move-to-previous-arg (&optional bound)
|
|
"Assuming that we are in front of a macro argument,
|
|
move backward to the closing parenthesis of the previous argument.
|
|
This function understands the splitting of macros over several lines
|
|
in TeX."
|
|
(cond
|
|
;; Just to be quick:
|
|
((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)))
|
|
|
|
;;;###autoload
|
|
(defun reftex-what-macro-safe (which &optional bound)
|
|
"Call `reftex-what-macro' with special syntax table."
|
|
(reftex-with-special-syntax
|
|
(reftex-what-macro which bound)))
|
|
|
|
;;;###autoload
|
|
(defun reftex-what-macro (which &optional bound)
|
|
"Find out if point is within the arguments of any TeX-macro.
|
|
The return value is either (\"\\macro\" . (point)) or a list of them.
|
|
|
|
If WHICH is nil, immediately return nil.
|
|
If WHICH is 1, return innermost enclosing macro.
|
|
If WHICH is t, return list of all macros enclosing point.
|
|
If WHICH is a list of macros, look only for those macros and return the
|
|
name of the first macro in this list found to enclose point.
|
|
If the optional BOUND is an integer, bound backwards directed
|
|
searches to this point. If it is nil, limit to nearest \\section -
|
|
like statement.
|
|
|
|
This function is pretty stable, but can be fooled if the text contains
|
|
things like \\macro{aa}{bb} where \\macro is defined to take only one
|
|
argument. As RefTeX cannot know this, the string \"bb\" would still be
|
|
considered an argument of macro \\macro."
|
|
(unless reftex-section-regexp (reftex-compile-variables))
|
|
(catch 'exit
|
|
(if (null which) (throw 'exit nil))
|
|
(let ((bound (or bound (save-excursion (re-search-backward
|
|
reftex-section-regexp nil 1)
|
|
(point))))
|
|
pos cmd-list cmd cnt cnt-opt entry)
|
|
(save-restriction
|
|
(save-excursion
|
|
(narrow-to-region (max (point-min) bound) (point-max))
|
|
;; move back out of the current parenthesis
|
|
(while (condition-case nil
|
|
(let ((forward-sexp-function nil))
|
|
(up-list -1) t)
|
|
(error nil))
|
|
(setq cnt 1 cnt-opt 0)
|
|
;; move back over any touching sexps
|
|
(while (and (reftex-move-to-previous-arg bound)
|
|
(condition-case nil
|
|
(let ((forward-sexp-function nil))
|
|
(backward-sexp) t)
|
|
(error nil)))
|
|
(if (eq (following-char) ?\[) (cl-incf cnt-opt))
|
|
(cl-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)))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-what-environment (which &optional bound)
|
|
"Find out if point is inside a LaTeX environment.
|
|
The return value is (e.g.) either (\"equation\" . (point)) or a list of
|
|
them.
|
|
|
|
If WHICH is nil, immediately return nil.
|
|
If WHICH is 1, return innermost enclosing environment.
|
|
If WHICH is t, return list of all environments enclosing point.
|
|
If WHICH is a list of environments, look only for those environments and
|
|
return the name of the first environment in this list found to enclose
|
|
point.
|
|
|
|
If the optional BOUND is an integer, bound backwards directed searches to
|
|
this point. If it is nil, limit to nearest \\section - like statement."
|
|
(unless reftex-section-regexp (reftex-compile-variables))
|
|
(catch 'exit
|
|
(save-excursion
|
|
(if (null which) (throw 'exit nil))
|
|
(let ((bound (or bound (save-excursion (re-search-backward
|
|
reftex-section-regexp nil 1)
|
|
(point))))
|
|
env-list end-list env)
|
|
(while (re-search-backward "\\\\\\(begin\\|end\\){\\([^}]+\\)}"
|
|
bound t)
|
|
(setq env (buffer-substring-no-properties
|
|
(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)
|
|
(push (cons env (point)) env-list))
|
|
((or (eq 1 which) (member env which))
|
|
(throw 'exit (cons env (point))))))
|
|
(nreverse env-list)))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-what-special-env (which &optional bound)
|
|
"Run the special environment parsers and return the matches.
|
|
|
|
The return value is (e.g.) either (\"my-parser-function\" . (point))
|
|
or a list of them.
|
|
|
|
If WHICH is nil, immediately return nil.
|
|
If WHICH is 1, return innermost enclosing environment.
|
|
If WHICH is t, return list of all environments enclosing point.
|
|
If WHICH is a list of environments, look only for those environments and
|
|
return the name of the first environment in this list found to enclose
|
|
point."
|
|
(unless reftex-section-regexp (reftex-compile-variables))
|
|
(catch 'exit
|
|
(save-excursion
|
|
(if (null reftex-special-env-parsers) (throw 'exit nil))
|
|
(if (null which) (throw 'exit nil))
|
|
(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,
|
|
move forward to the opening parenthesis of the next argument.
|
|
This function understands the splitting of macros over several lines
|
|
in TeX."
|
|
(cond
|
|
;; Just to be quick:
|
|
((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)))
|
|
|
|
(defun reftex-nth-arg-wrapper (key)
|
|
(let ((entry (assoc key reftex-env-or-mac-alist)))
|
|
(reftex-nth-arg (nth 5 entry) (nth 6 entry))))
|
|
|
|
;;;###autoload
|
|
(defun reftex-nth-arg (n &optional opt-args)
|
|
"Return the Nth following {} or [] parentheses content.
|
|
OPT-ARGS is a list of argument numbers which are optional."
|
|
|
|
;; If we are sitting at a macro start, skip to end of macro name.
|
|
(and (eq (following-char) ?\\) (skip-chars-forward "a-zA-Z*\\\\"))
|
|
|
|
(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) ?\{))
|
|
(cl-incf cnt))
|
|
(when (< cnt n)
|
|
(unless (and (condition-case nil
|
|
(or (forward-list 1) t)
|
|
(error nil))
|
|
(reftex-move-to-next-arg)
|
|
(cl-incf cnt))
|
|
(setq cnt 1000))))
|
|
|
|
(while (and (memq cnt opt-args)
|
|
(eq (following-char) ?\{))
|
|
(cl-incf cnt)))
|
|
(if (and (= n cnt)
|
|
(> (skip-chars-forward "{[") 0))
|
|
(reftex-context-substring)
|
|
nil))))
|
|
|
|
;;;###autoload
|
|
(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.
|
|
When point is just after a { or [, limit string to matching parenthesis."
|
|
(cond
|
|
(to-end
|
|
;; Environment - find next \end
|
|
(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))))))
|
|
((memq (preceding-char) '(?\{ ?\[))
|
|
;; Inside a list - get only the list.
|
|
(buffer-substring-no-properties
|
|
(point)
|
|
(min (+ (point) 150)
|
|
(point-max)
|
|
(condition-case nil
|
|
(let ((forward-sexp-function nil)) ;Unneeded fanciness.
|
|
(up-list 1)
|
|
(1- (point)))
|
|
(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))
|
|
|
|
;;;###autoload
|
|
(defun reftex-init-section-numbers (&optional toc-entry appendix)
|
|
"Initialize the section numbers with zeros or with what is found in the TOC-ENTRY."
|
|
(let* ((level (or (nth 5 toc-entry) -1))
|
|
(numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\.")))
|
|
(depth (1- (length reftex-section-numbers)))
|
|
(i depth) number-string)
|
|
(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-number number-string)))
|
|
(pop numbers))
|
|
(cl-decf i)))
|
|
(put 'reftex-section-numbers 'appendix appendix))
|
|
|
|
;;;###autoload
|
|
(defun reftex-section-number (&optional level star)
|
|
"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))
|
|
(cl-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))))
|
|
(cl-incf idx))
|
|
(save-match-data
|
|
(if (string-match "\\`\\([@0]\\.\\)+" 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-number (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))
|
|
|
|
(provide 'reftex-parse)
|
|
|
|
;;; reftex-parse.el ends here
|
|
|
|
;; Local Variables:
|
|
;; generated-autoload-file: "reftex-loaddefs.el"
|
|
;; End:
|