├── README.md └── cider-hydra.el /README.md: -------------------------------------------------------------------------------- 1 | [Hydras](https://github.com/abo-abo/hydra) for [CIDER](https://github.com/clojure-emacs/cider). 2 | 3 | ## Overview 4 | 5 | This package defines some hydras (pop-up menus of commands with common 6 | prefixes) for CIDER. 7 | 8 | Hydras serve several important purposes: discovery, memorization, and 9 | organization. 10 | 11 | - Discovery 12 | 13 | - Grouping related commands together under a common prefix and 14 | displaying them in a single menu facilitates discovery. 15 | 16 | - For example, if a user wants to know about CIDER's documentation 17 | commands, they could bring up a hydra that includes commands like 18 | `cider-doc', `cider-javadoc', etc, some of which may be new to them. 19 | 20 | - Memorization 21 | 22 | - Hydras serve as a memory aid for the user. By grouping related 23 | commands together, the user has less need to memorize every command; 24 | knowing one, she can find the others. 25 | 26 | - Organization 27 | 28 | - The process of creating hydras can aid in organizing code. This 29 | gives both developers and users a better overview of what the 30 | project can or cannot do. 31 | 32 | - Thus, each hydra is like a section of a quick-reference card. In 33 | fact, many of the hydras here are inspired by the CIDER refcard: 34 | https://github.com/clojure-emacs/cider/blob/master/doc/cider-refcard.pdf 35 | 36 | ## Install 37 | 38 | After setting up [MELPA](http://melpa.org/) as a repository, use `M-x package-install cider-hydra` to install the package. 39 | 40 | ## Setup 41 | 42 | Add the following to your init file: 43 | 44 | ```emacs-lisp 45 | (add-hook 'clojure-mode-hook #'cider-hydra-mode) 46 | ``` 47 | 48 | To turn hydras off, just disable the `cider-hydra-mode`, which will restore the previous CIDER commands. 49 | 50 | ## See Also 51 | 52 | - The [which-key](https://github.com/justbur/emacs-which-key) package, which 53 | displays keys following for a prefix key. 54 | -------------------------------------------------------------------------------- /cider-hydra.el: -------------------------------------------------------------------------------- 1 | ;;; cider-hydra.el --- Hydras for CIDER. -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2016-2018 Tianxiang Xiong 4 | 5 | ;; Author: Tianxiang Xiong 6 | ;; Keywords: convenience, tools 7 | ;; Package-Requires: ((cider "0.22.0") (hydra "0.13.0")) 8 | ;; URL: https://github.com/clojure-emacs/cider-hydra 9 | ;; Version: 0.2.0-snapshot 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;; This package defines some hydras (pop-up menus of commands with common 27 | ;; prefixes) for CIDER. 28 | 29 | ;; For more information about CIDER, see 30 | ;; https://github.com/clojure-emacs/cider 31 | 32 | ;; For more information about hydras, see https://github.com/abo-abo/hydra 33 | 34 | ;; Hydras serve several important purposes: discovery, memorization, and 35 | ;; organization. 36 | 37 | ;; - Discovery 38 | 39 | ;; - Grouping related commands together under a common prefix and 40 | ;; displaying them in a single menu facilitates discovery. 41 | 42 | ;; - For example, if a user wants to know about CIDER's documentation 43 | ;; commands, they could bring up a hydra that includes commands like 44 | ;; `cider-doc', `cider-javadoc', etc, some of which may be new to them. 45 | 46 | ;; - Memorization 47 | 48 | ;; - Hydras serve as a memory aid for the user. By grouping related 49 | ;; commands together, the user has less need to memorize every command; 50 | ;; knowing one, she can find the others. 51 | 52 | ;; - Organization 53 | 54 | ;; - The process of creating hydras can aid in organizing code. This 55 | ;; gives both developers and users a better overview of what the 56 | ;; project can or cannot do. 57 | ;; 58 | ;; - Thus, each hydra is like a section of a quick-reference card. In 59 | ;; fact, many of the hydras here are inspired by the CIDER refcard: 60 | ;; https://github.com/clojure-emacs/cider/blob/master/doc/cider-refcard.pdf 61 | 62 | ;;; Code: 63 | 64 | (require 'cider-apropos) 65 | (require 'cider-client) 66 | (require 'cider-doc) 67 | (require 'cider-clojuredocs) 68 | (require 'cider-eval) 69 | (require 'cider-macroexpansion) 70 | (require 'cider-mode) 71 | (require 'cider-repl) 72 | (require 'cider-test) 73 | (require 'cider-inspector) 74 | (require 'hydra) 75 | 76 | 77 | ;;;; Customize 78 | 79 | (defgroup cider-hydra nil 80 | "Hydras for CIDER." 81 | :prefix "cider-hydra-" 82 | :group 'cider) 83 | 84 | 85 | ;;;; Documentation 86 | 87 | (defhydra cider-hydra-doc (:color blue) 88 | " 89 | CIDER Documentation 90 | --------------------------------------------------------------------------- 91 | _d_: CiderDoc _j_: JavaDoc in browser 92 | _a_: Search symbols _s_: Search symbols & select 93 | _A_: Search documentation _e_: Search documentation & select 94 | _r_: ClojureDocs _h_: ClojureDocs in browser 95 | " 96 | ;; CiderDoc 97 | ("d" cider-doc nil) 98 | ;; JavaDoc 99 | ("j" cider-javadoc nil) 100 | ;; Apropos 101 | ("a" cider-apropos nil) 102 | ("s" cider-apropos-select nil) 103 | ("A" cider-apropos-documentation nil) 104 | ("e" cider-apropos-documentation-select nil) 105 | ;; ClojureDocs 106 | ("r" cider-clojuredocs nil) 107 | ("h" cider-clojuredocs-web nil)) 108 | 109 | 110 | ;;;; Loading and evaluation 111 | 112 | (defhydra cider-hydra-eval (:color blue) 113 | " 114 | CIDER Evaluation 115 | --------------------------------------------------------------------------- 116 | _k_: Load (eval) buffer _l_: Load (eval) file 117 | _p_: Load all project namespaces 118 | _r_: Eval region _n_: Eval ns form 119 | _e_: Eval last sexp _p_: Eval last sexp and pprint 120 | _w_: Eval last sexp and replace _E_: Eval last sexp to REPL 121 | _d_: Eval defun at point _f_: Eval defun at point and pprint 122 | _:_: Read and eval _i_: Inspect 123 | _m_: Macroexpand-1 _M_: Macroexpand all 124 | " 125 | ;; Load 126 | ("k" cider-load-buffer nil) 127 | ("l" cider-load-file nil) 128 | ("p" cider-load-all-project-ns nil) 129 | ;; Eval 130 | ("r" cider-eval-region nil) 131 | ("n" cider-eval-ns-form nil) 132 | ("e" cider-eval-last-sexp nil) 133 | ("p" cider-pprint-eval-last-sexp nil) 134 | ("w" cider-eval-last-sexp-and-replace nil) 135 | ("E" cider-eval-last-sexp-to-repl nil) 136 | ("d" cider-eval-defun-at-point nil) 137 | ("f" cider-pprint-eval-defun-at-point nil) 138 | (":" cider-read-and-eval nil) 139 | ;; Inspect 140 | ("i" cider-inspect nil) 141 | ;; Macroexpand 142 | ("m" cider-macroexpand-1 nil) 143 | ("M" cider-macroexpand-all nil)) 144 | 145 | 146 | ;;;; Testing and debugging 147 | 148 | (defhydra cider-hydra-test (:color blue) 149 | " 150 | CIDER Debug and Test 151 | --------------------------------------------------------------------------- 152 | _x_: Eval defun at point 153 | _v_: Toggle var tracing _n_: Toggle ns tracing 154 | _t_: Run test _l_: Run loaded tests 155 | _p_: Run project tests _r_: Rerun tests 156 | _s_: Show test report 157 | " 158 | ;; Debugging 159 | ("x" (lambda () (interactive) (cider-eval-defun-at-point t)) nil) 160 | ("v" cider-toggle-trace-var nil) 161 | ("n" cider-toggle-trace-ns nil) 162 | ;; Testing 163 | ("t" cider-test-run-test nil) 164 | ("l" cider-test-run-loaded-tests nil) 165 | ("r" cider-test-rerun-failed-tests nil) 166 | ("p" cider-test-run-project-tests nil) 167 | ("s" cider-test-show-report nil)) 168 | 169 | 170 | ;;;; REPL 171 | 172 | (defhydra cider-hydra-repl (:color blue) 173 | " 174 | CIDER REPL 175 | --------------------------------------------------------------------------- 176 | _d_: Display connection info _r_: Rotate default connection 177 | _z_: Switch to REPL _n_: Set REPL ns 178 | _p_: Insert last sexp in REPL _x_: Reload namespaces 179 | _o_: Clear REPL output _O_: Clear entire REPL 180 | _b_: Interrupt pending evaluations _Q_: Quit CIDER 181 | " 182 | ;; Connection 183 | ("d" cider-display-connection-info nil) 184 | ("r" cider-rotate-default-connection nil) 185 | ;; Input 186 | ("z" cider-switch-to-repl-buffer nil) 187 | ("n" cider-repl-set-ns nil) 188 | ("p" cider-insert-last-sexp-in-repl nil) 189 | ("x" cider-refresh nil) 190 | ;; Output 191 | ("o" cider-find-and-clear-repl-output nil) 192 | ("O" (lambda () (interactive) (cider-find-and-clear-repl-output t)) nil) 193 | ;; Interrupt/quit 194 | ("b" cider-interrupt nil) 195 | ("Q" cider-quit nil)) 196 | 197 | 198 | ;;;; Key bindings and minor mode 199 | 200 | (defvar cider-hydra-map 201 | (let ((map (make-sparse-keymap))) 202 | (set-keymap-parent map cider-mode-map) 203 | (define-key map (kbd "C-c C-d") #'cider-hydra-doc/body) 204 | (define-key map (kbd "C-c C-t") #'cider-hydra-test/body) 205 | (define-key map (kbd "C-c M-t") #'cider-hydra-test/body) 206 | (define-key map (kbd "C-c M-r") #'cider-hydra-repl/body) 207 | map) 208 | "Keymap for CIDER hydras.") 209 | 210 | ;;;###autoload 211 | (define-minor-mode cider-hydra-mode 212 | "Hydras for CIDER." 213 | :keymap cider-hydra-map 214 | :require 'cider) 215 | 216 | 217 | (provide 'cider-hydra) 218 | ;;; cider-hydra.el ends here 219 | --------------------------------------------------------------------------------