reftex-sel.el 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. ;;; reftex-sel.el --- the selection modes for RefTeX
  2. ;; Copyright (C) 1997-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <dominik@science.uva.nl>
  4. ;; Maintainer: auctex-devel@gnu.org
  5. ;; Version: 4.31
  6. ;; Package: reftex
  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. ;;; Commentary:
  19. ;;; Code:
  20. (eval-when-compile (require 'cl))
  21. (provide 'reftex-sel)
  22. (require 'reftex)
  23. ;;;
  24. ;; Common bindings in reftex-select-label-mode-map
  25. ;; and reftex-select-bib-mode-map.
  26. (defvar reftex-select-shared-map
  27. (let ((map (make-sparse-keymap)))
  28. (substitute-key-definition
  29. 'next-line 'reftex-select-next map global-map)
  30. (substitute-key-definition
  31. 'previous-line 'reftex-select-previous map global-map)
  32. (substitute-key-definition
  33. 'keyboard-quit 'reftex-select-keyboard-quit map global-map)
  34. (substitute-key-definition
  35. 'newline 'reftex-select-accept map global-map)
  36. (loop for x in
  37. '((" " . reftex-select-callback)
  38. ("n" . reftex-select-next)
  39. ([(down)] . reftex-select-next)
  40. ("p" . reftex-select-previous)
  41. ([(up)] . reftex-select-previous)
  42. ("f" . reftex-select-toggle-follow)
  43. ("\C-m" . reftex-select-accept)
  44. ([(return)] . reftex-select-accept)
  45. ("q" . reftex-select-quit)
  46. ("." . reftex-select-show-insertion-point)
  47. ("?" . reftex-select-help))
  48. do (define-key map (car x) (cdr x)))
  49. ;; The mouse-2 binding
  50. (if (featurep 'xemacs)
  51. (define-key map [(button2)] 'reftex-select-mouse-accept)
  52. (define-key map [(mouse-2)] 'reftex-select-mouse-accept)
  53. (define-key map [follow-link] 'mouse-face))
  54. ;; Digit arguments
  55. (loop for key across "0123456789" do
  56. (define-key map (vector (list key)) 'digit-argument))
  57. (define-key map "-" 'negative-argument)
  58. map))
  59. (defvar reftex-select-label-mode-map
  60. (let ((map (make-sparse-keymap)))
  61. (set-keymap-parent map reftex-select-shared-map)
  62. (loop for key across "aAcgFlrRstx#%" do
  63. (define-key map (vector (list key))
  64. (list 'lambda '()
  65. "Press `?' during selection to find out about this key."
  66. '(interactive) (list 'throw '(quote myexit) key))))
  67. (loop for x in
  68. '(("b" . reftex-select-jump-to-previous)
  69. ("z" . reftex-select-jump)
  70. ("v" . reftex-select-toggle-varioref)
  71. ("V" . reftex-select-toggle-fancyref)
  72. ("m" . reftex-select-mark)
  73. ("u" . reftex-select-unmark)
  74. ("," . reftex-select-mark-comma)
  75. ("-" . reftex-select-mark-to)
  76. ("+" . reftex-select-mark-and)
  77. ([(tab)] . reftex-select-read-label)
  78. ("\C-i" . reftex-select-read-label)
  79. ("\C-c\C-n" . reftex-select-next-heading)
  80. ("\C-c\C-p" . reftex-select-previous-heading))
  81. do
  82. (define-key map (car x) (cdr x)))
  83. map)
  84. "Keymap used for *RefTeX Select* buffer, when selecting a label.
  85. This keymap can be used to configure the label selection process which is
  86. started with the command \\[reftex-reference].")
  87. (define-obsolete-variable-alias
  88. 'reftex-select-label-map 'reftex-select-label-mode-map "24.1")
  89. (define-derived-mode reftex-select-label-mode fundamental-mode "LSelect"
  90. "Major mode for selecting a label in a LaTeX document.
  91. This buffer was created with RefTeX.
  92. It only has a meaningful keymap when you are in the middle of a
  93. selection process.
  94. To select a label, move the cursor to it and press RET.
  95. Press `?' for a summary of important key bindings.
  96. During a selection process, these are the local bindings.
  97. \\{reftex-select-label-mode-map}"
  98. (when (featurep 'xemacs)
  99. ;; XEmacs needs the call to make-local-hook
  100. (make-local-hook 'pre-command-hook)
  101. (make-local-hook 'post-command-hook))
  102. (set (make-local-variable 'reftex-select-marked) nil)
  103. (when (syntax-table-p reftex-latex-syntax-table)
  104. (set-syntax-table reftex-latex-syntax-table))
  105. ;; We do not set a local map - reftex-select-item does this.
  106. )
  107. (defvar reftex-select-bib-mode-map
  108. (let ((map (make-sparse-keymap)))
  109. (set-keymap-parent map reftex-select-shared-map)
  110. (loop for key across "grRaAeE" do
  111. (define-key map (vector (list key))
  112. (list 'lambda '()
  113. "Press `?' during selection to find out about this key."
  114. '(interactive) (list 'throw '(quote myexit) key))))
  115. (loop for x in
  116. '(("\C-i" . reftex-select-read-cite)
  117. ([(tab)] . reftex-select-read-cite)
  118. ("m" . reftex-select-mark)
  119. ("u" . reftex-select-unmark))
  120. do (define-key map (car x) (cdr x)))
  121. map)
  122. "Keymap used for *RefTeX Select* buffer, when selecting a BibTeX entry.
  123. This keymap can be used to configure the BibTeX selection process which is
  124. started with the command \\[reftex-citation].")
  125. (define-obsolete-variable-alias
  126. 'reftex-select-bib-map 'reftex-select-bib-mode-map "24.1")
  127. (define-derived-mode reftex-select-bib-mode fundamental-mode "BSelect"
  128. "Major mode for selecting a citation key in a LaTeX document.
  129. This buffer was created with RefTeX.
  130. It only has a meaningful keymap when you are in the middle of a
  131. selection process.
  132. In order to select a citation, move the cursor to it and press RET.
  133. Press `?' for a summary of important key bindings.
  134. During a selection process, these are the local bindings.
  135. \\{reftex-select-label-mode-map}"
  136. (when (featurep 'xemacs)
  137. ;; XEmacs needs the call to make-local-hook
  138. (make-local-hook 'pre-command-hook)
  139. (make-local-hook 'post-command-hook))
  140. (set (make-local-variable 'reftex-select-marked) nil)
  141. ;; We do not set a local map - reftex-select-item does this.
  142. )
  143. ;; (defun reftex-get-offset (buf here-am-I &optional typekey toc index file)
  144. ;; ;; Find the correct offset data, like insert-docstruct would, but faster.
  145. ;; ;; Buffer BUF knows the correct docstruct to use.
  146. ;; ;; Basically this finds the first docstruct entry after HERE-I-AM which
  147. ;; ;; is of allowed type. The optional arguments specify what is allowed.
  148. ;; (catch 'exit
  149. ;; (with-current-buffer buf
  150. ;; (reftex-access-scan-info)
  151. ;; (let* ((rest (memq here-am-I (symbol-value reftex-docstruct-symbol)))
  152. ;; entry)
  153. ;; (while (setq entry (pop rest))
  154. ;; (if (or (and typekey
  155. ;; (stringp (car entry))
  156. ;; (or (equal typekey " ")
  157. ;; (equal typekey (nth 1 entry))))
  158. ;; (and toc (eq (car entry) 'toc))
  159. ;; (and index (eq (car entry) 'index))
  160. ;; (and file
  161. ;; (memq (car entry) '(bof eof file-error))))
  162. ;; (throw 'exit entry)))
  163. ;; nil))))
  164. (defun reftex-get-offset (buf here-am-I &optional typekey toc index file)
  165. ;; Find the correct offset data, like insert-docstruct would, but faster.
  166. ;; Buffer BUF knows the correct docstruct to use.
  167. ;; Basically this finds the first docstruct entry before HERE-I-AM which
  168. ;; is of allowed type. The optional arguments specify what is allowed.
  169. (catch 'exit
  170. (with-current-buffer buf
  171. (reftex-access-scan-info)
  172. (let* ((rest (symbol-value reftex-docstruct-symbol))
  173. lastentry entry)
  174. (while (setq entry (pop rest))
  175. (if (or (and typekey
  176. (stringp (car entry))
  177. (or (equal typekey " ")
  178. (equal typekey (nth 1 entry))))
  179. (and toc (eq (car entry) 'toc))
  180. (and index (eq (car entry) 'index))
  181. (and file
  182. (memq (car entry) '(bof eof file-error))))
  183. (setq lastentry entry))
  184. (if (eq entry here-am-I)
  185. (throw 'exit (or lastentry entry))))
  186. nil))))
  187. (defun reftex-insert-docstruct
  188. (buf toc labels index-entries files context counter show-commented
  189. here-I-am xr-prefix toc-buffer)
  190. ;; Insert an excerpt of the docstruct list.
  191. ;; Return the data property of the entry corresponding to HERE-I-AM.
  192. ;; BUF is the buffer which has the correct docstruct-symbol.
  193. ;; LABELS non-nil means to include labels into the list.
  194. ;; When a string, indicates the label type to include
  195. ;; FILES non-nil means to display file boundaries.
  196. ;; CONTEXT non-nil means to include label context.
  197. ;; COUNTER means to count the labels.
  198. ;; SHOW-COMMENTED means to include also labels which are commented out.
  199. ;; HERE-I-AM is a member of the docstruct list. The function will return
  200. ;; a used member near to this one, as a possible starting point.
  201. ;; XR-PREFIX is the prefix to put in front of labels.
  202. ;; TOC-BUFFER means this is to fill the toc buffer.
  203. (let* ((font (reftex-use-fonts))
  204. (cnt 0)
  205. (index -1)
  206. (toc-indent " ")
  207. (label-indent
  208. (concat "> "
  209. (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
  210. (context-indent
  211. (concat ". "
  212. (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
  213. (mouse-face
  214. (if (memq reftex-highlight-selection '(mouse both))
  215. reftex-mouse-selected-face
  216. nil))
  217. (label-face (reftex-verified-face reftex-label-face
  218. 'font-lock-constant-face
  219. 'font-lock-reference-face))
  220. (index-face (reftex-verified-face reftex-index-face
  221. 'font-lock-constant-face
  222. 'font-lock-reference-face))
  223. all cell text label typekey note comment master-dir-re
  224. prev-inserted offset from to index-tag docstruct-symbol)
  225. ;; Pop to buffer buf to get the correct buffer-local variables
  226. (with-current-buffer buf
  227. ;; Ensure access to scanning info
  228. (reftex-access-scan-info)
  229. (setq docstruct-symbol reftex-docstruct-symbol
  230. all (symbol-value reftex-docstruct-symbol)
  231. reftex-active-toc nil
  232. master-dir-re
  233. (concat "\\`" (regexp-quote
  234. (file-name-directory (reftex-TeX-master-file))))))
  235. (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
  236. (set (make-local-variable 'reftex-prefix)
  237. (cdr (assoc labels reftex-typekey-to-prefix-alist)))
  238. (if (equal reftex-prefix " ") (setq reftex-prefix nil))
  239. ;; Walk the docstruct and insert the appropriate stuff
  240. (while (setq cell (pop all))
  241. (incf index)
  242. (setq from (point))
  243. (cond
  244. ((memq (car cell) '(bib thebib label-numbers appendix
  245. master-dir bibview-cache is-multi xr xr-doc)))
  246. ;; These are currently ignored
  247. ((memq (car cell) '(bof eof file-error))
  248. ;; Beginning or end of a file
  249. (when files
  250. (setq prev-inserted cell)
  251. ; (if (eq offset 'attention) (setq offset cell))
  252. (insert
  253. " File " (if (string-match master-dir-re (nth 1 cell))
  254. (substring (nth 1 cell) (match-end 0))
  255. (nth 1 cell))
  256. (cond ((eq (car cell) 'bof) " starts here\n")
  257. ((eq (car cell) 'eof) " ends here\n")
  258. ((eq (car cell) 'file-error) " was not found\n")))
  259. (setq to (point))
  260. (when font
  261. (put-text-property from to
  262. 'face reftex-file-boundary-face))
  263. (when toc-buffer
  264. (if mouse-face
  265. (put-text-property from (1- to)
  266. 'mouse-face mouse-face))
  267. (put-text-property from to :data cell))))
  268. ((eq (car cell) 'toc)
  269. ;; a table of contents entry
  270. (when (and toc
  271. (<= (nth 5 cell) reftex-toc-max-level))
  272. (setq prev-inserted cell)
  273. ; (if (eq offset 'attention) (setq offset cell))
  274. (setq reftex-active-toc cell)
  275. (insert (concat toc-indent (nth 2 cell) "\n"))
  276. (setq to (point))
  277. (when font
  278. (put-text-property from to
  279. 'face reftex-section-heading-face))
  280. (when toc-buffer
  281. (if mouse-face
  282. (put-text-property from (1- to)
  283. 'mouse-face mouse-face))
  284. (put-text-property from to :data cell))
  285. (goto-char to)))
  286. ((stringp (car cell))
  287. ;; a label
  288. (when (null (nth 2 cell))
  289. ;; No context yet. Quick update.
  290. (setcdr cell (cdr (reftex-label-info-update cell)))
  291. (put docstruct-symbol 'modified t))
  292. (setq label (car cell)
  293. typekey (nth 1 cell)
  294. text (nth 2 cell)
  295. comment (nth 4 cell)
  296. note (nth 5 cell))
  297. (when (and labels
  298. (or (eq labels t)
  299. (string= typekey labels)
  300. (string= labels " "))
  301. (or show-commented (null comment)))
  302. ;; Yes we want this one
  303. (incf cnt)
  304. (setq prev-inserted cell)
  305. ; (if (eq offset 'attention) (setq offset cell))
  306. (setq label (concat xr-prefix label))
  307. (when comment (setq label (concat "% " label)))
  308. (insert label-indent label)
  309. (when font
  310. (setq to (point))
  311. (put-text-property
  312. (- (point) (length label)) to
  313. 'face (if comment
  314. 'font-lock-comment-face
  315. label-face))
  316. (goto-char to))
  317. (insert (if counter (format " (%d) " cnt) "")
  318. (if comment " LABEL IS COMMENTED OUT " "")
  319. (if (stringp note) (concat " " note) "")
  320. "\n")
  321. (setq to (point))
  322. (when context
  323. (insert context-indent text "\n")
  324. (setq to (point)))
  325. (put-text-property from to :data cell)
  326. (when mouse-face
  327. (put-text-property from (1- to)
  328. 'mouse-face mouse-face))
  329. (goto-char to)))
  330. ((eq (car cell) 'index)
  331. ;; index entry
  332. (when (and index-entries
  333. (or (eq t index-entries)
  334. (string= index-entries (nth 1 cell))))
  335. (setq prev-inserted cell)
  336. ; (if (eq offset 'attention) (setq offset cell))
  337. (setq index-tag (format "<%s>" (nth 1 cell)))
  338. (and font
  339. (put-text-property 0 (length index-tag)
  340. 'face reftex-index-tag-face index-tag))
  341. (insert label-indent index-tag " " (nth 7 cell))
  342. (when font
  343. (setq to (point))
  344. (put-text-property
  345. (- (point) (length (nth 7 cell))) to
  346. 'face index-face)
  347. (goto-char to))
  348. (insert "\n")
  349. (setq to (point))
  350. (when context
  351. (insert context-indent (nth 2 cell) "\n")
  352. (setq to (point)))
  353. (put-text-property from to :data cell)
  354. (when mouse-face
  355. (put-text-property from (1- to)
  356. 'mouse-face mouse-face))
  357. (goto-char to))))
  358. (if (eq cell here-I-am)
  359. (setq offset 'attention))
  360. (if (and prev-inserted (eq offset 'attention))
  361. (setq offset prev-inserted))
  362. )
  363. (when (reftex-refontify)
  364. ;; we need to fontify the buffer
  365. (reftex-fontify-select-label-buffer buf))
  366. (run-hooks 'reftex-display-copied-context-hook)
  367. offset))
  368. (defun reftex-find-start-point (fallback &rest locations)
  369. ;; Set point to the first available LOCATION. When a LOCATION is a list,
  370. ;; search for such a :data text property. When it is an integer,
  371. ;; use is as line number. FALLBACK is a buffer position used if everything
  372. ;; else fails.
  373. (catch 'exit
  374. (goto-char (point-min))
  375. (let (loc pos)
  376. (while locations
  377. (setq loc (pop locations))
  378. (cond
  379. ((null loc))
  380. ((listp loc)
  381. (setq pos (text-property-any (point-min) (point-max) :data loc))
  382. (when pos
  383. (goto-char pos)
  384. (throw 'exit t)))
  385. ((integerp loc)
  386. (when (<= loc (count-lines (point-min) (point-max)))
  387. (goto-char (point-min))
  388. (forward-line (1- loc))
  389. (throw 'exit t)))))
  390. (goto-char fallback))))
  391. (defvar reftex-last-data nil)
  392. (defvar reftex-last-line nil)
  393. (defvar reftex-select-marked nil)
  394. (defun reftex-select-item (reftex-select-prompt help-string keymap
  395. &optional offset
  396. call-back cb-flag)
  397. ;; Select an item, using REFTEX-SELECT-PROMPT.
  398. ;; The function returns a key indicating an exit status, along with a
  399. ;; data structure indicating which item was selected.
  400. ;; HELP-STRING contains help. KEYMAP is a keymap with the available
  401. ;; selection commands.
  402. ;; OFFSET can be a label list item which will be selected at start.
  403. ;; When it is t, point will start out at the beginning of the buffer.
  404. ;; Any other value will cause restart where last selection left off.
  405. ;; When CALL-BACK is given, it is a function which is called with the index
  406. ;; of the element.
  407. ;; CB-FLAG is the initial value of that flag.
  408. (let (ev reftex-select-data last-data (selection-buffer (current-buffer)))
  409. (setq reftex-select-marked nil)
  410. (setq ev
  411. (catch 'myexit
  412. (save-window-excursion
  413. (setq truncate-lines t)
  414. ;; Find a good starting point
  415. (reftex-find-start-point
  416. (point-min) offset reftex-last-data reftex-last-line)
  417. (beginning-of-line 1)
  418. (set (make-local-variable 'reftex-last-follow-point) (point))
  419. (unwind-protect
  420. (progn
  421. (use-local-map keymap)
  422. (add-hook 'pre-command-hook 'reftex-select-pre-command-hook nil t)
  423. (add-hook 'post-command-hook 'reftex-select-post-command-hook nil t)
  424. (princ reftex-select-prompt)
  425. (set-marker reftex-recursive-edit-marker (point))
  426. ;; XEmacs does not run post-command-hook here
  427. (and (featurep 'xemacs) (run-hooks 'post-command-hook))
  428. (recursive-edit))
  429. (set-marker reftex-recursive-edit-marker nil)
  430. (with-current-buffer selection-buffer
  431. (use-local-map nil)
  432. (remove-hook 'pre-command-hook 'reftex-select-pre-command-hook t)
  433. (remove-hook 'post-command-hook
  434. 'reftex-select-post-command-hook t))
  435. ;; Kill the mark overlays
  436. (mapc (lambda (c) (reftex-delete-overlay (nth 1 c)))
  437. reftex-select-marked)))))
  438. (set (make-local-variable 'reftex-last-line)
  439. (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))
  440. (set (make-local-variable 'reftex-last-data) last-data)
  441. (reftex-kill-buffer "*RefTeX Help*")
  442. (setq reftex-callback-fwd (not reftex-callback-fwd)) ;; ;-)))
  443. (message "")
  444. (list ev reftex-select-data last-data)))
  445. ;; The following variables are all bound dynamically in `reftex-select-item'.
  446. ;; The defvars are here only to silence the byte compiler.
  447. (defvar found-list)
  448. (defvar cb-flag)
  449. (defvar reftex-select-data)
  450. (defvar reftex-select-prompt)
  451. (defvar last-data)
  452. (defvar call-back)
  453. (defvar help-string)
  454. ;; The selection commands
  455. (defun reftex-select-pre-command-hook ()
  456. (reftex-unhighlight 1)
  457. (reftex-unhighlight 0))
  458. (defun reftex-select-post-command-hook ()
  459. (let (b e)
  460. (setq reftex-select-data (get-text-property (point) :data))
  461. (setq last-data (or reftex-select-data last-data))
  462. (when (and reftex-select-data cb-flag
  463. (not (equal reftex-last-follow-point (point))))
  464. (setq reftex-last-follow-point (point))
  465. (funcall call-back reftex-select-data reftex-callback-fwd
  466. (not reftex-revisit-to-follow)))
  467. (if reftex-select-data
  468. (setq b (or (previous-single-property-change
  469. (1+ (point)) :data)
  470. (point-min))
  471. e (or (next-single-property-change
  472. (point) :data)
  473. (point-max)))
  474. (setq b (point) e (point)))
  475. (and (memq reftex-highlight-selection '(cursor both))
  476. (reftex-highlight 1 b e))
  477. (if (or (not (pos-visible-in-window-p b))
  478. (not (pos-visible-in-window-p e)))
  479. (recenter '(4)))
  480. (unless (current-message)
  481. (princ reftex-select-prompt))))
  482. (defun reftex-select-next (&optional arg)
  483. "Move to next selectable item."
  484. (interactive "p")
  485. (setq reftex-callback-fwd t)
  486. (or (eobp) (forward-char 1))
  487. (re-search-forward "^[^. \t\n\r]" nil t arg)
  488. (beginning-of-line 1))
  489. (defun reftex-select-previous (&optional arg)
  490. "Move to previous selectable item."
  491. (interactive "p")
  492. (setq reftex-callback-fwd nil)
  493. (re-search-backward "^[^. \t\n\r]" nil t arg))
  494. (defun reftex-select-jump (arg)
  495. "Jump to a specific section. E.g. '3 z' jumps to section 3.
  496. Useful for large TOC's."
  497. (interactive "P")
  498. (goto-char (point-min))
  499. (re-search-forward
  500. (concat "^ *" (number-to-string (if (numberp arg) arg 1)) " ")
  501. nil t)
  502. (beginning-of-line))
  503. (defun reftex-select-next-heading (&optional arg)
  504. "Move to next table of contents line."
  505. (interactive "p")
  506. (end-of-line)
  507. (re-search-forward "^ " nil t arg)
  508. (beginning-of-line))
  509. (defun reftex-select-previous-heading (&optional arg)
  510. "Move to previous table of contents line."
  511. (interactive "p")
  512. (re-search-backward "^ " nil t arg))
  513. (defun reftex-select-quit ()
  514. "Abort selection process."
  515. (interactive)
  516. (throw 'myexit nil))
  517. (defun reftex-select-keyboard-quit ()
  518. "Abort selection process."
  519. (interactive)
  520. (throw 'exit t))
  521. (defun reftex-select-jump-to-previous ()
  522. "Jump back to where previous selection process left off."
  523. (interactive)
  524. (let (pos)
  525. (cond
  526. ((and (local-variable-p 'reftex-last-data (current-buffer))
  527. reftex-last-data
  528. (setq pos (text-property-any (point-min) (point-max)
  529. :data reftex-last-data)))
  530. (goto-char pos))
  531. ((and (local-variable-p 'reftex-last-line (current-buffer))
  532. (integerp reftex-last-line))
  533. (goto-char (point-min))
  534. (forward-line (1- reftex-last-line)))
  535. (t (ding)))))
  536. (defun reftex-select-toggle-follow ()
  537. "Toggle follow mode: Other window follows with full context."
  538. (interactive)
  539. (setq reftex-last-follow-point -1)
  540. (setq cb-flag (not cb-flag)))
  541. (defvar reftex-refstyle) ; from reftex-reference
  542. (defun reftex-select-toggle-varioref ()
  543. "Toggle the macro used for referencing the label between \\ref and \\vref."
  544. (interactive)
  545. (if (string= reftex-refstyle "\\ref")
  546. (setq reftex-refstyle "\\vref")
  547. (setq reftex-refstyle "\\ref"))
  548. (force-mode-line-update))
  549. (defun reftex-select-toggle-fancyref ()
  550. "Toggle the macro used for referencing the label between \\ref and \\vref."
  551. (interactive)
  552. (setq reftex-refstyle
  553. (cond ((string= reftex-refstyle "\\ref") "\\fref")
  554. ((string= reftex-refstyle "\\fref") "\\Fref")
  555. (t "\\ref")))
  556. (force-mode-line-update))
  557. (defun reftex-select-show-insertion-point ()
  558. "Show the point from where selection was started in another window."
  559. (interactive)
  560. (let ((this-window (selected-window)))
  561. (unwind-protect
  562. (progn
  563. (switch-to-buffer-other-window
  564. (marker-buffer reftex-select-return-marker))
  565. (goto-char (marker-position reftex-select-return-marker))
  566. (recenter '(4)))
  567. (select-window this-window))))
  568. (defun reftex-select-callback ()
  569. "Show full context in another window."
  570. (interactive)
  571. (if reftex-select-data (funcall call-back reftex-select-data reftex-callback-fwd nil) (ding)))
  572. (defun reftex-select-accept ()
  573. "Accept the currently selected item."
  574. (interactive)
  575. (throw 'myexit 'return))
  576. (defun reftex-select-mouse-accept (ev)
  577. "Accept the item at the mouse click."
  578. (interactive "e")
  579. (mouse-set-point ev)
  580. (setq reftex-select-data (get-text-property (point) :data))
  581. (setq last-data (or reftex-select-data last-data))
  582. (throw 'myexit 'return))
  583. (defun reftex-select-read-label ()
  584. "Use minibuffer to read a label to reference, with completion."
  585. (interactive)
  586. (let ((label (completing-read
  587. "Label: " (symbol-value reftex-docstruct-symbol)
  588. nil nil reftex-prefix)))
  589. (unless (or (equal label "") (equal label reftex-prefix))
  590. (throw 'myexit label))))
  591. (defun reftex-select-read-cite ()
  592. "Use minibuffer to read a citation key with completion."
  593. (interactive)
  594. (let* ((key (completing-read "Citation key: " found-list))
  595. (entry (assoc key found-list)))
  596. (cond
  597. ((or (null key) (equal key "")))
  598. (entry
  599. (setq reftex-select-data entry)
  600. (setq last-data reftex-select-data)
  601. (throw 'myexit 'return))
  602. (t (throw 'myexit key)))))
  603. (defun reftex-select-mark (&optional separator)
  604. "Mark the entry."
  605. (interactive)
  606. (let* ((data (get-text-property (point) :data))
  607. boe eoe ovl)
  608. (or data (error "No entry to mark at point"))
  609. (if (assq data reftex-select-marked)
  610. (error "Entry is already marked"))
  611. (setq boe (or (previous-single-property-change (1+ (point)) :data)
  612. (point-min))
  613. eoe (or (next-single-property-change (point) :data) (point-max)))
  614. (setq ovl (reftex-make-overlay boe eoe))
  615. (push (list data ovl separator) reftex-select-marked)
  616. (reftex-overlay-put ovl 'face reftex-select-mark-face)
  617. (reftex-overlay-put ovl 'before-string
  618. (if separator
  619. (format "*%c%d* " separator
  620. (length reftex-select-marked))
  621. (format "*%d* " (length reftex-select-marked))))
  622. (message "Entry has mark no. %d" (length reftex-select-marked))))
  623. (defun reftex-select-mark-comma ()
  624. "Mark the entry and store the `comma' separator."
  625. (interactive)
  626. (reftex-select-mark ?,))
  627. (defun reftex-select-mark-to ()
  628. "Mark the entry and store the `to' separator."
  629. (interactive)
  630. (reftex-select-mark ?-))
  631. (defun reftex-select-mark-and ()
  632. "Mark the entry and store `and' to separator."
  633. (interactive)
  634. (reftex-select-mark ?+))
  635. (defun reftex-select-unmark ()
  636. "Unmark the entry."
  637. (interactive)
  638. (let* ((data (get-text-property (point) :data))
  639. (cell (assq data reftex-select-marked))
  640. (ovl (nth 1 cell))
  641. (cnt 0)
  642. sep)
  643. (unless cell
  644. (error "No marked entry at point"))
  645. (and ovl (reftex-delete-overlay ovl))
  646. (setq reftex-select-marked (delq cell reftex-select-marked))
  647. (setq cnt (1+ (length reftex-select-marked)))
  648. (mapc (lambda (c)
  649. (setq sep (nth 2 c))
  650. (reftex-overlay-put (nth 1 c) 'before-string
  651. (if sep
  652. (format "*%c%d* " sep (decf cnt))
  653. (format "*%d* " (decf cnt)))))
  654. reftex-select-marked)
  655. (message "Entry no longer marked")))
  656. (defun reftex-select-help ()
  657. "Display a summary of the special key bindings."
  658. (interactive)
  659. (with-output-to-temp-buffer "*RefTeX Help*"
  660. (princ help-string))
  661. (reftex-enlarge-to-fit "*RefTeX Help*" t))
  662. ;;; reftex-sel.el ends here