diff options
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | cider-doc.el | 9 | ||||
-rw-r--r-- | cider-mode.el | 199 | ||||
-rw-r--r-- | cider-test.el | 10 | ||||
-rw-r--r-- | cider-util.el | 14 | ||||
-rw-r--r-- | doc/images/menu_example.png | bin | 0 -> 33616 bytes | |||
-rw-r--r-- | doc/interactive_programming.md | 2 |
7 files changed, 163 insertions, 76 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 35227f27..b9576f0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ ### New Features +* Improve CIDER's menu-bar menu: + - Thoroughly reorganize it and split it into 3 separate menus; + - Add custom-written `:help` strings to some items, and automatically add help strings to the rest; + - Add a few commands; + - Grey-out commands that rely on connections while there is no connection. * Var docstrings are automatically displayed in mouse-over tooltips. * [#1636](https://github.com/clojure-emacs/cider/pull/1636): New minor-mode `cider-auto-test-mode` for test-driven-development. When activated, tests are rerun after every load-file. * Javadoc commands take into account the variable `clojure.java.javadoc/*remote-javadocs*`. diff --git a/cider-doc.el b/cider-doc.el index a5b21ef8..cab3f7f6 100644 --- a/cider-doc.el +++ b/cider-doc.el @@ -67,8 +67,8 @@ cider-doc-map) "CIDER documentation keymap.") -(defvar cider-doc-menu - '("Documentation ..." +(defconst cider-doc-menu + '("Documentation" ["CiderDoc" cider-doc] ["JavaDoc in browser" cider-javadoc] ["Grimoire" cider-grimoire] @@ -76,10 +76,11 @@ ["Search symbols" cider-apropos] ["Search symbols & select" cider-apropos-select] ["Search documentation" cider-apropos-documentation] - ["Search documentation & select" cider-apropos-documentation-select]) + ["Search documentation & select" cider-apropos-documentation-select] + "--" + ["Configure Doc buffer" (customize-group 'cider-docview-mode)]) "CIDER documentation submenu.") - ;;; cider-docview-mode diff --git a/cider-mode.el b/cider-mode.el index a536ac81..68c11d75 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -173,8 +173,108 @@ Returns to the buffer in which the command was invoked." (switch-to-buffer origin-buffer))) -;;; The minor mode -(defvar cider-mode-map +;;; The menu-bar +(defconst cider-mode-menu + `("CIDER" + ["Start a REPL" cider-jack-in + :help "Starts an nREPL server (with lein, boot, or maven) and connects a REPL to it."] + ["Connect to a REPL" cider-connect + :help "Connects to a REPL that's already running."] + ["Quit" cider-quit :active cider-connections] + ["Restart" cider-restart :active cider-connections] + ("Clojurescript" + ["Start a Clojure REPL, and a ClojureScript REPL" cider-jack-in-clojurescript + :help "Starts an nREPL server, connects a Clojure REPL to it, and then a ClojureScript REPL. +Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."] + ["Create a ClojureScript REPL from a Clojure REPL" cider-create-sibling-cljs-repl] + ["Configure the ClojureScript REPL to use" (customize-variable 'cider-cljs-lein-repl)]) + "--" + ["Connection info" cider-display-connection-info + :active cider-connections] + ["Rotate default connection" cider-rotate-default-connection + :active (cdr cider-connections)] + ["Select any CIDER buffer" cider-selector] + "--" + ["Configure CIDER" (customize-group 'cider)] + "--" + ["A sip of CIDER" cider-drink-a-sip] + ["View manual online" cider-view-manual] + ["View refcard online" cider-view-refcard] + ["Report a bug" cider-report-bug] + ["Version info" cider-version] + "--" + ["Close ancillary buffers" cider-close-ancillary-buffers + :active (seq-remove #'null cider-ancillary-buffers)] + ("nREPL" :active cider-connections + ["Describe session" cider-describe-nrepl-session] + ["Close session" cider-close-nrepl-session])) + "Menu for CIDER mode") + +(defconst cider-mode-eval-menu + '("CIDER Eval" :visible cider-connections + ["Eval top-level sexp" cider-eval-defun-at-point] + ["Eval last sexp" cider-eval-last-sexp] + ["Eval selected region" cider-eval-region] + ["Eval ns form" cider-eval-ns-form] + "--" + ["Interrupt evaluation" cider-interrupt] + "--" + ["Eval last sexp and insert" cider-eval-print-last-sexp + :keys "\\[universal-argument] \\[cider-eval-last-sexp]"] + ["Eval last sexp in popup buffer" cider-pprint-eval-last-sexp] + ["Eval last sexp and replace" cider-eval-last-sexp-and-replace] + ["Eval last sexp to REPL" cider-eval-last-sexp-to-repl] + ["Insert last sexp in REPL" cider-insert-last-sexp-in-repl] + ["Eval top-level sexp to comment" cider-eval-defun-to-comment] + "--" + ["Load this buffer" cider-load-buffer] + ["Load another file" cider-load-file] + ["Load all project files" cider-load-all-project-ns] + ["Refresh loaded code" cider-refresh] + ["Run project (-main function)" cider-run]) + "Menu for CIDER mode eval commands") + +(defconst cider-mode-interactions-menu + `("CIDER Interactions" :visible cider-connections + ["Complete symbol" complete-symbol] + "--" + ("REPL" + ["Set REPL to this ns" cider-repl-set-ns] + ["Switch to REPL" cider-switch-to-repl-buffer] + ["REPL Pretty Print" cider-repl-toggle-pretty-printing + :style toggle :selected cider-repl-use-pretty-printing] + ["Clear latest output" cider-find-and-clear-repl-output] + ["Clear all output" (cider-find-and-clear-repl-output t) + :keys "\\[universal-argument] \\[cider-find-and-clear-repl-output]"] + "--" + ["Configure the REPL" (customize-group 'cider-repl)]) + ,cider-doc-menu + ("Find (jump to)" + ["Find definition" cider-find-var] + ["Find resource" cider-find-resource] + ["Go back" cider-pop-back]) + ("Macroexpand" + ["Macroexpand-1" cider-macroexpand-1] + ["Macroexpand-all" cider-macroexpand-all]) + ,cider-test-menu + ("Debug" + ["Inspect" cider-inspect] + ["Toggle var tracing" cider-toggle-trace-var] + ["Toggle ns tracing" cider-toggle-trace-ns] + "--" + ["Debug top-level form" cider-debug-defun-at-point + :keys "\\[universal-argument] \\[cider-eval-defun-at-point]"] + ["List instrumented defs" cider-browse-instrumented-defs] + "--" + ["Configure the Debugger" (customize-group 'cider-debug)]) + ("Browse" + ["Browse namespace" cider-browse-ns] + ["Browse all namespaces" cider-browse-ns-all] + ["Browse classpath" cider-classpath] + ["Browse classpath entry" cider-open-classpath-entry])) + "Menu for CIDER interactions") + +(defconst cider-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c C-d") 'cider-doc-map) (define-key map (kbd "M-.") #'cider-find-var) @@ -215,75 +315,34 @@ Returns to the buffer in which the command was invoked." (define-key map (kbd "C-c M-d") #'cider-display-connection-info) (define-key map (kbd "C-c C-x") #'cider-refresh) (define-key map (kbd "C-c C-q") #'cider-quit) - (easy-menu-define cider-mode-menu map - "Menu for CIDER mode" - `("CIDER" - ["Complete symbol" complete-symbol] - "--" - ,cider-doc-menu - "--" - ("Eval" - ["Eval top-level sexp at point" cider-eval-defun-at-point] - ["Eval last sexp" cider-eval-last-sexp] - ["Eval last sexp in popup buffer" cider-pprint-eval-last-sexp] - ["Eval last sexp to REPL buffer" cider-eval-last-sexp-to-repl] - ["Eval last sexp and replace" cider-eval-last-sexp-and-replace] - ["Eval top-level sexp to comment" cider-eval-defun-to-comment] - ["Eval region" cider-eval-region] - ["Eval ns form" cider-eval-ns-form] - ["Insert last sexp in REPL" cider-insert-last-sexp-in-repl] - "--" - ["Load (eval) buffer" cider-load-buffer] - ["Load (eval) file" cider-load-file] - ["Load all project namespaces" cider-load-all-project-ns]) - ("Macroexpand" - ["Macroexpand-1" cider-macroexpand-1] - ["Macroexpand-all" cider-macroexpand-all]) - ("Find" - ["Find definition" cider-find-var] - ["Find resource" cider-find-resource] - ["Go back" cider-pop-back]) - ,cider-test-menu - "--" - ["Run project (-main function)" cider-run] - ["Inspect" cider-inspect] - ["Toggle var tracing" cider-toggle-trace-var] - ["Toggle ns tracing" cider-toggle-trace-ns] - ["Refresh loaded code" cider-refresh] - ["Select any CIDER buffer" cider-selector] - "--" - ["Debug top-level form" cider-debug-defun-at-point] - ["List instrumented defs" cider-browse-instrumented-defs] - "--" - ["Set ns" cider-repl-set-ns] - ["Switch to REPL" cider-switch-to-repl-buffer] - ["Toggle REPL Pretty Print" cider-repl-toggle-pretty-printing] - ["Clear REPL output" cider-find-and-clear-repl-output] - "--" - ["Browse classpath" cider-classpath] - ["Browse classpath entry" cider-open-classpath-entry] - ["Browse namespace" cider-browse-ns] - ["Browse all namespaces" cider-browse-ns-all] - "--" - ("nREPL" - ["Describe session" cider-describe-nrepl-session] - ["Close session" cider-close-nrepl-session] - ["Connection info" cider-display-connection-info] - ["Rotate default connection" cider-rotate-default-connection]) - "--" - ["Interrupt evaluation" cider-interrupt] - "--" - ["Close ancillary buffers" cider-close-ancillary-buffers] - ["Quit" cider-quit] - ["Restart" cider-restart] - "--" - ["A sip of CIDER" cider-drink-a-sip] - ["View manual online" cider-view-manual] - ["View refcard online" cider-view-refcard] - ["Report a bug" cider-report-bug] - ["Version info" cider-version])) + (dolist (variable '(cider-mode-interactions-menu + cider-mode-eval-menu + cider-mode-menu)) + (easy-menu-do-define (intern (format "%s-open" variable)) + map + (get variable 'variable-documentation) + (cider--menu-add-help-strings (symbol-value variable)))) map)) +;; This menu works as an easy entry-point into CIDER. Even if cider.el isn't +;; loaded yet, this will be shown in Clojure buffers next to the "Clojure" +;; menu. +;;;###autoload +(eval-after-load 'clojure-mode + '(easy-menu-define cider-clojure-mode-menu-open clojure-mode-map + "Menu for Clojure mode. + This is displayed in `clojure-mode' buffers, if `cider-mode' is not active." + `("CIDER" :visible (not cider-mode) + ["Start a REPL" cider-jack-in + :help "Starts an nREPL server (with lein, boot, or maven) and connects a REPL to it."] + ["Connect to a REPL" cider-connect + :help "Connects to a REPL that's already running."] + ["Start a Clojure REPL, and a ClojureScript REPL" cider-jack-in-clojurescript + :help "Starts an nREPL server, connects a Clojure REPL to it, and then a ClojureScript REPL. + Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."] + "--" + ["View manual online" cider-view-manual]))) + ;;; Dynamic indentation (defcustom cider-dynamic-indentation t "Whether CIDER should aid Clojure(Script) indentation. @@ -611,7 +670,7 @@ property." (apply func beg end rest))) -;;; Mode definition +;;; Minor-mode definition (defvar x-gtk-use-system-tooltips) ;;;###autoload diff --git a/cider-test.el b/cider-test.el index be68892e..1f1fb9b4 100644 --- a/cider-test.el +++ b/cider-test.el @@ -134,14 +134,20 @@ (define-key map (kbd "b") #'cider-test-show-report) map)) -(defvar cider-test-menu +(defconst cider-test-menu '("Test" ["Run test" cider-test-run-test] ["Run namespace tests" cider-test-run-ns-tests] ["Run all loaded tests" cider-test-run-loaded-tests] ["Run all project tests" cider-test-run-project-tests] + ["Run tests after load-file" cider-auto-test-mode + :style toggle :selected cider-auto-test-mode] + "--" + ["Interrupt running tests" cider-interrupt] ["Rerun failed/erring tests" cider-test-rerun-tests] - ["Show test report" cider-test-show-report]) + ["Show test report" cider-test-show-report] + "--" + ["Configure testing" (customize-group 'cider-test)]) "CIDER test submenu.") (defvar cider-test-report-mode-map diff --git a/cider-util.el b/cider-util.el index b0b49415..bf436438 100644 --- a/cider-util.el +++ b/cider-util.el @@ -363,6 +363,7 @@ plugin or dependency with: "The CIDER manual's url." (format cider-manual-url (cider--manual-version))) +;;;###autoload (defun cider-view-manual () "View the manual in your default browser." (interactive) @@ -547,6 +548,7 @@ Any other value is just returned." "Enable `eldoc-mode' to display function & method signatures in the minibuffer." "Enable `cider-enlighten-mode' to display the locals of a function when it's executed." "Use <\\[cider-close-ancillary-buffers]> to close all ancillary buffers created by CIDER (e.g. *cider-doc*)." + "Exploring CIDER's menu-bar entries is a great way to discover features." "Keep in mind that some commands don't have a keybinding by default. Explore CIDER!") "Some handy CIDER tips." ) @@ -574,6 +576,18 @@ KIND can be the symbols `ns', `var', `emph', or a face name." (`emph 'font-lock-keyword-face) (face face)))) +(defun cider--menu-add-help-strings (menu-list) + "Add a :help entries to items in MENU-LIST." + (mapcar (lambda (x) + (cond + ((listp x) (cider--menu-add-help-strings x)) + ((and (vectorp x) + (not (plist-get (append x nil) :help)) + (functionp (elt x 1))) + (vconcat x `[:help ,(documentation (elt x 1))])) + (t x))) + menu-list)) + (provide 'cider-util) ;;; cider-util.el ends here diff --git a/doc/images/menu_example.png b/doc/images/menu_example.png Binary files differnew file mode 100644 index 00000000..72f23dca --- /dev/null +++ b/doc/images/menu_example.png diff --git a/doc/interactive_programming.md b/doc/interactive_programming.md index ed702993..eca6a801 100644 --- a/doc/interactive_programming.md +++ b/doc/interactive_programming.md @@ -68,6 +68,8 @@ active you'll have a CIDER menu available, which lists all the most important commands and their keybindings. You can also invoke `C-h f RET cider-mode` to get a list of the keybindings for `cider-mode`. +![CIDER interactions menu](images/menu-example.png) + An even better solution would be to install [which-key][], which will automatically show you a list of available keybindings as you start typing some keys. This will simplify your interactions with CIDER quite a lot (especially in |