reftex.el 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592
  1. ;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX
  2. ;; Copyright (C) 1997-2000, 2003-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <dominik@science.uva.nl>
  4. ;; Maintainer: auctex-devel@gnu.org
  5. ;; Version: 4.31
  6. ;; Keywords: tex
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;---------------------------------------------------------------------------
  19. ;;
  20. ;;; Commentary:
  21. ;;
  22. ;; RefTeX is a minor mode with distinct support for \ref, \label, \cite,
  23. ;; and \index commands in (multi-file) LaTeX documents.
  24. ;; - A table of contents provides easy access to any part of a document.
  25. ;; - Labels are created semi-automatically.
  26. ;; - Definition context of labels is provided when creating a reference.
  27. ;; - Citations are simplified with efficient database lookup.
  28. ;; - Text phrases can be collected in a file, for later global indexing.
  29. ;; - The index preview buffer helps to check and edit index entries.
  30. ;;
  31. ;;
  32. ;; INSTALLATION
  33. ;; ------------
  34. ;;
  35. ;; - If this file is part of an X/Emacs distribution, it is installed.
  36. ;; - For XEmacs 21.x, you need to install the RefTeX plug-in package
  37. ;; available from the XEmacs distribution sites.
  38. ;; - If you have downloaded this file from the maintainers webpage, follow
  39. ;; the instructions in the INSTALL file of the distribution.
  40. ;;
  41. ;; To turn RefTeX Mode on and off in a buffer, use `M-x reftex-mode'.
  42. ;;
  43. ;; To turn on RefTeX Mode for all LaTeX files, add the following lines
  44. ;; to your .emacs file:
  45. ;;
  46. ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; AUCTeX LaTeX mode
  47. ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; Emacs latex mode
  48. ;;
  49. ;;
  50. ;; DOCUMENTATION
  51. ;; -------------
  52. ;;
  53. ;; See below for a short summary of how to use RefTeX.
  54. ;;
  55. ;; There is an extensive texinfo document describing RefTeX in detail.
  56. ;; One way to view this documentation is `M-x reftex-info RET'.
  57. ;;
  58. ;; The documentation in various formats is also available at
  59. ;;
  60. ;; http://zon.astro.uva.nl/~dominik/Tools/
  61. ;;
  62. ;;---------------------------------------------------------------------------
  63. ;;
  64. ;; Introduction
  65. ;; ************
  66. ;;
  67. ;; RefTeX is a specialized package for support of labels, references,
  68. ;; citations, and the index in LaTeX. RefTeX wraps itself round 4 LaTeX
  69. ;; macros: `\label', `\ref', `\cite', and `\index'. Using these macros
  70. ;; usually requires looking up different parts of the document and
  71. ;; searching through BibTeX database files. RefTeX automates these
  72. ;; time-consuming tasks almost entirely. It also provides functions to
  73. ;; display the structure of a document and to move around in this
  74. ;; structure quickly.
  75. ;;
  76. ;; *Note Imprint::, for information about who to contact for help, bug
  77. ;; reports or suggestions.
  78. ;;
  79. ;; Environment
  80. ;; ===========
  81. ;;
  82. ;; RefTeX needs to access all files which are part of a multifile
  83. ;; document, and the BibTeX database files requested by the
  84. ;; `\bibliography' command. To find these files, RefTeX will require a
  85. ;; search path, i.e. a list of directories to check. Normally this list
  86. ;; is stored in the environment variables `TEXINPUTS' and `BIBINPUTS'
  87. ;; which are also used by RefTeX. However, on some systems these
  88. ;; variables do not contain the full search path. If RefTeX does not work
  89. ;; for you because it cannot find some files, read *Note Finding Files::.
  90. ;;
  91. ;; Entering RefTeX Mode
  92. ;; ====================
  93. ;;
  94. ;; To turn RefTeX Mode on and off in a particular buffer, use `M-x
  95. ;; reftex-mode'. To turn on RefTeX Mode for all LaTeX files, add the
  96. ;; following lines to your `.emacs' file:
  97. ;;
  98. ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
  99. ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
  100. ;;
  101. ;; RefTeX in a Nutshell
  102. ;; ====================
  103. ;;
  104. ;; 1. Table of Contents
  105. ;; Typing `C-c =' (`reftex-toc') will show a table of contents of the
  106. ;; document. This buffer can display sections, labels and index
  107. ;; entries defined in the document. From the buffer, you can jump
  108. ;; quickly to every part of your document. Press `?' to get help.
  109. ;;
  110. ;; 2. Labels and References
  111. ;; RefTeX helps to create unique labels and to find the correct key
  112. ;; for references quickly. It distinguishes labels for different
  113. ;; environments, knows about all standard environments (and many
  114. ;; others), and can be configured to recognize any additional labeled
  115. ;; environments you have defined yourself (variable
  116. ;; `reftex-label-alist').
  117. ;;
  118. ;; * Creating Labels
  119. ;; Type `C-c (' (`reftex-label') to insert a label at point.
  120. ;; RefTeX will either
  121. ;; - derive a label from context (default for section labels)
  122. ;; - prompt for a label string (default for figures and
  123. ;; tables) or
  124. ;; - insert a simple label made of a prefix and a number (all
  125. ;; other environments)
  126. ;;
  127. ;; Which labels are created how is configurable with the variable
  128. ;; `reftex-insert-label-flags'.
  129. ;;
  130. ;; * Referencing Labels
  131. ;; To make a reference, type `C-c )' (`reftex-reference'). This
  132. ;; shows an outline of the document with all labels of a certain
  133. ;; type (figure, equation,...) and some label context.
  134. ;; Selecting a label inserts a `\ref{LABEL}' macro into the
  135. ;; original buffer.
  136. ;;
  137. ;; 3. Citations
  138. ;; Typing `C-c [' (`reftex-citation') will let you specify a regular
  139. ;; expression to search in current BibTeX database files (as
  140. ;; specified in the `\bibliography' command) and pull out a list of
  141. ;; matches for you to choose from. The list is _formatted_ and
  142. ;; sorted. The selected article is referenced as `\cite{KEY}' (see
  143. ;; the variable `reftex-cite-format' if you want to insert different
  144. ;; macros).
  145. ;;
  146. ;; 4. Index Support
  147. ;; RefTeX helps to enter index entries. It also compiles all entries
  148. ;; into an alphabetically sorted `*Index*' buffer which you can use
  149. ;; to check and edit the entries. RefTeX knows about the standard
  150. ;; index macros and can be configured to recognize any additional
  151. ;; macros you have defined (`reftex-index-macros'). Multiple indices
  152. ;; are supported.
  153. ;;
  154. ;; * Creating Index Entries
  155. ;; To index the current selection or the word at point, type
  156. ;; `C-c /' (`reftex-index-selection-or-word'). The default macro
  157. ;; `reftex-index-default-macro' will be used. For a more
  158. ;; complex entry type `C-c <' (`reftex-index'), select any of
  159. ;; the index macros and enter the arguments with completion.
  160. ;;
  161. ;; * The Index Phrases File (Delayed Indexing)
  162. ;; Type `C-c \' (`reftex-index-phrase-selection-or-word') to add
  163. ;; the current word or selection to a special _index phrase
  164. ;; file_. RefTeX can later search the document for occurrences
  165. ;; of these phrases and let you interactively index the matches.
  166. ;;
  167. ;; * Displaying and Editing the Index
  168. ;; To display the compiled index in a special buffer, type `C-c
  169. ;; >' (`reftex-display-index'). From that buffer you can check
  170. ;; and edit all entries.
  171. ;;
  172. ;; 5. Viewing Cross-References
  173. ;; When point is on the KEY argument of a cross-referencing macro
  174. ;; (`\label', `\ref', `\cite', `\bibitem', `\index', and variations)
  175. ;; or inside a BibTeX database entry, you can press `C-c &'
  176. ;; (`reftex-view-crossref') to display corresponding locations in the
  177. ;; document and associated BibTeX database files.
  178. ;; When the enclosing macro is `\cite' or `\ref' and no other message
  179. ;; occupies the echo area, information about the citation or label
  180. ;; will automatically be displayed in the echo area.
  181. ;;
  182. ;; 6. Multifile Documents
  183. ;; Multifile Documents are fully supported. The included files must
  184. ;; have a file variable `TeX-master' or `tex-main-file' pointing to
  185. ;; the master file. RefTeX provides cross-referencing information
  186. ;; from all parts of the document, and across document borders
  187. ;; (`xr.sty').
  188. ;;
  189. ;; 7. Document Parsing
  190. ;; RefTeX needs to parse the document in order to find labels and
  191. ;; other information. It does it automatically once and updates its
  192. ;; list internally when `reftex-label' and `reftex-index' are used.
  193. ;; To enforce reparsing, call any of the commands described above
  194. ;; with a raw `C-u' prefix, or press the `r' key in the label
  195. ;; selection buffer, the table of contents buffer, or the index
  196. ;; buffer.
  197. ;;
  198. ;; 8. AUCTeX
  199. ;; If your major LaTeX mode is AUCTeX, RefTeX can cooperate with it
  200. ;; (see variable `reftex-plug-into-AUCTeX'). AUCTeX contains style
  201. ;; files which trigger appropriate settings in RefTeX, so that for
  202. ;; many of the popular LaTeX packages no additional customizations
  203. ;; will be necessary.
  204. ;;
  205. ;; 9. Useful Settings
  206. ;; To make RefTeX faster for large documents, try these:
  207. ;; (setq reftex-enable-partial-scans t)
  208. ;; (setq reftex-save-parse-info t)
  209. ;; (setq reftex-use-multiple-selection-buffers t)
  210. ;;
  211. ;; To integrate with AUCTeX, use
  212. ;; (setq reftex-plug-into-AUCTeX t)
  213. ;;
  214. ;; To make your own LaTeX macro definitions known to RefTeX,
  215. ;; customize the variables
  216. ;; `reftex-label-alist' (for label macros/environments)
  217. ;; `reftex-section-levels' (for sectioning commands)
  218. ;; `reftex-cite-format' (for `\cite'-like macros)
  219. ;; `reftex-index-macros' (for `\index'-like macros)
  220. ;; `reftex-index-default-macro' (to set the default macro)
  221. ;; If you have a large number of macros defined, you may want to write
  222. ;; an AUCTeX style file to support them with both AUCTeX and RefTeX.
  223. ;;
  224. ;; 10. Where Next?
  225. ;; Go ahead and use RefTeX. Use its menus until you have picked up
  226. ;; the key bindings. For an overview of what you can do in each of
  227. ;; the different special buffers, press `?'. Read the manual if you
  228. ;; get stuck, of if you are curious what else might be available.
  229. ;; The first part of the manual explains in a tutorial way how to use
  230. ;; and customize RefTeX. The second part is a command and variable
  231. ;; reference.
  232. ;;
  233. ;;---------------------------------------------------------------------------
  234. ;;
  235. ;; AUTHOR
  236. ;; ======
  237. ;;
  238. ;; Carsten Dominik <dominik@science.uva.nl>
  239. ;;
  240. ;; with contributions from Stephen Eglen
  241. ;;
  242. ;; RefTeX is bundled with Emacs and available as a plug-in package for
  243. ;; XEmacs 21.x. If you need to install it yourself, you can find a
  244. ;; distribution at
  245. ;;
  246. ;; http://zon.astro.uva.nl/~dominik/Tools/
  247. ;;
  248. ;; THANKS TO:
  249. ;; ---------
  250. ;; Thanks to the people on the Net who have used RefTeX and helped
  251. ;; developing it with their reports. In particular thanks to
  252. ;;
  253. ;; Fran Burstall, Alastair Burt, Soren Dayton, Stephen Eglen,
  254. ;; Karl Eichwalder, Peter Galbraith, Dieter Kraft, Kai Grossjohann,
  255. ;; Frank Harrell, Adrian Lanz, Rory Molinari, Stefan Monnier,
  256. ;; Laurent Mugnier, Sudeep Kumar Palat, Daniel Polani, Robin Socha,
  257. ;; Richard Stanton, Allan Strand, Jan Vroonhof, Christoph Wedler,
  258. ;; Alan Williams.
  259. ;;
  260. ;; Finally thanks to Uwe Bolick who first got me (some years ago) into
  261. ;; supporting LaTeX labels and references with an editor (which was
  262. ;; MicroEmacs at the time).
  263. ;;
  264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ;;
  266. ;;;;;;
  267. ;;; Code:
  268. (eval-when-compile (require 'cl))
  269. ;; Stuff that needs to be there when we use defcustom
  270. (require 'custom)
  271. (require 'easymenu)
  272. (defvar reftex-tables-dirty t
  273. "Flag showing if tables need to be re-computed.")
  274. (eval-and-compile
  275. (defun reftex-set-dirty (symbol value)
  276. (setq reftex-tables-dirty t)
  277. (set symbol value)))
  278. ;;; =========================================================================
  279. ;;;
  280. ;;; Configuration variables
  281. (require 'reftex-vars)
  282. ;;; =========================================================================
  283. ;;;
  284. ;;; Define the formal stuff for a minor mode named RefTeX.
  285. ;;;
  286. (defconst reftex-version "RefTeX version 4.31"
  287. "Version string for RefTeX.")
  288. (defvar reftex-mode-map (make-sparse-keymap)
  289. "Keymap for RefTeX mode.")
  290. (defvar reftex-mode-menu nil)
  291. (defvar reftex-syntax-table nil)
  292. (defvar reftex-syntax-table-for-bib nil)
  293. (unless reftex-syntax-table
  294. (setq reftex-syntax-table (copy-syntax-table))
  295. (modify-syntax-entry ?\( "." reftex-syntax-table)
  296. (modify-syntax-entry ?\) "." reftex-syntax-table))
  297. (unless reftex-syntax-table-for-bib
  298. (setq reftex-syntax-table-for-bib
  299. (copy-syntax-table reftex-syntax-table))
  300. (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib)
  301. (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib)
  302. (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib)
  303. (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib))
  304. ;; The following definitions are out of place, but I need them here
  305. ;; to make the compilation of reftex-mode not complain.
  306. (defvar reftex-auto-view-crossref-timer nil
  307. "The timer used for auto-view-crossref.")
  308. (defvar reftex-toc-auto-recenter-timer nil
  309. "The idle timer used to recenter the toc window.")
  310. ;;; =========================================================================
  311. ;;;
  312. ;;; Parser functions
  313. (autoload 'reftex-parse-one "reftex-parse"
  314. "Re-parse this file." t)
  315. (autoload 'reftex-parse-all "reftex-parse"
  316. "Re-parse entire document." t)
  317. (autoload 'reftex-do-parse "reftex-parse")
  318. (autoload 'reftex-where-am-I "reftex-parse")
  319. (autoload 'reftex-init-section-numbers "reftex-parse")
  320. (autoload 'reftex-section-info "reftex-parse")
  321. (autoload 'reftex-section-number "reftex-parse")
  322. (autoload 'reftex-what-macro "reftex-parse")
  323. (autoload 'reftex-what-macro-safe "reftex-parse")
  324. (autoload 'reftex-index-info "reftex-parse")
  325. (autoload 'reftex-index-info-safe "reftex-parse")
  326. (autoload 'reftex-short-context "reftex-parse")
  327. (autoload 'reftex-what-environment "reftex-parse")
  328. (autoload 'reftex-what-special-env "reftex-parse")
  329. (autoload 'reftex-move-over-touching-args "reftex-parse")
  330. (autoload 'reftex-notice-new "reftex-parse")
  331. (autoload 'reftex-nth-arg "reftex-parse")
  332. (autoload 'reftex-locate-bibliography-files "reftex-parse")
  333. (autoload 'reftex-ensure-index-support "reftex-parse")
  334. (autoload 'reftex-everything-regexp "reftex-parse")
  335. ;;; =========================================================================
  336. ;;;
  337. ;;; Labels and References
  338. (autoload 'reftex-label-location "reftex-ref")
  339. (autoload 'reftex-label-info-update "reftex-ref")
  340. (autoload 'reftex-label-info "reftex-ref")
  341. (autoload 'reftex-label "reftex-ref"
  342. "Insert a unique label." t)
  343. (autoload 'reftex-reference "reftex-ref"
  344. "Make a LaTeX reference." t)
  345. (autoload 'reftex-varioref-vref "reftex-ref"
  346. "Make a varioref reference." t)
  347. (autoload 'reftex-fancyref-fref "reftex-ref"
  348. "Make a fancyref \\fref reference." t)
  349. (autoload 'reftex-fancyref-Fref "reftex-ref"
  350. "Make a fancyref \\Fref reference." t)
  351. (autoload 'reftex-show-label-location "reftex-ref")
  352. (autoload 'reftex-query-label-type "reftex-ref")
  353. (autoload 'reftex-goto-label "reftex-ref"
  354. "Prompt for label name and go to that location." t)
  355. ;;; =========================================================================
  356. ;;;
  357. ;;; Table of contents
  358. (autoload 'reftex-toc "reftex-toc"
  359. "Show the table of contents for the current document." t)
  360. (autoload 'reftex-toc-recenter "reftex-toc"
  361. "Display the TOC window and highlight line corresponding to current position." t)
  362. (autoload 'reftex-toggle-auto-toc-recenter "reftex-toc"
  363. "Toggle automatic recentering of TOC window." t)
  364. ;;; =========================================================================
  365. ;;;
  366. ;;; BibTeX citations.
  367. (autoload 'reftex-citep "reftex-cite")
  368. (autoload 'reftex-citet "reftex-cite")
  369. (autoload 'reftex-make-cite-echo-string "reftex-cite")
  370. (autoload 'reftex-get-bibfile-list "reftex-cite")
  371. (autoload 'reftex-pop-to-bibtex-entry "reftex-cite")
  372. (autoload 'reftex-end-of-bib-entry "reftex-cite")
  373. (autoload 'reftex-parse-bibtex-entry "reftex-cite")
  374. (autoload 'reftex-citation "reftex-cite"
  375. "Make a citation using BibTeX database files." t)
  376. (autoload 'reftex-default-bibliography "reftex-cite")
  377. (autoload 'reftex-bib-or-thebib "reftex-cite")
  378. (autoload 'reftex-create-bibtex-file "reftex-cite")
  379. ;;; =========================================================================
  380. ;;;
  381. ;;; Selection
  382. (autoload 'reftex-select-label-mode "reftex-sel")
  383. (autoload 'reftex-select-bib-mode "reftex-sel")
  384. (autoload 'reftex-find-start-point "reftex-sel")
  385. (autoload 'reftex-insert-docstruct "reftex-sel")
  386. (autoload 'reftex-get-offset "reftex-sel")
  387. (autoload 'reftex-select-item "reftex-sel")
  388. ;;; =========================================================================
  389. ;;;
  390. ;;; Index support
  391. (autoload 'reftex-index "reftex-index"
  392. "Query for an index macro and insert it along with its arguments." t)
  393. (autoload 'reftex-index-selection-or-word "reftex-index"
  394. "Put selection or the word near point into the default index macro." t)
  395. (autoload 'reftex-index-phrase-selection-or-word "reftex-index"
  396. "Put selection or the word near point into Index Phrases File." t)
  397. (autoload 'reftex-display-index "reftex-index"
  398. "Display a buffer with an index compiled from the current document." t)
  399. (autoload 'reftex-index-visit-phrases-buffer "reftex-index"
  400. "Visit the Index Phrases File." t)
  401. (autoload 'reftex-index-phrases-mode "reftex-index"
  402. "Major mode for managing the Index phrases of a LaTeX document." t)
  403. (autoload 'reftex-index-complete-tag "reftex-index")
  404. (autoload 'reftex-index-complete-key "reftex-index")
  405. (autoload 'reftex-index-show-entry "reftex-index")
  406. (autoload 'reftex-index-select-tag "reftex-index")
  407. ;;; =========================================================================
  408. ;;;
  409. ;;; View cross references
  410. (autoload 'reftex-view-crossref "reftex-dcr"
  411. "View cross reference of \\ref or \\cite macro at point." t)
  412. (autoload 'reftex-mouse-view-crossref "reftex-dcr"
  413. "View cross reference of \\ref or \\cite macro where you click." t)
  414. (autoload 'reftex-toggle-auto-view-crossref "reftex-dcr")
  415. (autoload 'reftex-view-crossref-from-bibtex "reftex-dcr"
  416. "View location in a LaTeX document which cites the BibTeX entry at point." t)
  417. ;;; =========================================================================
  418. ;;;
  419. ;;; Operations on entire Multifile documents
  420. (autoload 'reftex-create-tags-file "reftex-global"
  421. "Create TAGS file by running `etags' on the current document." t)
  422. (autoload 'reftex-grep-document "reftex-global"
  423. "Run grep query through all files related to this document." t)
  424. (autoload 'reftex-search-document "reftex-global"
  425. "Regexp search through all files of the current TeX document." t)
  426. (autoload 'reftex-query-replace-document "reftex-global"
  427. "Run a query-replace-regexp of FROM with TO over the entire TeX document." t)
  428. (autoload 'reftex-find-duplicate-labels "reftex-global"
  429. "Produce a list of all duplicate labels in the document." t)
  430. (autoload 'reftex-change-label "reftex-global"
  431. "Query replace FROM with TO in all \\label and \\ref commands." t)
  432. (autoload 'reftex-renumber-simple-labels "reftex-global"
  433. "Renumber all simple labels in the document to make them sequentially." t)
  434. (autoload 'reftex-save-all-document-buffers "reftex-global"
  435. "Save all documents associated with the current document." t)
  436. ;;; =========================================================================
  437. ;;;
  438. ;;; AUCTeX Interface
  439. (autoload 'reftex-arg-label "reftex-auc")
  440. (autoload 'reftex-arg-cite "reftex-auc")
  441. (autoload 'reftex-arg-index-tag "reftex-auc")
  442. (autoload 'reftex-arg-index "reftex-auc")
  443. (autoload 'reftex-plug-into-AUCTeX "reftex-auc")
  444. (autoload 'reftex-toggle-plug-into-AUCTeX "reftex-auc"
  445. "Toggle Interface between AUCTeX and RefTeX on and off." t)
  446. (autoload 'reftex-add-label-environments "reftex-auc")
  447. (autoload 'reftex-add-to-label-alist "reftex-auc")
  448. (autoload 'reftex-add-section-levels "reftex-auc")
  449. (autoload 'reftex-notice-new-section "reftex-auc")
  450. ;;;###autoload
  451. (defun turn-on-reftex ()
  452. "Turn on RefTeX mode."
  453. (reftex-mode t))
  454. (put 'reftex-mode :included '(memq major-mode '(latex-mode tex-mode)))
  455. (put 'reftex-mode :menu-tag "RefTeX Mode")
  456. ;;;###autoload
  457. (define-minor-mode reftex-mode
  458. "Toggle RefTeX mode.
  459. With a prefix argument ARG, enable RefTeX mode if ARG is
  460. positive, and disable it otherwise. If called from Lisp, enable
  461. the mode if ARG is omitted or nil.
  462. RefTeX mode is a buffer-local minor mode with distinct support
  463. for \\label, \\ref and \\cite in LaTeX.
  464. \\<reftex-mode-map>A Table of Contents of the entire (multifile) document with browsing
  465. capabilities is available with `\\[reftex-toc]'.
  466. Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'.
  467. When referencing, you get a menu with all labels of a given type and
  468. context of the label definition. The selected label is inserted as a
  469. \\ref macro.
  470. Citations can be made with `\\[reftex-citation]' which will use a regular expression
  471. to pull out a *formatted* list of articles from your BibTeX
  472. database. The selected citation is inserted as a \\cite macro.
  473. Index entries can be made with `\\[reftex-index-selection-or-word]' which indexes the word at point
  474. or the current selection. More general index entries are created with
  475. `\\[reftex-index]'. `\\[reftex-display-index]' displays the compiled index.
  476. Most command have help available on the fly. This help is accessed by
  477. pressing `?' to any prompt mentioning this feature.
  478. Extensive documentation about RefTeX is available in Info format.
  479. You can view this information with `\\[reftex-info]'.
  480. \\{reftex-mode-map}
  481. Under X, these and other functions will also be available as `Ref' menu
  482. on the menu bar.
  483. ------------------------------------------------------------------------------"
  484. :lighter " Ref" :keymap reftex-mode-map
  485. (if reftex-mode
  486. (progn
  487. ;; Mode was turned on
  488. (easy-menu-add reftex-mode-menu)
  489. (and reftex-plug-into-AUCTeX
  490. (reftex-plug-into-AUCTeX))
  491. (unless (get 'reftex-auto-view-crossref 'initialized)
  492. (and reftex-auto-view-crossref
  493. (reftex-toggle-auto-view-crossref))
  494. (put 'reftex-auto-view-crossref 'initialized t))
  495. (unless (get 'reftex-auto-recenter-toc 'initialized)
  496. (and (eq reftex-auto-recenter-toc t)
  497. (reftex-toggle-auto-toc-recenter))
  498. (put 'reftex-auto-recenter-toc 'initialized t))
  499. ;; Prepare the special syntax tables.
  500. (setq reftex-syntax-table (copy-syntax-table (syntax-table)))
  501. (modify-syntax-entry ?\( "." reftex-syntax-table)
  502. (modify-syntax-entry ?\) "." reftex-syntax-table)
  503. (setq reftex-syntax-table-for-bib
  504. (copy-syntax-table reftex-syntax-table))
  505. (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib)
  506. (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib)
  507. (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib)
  508. (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib))
  509. ;; Mode was turned off
  510. (easy-menu-remove reftex-mode-menu)))
  511. (defvar reftex-docstruct-symbol)
  512. (defun reftex-kill-buffer-hook ()
  513. "Save RefTeX's parse file for this buffer if the information has changed."
  514. ;; Save the parsing information if it was modified.
  515. ;; This function should be installed in `kill-buffer-hook'.
  516. ;; We are careful to make sure nothing goes wrong in this function.
  517. (when (and (boundp 'reftex-mode) reftex-mode
  518. (boundp 'reftex-save-parse-info) reftex-save-parse-info
  519. (boundp 'reftex-docstruct-symbol) reftex-docstruct-symbol
  520. (symbol-value reftex-docstruct-symbol)
  521. (get reftex-docstruct-symbol 'modified))
  522. ;; Write the file.
  523. (condition-case nil
  524. (reftex-access-parse-file 'write)
  525. (error nil))))
  526. (defun reftex-kill-emacs-hook ()
  527. "Call `reftex-kill-buffer-hook' on all buffers."
  528. ;; This function should be installed in `kill-emacs-hook'.
  529. (save-excursion
  530. (mapcar (lambda (buf)
  531. (set-buffer buf)
  532. (reftex-kill-buffer-hook))
  533. (buffer-list))))
  534. ;;; =========================================================================
  535. ;;;
  536. ;;; Silence warnings about variables in other packages.
  537. (defvar TeX-master)
  538. (defvar LaTeX-section-hook)
  539. (defvar LaTeX-label-function)
  540. (defvar tex-main-file)
  541. (defvar outline-minor-mode)
  542. (defvar font-lock-mode)
  543. (defvar font-lock-keywords)
  544. (defvar font-lock-fontify-region-function)
  545. ;;; =========================================================================
  546. ;;;
  547. ;;; Multibuffer Variables
  548. ;;;
  549. ;; Technical notes: These work as follows: We keep just one list
  550. ;; of labels for each master file - this can save a lot of memory.
  551. ;; `reftex-master-index-list' is an alist which connects the true file name
  552. ;; of each master file with the symbols holding the information on that
  553. ;; document. Each buffer has local variables which point to these symbols.
  554. ;; List of variables which handle the multifile stuff.
  555. ;; This list is used to tie, untie, and reset these symbols.
  556. (defconst reftex-multifile-symbols
  557. '(reftex-docstruct-symbol))
  558. ;; Alist connecting master file names with the corresponding lisp symbols.
  559. (defvar reftex-master-index-list nil)
  560. ;; Last index used for a master file.
  561. (defvar reftex-multifile-index 0)
  562. ;; Variable holding the symbol with the label list of the document.
  563. (defvar reftex-docstruct-symbol nil)
  564. (make-variable-buffer-local 'reftex-docstruct-symbol)
  565. (defun reftex-next-multifile-index ()
  566. ;; Return the next free index for multifile symbols.
  567. (incf reftex-multifile-index))
  568. (defun reftex-tie-multifile-symbols ()
  569. ;; Tie the buffer-local symbols to globals connected with the master file.
  570. ;; If the symbols for the current master file do not exist, they are created.
  571. (let* ((master (file-truename (reftex-TeX-master-file)))
  572. (index (assoc master reftex-master-index-list))
  573. (symlist reftex-multifile-symbols)
  574. symbol symname newflag)
  575. ;; Find the correct index.
  576. (if index
  577. ;; symbols do exist
  578. (setq index (cdr index))
  579. ;; Get a new index and add info to the alist.
  580. (setq index (reftex-next-multifile-index)
  581. newflag t)
  582. (push (cons master index) reftex-master-index-list))
  583. ;; Get/create symbols and tie them.
  584. (while symlist
  585. (setq symbol (car symlist)
  586. symlist (cdr symlist)
  587. symname (symbol-name symbol))
  588. (set symbol (intern (concat symname "-" (int-to-string index))))
  589. (put (symbol-value symbol) :master-index index)
  590. ;; Initialize if new symbols.
  591. (when newflag
  592. (set (symbol-value symbol) nil)
  593. (put (symbol-value symbol) 'reftex-index-macros-style '(default))))
  594. ;; Return t if the symbols did already exist, nil when we've made them.
  595. (not newflag)))
  596. (defun reftex-untie-multifile-symbols ()
  597. ;; Remove ties from multifile symbols, so that next use makes new ones.
  598. (let ((symlist reftex-multifile-symbols)
  599. (symbol nil))
  600. (while symlist
  601. (setq symbol (car symlist)
  602. symlist (cdr symlist))
  603. (set symbol nil))))
  604. (defun reftex-TeX-master-file ()
  605. ;; Return the name of the master file associated with the current buffer.
  606. ;; When AUCTeX is loaded, we will use it's more sophisticated method.
  607. ;; We also support the default TeX and LaTeX modes by checking for a
  608. ;; variable tex-main-file.
  609. (let
  610. ((master
  611. (cond
  612. ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism.
  613. (condition-case nil
  614. (TeX-master-file t)
  615. (error (buffer-file-name))))
  616. ((fboundp 'tex-main-file) (tex-main-file)) ; Emacs LaTeX mode
  617. ((boundp 'TeX-master) ; The variable is defined - let's use it.
  618. (cond
  619. ((eq TeX-master t)
  620. (buffer-file-name))
  621. ((eq TeX-master 'shared)
  622. (setq TeX-master (read-file-name "Master file: "
  623. nil nil t nil)))
  624. (TeX-master)
  625. (t
  626. (setq TeX-master (read-file-name "Master file: "
  627. nil nil t nil)))))
  628. ((boundp 'tex-main-file)
  629. ;; This is the variable from the default TeX modes.
  630. (cond
  631. ((stringp tex-main-file)
  632. ;; ok, this must be it
  633. tex-main-file)
  634. (t
  635. ;; In this case, the buffer is its own master.
  636. (buffer-file-name))))
  637. (t
  638. ;; Know nothing about master file. Assume this is a master file.
  639. (buffer-file-name)))))
  640. (cond
  641. ((null master)
  642. (error "Need a filename for this buffer, please save it first"))
  643. ((or (file-exists-p (concat master ".tex"))
  644. (reftex-get-buffer-visiting (concat master ".tex")))
  645. ;; Ahh, an extra .tex was missing...
  646. (setq master (concat master ".tex")))
  647. ((or (file-exists-p master)
  648. (reftex-get-buffer-visiting master))
  649. ;; We either see the file, or have a buffer on it. OK.
  650. )
  651. (t
  652. ;; Use buffer file name.
  653. (setq master (buffer-file-name))))
  654. (expand-file-name master)))
  655. (defun reftex-is-multi ()
  656. ;; Tell if this is a multifile document. When not sure, say yes.
  657. (let ((entry (assq 'is-multi (symbol-value reftex-docstruct-symbol))))
  658. (if entry
  659. (nth 1 entry)
  660. t)))
  661. (defun reftex-set-cite-format (value)
  662. "Set the document-local value of `reftex-cite-format'.
  663. When such a value exists, it overwrites the setting given with
  664. `reftex-cite-format'. See the documentation of `reftex-cite-format'
  665. for possible values. This function should be used from AUCTeX style files."
  666. (unless reftex-docstruct-symbol
  667. (reftex-tie-multifile-symbols))
  668. (when (and reftex-docstruct-symbol
  669. (symbolp reftex-docstruct-symbol))
  670. (put reftex-docstruct-symbol 'reftex-cite-format value)))
  671. (defun reftex-get-cite-format ()
  672. ;; Return the current citation format. Either the document-local value in
  673. ;; reftex-cite-format-symbol, or the global value in reftex-cite-format.
  674. (if (and reftex-docstruct-symbol
  675. (symbolp reftex-docstruct-symbol)
  676. (get reftex-docstruct-symbol 'reftex-cite-format))
  677. (get reftex-docstruct-symbol 'reftex-cite-format)
  678. reftex-cite-format))
  679. (defun reftex-add-index-macros (entry-list)
  680. "Add index macro descriptions to `reftex-index-macros-style'.
  681. The format of ENTRY-LIST is exactly like `reftex-index-macros'. See there
  682. for details.
  683. This function makes it possible to support RefTeX from AUCTeX style files.
  684. The entries in ENTRY-LIST will be processed after the user settings in
  685. `reftex-index-entries', and before the defaults. Any changes made to
  686. `reftex-label-alist-style' will raise a flag to the effect that
  687. the label information is recompiled on next use."
  688. (unless reftex-docstruct-symbol
  689. (reftex-tie-multifile-symbols))
  690. (when (and reftex-docstruct-symbol
  691. (symbolp reftex-docstruct-symbol))
  692. (let ((list (get reftex-docstruct-symbol 'reftex-index-macros-style))
  693. entry changed)
  694. (while entry-list
  695. (setq entry (pop entry-list))
  696. ;; When it is a symbol, remove all other symbols
  697. (and (symbolp entry)
  698. (not (memq entry list))
  699. (setq list (reftex-remove-symbols-from-list list)))
  700. ;; Add to list unless already member
  701. (unless (member entry list)
  702. (setq reftex-tables-dirty t
  703. changed t)
  704. (push entry list)))
  705. (when changed
  706. (put reftex-docstruct-symbol 'reftex-index-macros-style list)))))
  707. ;;; =========================================================================
  708. ;;;
  709. ;;; Functions to compile the tables, reset the mode etc.
  710. ;; The following constants are derived from `reftex-label-alist'.
  711. ;; Prompt used for label type queries directed to the user.
  712. (defvar reftex-type-query-prompt nil)
  713. ;; Help string for label type queries.
  714. (defvar reftex-type-query-help nil)
  715. ;; Alist relating label type to reference format.
  716. (defvar reftex-typekey-to-format-alist nil)
  717. ;; Alist relating label type to label prefix.
  718. (defvar reftex-typekey-to-prefix-alist nil)
  719. ;; Alist relating environments or macros to label type and context regexp.
  720. (defvar reftex-env-or-mac-alist nil)
  721. ;; List of special environment parser functions
  722. (defvar reftex-special-env-parsers nil)
  723. ;; List of macros carrying a label.
  724. (defvar reftex-label-mac-list nil)
  725. ;; List of environments carrying a label.
  726. (defvar reftex-label-env-list nil)
  727. ;; List of all typekey letters in use.
  728. (defvar reftex-typekey-list nil)
  729. ;; Alist relating magic words to a label type.
  730. (defvar reftex-words-to-typekey-alist nil)
  731. ;; Alist relating label prefixes to a label type.
  732. (defvar reftex-prefix-to-typekey-alist nil)
  733. ;; The last list-of-labels entry used in a reference.
  734. (defvar reftex-last-used-reference (list nil nil nil nil))
  735. ;; Alist relating index macros to other info.
  736. (defvar reftex-key-to-index-macro-alist nil)
  737. ;; Prompt for index macro queries
  738. (defvar reftex-query-index-macro-prompt nil)
  739. ;; Help string for index macro queries
  740. (defvar reftex-query-index-macro-help nil)
  741. ;; The message when follow-mode is suspended
  742. (defvar reftex-no-follow-message
  743. "No follow-mode into unvisited file. Press SPC to visit it.")
  744. (defvar reftex-no-info-message
  745. "%s: info not available, use `\\[reftex-view-crossref]' to get it.")
  746. ;; Global variables used for communication between functions.
  747. (defvar reftex-default-context-position nil)
  748. (defvar reftex-location-start nil)
  749. (defvar reftex-call-back-to-this-buffer nil)
  750. (defvar reftex-select-return-marker (make-marker))
  751. (defvar reftex-active-toc nil)
  752. (defvar reftex-tex-path nil)
  753. (defvar reftex-bib-path nil)
  754. (defvar reftex-select-marked nil)
  755. (defvar reftex-last-follow-point nil)
  756. (defvar reftex-latex-syntax-table nil)
  757. (defvar reftex-prefix nil)
  758. (defvar reftex-section-levels-all nil)
  759. (defvar reftex-buffers-with-changed-invisibility nil)
  760. (defvar reftex-callback-fwd t)
  761. (defvar reftex-last-toc-master nil
  762. "Stores the name of the tex file that `reftex-toc' was last run on.")
  763. ;; Marker for return point from recursive edit
  764. (defvar reftex-recursive-edit-marker (make-marker))
  765. ;; List of buffers created temporarily for lookup, which should be killed.
  766. (defvar reftex-buffers-to-kill nil)
  767. ;; Regexp to find anything.
  768. (defvar reftex-section-regexp nil)
  769. (defvar reftex-section-or-include-regexp nil)
  770. (defvar reftex-index-macro-regexp nil)
  771. (defvar reftex-index-level-re nil)
  772. (defvar reftex-index-key-end-re nil)
  773. (defvar reftex-find-index-entry-regexp-format nil)
  774. (defvar reftex-everything-regexp nil)
  775. (defvar reftex-everything-regexp-no-index nil)
  776. (defvar reftex-index-re nil)
  777. (defvar reftex-find-citation-regexp-format
  778. "\\\\\\([a-zA-Z]*cite[*a-zA-Z]*\\*?\\|bibentry\\)\\(\\[[^]]*\\]\\|{[^}]*}\\)*{\\([^}]*,\\)?\\(%s\\)[},]")
  779. (defvar reftex-find-reference-format
  780. "\\\\\\(ref[a-zA-Z]*\\|[a-zA-Z]*ref\\(range\\)?\\)\\*?\\(\\[[^]]*\\]\\|{[^}]*}\\)*{\\(%s\\)}")
  781. (defvar reftex-macros-with-labels nil)
  782. (defvar reftex-macros-with-index nil)
  783. (defvar reftex-index-macro-alist nil)
  784. (defvar reftex-find-label-regexp-format nil)
  785. (defvar reftex-find-label-regexp-format2 nil)
  786. (defvar reftex-memory nil
  787. "Memorizes old variable values to indicate changes in these variables.")
  788. ;; A list of all variables in the cache.
  789. ;; The cache is used to save the compiled versions of some variables.
  790. (defconst reftex-cache-variables
  791. '(reftex-memory ;; This MUST ALWAYS be the first!
  792. ;; Outline
  793. reftex-section-levels-all
  794. ;; Labels
  795. reftex-env-or-mac-alist
  796. reftex-special-env-parsers
  797. reftex-macros-with-labels
  798. reftex-label-mac-list
  799. reftex-label-env-list
  800. reftex-typekey-list
  801. reftex-typekey-to-format-alist
  802. reftex-typekey-to-prefix-alist
  803. reftex-words-to-typekey-alist
  804. reftex-prefix-to-typekey-alist
  805. reftex-type-query-prompt
  806. reftex-type-query-help
  807. ;; Index
  808. reftex-index-macro-alist
  809. reftex-macros-with-index
  810. reftex-query-index-macro-prompt
  811. reftex-query-index-macro-help
  812. reftex-key-to-index-macro-alist
  813. ;; Regular expressions
  814. reftex-section-regexp
  815. reftex-section-or-include-regexp
  816. reftex-index-re
  817. reftex-everything-regexp
  818. reftex-everything-regexp-no-index
  819. reftex-find-label-regexp-format
  820. reftex-find-label-regexp-format2
  821. reftex-find-index-entry-regexp-format
  822. ))
  823. (defun reftex-ensure-compiled-variables ()
  824. ;; Recompile the label alist when necessary
  825. (let* ((mem reftex-memory)
  826. (cache (get reftex-docstruct-symbol 'reftex-cache))
  827. (cmem (car cache))
  828. (alist reftex-label-alist)
  829. (levels (get reftex-docstruct-symbol 'reftex-section-levels))
  830. (style (get reftex-docstruct-symbol 'reftex-label-alist-style))
  831. (default reftex-default-label-alist-entries)
  832. (index reftex-index-macros)
  833. (istyle (get reftex-docstruct-symbol 'reftex-index-macros-style)))
  834. (cond
  835. (reftex-tables-dirty (reftex-compile-variables))
  836. ((and (eq alist (nth 0 mem))
  837. (eq levels (nth 1 mem))
  838. (eq style (nth 2 mem))
  839. (eq default (nth 3 mem))
  840. (eq index (nth 4 mem))
  841. (eq istyle (nth 5 mem)))) ;; everything is OK
  842. ((and (eq alist (nth 0 cmem))
  843. (eq levels (nth 1 cmem))
  844. (eq style (nth 2 cmem))
  845. (eq default (nth 2 cmem))
  846. (eq index (nth 4 cmem))
  847. (eq istyle (nth 5 cmem)))
  848. ;; restore the cache
  849. (message "Restoring cache")
  850. (mapcar (lambda (sym) (set sym (pop cache))) reftex-cache-variables))
  851. (t (reftex-compile-variables)))))
  852. (defun reftex-reset-mode ()
  853. "Reset RefTeX Mode.
  854. This will re-compile the configuration information and remove all
  855. current scanning information and the parse file to enforce a rescan
  856. on next use."
  857. (interactive)
  858. ;; Reset the file search path variables
  859. (loop for prop in '(status master-dir recursive-path rec-type) do
  860. (put 'reftex-tex-path prop nil)
  861. (put 'reftex-bib-path prop nil))
  862. ;; Kill temporary buffers associated with RefTeX - just in case they
  863. ;; were not cleaned up properly
  864. (save-excursion
  865. (let ((buffer-list '("*RefTeX Help*" "*RefTeX Select*"
  866. "*Duplicate Labels*" "*toc*" " *RefTeX-scratch*"))
  867. buf)
  868. (while (setq buf (pop buffer-list))
  869. (if (get-buffer buf)
  870. (kill-buffer buf))))
  871. (reftex-erase-all-selection-and-index-buffers))
  872. ;; Make sure the current document will be rescanned soon.
  873. (reftex-reset-scanning-information)
  874. ;; Remove any parse info file
  875. (reftex-access-parse-file 'kill)
  876. ;; Plug functions into AUCTeX if the user option says so.
  877. (and reftex-plug-into-AUCTeX
  878. (reftex-plug-into-AUCTeX))
  879. (reftex-compile-variables))
  880. ;;;###autoload
  881. (defun reftex-reset-scanning-information ()
  882. "Reset the symbols containing information from buffer scanning.
  883. This enforces rescanning the buffer on next use."
  884. (if (string= reftex-last-toc-master (reftex-TeX-master-file))
  885. (reftex-erase-buffer "*toc*"))
  886. (let ((symlist reftex-multifile-symbols)
  887. symbol)
  888. (while symlist
  889. (setq symbol (car symlist)
  890. symlist (cdr symlist))
  891. (if (and (symbolp (symbol-value symbol))
  892. (not (null (symbol-value symbol))))
  893. (set (symbol-value symbol) nil)))))
  894. (defun reftex-erase-all-selection-and-index-buffers ()
  895. ;; Remove all selection buffers associated with current document.
  896. (mapc
  897. (lambda (type)
  898. (reftex-erase-buffer (reftex-make-selection-buffer-name type)))
  899. reftex-typekey-list)
  900. ;; Kill all index buffers
  901. (mapc
  902. (lambda (tag)
  903. (reftex-kill-buffer (reftex-make-index-buffer-name tag)))
  904. (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))))
  905. (defun reftex-compile-variables ()
  906. ;; Compile the information in reftex-label-alist & Co.
  907. (message "Compiling label environment definitions...")
  908. ;; Update AUCTeX style information
  909. (when (and (featurep 'tex-site) (fboundp 'TeX-update-style))
  910. (condition-case nil (TeX-update-style) (error nil)))
  911. ;; Record that we have done this, and what we have used.
  912. (setq reftex-tables-dirty nil)
  913. (setq reftex-memory
  914. (list reftex-label-alist
  915. (get reftex-docstruct-symbol 'reftex-section-levels)
  916. (get reftex-docstruct-symbol 'reftex-label-alist-style)
  917. reftex-default-label-alist-entries
  918. reftex-index-macros
  919. (get reftex-docstruct-symbol 'reftex-index-macros-style)))
  920. ;; Compile information in reftex-label-alist
  921. (let ((all (reftex-uniquify-by-car
  922. (reftex-splice-symbols-into-list
  923. (append reftex-label-alist
  924. (get reftex-docstruct-symbol
  925. 'reftex-label-alist-style)
  926. reftex-default-label-alist-entries)
  927. reftex-label-alist-builtin)
  928. '(nil)))
  929. (all-index (reftex-uniquify-by-car
  930. (reftex-splice-symbols-into-list
  931. (append reftex-index-macros
  932. (get reftex-docstruct-symbol
  933. 'reftex-index-macros-style)
  934. '(default))
  935. reftex-index-macros-builtin)))
  936. entry env-or-mac typekeychar typekey prefix context word
  937. fmt reffmt labelfmt wordlist qh-list macros-with-labels
  938. nargs nlabel opt-args cell sum i
  939. macro verify repeat nindex tag key toc-level toc-levels)
  940. (setq reftex-words-to-typekey-alist nil
  941. reftex-prefix-to-typekey-alist
  942. '(("sec:" . "s") ("cha:" . "s") ("chap:" . "s"))
  943. reftex-typekey-list nil
  944. reftex-typekey-to-format-alist nil
  945. reftex-typekey-to-prefix-alist nil
  946. reftex-env-or-mac-alist nil
  947. reftex-label-env-list nil
  948. reftex-label-mac-list nil)
  949. (while all
  950. (catch 'next-entry
  951. (setq entry (car all)
  952. env-or-mac (car entry)
  953. entry (cdr entry)
  954. all (cdr all))
  955. (if (null env-or-mac)
  956. (setq env-or-mac ""))
  957. (if (stringp (car entry))
  958. ;; This is before version 2.00 - convert entry to new format
  959. ;; This is just to keep old users happy
  960. (setq entry (cons (string-to-char (car entry))
  961. (cons (concat (car entry) ":")
  962. (cdr entry)))))
  963. (setq typekeychar (nth 0 entry)
  964. typekey (if typekeychar (char-to-string typekeychar) nil)
  965. prefix (nth 1 entry)
  966. fmt (nth 2 entry)
  967. context (nth 3 entry)
  968. wordlist (nth 4 entry)
  969. toc-level (nth 5 entry))
  970. (if (stringp wordlist)
  971. ;; This is before version 2.04 - convert to new format
  972. (setq wordlist (nthcdr 4 entry)))
  973. (if (and (stringp fmt)
  974. (string-match "@" fmt))
  975. ;; Special syntax for specifying a label format
  976. (setq fmt (split-string fmt "@+"))
  977. (setq fmt (list "\\label{%s}" fmt)))
  978. (setq labelfmt (car fmt)
  979. reffmt (nth 1 fmt))
  980. ;; Note a new typekey
  981. (if typekey
  982. (add-to-list 'reftex-typekey-list typekey))
  983. (if (and typekey prefix
  984. (not (assoc prefix reftex-prefix-to-typekey-alist)))
  985. (add-to-list 'reftex-prefix-to-typekey-alist
  986. (cons prefix typekey)))
  987. (if (and typekey prefix
  988. (not (assoc typekey reftex-typekey-to-prefix-alist)))
  989. (add-to-list 'reftex-typekey-to-prefix-alist
  990. (cons typekey prefix)))
  991. ;; Check if this is a macro or environment
  992. (cond
  993. ((symbolp env-or-mac)
  994. ;; A special parser function
  995. (unless (fboundp env-or-mac)
  996. (message "Warning: %s does not seem to be a valid function"
  997. env-or-mac))
  998. (setq nargs nil nlabel nil opt-args nil)
  999. (add-to-list 'reftex-special-env-parsers env-or-mac)
  1000. (setq env-or-mac (symbol-name env-or-mac)))
  1001. ((string-match "\\`\\\\" env-or-mac)
  1002. ;; It's a macro
  1003. (let ((result (reftex-parse-args env-or-mac)))
  1004. (setq env-or-mac (or (first result) env-or-mac)
  1005. nargs (second result)
  1006. nlabel (third result)
  1007. opt-args (fourth result))
  1008. (if nlabel (add-to-list 'macros-with-labels env-or-mac)))
  1009. (if typekey (add-to-list 'reftex-label-mac-list env-or-mac)))
  1010. (t
  1011. ;; It's an environment
  1012. (setq nargs nil nlabel nil opt-args nil)
  1013. (cond ((string= env-or-mac "any"))
  1014. ((string= env-or-mac ""))
  1015. ((string= env-or-mac "section"))
  1016. (t
  1017. (add-to-list 'reftex-label-env-list env-or-mac)
  1018. (if toc-level
  1019. (let ((string (format "begin{%s}" env-or-mac)))
  1020. (or (assoc string toc-levels)
  1021. (push (cons string toc-level) toc-levels))))))))
  1022. ;; Translate some special context cases
  1023. (when (assq context reftex-default-context-regexps)
  1024. (setq context
  1025. (format
  1026. (cdr (assq context reftex-default-context-regexps))
  1027. (regexp-quote env-or-mac))))
  1028. ;; See if this is the first format for this typekey
  1029. (and reffmt
  1030. (not (assoc typekey reftex-typekey-to-format-alist))
  1031. (push (cons typekey reffmt) reftex-typekey-to-format-alist))
  1032. ;; See if this is the first definition for this env-or-mac
  1033. (and (not (string= env-or-mac "any"))
  1034. (not (string= env-or-mac ""))
  1035. (not (assoc env-or-mac reftex-env-or-mac-alist))
  1036. (push (list env-or-mac typekey context labelfmt
  1037. nargs nlabel opt-args)
  1038. reftex-env-or-mac-alist))
  1039. ;; Are the magic words regular expressions? Quote normal words.
  1040. (if (eq (car wordlist) 'regexp)
  1041. (setq wordlist (cdr wordlist))
  1042. (setq wordlist (mapcar 'regexp-quote wordlist)))
  1043. ;; Remember the first association of each word.
  1044. (while (stringp (setq word (pop wordlist)))
  1045. (or (assoc word reftex-words-to-typekey-alist)
  1046. (push (cons word typekey) reftex-words-to-typekey-alist)))
  1047. (cond
  1048. ((string= "" env-or-mac) nil)
  1049. ((setq cell (assoc typekey qh-list))
  1050. (push env-or-mac (cdr cell)))
  1051. (typekey
  1052. (push (list typekey env-or-mac) qh-list)))))
  1053. (setq reftex-typekey-to-prefix-alist
  1054. (nreverse reftex-typekey-to-prefix-alist))
  1055. ;; Prepare the typekey query prompt and help string.
  1056. (setq qh-list
  1057. (sort qh-list
  1058. (lambda (x1 x2)
  1059. (string< (downcase (car x1)) (downcase (car x2))))))
  1060. (setq reftex-type-query-prompt
  1061. (concat "Label type: ["
  1062. (mapconcat (lambda(x) (format "%s" (car x)))
  1063. qh-list "")
  1064. "]"))
  1065. ;; In the help string, we need to wrap lines...
  1066. (setq reftex-type-query-help
  1067. (concat
  1068. "SELECT A LABEL TYPE:\n--------------------\n"
  1069. (mapconcat
  1070. (lambda(x)
  1071. (setq sum 0)
  1072. (format " [%s] %s"
  1073. (car x)
  1074. (mapconcat (lambda(env)
  1075. (setq sum (+ sum (length env)))
  1076. (if (< sum 60)
  1077. env
  1078. (setq sum 0)
  1079. (concat "\n " env)))
  1080. (cdr x) " ")))
  1081. qh-list "\n")))
  1082. ;; Convert magic words to regular expressions. We make regular expressions
  1083. ;; which allow for some chars from the ref format to be in the buffer.
  1084. ;; These characters will be seen and removed.
  1085. (setq reftex-words-to-typekey-alist
  1086. (mapcar
  1087. (lambda (x)
  1088. (setq word (car x)
  1089. typekey (cdr x)
  1090. fmt (cdr (assoc typekey reftex-typekey-to-format-alist)))
  1091. (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\("))
  1092. (setq i 0)
  1093. (while (and (< i 10) ; maximum number of format chars allowed
  1094. (< i (length fmt))
  1095. (not (member (aref fmt i) '(?%))))
  1096. (setq word (concat word "\\|" (regexp-quote
  1097. (substring fmt 0 (1+ i)))))
  1098. (incf i))
  1099. (cons (concat word "\\)\\=") typekey))
  1100. (nreverse reftex-words-to-typekey-alist)))
  1101. ;; Parse the index macros
  1102. (setq reftex-index-macro-alist nil
  1103. reftex-key-to-index-macro-alist nil
  1104. reftex-macros-with-index nil)
  1105. (while all-index
  1106. (setq entry (car all-index)
  1107. macro (car entry)
  1108. tag (nth 1 entry)
  1109. key (nth 2 entry)
  1110. prefix (or (nth 3 entry) "")
  1111. verify (nth 4 entry)
  1112. ;; For repeat, we need to be compatible with older code
  1113. ;; This information used to be given only for the default macro,
  1114. ;; but later we required to have it for *every* index macro
  1115. repeat (cond ((> (length entry) 5) (nth 5 entry))
  1116. ((and (eq key (car reftex-index-default-macro))
  1117. (> (length reftex-index-default-macro) 2))
  1118. ;; User has old setting - respect it
  1119. (nth 2 reftex-index-default-macro))
  1120. (t t))
  1121. all-index (cdr all-index))
  1122. (let ((result (reftex-parse-args macro)))
  1123. (setq macro (or (first result) macro)
  1124. nargs (second result)
  1125. nindex (third result)
  1126. opt-args (fourth result))
  1127. (unless (member macro reftex-macros-with-index)
  1128. ;; 0 1 2 3 4 5 6 7
  1129. (push (list macro tag prefix verify nargs nindex opt-args repeat)
  1130. reftex-index-macro-alist)
  1131. (or (assoc key reftex-key-to-index-macro-alist)
  1132. (push (list key macro) reftex-key-to-index-macro-alist))
  1133. (push macro reftex-macros-with-index))))
  1134. ;; Make the prompt and help string for index macros query
  1135. (setq reftex-key-to-index-macro-alist
  1136. (sort reftex-key-to-index-macro-alist
  1137. (lambda (a b) (< (downcase (car a)) (downcase (car b))))))
  1138. (setq reftex-query-index-macro-prompt
  1139. (concat "Index macro: ["
  1140. (mapconcat (lambda (x) (char-to-string (car x)))
  1141. reftex-key-to-index-macro-alist "")
  1142. "]"))
  1143. (setq i 0
  1144. reftex-query-index-macro-help
  1145. (concat
  1146. "SELECT A MACRO:\n---------------\n"
  1147. (mapconcat
  1148. (lambda(x)
  1149. (format "[%c] %-20.20s%s" (car x) (nth 1 x)
  1150. (if (= 0 (mod (incf i) 3)) "\n" "")))
  1151. reftex-key-to-index-macro-alist "")))
  1152. ;; Make the full list of section levels
  1153. (setq reftex-section-levels-all
  1154. (append toc-levels
  1155. (get reftex-docstruct-symbol 'reftex-section-levels)
  1156. reftex-section-levels))
  1157. ;; Calculate the regular expressions
  1158. (let* (
  1159. ; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
  1160. (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because
  1161. ;;; because match number are hard coded
  1162. (label-re "\\\\label{\\([^}]*\\)}")
  1163. (include-re (concat wbol
  1164. "\\\\\\("
  1165. (mapconcat 'identity
  1166. reftex-include-file-commands "\\|")
  1167. "\\)[{ \t]+\\([^} \t\n\r]+\\)"))
  1168. (section-re
  1169. (concat wbol "\\\\\\("
  1170. (mapconcat (lambda (x) (regexp-quote (car x)))
  1171. reftex-section-levels-all "\\|")
  1172. "\\)\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n]"))
  1173. (appendix-re (concat wbol "\\(\\\\appendix\\)"))
  1174. (macro-re
  1175. (if macros-with-labels
  1176. (concat "\\("
  1177. (mapconcat 'regexp-quote macros-with-labels "\\|")
  1178. "\\)[[{]")
  1179. ""))
  1180. (index-re
  1181. (concat "\\("
  1182. (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
  1183. "\\)[[{]"))
  1184. (find-index-re-format
  1185. (concat "\\("
  1186. (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
  1187. "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
  1188. (find-label-re-format
  1189. (concat "\\("
  1190. (mapconcat 'regexp-quote (append '("\\label")
  1191. macros-with-labels) "\\|")
  1192. "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
  1193. (index-level-re
  1194. (regexp-quote (nth 0 reftex-index-special-chars)))
  1195. (index-key-end-re ;; ^]- not allowed
  1196. (concat "[^" (nth 3 reftex-index-special-chars) "]"
  1197. "[" (nth 1 reftex-index-special-chars)
  1198. (nth 2 reftex-index-special-chars) "]"))
  1199. )
  1200. (setq reftex-section-regexp section-re
  1201. reftex-section-or-include-regexp
  1202. (concat section-re "\\|" include-re)
  1203. reftex-everything-regexp
  1204. (concat label-re "\\|" section-re "\\|" include-re
  1205. "\\|" appendix-re
  1206. "\\|" index-re
  1207. (if macros-with-labels "\\|" "") macro-re)
  1208. reftex-everything-regexp-no-index
  1209. (concat label-re "\\|" section-re "\\|" include-re
  1210. "\\|" appendix-re
  1211. "\\|" "\\(\\\\6\\\\3\\\\1\\)" ; This is unlikely to match
  1212. (if macros-with-labels "\\|" "") macro-re)
  1213. reftex-index-re index-re
  1214. reftex-index-level-re index-level-re
  1215. reftex-index-key-end-re index-key-end-re
  1216. reftex-macros-with-labels macros-with-labels
  1217. reftex-find-index-entry-regexp-format find-index-re-format
  1218. reftex-find-label-regexp-format find-label-re-format
  1219. reftex-find-label-regexp-format2
  1220. "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]")
  1221. (message "Compiling label environment definitions...done")))
  1222. (put reftex-docstruct-symbol 'reftex-cache
  1223. (mapcar 'symbol-value reftex-cache-variables)))
  1224. (defun reftex-parse-args (macro)
  1225. ;; Return a list of macro name, nargs, arg-nr which is label and a list of
  1226. ;; optional argument indices.
  1227. (if (string-match "[[{]\\*?[]}]" macro)
  1228. (progn
  1229. (let ((must-match (substring macro 0 (match-beginning 0)))
  1230. (args (substring macro (match-beginning 0)))
  1231. opt-list nlabel (cnt 0))
  1232. (while (string-match "\\`[[{]\\(\\*\\)?[]}]" args)
  1233. (incf cnt)
  1234. (when (eq ?\[ (string-to-char args))
  1235. (push cnt opt-list))
  1236. (when (and (match-end 1)
  1237. (not nlabel))
  1238. (setq nlabel cnt))
  1239. (setq args (substring args (match-end 0))))
  1240. (list must-match cnt nlabel opt-list)))
  1241. nil))
  1242. ;;; =========================================================================
  1243. ;;;
  1244. ;;; Accessing the parse information
  1245. (defun reftex-access-scan-info (&optional rescan file)
  1246. "Ensure access to the scanning info for the current file."
  1247. ;; When the multifile symbols are not yet tied,
  1248. ;; tie them. When they are empty or RESCAN is non-nil, scan the document.
  1249. ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
  1250. ;; When FILE is non-nil, parse only from that file.
  1251. ;; Error out in a buffer without a file.
  1252. (if (and reftex-mode
  1253. (not (buffer-file-name)))
  1254. (error "RefTeX works only in buffers visiting a file"))
  1255. ;; Make sure we have the symbols tied
  1256. (if (eq reftex-docstruct-symbol nil)
  1257. ;; Symbols are not yet tied: Tie them.
  1258. (reftex-tie-multifile-symbols))
  1259. (reftex-ensure-compiled-variables)
  1260. (when (or (null (symbol-value reftex-docstruct-symbol))
  1261. (member rescan '(t 1 (4) (16))))
  1262. ;; The docstruct will change: Remove selection buffers.
  1263. (save-excursion
  1264. (reftex-erase-buffer "*toc*")
  1265. (reftex-erase-all-selection-and-index-buffers)))
  1266. (if (and (null (symbol-value reftex-docstruct-symbol))
  1267. (not (member rescan '(t 1 (4) (16))))
  1268. reftex-save-parse-info)
  1269. ;; Try to read the stuff from a file
  1270. (reftex-access-parse-file 'read))
  1271. (cond
  1272. ((equal rescan -1)) ;; We are not allowed to scan.
  1273. ((not (symbol-value reftex-docstruct-symbol))
  1274. ;; Scan the whole document
  1275. (reftex-do-parse 1 file))
  1276. ((member rescan '(t 1 (4) (16)))
  1277. ;; Scan whatever was required by the caller.
  1278. (reftex-do-parse rescan file))))
  1279. (defun reftex-scanning-info-available-p ()
  1280. "Is the scanning info about the current document available?"
  1281. (unless reftex-docstruct-symbol
  1282. (reftex-tie-multifile-symbols))
  1283. (and (symbolp reftex-docstruct-symbol)
  1284. (symbol-value reftex-docstruct-symbol)
  1285. t))
  1286. (defun reftex-silence-toc-markers (list n)
  1287. ;; Set all toc markers in the first N entries in list to nil
  1288. (while (and list (> (decf n) -1))
  1289. (and (eq (car (car list)) 'toc)
  1290. (markerp (nth 4 (car list)))
  1291. (set-marker (nth 4 (car list)) nil))
  1292. (pop list)))
  1293. (defun reftex-access-parse-file (action)
  1294. "Perform ACTION on the parse file (the .rel file).
  1295. Valid actions are: readable, restore, read, kill, write."
  1296. (let* ((list (symbol-value reftex-docstruct-symbol))
  1297. (docstruct-symbol reftex-docstruct-symbol)
  1298. (master (reftex-TeX-master-file))
  1299. (enable-local-variables nil)
  1300. (file (if (string-match "\\.[a-zA-Z]+\\'" master)
  1301. (concat (substring master 0 (match-beginning 0))
  1302. reftex-parse-file-extension)
  1303. (concat master reftex-parse-file-extension))))
  1304. (cond
  1305. ((eq action 'readable)
  1306. (file-readable-p file))
  1307. ((eq action 'restore)
  1308. (put reftex-docstruct-symbol 'modified nil)
  1309. (if (eq reftex-docstruct-symbol nil)
  1310. ;; Symbols are not yet tied: Tie them.
  1311. (reftex-tie-multifile-symbols))
  1312. (if (file-exists-p file)
  1313. ;; load the file and return t for success
  1314. (condition-case nil
  1315. (progn (load-file file) t)
  1316. (error (set reftex-docstruct-symbol nil)
  1317. (error "Error while loading file %s" file)))
  1318. ;; Throw an exception if the file does not exist
  1319. (error "No restore file %s" file)))
  1320. ((eq action 'read)
  1321. (put reftex-docstruct-symbol 'modified nil)
  1322. (if (file-exists-p file)
  1323. ;; load the file and return t for success
  1324. (condition-case nil
  1325. (progn
  1326. (load-file file)
  1327. (reftex-check-parse-consistency)
  1328. t)
  1329. (error (message "Error while restoring file %s" file)
  1330. (set reftex-docstruct-symbol nil)
  1331. nil))
  1332. ;; return nil for failure, but no exception
  1333. nil))
  1334. ((eq action 'kill)
  1335. ;; Remove the file
  1336. (when (and (file-exists-p file) (file-writable-p file))
  1337. (message "Unlinking file %s" file)
  1338. (delete-file file)))
  1339. (t
  1340. (put docstruct-symbol 'modified nil)
  1341. (save-excursion
  1342. (if (file-writable-p file)
  1343. (with-temp-file file
  1344. (message "Writing parse file %s" (abbreviate-file-name file))
  1345. (insert (format ";; RefTeX parse info file\n"))
  1346. (insert (format ";; File: %s\n" master))
  1347. (insert (format ";; User: %s (%s)\n\n"
  1348. (user-login-name) (user-full-name)))
  1349. (insert "(set reftex-docstruct-symbol '(\n\n")
  1350. (let ((standard-output (current-buffer)))
  1351. (mapc
  1352. (lambda (x)
  1353. (cond ((eq (car x) 'toc)
  1354. ;; A toc entry. Do not save the marker.
  1355. ;; Save the markers position at position 8
  1356. (print (list 'toc "toc" (nth 2 x) (nth 3 x)
  1357. nil (nth 5 x) (nth 6 x) (nth 7 x)
  1358. (or (and (markerp (nth 4 x))
  1359. (marker-position (nth 4 x)))
  1360. (nth 8 x)))))
  1361. ((and (not (eq t reftex-support-index))
  1362. (eq (car x) 'index))
  1363. ;; Don't save index entries
  1364. )
  1365. (t (print x))))
  1366. list))
  1367. (insert "))\n\n"))
  1368. (error "Cannot write to file %s" file)))
  1369. t))))
  1370. (defun reftex-check-parse-consistency ()
  1371. ;; Check if parse file is consistent, throw an error if not.
  1372. ;; Check if the master is the same: when moving a document, this will see it.
  1373. (let* ((real-master (reftex-TeX-master-file))
  1374. (parsed-master
  1375. (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol)))))
  1376. (unless (string= (file-truename real-master) (file-truename parsed-master))
  1377. (message "Master file name in load file is different: %s versus %s"
  1378. parsed-master real-master)
  1379. (error "Master file name error")))
  1380. ;; Check for the existence of all document files
  1381. ;;; (let* ((all (symbol-value reftex-docstruct-symbol)))
  1382. ;;; (while all
  1383. ;;; (when (and (eq (car (car all)) 'bof)
  1384. ;;; (not (file-regular-p (nth 1 (car all)))))
  1385. ;;; (message "File %s in saved parse info not available" (cdr (car all)))
  1386. ;;; (error "File not found"))
  1387. ;;; (setq all (cdr all))))
  1388. )
  1389. (defun reftex-select-external-document (xr-alist xr-index)
  1390. ;; Return index of an external document.
  1391. (let* ((len (length xr-alist)) (highest (1- (+ ?0 len)))
  1392. (prompt (format "[%c-%c] Select TAB: Read prefix with completion"
  1393. ?0 highest))
  1394. key prefix)
  1395. (cond
  1396. ((= len 1)
  1397. (message "No external documents available")
  1398. (ding) (sit-for 1) 0)
  1399. ((= len 2)
  1400. (- 1 xr-index))
  1401. (t
  1402. (save-excursion
  1403. (let* ((length (apply 'max (mapcar
  1404. (lambda(x) (length (car x))) xr-alist)))
  1405. (fmt (format " [%%c] %%-%ds %%s\n" length))
  1406. (n (1- ?0)))
  1407. (setq key
  1408. (reftex-select-with-char
  1409. prompt
  1410. (concat
  1411. "SELECT EXTERNAL DOCUMENT\n------------------------\n"
  1412. (mapconcat
  1413. (lambda (x)
  1414. (format fmt (incf n) (or (car x) "")
  1415. (abbreviate-file-name (cdr x))))
  1416. xr-alist ""))
  1417. nil t))
  1418. (cond
  1419. ((and (>= key ?0) (<= key highest)) (- key ?0))
  1420. ((= key ?\C-i)
  1421. (setq prefix (completing-read "Prefix: " xr-alist nil t))
  1422. (- len (length (memq (assoc prefix xr-alist) xr-alist))))
  1423. (t (error "Invalid document selection [%c]" key)))))))))
  1424. ;;; =========================================================================
  1425. ;;;
  1426. ;;; Finding files
  1427. (defun reftex-locate-file (file type master-dir &optional die)
  1428. "Find FILE of type TYPE in MASTER-DIR or on the path associated with TYPE.
  1429. If the file does not have any of the valid extensions for TYPE,
  1430. try first the default extension and only then the naked file name.
  1431. When DIE is non-nil, throw an error if file not found."
  1432. (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
  1433. (extensions (cdr (assoc type reftex-file-extensions)))
  1434. (def-ext (car extensions))
  1435. (ext-re (concat "\\("
  1436. (mapconcat 'regexp-quote extensions "\\|")
  1437. "\\)\\'"))
  1438. (files (if (string-match ext-re file)
  1439. (cons file nil)
  1440. (if reftex-try-all-extensions
  1441. (append (mapcar (lambda (x) (concat file x))
  1442. extensions)
  1443. (list file))
  1444. (list (concat file def-ext) file))))
  1445. path old-path file1 f fs)
  1446. (cond
  1447. ((file-name-absolute-p file)
  1448. (while (setq f (pop files))
  1449. (if (file-regular-p f)
  1450. (setq file1 f files nil))))
  1451. ((and reftex-use-external-file-finders
  1452. (assoc type reftex-external-file-finders))
  1453. (setq file1 (reftex-find-file-externally file type master-dir)))
  1454. (t
  1455. (while (and (null file1) rec-values)
  1456. (setq path (reftex-access-search-path
  1457. type (pop rec-values) master-dir file))
  1458. (setq fs files)
  1459. (while (and (null file1) (setq f (pop fs)))
  1460. (when (or (null old-path)
  1461. (not (eq old-path path)))
  1462. (setq old-path path
  1463. path (cons master-dir path))
  1464. (setq file1 (reftex-find-file-on-path f path master-dir)))))))
  1465. (cond (file1 file1)
  1466. (die (error "No such file: %s" file) nil)
  1467. (t (message "No such file: %s (ignored)" file) nil))))
  1468. (defun reftex-find-file-externally (file type &optional master-dir)
  1469. ;; Use external program to find FILE.
  1470. ;; The program is taken from `reftex-external-file-finders'.
  1471. ;; Interpret relative path definitions starting from MASTER-DIR.
  1472. (let ((default-directory (or master-dir default-directory))
  1473. (prg (cdr (assoc type reftex-external-file-finders)))
  1474. out)
  1475. (if (string-match "%f" prg)
  1476. (setq prg (replace-match file t t prg)))
  1477. (setq out (apply 'reftex-process-string (split-string prg)))
  1478. (if (string-match "[ \t\n]+\\'" out) ; chomp
  1479. (setq out (replace-match "" nil nil out)))
  1480. (cond ((equal out "") nil)
  1481. ((file-regular-p out) (expand-file-name out master-dir))
  1482. (t nil))))
  1483. (defun reftex-process-string (program &rest args)
  1484. "Execute PROGRAM with arguments ARGS and return its STDOUT as a string."
  1485. (let ((calling-dir default-directory)) ; remember default directory
  1486. (with-output-to-string
  1487. (with-current-buffer standard-output
  1488. (let ((default-directory calling-dir)) ; set default directory
  1489. (apply 'call-process program nil '(t nil) nil args))))))
  1490. (defun reftex-access-search-path (type &optional recurse master-dir file)
  1491. ;; Access path from environment variables. TYPE is either "tex" or "bib".
  1492. ;; When RECURSE is t, expand path elements ending in `//' recursively.
  1493. ;; Relative path elements are left as they are. However, relative recursive
  1494. ;; elements are expanded with MASTER-DIR as default directory.
  1495. ;; The expanded path is cached for the next search.
  1496. ;; FILE is just for the progress message.
  1497. ;; Returns the derived path.
  1498. (let* ((pathvar (intern (concat "reftex-" type "-path"))))
  1499. (when (null (get pathvar 'status))
  1500. ;; Get basic path
  1501. (set pathvar
  1502. (reftex-uniquify
  1503. (reftex-parse-colon-path
  1504. (mapconcat
  1505. (lambda(x)
  1506. (if (string-match "^!" x)
  1507. (apply 'reftex-process-string
  1508. (split-string (substring x 1)))
  1509. (or (getenv x) x)))
  1510. ;; For consistency, the next line should look like this:
  1511. ;; (cdr (assoc type reftex-path-environment))
  1512. ;; However, historically we have separate options for the
  1513. ;; environment variables, so we have to do this:
  1514. (symbol-value (intern (concat "reftex-" type
  1515. "path-environment-variables")))
  1516. path-separator))))
  1517. (put pathvar 'status 'split)
  1518. ;; Check if we have recursive elements
  1519. (let ((path (symbol-value pathvar)) dir rec)
  1520. (while (setq dir (pop path))
  1521. (when (string= (substring dir -2) "//")
  1522. (if (file-name-absolute-p dir)
  1523. (setq rec (or rec 'absolute))
  1524. (setq rec 'relative))))
  1525. (put pathvar 'rec-type rec)))
  1526. (if recurse
  1527. ;; Return the recursive expansion of the path
  1528. (cond
  1529. ((not (get pathvar 'rec-type))
  1530. ;; Path does not contain recursive elements - use simple path
  1531. (symbol-value pathvar))
  1532. ((or (not (get pathvar 'recursive-path))
  1533. (and (eq (get pathvar 'rec-type) 'relative)
  1534. (not (equal master-dir (get pathvar 'master-dir)))))
  1535. ;; Either: We don't have a recursive expansion yet.
  1536. ;; or: Relative recursive path elements need to be expanded
  1537. ;; relative to new default directory
  1538. (message "Expanding search path to find %s file: %s ..." type file)
  1539. (put pathvar 'recursive-path
  1540. (reftex-expand-path (symbol-value pathvar) master-dir))
  1541. (put pathvar 'master-dir master-dir)
  1542. (get pathvar 'recursive-path))
  1543. (t
  1544. ;; Recursive path computed earlier is still OK.
  1545. (get pathvar 'recursive-path)))
  1546. ;; The simple path was requested
  1547. (symbol-value pathvar))))
  1548. (defun reftex-find-file-on-path (file path &optional def-dir)
  1549. ;; Find FILE along the directory list PATH.
  1550. ;; DEF-DIR is the default directory for expanding relative path elements.
  1551. (catch 'exit
  1552. (when (file-name-absolute-p file)
  1553. (if (file-regular-p file)
  1554. (throw 'exit file)
  1555. (throw 'exit nil)))
  1556. (let* ((thepath path) file1 dir)
  1557. (while (setq dir (pop thepath))
  1558. (when (string= (substring dir -2) "//")
  1559. (setq dir (substring dir 0 -1)))
  1560. (setq file1 (expand-file-name file (expand-file-name dir def-dir)))
  1561. (if (file-regular-p file1)
  1562. (throw 'exit file1)))
  1563. ;; No such file
  1564. nil)))
  1565. (defun reftex-parse-colon-path (path)
  1566. ;; Like parse-colon-parse, but // or /~ are left alone.
  1567. ;; Trailing ! or !! will be converted into `//' (emTeX convention)
  1568. (mapcar
  1569. (lambda (dir)
  1570. (if (string-match "\\(//+\\|/*!+\\)\\'" dir)
  1571. (setq dir (replace-match "//" t t dir)))
  1572. (file-name-as-directory dir))
  1573. (delete "" (split-string path (concat path-separator "+")))))
  1574. (defun reftex-expand-path (path &optional default-dir)
  1575. ;; Expand parts of path ending in `//' recursively into directory list.
  1576. ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
  1577. (let (path1 dir recursive)
  1578. (while (setq dir (pop path))
  1579. (if (setq recursive (string= (substring dir -2) "//"))
  1580. (setq dir (substring dir 0 -1)))
  1581. (if (and recursive
  1582. (not (file-name-absolute-p dir)))
  1583. (setq dir (expand-file-name dir default-dir)))
  1584. (if recursive
  1585. ;; Expand recursively
  1586. (setq path1 (append (reftex-recursive-directory-list dir) path1))
  1587. ;; Keep unchanged
  1588. (push dir path1)))
  1589. (nreverse path1)))
  1590. (defun reftex-recursive-directory-list (dir)
  1591. ;; Return a list of all directories below DIR, including DIR itself
  1592. (let ((path (list dir)) path1 file files)
  1593. (while (setq dir (pop path))
  1594. (when (file-directory-p dir)
  1595. (setq files (nreverse (directory-files dir t "[^.]")))
  1596. (while (setq file (pop files))
  1597. (if (file-directory-p file)
  1598. (push (file-name-as-directory file) path)))
  1599. (push dir path1)))
  1600. path1))
  1601. ;;; =========================================================================
  1602. ;;;
  1603. ;;; Some generally useful functions
  1604. (defun reftex-typekey-check (typekey conf-variable &optional n)
  1605. ;; Check if CONF-VARIABLE is true or contains TYPEKEY
  1606. (and n (setq conf-variable (nth n conf-variable)))
  1607. (or (eq conf-variable t)
  1608. (and (stringp conf-variable)
  1609. (string-match (concat "[" conf-variable "]") typekey))))
  1610. (defun reftex-check-recursive-edit ()
  1611. ;; Check if we are already in a recursive edit. Abort with helpful
  1612. ;; message if so.
  1613. (if (marker-position reftex-recursive-edit-marker)
  1614. (error
  1615. (substitute-command-keys
  1616. "In unfinished selection process. Finish, or abort with \\[abort-recursive-edit]"))))
  1617. (defun reftex-in-comment ()
  1618. (save-excursion
  1619. (skip-chars-backward "^%\n\r")
  1620. (eq (preceding-char) ?%)))
  1621. (defun reftex-no-props (string)
  1622. ;; Return STRING with all text properties removed
  1623. (and (stringp string)
  1624. (set-text-properties 0 (length string) nil string))
  1625. string)
  1626. (defun reftex-match-string (n)
  1627. ;; Match string without properties
  1628. (when (match-beginning n)
  1629. (buffer-substring-no-properties (match-beginning n) (match-end n))))
  1630. (defun reftex-region-active-p ()
  1631. "Should we operate on an active region?"
  1632. (if (fboundp 'use-region-p)
  1633. (use-region-p)
  1634. ;; For XEmacs.
  1635. (region-active-p)))
  1636. (defun reftex-kill-buffer (buffer)
  1637. ;; Kill buffer if it exists.
  1638. (and (setq buffer (get-buffer buffer))
  1639. (kill-buffer buffer)))
  1640. (defun reftex-erase-buffer (&optional buffer)
  1641. ;; Erase BUFFER if it exists. BUFFER defaults to current buffer.
  1642. ;; This even erases read-only buffers.
  1643. (cond
  1644. ((null buffer)
  1645. ;; erase current buffer
  1646. (let ((buffer-read-only nil)) (erase-buffer)))
  1647. ((setq buffer (get-buffer buffer))
  1648. ;; buffer exists
  1649. (with-current-buffer buffer
  1650. (let ((inhibit-read-only t)) (erase-buffer))))))
  1651. (defun reftex-this-word (&optional class)
  1652. ;; Grab the word around point.
  1653. (setq class (or class "-a-zA-Z0-9:_/.*;|"))
  1654. (save-excursion
  1655. (buffer-substring-no-properties
  1656. (progn (skip-chars-backward class) (point))
  1657. (progn (skip-chars-forward class) (point)))))
  1658. (defun reftex-number (n unit &optional ending)
  1659. (if (and (integerp n) (stringp unit))
  1660. (format "%d %s%s" n unit (if (= n 1) "" (or ending "s")))
  1661. ""))
  1662. (defun reftex-all-assq (key list)
  1663. ;; Return a list of all associations of KEY in LIST. Comparison with eq.
  1664. (let (rtn)
  1665. (while (setq list (memq (assq key list) list))
  1666. (push (car list) rtn)
  1667. (pop list))
  1668. (nreverse rtn)))
  1669. (defun reftex-all-assoc-string (key list)
  1670. ;; Return a list of all associations of KEY in LIST. Comparison with string=.
  1671. (let (rtn)
  1672. (while list
  1673. (if (string= (car (car list)) key)
  1674. (push (car list) rtn))
  1675. (pop list))
  1676. (nreverse rtn)))
  1677. (defun reftex-last-assoc-before-elt (key elt list &optional exclusive)
  1678. ;; Find the last association of KEY in LIST before or at ELT
  1679. ;; ELT is found in LIST with equal, not eq.
  1680. ;; Returns nil when either KEY or elt are not found in LIST.
  1681. ;; When EXCLUSIVE is non-nil, ELT cannot be the return value.
  1682. ;; On success, returns the association.
  1683. (let* ((elt (car (member elt list))) (ex (not exclusive)) ass last-ass)
  1684. (while (and (setq ass (assoc key list))
  1685. (setq list (memq ass list))
  1686. (or ex (not (eq elt (car list))))
  1687. (memq elt list))
  1688. (setq last-ass ass
  1689. list (cdr list)))
  1690. last-ass))
  1691. (defun reftex-sublist-nth (list nth predicate &optional completion)
  1692. ;; Make a list of the NTH elements of all members of LIST which
  1693. ;; fulfill PREDICATE.
  1694. ;; When COMPLETION is non-nil, make all elements of the resulting
  1695. ;; list also a list, so that the result can be used for completion.
  1696. (let (rtn)
  1697. (while list
  1698. (if (funcall predicate (car list))
  1699. (push (if completion
  1700. (list (nth nth (car list)))
  1701. (nth nth (car list)))
  1702. rtn))
  1703. (setq list (cdr list)))
  1704. (nreverse rtn)))
  1705. (defun reftex-make-selection-buffer-name (type &optional index)
  1706. ;; Make unique name for a selection buffer.
  1707. (format " *RefTeX[%s][%d]*"
  1708. type (or index (get reftex-docstruct-symbol :master-index) 0)))
  1709. (defun reftex-make-index-buffer-name (tag &optional cnt)
  1710. ;; Make unique name for an index buffer.
  1711. (format "*Index[%s][%d]*"
  1712. tag (or cnt (get reftex-docstruct-symbol :master-index) 0)))
  1713. (defun reftex-truncate (string ncols &optional ellipses padding)
  1714. ;; Truncate STRING to NCOLS characters.
  1715. ;; When PADDING is non-nil, and string is shorter than NCOLS, fill with
  1716. ;; white space to NCOLS characters. When ELLIPSES is non-nil and the
  1717. ;; string needs to be truncated, replace last 3 characters by dots.
  1718. (setq string
  1719. (if (<= (length string) ncols)
  1720. string
  1721. (if ellipses
  1722. (concat (substring string 0 (- ncols 3)) "...")
  1723. (substring string 0 ncols))))
  1724. (if padding
  1725. (format (format "%%-%ds" ncols) string)
  1726. string))
  1727. (defun reftex-nearest-match (regexp &optional max-length)
  1728. ;; Find the nearest match of REGEXP. Set the match data.
  1729. ;; If POS is given, calculate distances relative to it.
  1730. ;; Return nil if there is no match.
  1731. (let ((pos (point))
  1732. (dist (or max-length (length regexp)))
  1733. match1 match2 match)
  1734. (goto-char (min (+ pos dist) (point-max)))
  1735. (when (re-search-backward regexp nil t)
  1736. (setq match1 (match-data)))
  1737. (goto-char (max (- pos dist) (point-min)))
  1738. (when (re-search-forward regexp nil t)
  1739. (setq match2 (match-data)))
  1740. (goto-char pos)
  1741. (setq match
  1742. (cond
  1743. ((not match1) match2)
  1744. ((not match2) match1)
  1745. ((< (abs (- pos (car match1))) (abs (- pos (car match2)))) match1)
  1746. (t match2)))
  1747. (if match (progn (set-match-data match) t) nil)))
  1748. (defun reftex-auto-mode-alist ()
  1749. ;; Return an `auto-mode-alist' with only the .gz (etc) thingies.
  1750. ;; Stolen from gnus nnheader.
  1751. (let ((alist auto-mode-alist)
  1752. out)
  1753. (while alist
  1754. (when (listp (cdr (car alist)))
  1755. (push (car alist) out))
  1756. (pop alist))
  1757. (nreverse out)))
  1758. (defun reftex-window-height ()
  1759. (if (fboundp 'window-displayed-height)
  1760. (window-displayed-height)
  1761. (window-height)))
  1762. (defun reftex-enlarge-to-fit (buf2 &optional keep-current)
  1763. ;; Enlarge other window displaying buffer to show whole buffer if possible.
  1764. ;; If KEEP-CURRENT in non-nil, current buffer must remain visible.
  1765. (let* ((win1 (selected-window))
  1766. (buf1 (current-buffer))
  1767. (win2 (get-buffer-window buf2))) ;; Only on current frame.
  1768. (when win2
  1769. (select-window win2)
  1770. (unless (and (pos-visible-in-window-p (point-min))
  1771. (pos-visible-in-window-p (point-max)))
  1772. (enlarge-window (1+ (- (count-lines (point-min) (point-max))
  1773. (reftex-window-height))))))
  1774. (cond
  1775. ((window-live-p win1) (select-window win1))
  1776. (keep-current
  1777. ;; we must have the old buffer!
  1778. (switch-to-buffer-other-window buf1)
  1779. (shrink-window (- (window-height) window-min-height))))))
  1780. (defun reftex-select-with-char (prompt help-string &optional delay-time scroll)
  1781. ;; Offer to select something with PROMPT and, after DELAY-TIME seconds,
  1782. ;; also with HELP-STRING.
  1783. ;; When SCROLL is non-nil, use SPC and DEL to scroll help window.
  1784. (let ((char ?\?))
  1785. (save-window-excursion
  1786. (catch 'exit
  1787. (message "%s (?=Help)" prompt)
  1788. (when (or (sit-for (or delay-time 0))
  1789. (= ?\? (setq char (read-char-exclusive))))
  1790. (reftex-kill-buffer "*RefTeX Select*")
  1791. (switch-to-buffer-other-window "*RefTeX Select*")
  1792. (insert help-string)
  1793. (goto-char 1)
  1794. (unless (and (pos-visible-in-window-p (point-min))
  1795. (pos-visible-in-window-p (point-max)))
  1796. (enlarge-window (1+ (- (count-lines (point-min) (point-max))
  1797. (reftex-window-height)))))
  1798. (setq truncate-lines t))
  1799. (if (and (pos-visible-in-window-p (point-min))
  1800. (pos-visible-in-window-p (point-max)))
  1801. nil
  1802. (setq prompt (concat prompt (if scroll " (SPC/DEL=Scroll)" ""))))
  1803. (message "%s" prompt)
  1804. (and (equal char ?\?) (setq char (read-char-exclusive)))
  1805. (while t
  1806. (cond ((equal char ?\C-g) (keyboard-quit))
  1807. ((equal char ?\?))
  1808. ((and scroll (equal char ?\ ))
  1809. (condition-case nil (scroll-up) (error nil))
  1810. (message "%s" prompt))
  1811. ((and scroll (equal char ?\C-? ))
  1812. (condition-case nil (scroll-down) (error nil))
  1813. (message "%s" prompt))
  1814. (t (message "")
  1815. (throw 'exit char)))
  1816. (setq char (read-char-exclusive)))))))
  1817. (defun reftex-make-regexp-allow-for-ctrl-m (string)
  1818. ;; convert STRING into a regexp, allowing ^M for \n and vice versa
  1819. (let ((start -2))
  1820. (setq string (regexp-quote string))
  1821. (while (setq start (string-match "[\n\r]" string (+ 3 start)))
  1822. (setq string (replace-match "[\n\r]" nil t string)))
  1823. string))
  1824. (defun reftex-get-buffer-visiting (file)
  1825. ;; return a buffer visiting FILE
  1826. (cond
  1827. ((boundp 'find-file-compare-truenames) ; XEmacs
  1828. (let ((find-file-compare-truenames t))
  1829. (get-file-buffer file)))
  1830. ((fboundp 'find-buffer-visiting) ; Emacs
  1831. (find-buffer-visiting file))
  1832. (t (error "This should not happen (reftex-get-buffer-visiting)"))))
  1833. ;; Define `current-message' for compatibility with XEmacs prior to 20.4
  1834. (defvar message-stack)
  1835. (if (and (featurep 'xemacs)
  1836. (not (fboundp 'current-message)))
  1837. (defun current-message (&optional frame)
  1838. (cdr (car message-stack))))
  1839. (defun reftex-visited-files (list)
  1840. ;; Takes a list of filenames and returns the buffers of those already visited
  1841. (delq nil (mapcar (lambda (x) (if (reftex-get-buffer-visiting x) x nil))
  1842. list)))
  1843. (defun reftex-get-file-buffer-force (file &optional mark-to-kill)
  1844. ;; Return a buffer visiting file. Make one, if necessary.
  1845. ;; If neither such a buffer nor the file exist, return nil.
  1846. ;; If MARK-TO-KILL is t and there is no live buffer, visit the file with
  1847. ;; initializations according to `reftex-initialize-temporary-buffers',
  1848. ;; and mark the buffer to be killed after use.
  1849. (let ((buf (reftex-get-buffer-visiting file)))
  1850. (cond (buf
  1851. ;; We have it already as a buffer - just return it
  1852. buf)
  1853. ((file-readable-p file)
  1854. ;; At least there is such a file and we can read it.
  1855. (if (or (not mark-to-kill)
  1856. (eq t reftex-initialize-temporary-buffers))
  1857. ;; Visit the file with full magic
  1858. (setq buf (find-file-noselect file))
  1859. ;; Else: Visit the file just briefly, without or
  1860. ;; with limited Magic
  1861. ;; The magic goes away
  1862. (letf ((format-alist nil)
  1863. (auto-mode-alist (reftex-auto-mode-alist))
  1864. ((default-value 'major-mode) 'fundamental-mode)
  1865. (enable-local-variables nil)
  1866. (after-insert-file-functions nil))
  1867. (setq buf (find-file-noselect file)))
  1868. ;; Is there a hook to run?
  1869. (when (listp reftex-initialize-temporary-buffers)
  1870. (with-current-buffer buf
  1871. (run-hooks 'reftex-initialize-temporary-buffers))))
  1872. ;; Let's see if we got a license to kill :-|
  1873. (and mark-to-kill
  1874. (add-to-list 'reftex-buffers-to-kill buf))
  1875. ;; Return the new buffer
  1876. buf)
  1877. ;; If no such file exists, return nil
  1878. (t nil))))
  1879. (defun reftex-kill-temporary-buffers (&optional buffer)
  1880. ;; Kill all buffers in the list reftex-kill-temporary-buffers.
  1881. (cond
  1882. (buffer
  1883. (when (member buffer reftex-buffers-to-kill)
  1884. (kill-buffer buffer)
  1885. (setq reftex-buffers-to-kill
  1886. (delete buffer reftex-buffers-to-kill))))
  1887. (t
  1888. (while (setq buffer (pop reftex-buffers-to-kill))
  1889. (when (bufferp buffer)
  1890. (and (buffer-modified-p buffer)
  1891. (y-or-n-p (format "Save file %s? "
  1892. (buffer-file-name buffer)))
  1893. (with-current-buffer buffer
  1894. (save-buffer)))
  1895. (kill-buffer buffer))
  1896. (pop reftex-buffers-to-kill)))))
  1897. (defun reftex-splice-symbols-into-list (list alist)
  1898. ;; Splice the association in ALIST of any symbols in LIST into the list.
  1899. ;; Return new list.
  1900. (let (rtn tmp)
  1901. (while list
  1902. (while (and (not (null (car list))) ;; keep list elements nil
  1903. (symbolp (car list)))
  1904. (setq tmp (car list))
  1905. (cond
  1906. ((assoc tmp alist)
  1907. (setq list (append (nth 2 (assoc tmp alist)) (cdr list))))
  1908. (t
  1909. (error "Cannot treat symbol %s in reftex-label-alist"
  1910. (symbol-name tmp)))))
  1911. (push (pop list) rtn))
  1912. (nreverse rtn)))
  1913. (defun reftex-remove-symbols-from-list (list)
  1914. ;; Remove all symbols from list
  1915. (let (rtn)
  1916. (while list
  1917. (unless (symbolp (car list))
  1918. (push (car list) rtn))
  1919. (setq list (cdr list)))
  1920. (nreverse rtn)))
  1921. (defun reftex-uniquify (list)
  1922. ;; Return a list of all elements in LIST, but each only once, keeping order
  1923. (let (new elm)
  1924. (while list
  1925. (setq elm (pop list))
  1926. (unless (member elm new)
  1927. (push elm new)))
  1928. (nreverse new)))
  1929. (defun reftex-uniquify-by-car (alist &optional keep-list)
  1930. ;; Return a list of all elements in ALIST, but each car only once.
  1931. ;; Elements of KEEP-LIST are not removed even if duplicate.
  1932. (let (new elm)
  1933. (while alist
  1934. (setq elm (pop alist))
  1935. (if (or (member (car elm) keep-list)
  1936. (not (assoc (car elm) new)))
  1937. (push elm new)))
  1938. (nreverse new)))
  1939. (defun reftex-abbreviate-title (string)
  1940. (reftex-convert-string string "[-~ \t\n\r,;]" nil t t
  1941. 5 40 nil 1 " " (nth 5 reftex-derive-label-parameters)))
  1942. (defun reftex-convert-string (string split-re invalid-re dot keep-fp
  1943. nwords maxchar invalid abbrev sep
  1944. ignore-words &optional downcase)
  1945. "Convert a string (a sentence) to something shorter.
  1946. SPLIT-RE is the regular expression used to split the string into words.
  1947. INVALID-RE matches characters which are invalid in the final string.
  1948. DOT t means add dots to abbreviated words.
  1949. KEEP-FP t means to keep a final punctuation when applicable.
  1950. NWORDS Number of words to use.
  1951. MAXCHAR Maximum number of characters in the final string.
  1952. INVALID nil: Throw away any words containing stuff matched with INVALID-RE.
  1953. t: Throw away only the matched part, not the whole word.
  1954. ABBREV nil: Never abbreviate words.
  1955. t: Always abbreviate words (see `reftex-abbrev-parameters').
  1956. not t and not nil: Abbreviate words if necessary to shorten
  1957. string below MAXCHAR.
  1958. SEP String separating different words in the output string.
  1959. IGNORE-WORDS List of words which should be removed from the string."
  1960. (let* ((words0 (split-string string (or split-re "[ \t\n\r]")))
  1961. (reftex-label-illegal-re (or invalid-re "\000"))
  1962. (abbrev-re (concat
  1963. "\\`\\("
  1964. (make-string (nth 0 reftex-abbrev-parameters) ?.)
  1965. "[" (nth 2 reftex-abbrev-parameters) "]*"
  1966. "\\)"
  1967. "[" (nth 3 reftex-abbrev-parameters) "]"
  1968. (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
  1969. words word)
  1970. ;; Remove words from the ignore list or with funny characters
  1971. (while (setq word (pop words0))
  1972. (if downcase (setq word (downcase word)))
  1973. (cond
  1974. ((member (downcase word) ignore-words))
  1975. ((string-match reftex-label-illegal-re word)
  1976. (when invalid
  1977. (while (string-match reftex-label-illegal-re word)
  1978. (setq word (replace-match "" nil nil word)))
  1979. (push word words)))
  1980. (t
  1981. (push word words))))
  1982. (setq words (nreverse words))
  1983. ;; Restrict number of words
  1984. (if (> (length words) nwords)
  1985. (setcdr (nthcdr (1- nwords) words) nil))
  1986. ;; First, try to use all words
  1987. (setq string (mapconcat 'identity words sep))
  1988. ;; Abbreviate words if enforced by user settings or string length
  1989. (if (or (eq t abbrev)
  1990. (and abbrev
  1991. (> (length string) maxchar)))
  1992. (setq words
  1993. (mapcar
  1994. (lambda (w) (if (string-match abbrev-re w)
  1995. (if dot
  1996. (concat (match-string 1 w) ".")
  1997. (match-string 1 w))
  1998. w))
  1999. words)
  2000. string (mapconcat 'identity words sep)))
  2001. ;; Shorten if still to long
  2002. (setq string
  2003. (if (> (length string) maxchar)
  2004. (substring string 0 maxchar)
  2005. string))
  2006. ;; Delete the final punctuation, if any
  2007. (if (and (not keep-fp) (string-match "\\s.+\\'" string))
  2008. (setq string (replace-match "" nil nil string)))
  2009. string))
  2010. (defun reftex-nicify-text (text)
  2011. ;; Make TEXT nice for inclusion as context into label menu.
  2012. ;; 1. remove line breaks and extra white space
  2013. (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text)
  2014. (setq text (replace-match " " nil t text)))
  2015. ;; 2. cut before the next `\end{' or `\item' or `\\'
  2016. (if (string-match "\\(\\\\end{\\|\\\\item\\|\\\\\\\\\\).*" text)
  2017. (setq text (replace-match "" nil t text)))
  2018. ;; 3. kill the embedded label
  2019. (if (string-match "\\\\label{[^}]*}" text)
  2020. (setq text (replace-match "" nil t text)))
  2021. ;; 4. remove leading garbage
  2022. (if (string-match "\\`[ }]+" text)
  2023. (setq text (replace-match "" nil t text)))
  2024. ;; 5. limit length
  2025. (cond
  2026. ((> (length text) 100) (substring text 0 100))
  2027. ((= (length text) 0) (make-string 1 ?\ ))
  2028. (t text)))
  2029. ;;; =========================================================================
  2030. ;;;
  2031. ;;; Fontification and Highlighting
  2032. (defun reftex-use-fonts ()
  2033. ;; Return t if we can and want to use fonts.
  2034. (and ; window-system
  2035. reftex-use-fonts
  2036. (featurep 'font-lock)))
  2037. (defun reftex-refontify ()
  2038. ;; Return t if we need to refontify context
  2039. (and (reftex-use-fonts)
  2040. (or (eq t reftex-refontify-context)
  2041. (and (eq 1 reftex-refontify-context)
  2042. ;; Test of we use the font-lock version of x-symbol
  2043. (and (featurep 'x-symbol-tex) (not (boundp 'x-symbol-mode)))))))
  2044. (defvar font-lock-defaults-computed)
  2045. (defun reftex-fontify-select-label-buffer (parent-buffer)
  2046. ;; Fontify the `*RefTeX Select*' buffer. Buffer is temporarily renamed to
  2047. ;; start with none-SPC char, because Font-Lock otherwise refuses operation.
  2048. (run-hook-with-args 'reftex-pre-refontification-functions
  2049. parent-buffer 'reftex-ref)
  2050. (let* ((oldname (buffer-name))
  2051. (newname (concat "Fontify-me-" oldname)))
  2052. (unwind-protect
  2053. (progn
  2054. ;; Rename buffer temporarily to start w/o space (because of font-lock)
  2055. (rename-buffer newname t)
  2056. (cond
  2057. ((fboundp 'font-lock-default-fontify-region)
  2058. ;; Good: we have the indirection functions
  2059. (set (make-local-variable 'font-lock-fontify-region-function)
  2060. 'reftex-select-font-lock-fontify-region)
  2061. (let ((major-mode 'latex-mode))
  2062. (font-lock-mode 1)))
  2063. ((fboundp 'font-lock-set-defaults-1)
  2064. ;; Looks like the XEmacs font-lock stuff.
  2065. ;; FIXME: this is still kind of a hack, but it works.
  2066. (set (make-local-variable 'font-lock-keywords) nil)
  2067. (let ((major-mode 'latex-mode)
  2068. (font-lock-defaults-computed nil))
  2069. (font-lock-set-defaults-1)
  2070. (reftex-select-font-lock-fontify-region (point-min) (point-max))))
  2071. (t
  2072. ;; Oops?
  2073. (message "Sorry: cannot refontify RefTeX Select buffer."))))
  2074. (rename-buffer oldname))))
  2075. (defun reftex-select-font-lock-fontify-region (beg end &optional loudly)
  2076. ;; Fontify a region, but only lines starting with a dot.
  2077. (let ((func (if (fboundp 'font-lock-default-fontify-region)
  2078. 'font-lock-default-fontify-region
  2079. 'font-lock-fontify-region))
  2080. beg1 end1)
  2081. (goto-char beg)
  2082. (while (re-search-forward "^\\." end t)
  2083. (setq beg1 (point) end1 (progn (skip-chars-forward "^\n") (point)))
  2084. (funcall func beg1 end1 nil)
  2085. (goto-char end1))))
  2086. (defun reftex-select-font-lock-unfontify (&rest ignore) t)
  2087. (defun reftex-verified-face (&rest faces)
  2088. ;; Return the first valid face in FACES, or nil if none is valid.
  2089. ;; Also, when finding a nil element in FACES, return nil. This
  2090. ;; function is just a safety net to catch name changes of builtin
  2091. ;; fonts. Currently it is only used for reftex-label-face, which has
  2092. ;; as default font-lock-reference-face, which was recently renamed
  2093. ;; to font-lock-constant-face.
  2094. (let (face)
  2095. (catch 'exit
  2096. (while (setq face (pop faces))
  2097. (if (featurep 'xemacs)
  2098. (if (find-face face) (throw 'exit face))
  2099. (if (facep face) (throw 'exit face)))))))
  2100. ;; Highlighting uses overlays. For XEmacs, we use extends.
  2101. (defalias 'reftex-make-overlay
  2102. (if (featurep 'xemacs) 'make-extent 'make-overlay))
  2103. (defalias 'reftex-overlay-put
  2104. (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
  2105. (defalias 'reftex-move-overlay
  2106. (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay))
  2107. (defalias 'reftex-delete-overlay
  2108. (if (featurep 'xemacs) 'detach-extent 'delete-overlay))
  2109. ;; We keep a vector with several different overlays to do our highlighting.
  2110. (defvar reftex-highlight-overlays [nil nil nil])
  2111. ;; Initialize the overlays
  2112. (aset reftex-highlight-overlays 0 (reftex-make-overlay 1 1))
  2113. (reftex-overlay-put (aref reftex-highlight-overlays 0)
  2114. 'face 'highlight)
  2115. (aset reftex-highlight-overlays 1 (reftex-make-overlay 1 1))
  2116. (reftex-overlay-put (aref reftex-highlight-overlays 1)
  2117. 'face reftex-cursor-selected-face)
  2118. (aset reftex-highlight-overlays 2 (reftex-make-overlay 1 1))
  2119. (reftex-overlay-put (aref reftex-highlight-overlays 2)
  2120. 'face reftex-cursor-selected-face)
  2121. ;; Two functions for activating and deactivation highlight overlays
  2122. (defun reftex-highlight (index begin end &optional buffer)
  2123. "Highlight a region with overlay INDEX."
  2124. (reftex-move-overlay (aref reftex-highlight-overlays index)
  2125. begin end (or buffer (current-buffer))))
  2126. (defun reftex-unhighlight (index)
  2127. "Detach overlay INDEX."
  2128. (reftex-delete-overlay (aref reftex-highlight-overlays index)))
  2129. (defun reftex-highlight-shall-die ()
  2130. ;; Function used in pre-command-hook to remove highlights.
  2131. (remove-hook 'pre-command-hook 'reftex-highlight-shall-die)
  2132. (reftex-unhighlight 0))
  2133. ;;; =========================================================================
  2134. ;;;
  2135. ;;; Keybindings
  2136. ;; The default bindings in the mode map.
  2137. (loop for x in
  2138. '(("\C-c=" . reftex-toc)
  2139. ("\C-c-" . reftex-toc-recenter)
  2140. ("\C-c(" . reftex-label)
  2141. ("\C-c)" . reftex-reference)
  2142. ("\C-c[" . reftex-citation)
  2143. ("\C-c<" . reftex-index)
  2144. ("\C-c>" . reftex-display-index)
  2145. ("\C-c/" . reftex-index-selection-or-word)
  2146. ("\C-c\\" . reftex-index-phrase-selection-or-word)
  2147. ("\C-c|" . reftex-index-visit-phrases-buffer)
  2148. ("\C-c&" . reftex-view-crossref))
  2149. do (define-key reftex-mode-map (car x) (cdr x)))
  2150. ;; Bind `reftex-mouse-view-crossref' only when the key is still free
  2151. (if (featurep 'xemacs)
  2152. (unless (key-binding [(shift button2)])
  2153. (define-key reftex-mode-map [(shift button2)]
  2154. 'reftex-mouse-view-crossref))
  2155. (unless (key-binding [(shift mouse-2)])
  2156. (define-key reftex-mode-map [(shift mouse-2)]
  2157. 'reftex-mouse-view-crossref)))
  2158. ;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map
  2159. (eval-after-load
  2160. "bibtex"
  2161. '(define-key bibtex-mode-map "\C-c&" 'reftex-view-crossref-from-bibtex))
  2162. ;; If the user requests so, she can have a few more bindings:
  2163. ;; For most of these commands there are already bindings in place.
  2164. ;; Setting `reftex-extra-bindings' really is only there to spare users
  2165. ;; the hassle of defining bindings in the user space themselves. This
  2166. ;; is why they violate the key binding recommendations.
  2167. (defvar reftex-extra-bindings-map
  2168. (let ((map (make-sparse-keymap)))
  2169. (define-key map "t" 'reftex-toc)
  2170. (define-key map "l" 'reftex-label)
  2171. (define-key map "r" 'reftex-reference)
  2172. (define-key map "c" 'reftex-citation)
  2173. (define-key map "v" 'reftex-view-crossref)
  2174. (define-key map "g" 'reftex-grep-document)
  2175. (define-key map "s" 'reftex-search-document)
  2176. map)
  2177. "Reftex extra bindings map")
  2178. (when reftex-extra-bindings
  2179. (define-key reftex-mode-map
  2180. reftex-extra-bindings-prefix
  2181. reftex-extra-bindings-map))
  2182. ;;; =========================================================================
  2183. ;;;
  2184. ;;; Menu
  2185. ;; Define a menu for the menu bar if Emacs is running under X
  2186. (defvar reftex-isearch-minor-mode nil)
  2187. (make-variable-buffer-local 'reftex-isearch-minor-mode)
  2188. (easy-menu-define reftex-mode-menu reftex-mode-map
  2189. "Menu used in RefTeX mode"
  2190. `("Ref"
  2191. ["Table of Contents" reftex-toc t]
  2192. ["Recenter TOC" reftex-toc-recenter t]
  2193. "--"
  2194. ["\\label" reftex-label t]
  2195. ["\\ref" reftex-reference t]
  2196. ["\\cite" reftex-citation t]
  2197. ("\\index"
  2198. ["\\index" reftex-index t]
  2199. ["\\index{THIS}" reftex-index-selection-or-word t]
  2200. "--"
  2201. ["Add THIS to Index Phrases" reftex-index-phrase-selection-or-word t]
  2202. ["Visit Phrase Buffer" reftex-index-visit-phrases-buffer t]
  2203. ["Apply Phrases to Region" reftex-index-phrases-apply-to-region t]
  2204. "--"
  2205. ["Display the Index" reftex-display-index t])
  2206. "--"
  2207. ["View Crossref" reftex-view-crossref t]
  2208. "--"
  2209. ("Parse Document"
  2210. ["One File" reftex-parse-one reftex-enable-partial-scans]
  2211. ["Entire Document" reftex-parse-all t]
  2212. ["Save to File" (reftex-access-parse-file 'write)
  2213. (> (length (symbol-value reftex-docstruct-symbol)) 0)]
  2214. ["Restore from File" (reftex-access-parse-file 'restore) t])
  2215. ("Global Actions"
  2216. ["Search Whole Document" reftex-search-document t]
  2217. ["Search Again" tags-loop-continue t]
  2218. ["Replace in Document" reftex-query-replace-document t]
  2219. ["Grep on Document" reftex-grep-document t]
  2220. "--"
  2221. ["Goto Label" reftex-goto-label t]
  2222. ["Find Duplicate Labels" reftex-find-duplicate-labels t]
  2223. ["Change Label and Refs" reftex-change-label t]
  2224. ["Renumber Simple Labels" reftex-renumber-simple-labels t]
  2225. "--"
  2226. ["Create BibTeX File" reftex-create-bibtex-file t]
  2227. "--"
  2228. ["Create TAGS File" reftex-create-tags-file t]
  2229. "--"
  2230. ["Save Document" reftex-save-all-document-buffers t])
  2231. "--"
  2232. ("Options"
  2233. "PARSER"
  2234. ["Partial Scans"
  2235. (setq reftex-enable-partial-scans (not reftex-enable-partial-scans))
  2236. :style toggle :selected reftex-enable-partial-scans]
  2237. ["Auto-Save Parse Info"
  2238. (setq reftex-save-parse-info (not reftex-save-parse-info))
  2239. :style toggle :selected reftex-save-parse-info]
  2240. "--"
  2241. "TOC RECENTER"
  2242. ["Automatic Recenter" reftex-toggle-auto-toc-recenter
  2243. :style toggle :selected reftex-toc-auto-recenter-timer]
  2244. "--"
  2245. "CROSSREF INFO"
  2246. ["Automatic Info" reftex-toggle-auto-view-crossref
  2247. :style toggle :selected reftex-auto-view-crossref-timer]
  2248. ["...in Echo Area" (setq reftex-auto-view-crossref t)
  2249. :style radio :selected (eq reftex-auto-view-crossref t)]
  2250. ["...in Other Window" (setq reftex-auto-view-crossref 'window)
  2251. :style radio :selected (eq reftex-auto-view-crossref 'window)]
  2252. "--"
  2253. "MISC"
  2254. ["AUC TeX Interface" reftex-toggle-plug-into-AUCTeX
  2255. :style toggle :selected reftex-plug-into-AUCTeX]
  2256. ["isearch whole document" reftex-isearch-minor-mode
  2257. :style toggle :selected reftex-isearch-minor-mode])
  2258. ("Reference Style"
  2259. ["Default" (setq reftex-vref-is-default nil
  2260. reftex-fref-is-default nil)
  2261. :style radio :selected (not (or reftex-vref-is-default
  2262. reftex-fref-is-default))]
  2263. ["Varioref" (setq reftex-vref-is-default t
  2264. reftex-fref-is-default nil)
  2265. :style radio :selected reftex-vref-is-default]
  2266. ["Fancyref" (setq reftex-fref-is-default t
  2267. reftex-vref-is-default nil)
  2268. :style radio :selected reftex-fref-is-default])
  2269. ("Citation Style"
  2270. ,@(mapcar
  2271. (lambda (x)
  2272. (vector
  2273. (capitalize (symbol-name (car x)))
  2274. (list 'reftex-set-cite-format (list 'quote (car x)))
  2275. :style 'radio :selected
  2276. (list 'eq (list 'reftex-get-cite-format) (list 'quote (car x)))))
  2277. reftex-cite-format-builtin)
  2278. "--"
  2279. "Sort Database Matches"
  2280. ["Not" (setq reftex-sort-bibtex-matches nil)
  2281. :style radio :selected (eq reftex-sort-bibtex-matches nil)]
  2282. ["by Author" (setq reftex-sort-bibtex-matches 'author)
  2283. :style radio :selected (eq reftex-sort-bibtex-matches 'author)]
  2284. ["by Year" (setq reftex-sort-bibtex-matches 'year)
  2285. :style radio :selected (eq reftex-sort-bibtex-matches 'year)]
  2286. ["by Year, reversed" (setq reftex-sort-bibtex-matches 'reverse-year)
  2287. :style radio :selected (eq reftex-sort-bibtex-matches 'reverse-year)])
  2288. ("Index Style"
  2289. ,@(mapcar
  2290. (lambda (x)
  2291. (vector
  2292. (capitalize (symbol-name (car x)))
  2293. (list 'reftex-add-index-macros (list 'list (list 'quote (car x))))
  2294. :style 'radio :selected
  2295. (list 'memq (list 'quote (car x))
  2296. (list 'get 'reftex-docstruct-symbol
  2297. (list 'quote 'reftex-index-macros-style)))))
  2298. reftex-index-macros-builtin))
  2299. "--"
  2300. ["Reset RefTeX Mode" reftex-reset-mode t]
  2301. "--"
  2302. ("Customize"
  2303. ["Browse RefTeX Group" reftex-customize t]
  2304. "--"
  2305. ["Build Full Customize Menu" reftex-create-customize-menu
  2306. (fboundp 'customize-menu-create)])
  2307. ("Documentation"
  2308. ["Info" reftex-info t]
  2309. ["Commentary" reftex-show-commentary t])))
  2310. (defun reftex-customize ()
  2311. "Call the customize function with reftex as argument."
  2312. (interactive)
  2313. (customize-browse 'reftex))
  2314. (defun reftex-create-customize-menu ()
  2315. "Create a full customization menu for RefTeX, insert it into the menu."
  2316. (interactive)
  2317. (if (fboundp 'customize-menu-create)
  2318. (progn
  2319. (easy-menu-change
  2320. '("Ref") "Customize"
  2321. `(["Browse RefTeX group" reftex-customize t]
  2322. "--"
  2323. ,(customize-menu-create 'reftex)
  2324. ["Set" Custom-set t]
  2325. ["Save" Custom-save t]
  2326. ["Reset to Current" Custom-reset-current t]
  2327. ["Reset to Saved" Custom-reset-saved t]
  2328. ["Reset to Standard Settings" Custom-reset-standard t]))
  2329. (message "\"Ref\"-menu now contains full customization menu"))
  2330. (error "Cannot expand menu (outdated version of cus-edit.el)")))
  2331. (defun reftex-show-commentary ()
  2332. "Use the finder to view the file documentation from `reftex.el'."
  2333. (interactive)
  2334. (finder-commentary "reftex.el"))
  2335. (defun reftex-info (&optional node)
  2336. "Read documentation for RefTeX in the info system.
  2337. With optional NODE, go directly to that node."
  2338. (interactive)
  2339. (info (format "(reftex)%s" (or node ""))))
  2340. ;;; Install the kill-buffer and kill-emacs hooks ------------------------------
  2341. (add-hook 'kill-buffer-hook 'reftex-kill-buffer-hook)
  2342. (unless noninteractive
  2343. (add-hook 'kill-emacs-hook 'reftex-kill-emacs-hook))
  2344. ;;; Run Hook ------------------------------------------------------------------
  2345. (run-hooks 'reftex-load-hook)
  2346. ;;; That's it! ----------------------------------------------------------------
  2347. (setq reftex-tables-dirty t) ; in case this file is evaluated by hand
  2348. (provide 'reftex)
  2349. ;;;============================================================================
  2350. ;;; reftex.el ends here