summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar.batsov@gmail.com>2015-03-27 00:04:26 +0200
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2015-03-27 00:04:26 +0200
commit9492a05223758b698f273f628a617661570834a0 (patch)
tree4a318b36d2158baa4de9db9107d6adcacf39703f
parenta3083cbded49f2cddb07aebb71ccf4908bba8103 (diff)
parent1202eb5b481cd6ccc2b0a99b63baa5f816aca7d9 (diff)
Merge pull request #1044 from cichli/prompt-option
Add `cider-prompt-for-symbol` option
-rw-r--r--CHANGELOG.md3
-rw-r--r--README.md5
-rw-r--r--cider-doc.el8
-rw-r--r--cider-grimoire.el32
-rw-r--r--cider-interaction.el112
-rw-r--r--cider-stacktrace.el6
-rw-r--r--cider-test.el8
7 files changed, 121 insertions, 53 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 237a9fa3..7490f938 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,9 @@
* [#958](https://github.com/clojure-emacs/cider/pull/958) Reuse existing repl
buffers with dead processes. Users are now informed about existing zombie repl
buffers and are offered the choice to reuse those for new connections.
+* New defcustom, `cider-prompt-for-symbol`. Controls whether to prompt for
+ symbol when interactive commands require one. Defaults to t, which always
+ prompts. Currently applies to all documentation and source lookup commands.
### Changes
diff --git a/README.md b/README.md
index fd73857a..5539a508 100644
--- a/README.md
+++ b/README.md
@@ -256,6 +256,11 @@ When using `switch-to-buffer`, pressing <kbd>SPC</kbd> after the command will
make the hidden buffers visible. They'll always be visible in
`list-buffers` (<kbd>C-x C-b</kbd>).
+* By default, interactive commands that require a symbol will prompt for the
+ symbol, with the prompt defaulting to the symbol at point. You can set
+ `cider-prompt-for-symbol` to nil to instead try the command with the symbol at
+ point first, and only prompt if that fails.
+
* You can control the <kbd>TAB</kbd> key behavior in the REPL via the
`cider-repl-tab-command` variable. While the default command
`cider-repl-indent-and-complete-symbol` should be an adequate choice for
diff --git a/cider-doc.el b/cider-doc.el
index 87dbe2c9..d4306647 100644
--- a/cider-doc.el
+++ b/cider-doc.el
@@ -169,7 +169,7 @@
(interactive)
(if cider-docview-javadoc-url
(browse-url cider-docview-javadoc-url)
- (message "No Javadoc available for %s" cider-docview-symbol)))
+ (error "No Javadoc available for %s" cider-docview-symbol)))
(defun cider-docview-source ()
"Open the source for the current symbol, if available."
@@ -179,19 +179,19 @@
(not (cider--tooling-file-p cider-docview-file))
(cider-find-file cider-docview-file))))
(cider-jump-to buffer (cons cider-docview-line nil) nil))
- (message "No source location for %s" cider-docview-symbol)))
+ (error "No source location for %s" cider-docview-symbol)))
(defun cider-docview-grimoire ()
(interactive)
(if cider-buffer-ns
(cider-grimoire-lookup cider-docview-symbol)
- (message "%s cannot be looked up on Grimoire" cider-docview-symbol)))
+ (error "%s cannot be looked up on Grimoire" cider-docview-symbol)))
(defun cider-docview-grimoire-web ()
(interactive)
(if cider-buffer-ns
(cider-grimoire-web-lookup cider-docview-symbol)
- (message "%s cannot be looked up on Grimoire" cider-docview-symbol)))
+ (error "%s cannot be looked up on Grimoire" cider-docview-symbol)))
;;; Font Lock and Formatting
diff --git a/cider-grimoire.el b/cider-grimoire.el
index 9fcaa35c..64886d24 100644
--- a/cider-grimoire.el
+++ b/cider-grimoire.el
@@ -49,13 +49,19 @@
(let ((name (nrepl-dict-get var-info "name"))
(ns (nrepl-dict-get var-info "ns")))
(browse-url (cider-grimoire-url name ns)))
- (message "Symbol %s not resolved" symbol)))
+ (error "Symbol %s not resolved" symbol)))
;;;###autoload
-(defun cider-grimoire-web ()
- "Open the grimoire documentation for QUERY in the default web browser."
- (interactive)
- (cider-read-symbol-name "Grimoire doc for: " 'cider-grimoire-web-lookup))
+(defun cider-grimoire-web (&optional arg)
+ "Open grimoire documentation in the default web browser.
+
+Prompts for the symbol to use, or uses the symbol at point, depending on
+the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
+opposite of what that option dictates."
+ (interactive "P")
+ (funcall (cider-prompt-for-symbol-function arg)
+ "Grimoire doc for: "
+ #'cider-grimoire-web-lookup))
(defun cider-create-grimoire-buffer (content)
"Create a new grimoire buffer with CONTENT."
@@ -82,12 +88,18 @@
(delete-blank-lines)
;; and create a new buffer with whatever is left
(pop-to-buffer (cider-create-grimoire-buffer (buffer-string))))))
- (message "Symbol %s not resolved" symbol)))
+ (error "Symbol %s not resolved" symbol)))
;;;###autoload
-(defun cider-grimoire ()
- "Open the grimoire documentation for QUERY in a popup buffer."
- (interactive)
- (cider-read-symbol-name "Grimoire doc for: " 'cider-grimoire-lookup))
+(defun cider-grimoire (&optional arg)
+ "Open grimoire documentation in a popup buffer.
+
+Prompts for the symbol to use, or uses the symbol at point, depending on
+the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
+opposite of what that option dictates."
+ (interactive "P")
+ (funcall (cider-prompt-for-symbol-function arg)
+ "Grimoire doc for:"
+ #'cider-grimoire-lookup))
(provide 'cider-grimoire)
diff --git a/cider-interaction.el b/cider-interaction.el
index b9f7099a..f2f8b5e4 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -113,6 +113,19 @@ which will use the default REPL connection."
:group 'cider
:package-version '(cider . "0.6.0"))
+(defcustom cider-prompt-for-symbol t
+ "Controls when to prompt for symbol when a command requires one.
+
+When non-nil, always prompt, and use the symbol at point as the default
+value at the prompt.
+
+When nil, attempt to use the symbol at point for the command, and only
+prompt if that throws an error."
+ :type '(choice (const :tag "always" t)
+ (const :tag "dwim" nil))
+ :group 'cider
+ :package-version '(cider . "0.9.0"))
+
(defcustom cider-completion-use-context t
"When true, uses context at point to improve completion suggestions."
:type 'boolean
@@ -770,7 +783,7 @@ When called interactively, this operates on point."
(-if-let* ((resource (cider-sync-request:resource path))
(buffer (cider-find-file resource)))
(cider-jump-to buffer)
- (message "Cannot find resource %s" path)))
+ (error "Cannot find resource %s" path)))
(defun cider--jump-to-loc-from-info (info &optional other-window)
"Jump to location give by INFO.
@@ -783,7 +796,7 @@ OTHER-WINDOW is passed to `cider-jamp-to'."
(cider-find-file file))))
(if buffer
(cider-jump-to buffer (cons line nil) other-window)
- (message "No source location"))))
+ (error "No source location"))))
(defun cider--jump-to-var (var &optional line)
"Jump to the definition of VAR, optionally at a specific LINE."
@@ -791,16 +804,21 @@ OTHER-WINDOW is passed to `cider-jamp-to'."
(progn
(if line (setq info (nrepl-dict-put info "line" line)))
(cider--jump-to-loc-from-info info))
- (message "Symbol %s not resolved" var)))
+ (error "Symbol %s not resolved" var)))
-(defun cider-jump-to-var (&optional var line)
+(defun cider-jump-to-var (&optional arg var line)
"Jump to the definition of VAR, optionally at a specific LINE.
-When called interactively, prompts with symbol at point."
- (interactive)
+
+Prompts for the symbol to use, or uses the symbol at point, depending on
+the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
+opposite of what that option dictates."
+ (interactive "P")
(cider-ensure-op-supported "info")
(if var
(cider--jump-to-var var line)
- (cider-read-symbol-name "Symbol: " #'cider--jump-to-var)))
+ (funcall (cider-prompt-for-symbol-function arg)
+ "Symbol: "
+ #'cider--jump-to-var)))
(define-obsolete-function-alias 'cider-jump 'cider-jump-to-var "0.7.0")
(defalias 'cider-jump-back 'pop-tag-mark)
@@ -941,10 +959,16 @@ in the buffer."
(browse-url url)
(error "No Javadoc available for %s" symbol-name)))))
-(defun cider-javadoc ()
- "Browse Javadoc on the Java symbol at point."
- (interactive)
- (cider-read-symbol-name "Javadoc for: " 'cider-javadoc-handler))
+(defun cider-javadoc (arg)
+ "Open Javadoc documentation in a popup buffer.
+
+Prompts for the symbol to use, or uses the symbol at point, depending on
+the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
+opposite of what that option dictates."
+ (interactive "P")
+ (funcall (cider-prompt-for-symbol-function arg)
+ "Javadoc for: "
+ #'cider-javadoc-handler))
(defun cider-stdin-handler (&optional buffer)
"Make a stdin response handler for BUFFER."
@@ -1745,11 +1769,25 @@ ready to call."
(cider-repl--replace-input (format "(%s)" f))
(goto-char (- (point-max) 1)))))))
-(defun cider-read-symbol-name (prompt callback &optional query)
+(defun cider-read-symbol-name (prompt callback)
"Read a symbol name using PROMPT with a default of the one at point.
Use CALLBACK as the completing read var callback."
(funcall callback (cider-read-from-minibuffer prompt (cider-symbol-at-point))))
+(defun cider-try-symbol-at-point (prompt callback)
+ "Call CALLBACK with symbol at point.
+On failure, read a symbol name using PROMPT and call CALLBACK with that."
+ (condition-case nil (funcall callback (cider-symbol-at-point))
+ ('error (funcall callback (cider-read-from-minibuffer prompt)))))
+
+(defun cider--should-prompt-for-symbol (&optional invert)
+ (if invert (not cider-prompt-for-symbol) cider-prompt-for-symbol))
+
+(defun cider-prompt-for-symbol-function (&optional invert)
+ (if (cider--should-prompt-for-symbol invert)
+ #'cider-read-symbol-name
+ #'cider-try-symbol-at-point))
+
(defun cider-sync-request:toggle-trace-var (symbol)
"Toggle var tracing for SYMBOL."
(cider-ensure-op-supported "toggle-trace-var")
@@ -1758,21 +1796,26 @@ Use CALLBACK as the completing read var callback."
"sym" symbol)
(nrepl-send-sync-request)))
-(defun cider-toggle-trace-var ()
+(defun cider--toggle-trace-var (sym)
+ (let* ((trace-response (cider-sync-request:toggle-trace-var sym))
+ (var-name (nrepl-dict-get trace-response "var-name"))
+ (var-status (nrepl-dict-get trace-response "var-status")))
+ (pcase var-status
+ ("not-found" (error "Var %s not found" sym))
+ ("not-traceable" (error "Var %s can't be traced because it's not bound to a function" var-name))
+ (t (message "Var %s %s" var-name var-status)))))
+
+(defun cider-toggle-trace-var (arg)
"Toggle var tracing.
-Defaults to the symbol at point."
- (interactive)
+
+Prompts for the symbol to use, or uses the symbol at point, depending on
+the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
+opposite of what that option dictates."
+ (interactive "P")
(cider-ensure-op-supported "toggle-trace-var")
- (cider-read-symbol-name
- "Toggle trace for var: "
- (lambda (sym)
- (let* ((trace-response (cider-sync-request:toggle-trace-var sym))
- (var-name (nrepl-dict-get trace-response "var-name"))
- (var-status (nrepl-dict-get trace-response "var-status")))
- (pcase var-status
- ("not-found" (message "Var %s not found" sym))
- ("not-traceable" (message "Var %s can't be traced because it's not bound to a function" var-name))
- (t (message "Var %s %s" var-name var-status)))))))
+ (funcall (cider-prompt-for-symbol-function arg)
+ "Toggle trace for var: "
+ #'cider--toggle-trace-var))
(defun cider-sync-request:toggle-trace-ns (ns)
"Toggle namespace tracing for NS."
@@ -1792,7 +1835,7 @@ Defaults to the current ns. With prefix arg QUERY, prompts for a ns."
(let* ((trace-response (cider-sync-request:toggle-trace-ns ns))
(ns-status (nrepl-dict-get trace-response "ns-status")))
(pcase ns-status
- ("not-found" (message "ns %s not found" ns))
+ ("not-found" (error "ns %s not found" ns))
(t (message "ns %s %s" ns ns-status))))))
(defun cider-create-doc-buffer (symbol)
@@ -1804,13 +1847,18 @@ Defaults to the current ns. With prefix arg QUERY, prompts for a ns."
"Look up documentation for SYMBOL."
(-if-let (buffer (cider-create-doc-buffer symbol))
(cider-popup-buffer-display buffer t)
- (message "Symbol %s not resolved" symbol)))
+ (error "Symbol %s not resolved" symbol)))
-(defun cider-doc ()
- "Open a window with the docstring for the given symbol.
-Defaults to the symbol at point."
- (interactive)
- (cider-read-symbol-name "Doc for: " 'cider-doc-lookup))
+(defun cider-doc (&optional arg)
+ "Open Clojure documentation in a popup buffer.
+
+Prompts for the symbol to use, or uses the symbol at point, depending on
+the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
+opposite of what that option dictates."
+ (interactive "P")
+ (funcall (cider-prompt-for-symbol-function arg)
+ "Doc for: "
+ #'cider-doc-lookup))
(defun cider-undef ()
"Undefine the SYMBOL."
diff --git a/cider-stacktrace.el b/cider-stacktrace.el
index 513a4380..4cc3959d 100644
--- a/cider-stacktrace.el
+++ b/cider-stacktrace.el
@@ -429,13 +429,13 @@ it wraps to 0."
(button-get button 'file)))))
(cider--jump-to-loc-from-info info t)))
-(defun cider-stacktrace-jump ()
+(defun cider-stacktrace-jump (&optional arg)
"Like `cider-jump-to-var', but uses the stack frame source at point, if available."
- (interactive)
+ (interactive "P")
(let ((button (button-at (point))))
(if (and button (button-get button 'line))
(cider-stacktrace-navigate button)
- (call-interactively 'cider-jump-to-var))))
+ (cider-jump-to-var arg))))
;; Rendering
diff --git a/cider-test.el b/cider-test.el
index 6ce527fe..fc29c067 100644
--- a/cider-test.el
+++ b/cider-test.el
@@ -161,15 +161,15 @@
(-when-let (pos (next-single-property-change (point) 'type))
(goto-char pos))))
-(defun cider-test-jump ()
+(defun cider-test-jump (&optional arg)
"Like `cider-jump-to-var', but uses the test at point's definition, if available."
- (interactive)
+ (interactive "P")
(let ((ns (get-text-property (point) 'ns))
(var (get-text-property (point) 'var))
(line (get-text-property (point) 'line)))
(if (and ns var)
- (cider-jump-to-var (concat ns "/" var) line)
- (call-interactively 'cider-jump-to-var))))
+ (cider-jump-to-var arg (concat ns "/" var) line)
+ (cider-jump-to-var arg))))
;;; Error stacktraces