]> code.delx.au - gnu-emacs-elpa/blob - packages/ivy/ivy-hydra.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / ivy / ivy-hydra.el
1 ;;; ivy-hydra.el --- Additional key bindings for Ivy -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Author: Oleh Krehel
6
7 ;; This file is part of GNU Emacs.
8
9 ;; This file is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; For a full copy of the GNU General Public License
20 ;; see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23 ;;
24 ;; This package provides the `hydra-ivy/body' command, which is a
25 ;; quasi-prefix map, with many useful bindings. These bindings are
26 ;; shorter than usual, using mostly unprefixed keys.
27
28 ;;; Code:
29 (require 'hydra nil t)
30 (require 'ivy)
31
32 (eval-when-compile
33 (unless (or (featurep 'hydra) (package-installed-p 'hydra))
34 (defmacro defhydra (name &rest _)
35 "This is a stub for the uninstalled `hydra' package."
36 `(defun ,(intern (format "%S/body" name)) ()
37 (interactive)
38 (let ((enable-recursive-minibuffers t))
39 (if (yes-or-no-p "Package `hydra' not installed. Install?")
40 (progn
41 (package-install 'hydra)
42 (save-window-excursion
43 (find-library "ivy-hydra")
44 (byte-compile-file (buffer-file-name) t)))
45 (error "Please install `hydra' and recompile/reinstall `ivy-hydra'")))))))
46
47 (defun ivy--matcher-desc ()
48 (if (eq ivy--regex-function
49 'ivy--regex-fuzzy)
50 "fuzzy"
51 "ivy"))
52
53 (defhydra hydra-ivy (:hint nil
54 :color pink)
55 "
56 ^ ^ ^ ^ ^ ^ | ^Call^ ^ ^ | ^Cancel^ | ^Options^ | Action _w_/_s_/_a_: %-14s(ivy-action-name)
57 ^-^-^-^-^-^-+-^-^---------^-^--+-^-^------+-^-^-------+-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------
58 ^ ^ _k_ ^ ^ | _f_ollow occ_u_r | _i_nsert | _c_: calling %-5s(if ivy-calling \"on\" \"off\") _C_ase-fold: %-10`ivy-case-fold-search
59 _h_ ^+^ _l_ | _d_one ^ ^ | _o_ops | _m_: matcher %-5s(ivy--matcher-desc)^^^^^^^^^^^^ _t_runcate: %-11`truncate-lines
60 ^ ^ _j_ ^ ^ | _g_o ^ ^ | ^ ^ | _<_/_>_: shrink/grow^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _D_efinition of this menu
61 "
62 ;; arrows
63 ("h" ivy-beginning-of-buffer)
64 ("j" ivy-next-line)
65 ("k" ivy-previous-line)
66 ("l" ivy-end-of-buffer)
67 ;; actions
68 ("o" keyboard-escape-quit :exit t)
69 ("C-g" keyboard-escape-quit :exit t)
70 ("i" nil)
71 ("C-o" nil)
72 ("f" ivy-alt-done :exit nil)
73 ("C-j" ivy-alt-done :exit nil)
74 ("d" ivy-done :exit t)
75 ("g" ivy-call)
76 ("C-m" ivy-done :exit t)
77 ("c" ivy-toggle-calling)
78 ("m" ivy-toggle-fuzzy)
79 (">" ivy-minibuffer-grow)
80 ("<" ivy-minibuffer-shrink)
81 ("w" ivy-prev-action)
82 ("s" ivy-next-action)
83 ("a" ivy-read-action)
84 ("t" (setq truncate-lines (not truncate-lines)))
85 ("C" ivy-toggle-case-fold)
86 ("u" ivy-occur :exit t)
87 ("D" (ivy-exit-with-action
88 (lambda (_) (find-function 'hydra-ivy/body)))
89 :exit t))
90
91 (provide 'ivy-hydra)
92
93 ;;; ivy-hydra.el ends here