reftex-sel.el 28 KB

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