evil-collection/evil-collection-reftex.el

143 lines
5.8 KiB
EmacsLisp
Raw Normal View History

2018-01-26 18:38:26 +01:00
;;; evil-collection-reftex.el --- Bindings for `reftex'. -*- lexical-binding: t -*-
2018-01-27 02:29:12 +01:00
;; Copyright (C) 2017 Pierre Neidhardt
2018-01-26 18:38:26 +01:00
;; Author: Maximiliano Sandoval <msandova@protonmail.com>
;; Maintainer: James Nguyen <james@jojojames.com>
2018-08-27 10:41:51 +02:00
;; Pierre Neidhardt <mail@ambrevar.xyz>
2018-03-02 02:22:38 +01:00
;; URL: https://github.com/emacs-evil/evil-collection
2018-01-26 18:38:26 +01:00
;; Version: 0.0.1
;; Package-Requires: ((emacs "25.1"))
;; Keywords: evil, reftex, tools
2018-01-27 02:29:12 +01:00
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.
;;
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
2018-01-26 18:38:26 +01:00
;;; Commentary:
;; Evil bindings for `reftex-mode'.
;;; Code:
(require 'evil-collection)
2018-01-26 18:38:26 +01:00
(require 'reftex-ref nil t)
(require 'reftex-ref nil t)
(require 'reftex-cite nil t)
(defconst evil-collection-reftex-maps '(reftex-select-shared-map
reftex-toc-mode-map))
2018-01-26 19:00:39 +01:00
;; original code can be found in reftex-ref.el
2018-01-27 03:13:21 +01:00
(setq reftex-select-label-prompt
2018-01-27 20:49:36 +01:00
"Select: [RET]select [j]next [k]previous [gr]escan [go]context [q]uit [g?]help")
2018-01-26 18:38:26 +01:00
2018-01-26 19:00:39 +01:00
;; original code can be found in reftex-cite.el
2018-01-27 03:13:21 +01:00
(setq reftex-citation-prompt
2018-01-27 20:49:36 +01:00
"Select: [RET]select [j]next [k]previous [q]uit [g?]help")
2018-01-26 19:00:39 +01:00
;; original at reftex-ref.el
2018-01-27 03:13:21 +01:00
(setq reftex-select-label-help
2018-01-26 18:38:26 +01:00
" j / k Go to next/previous label (Cursor motion works as well)
2018-02-24 15:42:01 +01:00
[ / ] Go to previous/next section heading.
c Reuse last referenced label.
2018-01-27 03:13:21 +01:00
J Jump to a specific section, e.g. '3 J' jumps to section 3.
2018-02-24 15:42:01 +01:00
s Switch label type.
gr Reparse document.
2018-01-26 21:30:56 +01:00
go / gO Show context / Show insertion point.
S Switch to label menu of external document (with LaTeX package `xr').
r / R Toggle \\ref <-> \\vref / Rotate \\ref <=> \\fref <=> \\Fref.
2018-01-26 18:38:26 +01:00
TAB Enter a label with completion.
2018-01-26 21:30:56 +01:00
m / M Mark/unmark entry.
x / X Put all marked entries into one/many \\ref commands.
2018-01-26 18:38:26 +01:00
q / RET Quit without referencing / Accept current label.")
2018-01-26 19:00:39 +01:00
;; code can be found in reftex-cite.el
2018-01-27 03:13:21 +01:00
(setq reftex-citation-help
2018-01-26 18:38:26 +01:00
" j / k Go to next/previous entry (Cursor motion works as well).
2018-01-26 21:30:56 +01:00
go / gO Show citation / Show insertion point.
2018-01-26 18:38:26 +01:00
q Quit without inserting \\cite macro into buffer.
TAB Enter citation key with completion.
RET Accept current entry and create \\cite macro.
2018-01-26 21:30:56 +01:00
m / M Mark/Unmark the entry.
o / O Create BibTeX file with all marked / unmarked entries.
X / X Put all (marked) entries into one/many \\cite commands.")
2018-01-26 19:00:39 +01:00
;;;###autoload
2018-01-26 19:00:39 +01:00
(defun evil-collection-reftex-setup ()
"Set up `evil' bindings for `reftex'."
(evil-set-initial-state 'reftex-select-label-mode 'normal)
(evil-set-initial-state 'reftex-select-bib-mode 'normal)
2018-02-24 15:42:01 +01:00
(evil-collection-define-key 'normal 'reftex-select-shared-map
2018-01-26 18:38:26 +01:00
"j" 'reftex-select-next
"k" 'reftex-select-previous
2019-03-16 18:54:12 +01:00
(kbd "]]") 'reftex-select-next-heading
(kbd "[[") 'reftex-select-previous-heading
2018-01-26 21:30:56 +01:00
(kbd "gj") 'reftex-select-next-heading
(kbd "gk") 'reftex-select-previous-heading
2018-01-27 03:13:21 +01:00
(kbd "C-j") 'reftex-select-next-heading
2018-01-27 03:15:00 +01:00
(kbd "C-k") 'reftex-select-previous-heading
2018-02-24 15:42:01 +01:00
"go" 'reftex-select-callback ;shows the point where the label is
2018-01-26 18:38:26 +01:00
"gr" (lambda nil "Press `?' during selection to find out
2018-01-26 19:00:39 +01:00
about this key" (interactive) (throw (quote myexit) 114)) ;reftex binds keys in a very arcane way using the number asigned by describe-char, in this case the value of "g" is 114
2018-01-26 18:38:26 +01:00
"q" 'reftex-select-quit
2018-01-26 21:30:56 +01:00
"ZZ" 'reftex-select-quit
"ZQ" 'evil-quit
2018-01-27 03:13:21 +01:00
"g?" 'reftex-select-help
2018-01-26 21:30:56 +01:00
"c" (lambda nil "Press `?' during selection to find out
2018-01-26 18:38:26 +01:00
about this key." (interactive) (throw (quote myexit) 108))
2018-01-27 03:13:21 +01:00
"J" 'reftex-select-jump ;; weird binding, using default
2018-01-26 18:38:26 +01:00
(kbd "<tab>") 'reftex-select-read-label
"s" (lambda nil "Press `?' during selection to find out
about this key." (interactive) (throw (quote myexit) 115))
2018-01-26 21:30:56 +01:00
"x" (lambda nil "Press `?' during selection to find out
2018-01-26 18:38:26 +01:00
about this key." (interactive) (throw (quote myexit) 97))
2018-01-26 21:30:56 +01:00
"X" (lambda nil "Press `?' during selection to find out
2018-01-26 18:38:26 +01:00
about this key." (interactive) (throw (quote myexit) 65))
2018-01-26 21:30:56 +01:00
"S" (lambda nil "Press `?' during selection to find out
2018-01-26 18:38:26 +01:00
about this key." (interactive) (throw (quote myexit) 120))
2018-01-26 21:30:56 +01:00
"r" 'reftex-select-cycle-ref-style-forward
"R" 'reftex-select-cycle-ref-style-backward
2018-02-24 15:42:01 +01:00
"gO" 'reftex-select-show-insertion-point
2018-01-26 21:30:56 +01:00
"o" (lambda nil "Press `?' during selection to find out
2018-01-26 18:38:26 +01:00
about this key." (interactive) (throw (quote myexit) 101))
2018-01-26 21:30:56 +01:00
"O" (lambda nil "Press `?' during selection to find out
2018-02-24 15:42:01 +01:00
about this key." (interactive) (throw (quote myexit) 69))
;; mark
"m" 'reftex-select-mark ; TODO: Need a mark toggle function.
"u" 'reftex-select-unmark)
2018-01-26 18:38:26 +01:00
2018-01-26 19:00:39 +01:00
(evil-set-initial-state 'reftex-toc-mode 'normal)
2018-02-24 15:42:01 +01:00
2018-01-26 18:38:26 +01:00
;; This one is more involved, in reftex-toc.el, line 282 it shows the prompt
;; string with the keybinds and I don't see any way of changing it to show evil-like binds.
(evil-collection-define-key 'normal 'reftex-toc-mode-map
2018-01-26 18:38:26 +01:00
"j" 'reftex-toc-next
"k" 'reftex-toc-previous
(kbd "RET") 'reftex-toc-goto-line-and-hide
(kbd "<tab>") 'reftex-toc-goto-line
2018-01-27 03:13:21 +01:00
"g?" 'reftex-toc-show-help
2018-01-26 21:30:56 +01:00
"q" 'reftex-toc-quit
"ZZ" 'reftex-toc-quit
"ZQ" 'evil-quit
2018-01-26 18:38:26 +01:00
"gr" 'reftex-toc-rescan
"r" 'reftex-toc-rescan
"l" 'reftex-toc-toggle-labels
"?" 'reftex-toc-show-help
"x" 'reftex-toc-external
;; (kbd "SPC") 'reftex-toc-view-line
2018-01-27 03:13:21 +01:00
"f" 'reftex-toc-toggle-follow))
2018-01-26 18:38:26 +01:00
(provide 'evil-collection-reftex)
;;; evil-collection-reftex.el ends here