evil-collection/modes/reftex/evil-collection-reftex.el

174 lines
7.4 KiB
EmacsLisp
Raw Normal View History

2020-04-26 07:37:30 +02:00
;;; evil-collection-reftex.el --- Bindings for `reftex' -*- lexical-binding: t -*-
2018-01-26 18:38:26 +01:00
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 "26.3"))
2018-01-26 18:38:26 +01:00
;; 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)
(require 'reftex-toc nil t)
2018-01-26 18:38:26 +01:00
(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
(setq reftex-toc-help
" AVAILABLE KEYS IN TOC BUFFER
============================
2021-04-27 09:47:20 +02:00
j / k next-line / previous-line
go Show the corresponding location of the LaTeX document.
TAB Goto the location and keep the TOC window.
RET Goto the location and hide the TOC window (also on mouse-2).
< / > Promote / Demote section, or all sections in region.
zi Display Index. With prefix arg, restrict index to current section.
q / ZZ Hide/Kill *toc* buffer, return to position of reftex-toc command.
l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders.
f Toggle follow mode
gr / gR Reparse the LaTeX document / Reparse entire LaTeX document.
. In other window, show position from where `reftex-toc' was called.
rl Global search and replace to rename label at point.
x Switch to TOC of external document (with LaTeX package `xr').
J Jump to a specific section (e.g. '3 J' goes to section 3).")
;;;###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
2021-04-27 09:47:20 +02:00
;; This one is more involved, in reftex-toc.el, line 267 it shows the prompt
2018-01-26 18:38:26 +01:00
;; 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
2021-04-27 09:47:20 +02:00
"go" 'reftex-toc-view-line
"gO" 'reftex-toc-view-line
2018-01-26 18:38:26 +01:00
(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
2021-04-27 09:47:20 +02:00
"?" 'reftex-toc-show-help
2018-01-26 21:30:56 +01:00
"q" 'reftex-toc-quit
2021-04-27 09:47:20 +02:00
"ZZ" 'reftex-toc-quit-and-kill
2018-01-26 21:30:56 +01:00
"ZQ" 'evil-quit
2018-01-26 18:38:26 +01:00
"gr" 'reftex-toc-rescan
2021-04-27 09:47:20 +02:00
"gR" 'reftex-toc-Rescan
2018-01-26 18:38:26 +01:00
"l" 'reftex-toc-toggle-labels
2021-04-27 09:47:20 +02:00
"i" 'reftex-toc-toggle-index
"c" 'reftex-toc-toggle-context
"F" 'reftex-toc-toggle-file-boundary
"rl" 'reftex-toc-rename-label
"zi" 'reftex-toc-display-index
2018-01-26 18:38:26 +01:00
"x" 'reftex-toc-external
2021-04-27 09:47:20 +02:00
"." 'reftex-toc-show-calling-point
2021-05-05 05:40:21 +02:00
"J" 'reftex-toc-jump
2021-04-27 09:47:20 +02:00
(kbd "[[") 'reftex-toc-previous-heading
(kbd "]]") 'reftex-toc-next-heading
(kbd ">") 'reftex-toc-promote
(kbd "<") 'reftex-toc-demote
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