This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-01
Channels
- # announcements (4)
- # babashka (7)
- # beginners (11)
- # biff (4)
- # calva (11)
- # cider (21)
- # clerk (1)
- # clj-otel (1)
- # clojure (84)
- # clojure-art (3)
- # clojure-austin (1)
- # clojure-europe (25)
- # clojure-norway (14)
- # community-development (5)
- # events (1)
- # hyperfiddle (12)
- # off-topic (16)
- # polylith (23)
- # random (1)
- # re-frame (6)
- # releases (1)
- # thejaloniki (1)
How can I change the cider-spinner to show in my file buffer, rather than in the REPL buffer?
That's a tricky one. I remember having to modify some code inside CIDER sources to achieve that, and my changes got overwritten by an update, so I don't know how to do it anymore 😅
@alexyakushev Thanks for the response! Watching one of your screencasts for your Clojure profiler and seeing the spinner active in the file buffer is what inspired me to look into this! (It’s not as often that I have a REPL buffer visible, but knowing there’s a longer-running computation is useful feedback.) I want to thank you so much for your tools! I use them everyday. So much so that I have an emacs shortcut wrapping them to run at a key press. Including in case it’s useful to others:
(defun clojurize-last-sexp (f)
(let* ((bounds (cider-last-sexp 'bounds))
(s (cider-last-sexp))
(clojurize (concat "(" f " " s ")")))
(cider-interactive-eval clojurize nil bounds (cider--nrepl-print-request-map))))
(defun clojurize-defun-at-point (f)
(let* ((bounds (cider-defun-at-point 'bounds))
(s (cider-defun-at-point))
(clojurize (concat "(" f " " s ")")))
(cider-interactive-eval clojurize nil bounds (cider--nrepl-print-request-map))))
;; ----------------------------------------------------------------------
(defun clj-quickbench-at-point ()
(interactive)
(clojurize-defun-at-point "criterium.core/quick-bench"))
(defun clj-quickbench-last-sexp ()
(interactive)
(clojurize-last-sexp "criterium.core/quick-bench"))
So, I am able to get the spinner to display in file buffer by modifying two lines in cider-client.el, changing connection
to eval-buffer
and adding (add-hook 'cider-after-eval-done-hook 'spinner-stop)
to my config. Below is the modified function with the original lines commented out:
(defun cider-nrepl-request:eval (input callback &optional ns line column additional-params connection)
"Send the request INPUT and register the CALLBACK as the response handler.
If NS is non-nil, include it in the request. LINE and COLUMN, if non-nil,
define the position of INPUT in its buffer. ADDITIONAL-PARAMS is a plist
to be appended to the request message. CONNECTION is the connection
buffer, defaults to (cider-current-repl)."
(let ((connection (or connection (cider-current-repl nil 'ensure)))
(eval-buffer (current-buffer)))
(run-hooks 'cider-before-eval-hook)
(nrepl-request:eval input
(lambda (response)
(when cider-show-eval-spinner
;; (cider-eval-spinner connection response)
(cider-eval-spinner eval-buffer response)
)
(when (and (buffer-live-p eval-buffer)
(member "done" (nrepl-dict-get response "status")))
(with-current-buffer eval-buffer
(run-hooks 'cider-after-eval-done-hook)))
(funcall callback response))
connection
ns line column additional-params)
;; (cider-spinner-start connection)
(cider-spinner-start eval-buffer)))
Cool that you've got to the bottom of it! Perhaps, this could make a good feature request for Cider. I also almost never have the REPL buffer open, so a spinner in the current code buffer makes more sense.
This would be a nice feature (e.g. I have keybindings for running stuff like (user/reset)
for integrant-repl which take a non-trivial amount of time to execute). I tried hacking together a solution some time ago but had to abort as I realized I just don't understand elisp enough 🙂
@U0178V2SLAY You should be able to just replace cider-nrepl-request:eval
into cider-client.el with the one above, and remember to add and evaluate (add-hook 'cider-after-eval-done-hook 'spinner-stop)
somewhere in your user config, otherwise the spinner handler isn’t receiving the finished signal properly. Hooks are like event handlers that get run after some condition happens. If for some reason you get an infinite spinner, you can always manually run M-:
(spinner-stop)
.
This change has been working great for my intentions. The code I changed only effects the spinner logic, so I don’t see this interfering with anything else.
Oh no… I’m finally finding some time to do a little work on one of my open source projects, and something about the current versions of cider and my other Clojure packages are breaking in a bad way. As soon as I jack in, I get the following error popping up in the minibar:
error in process filter: Wrong number of arguments: ((clojure-mode-abbrev-table paredit-mode paredit-version paredit-space-for-delimiter-predicates font-lock-end font-lock-beg calculate-lisp-indent-last-sexp t) nil "Return the namespace of the current Clojure buffer.
Return the namespace closest to point and above it. If there are
no namespaces above point, return the first one in the buffer.
The results will be cached if `clojure-cache-ns' is set to t." (if (and clojure-cache-ns clojure-cached-ns) clojure-cached-ns (let ((ns (save-excursion (save-restriction (widen) (condition-case nil (progn (while t (up-list nil t t))) (error nil)) (or (clojure--find-ns-in-direction 'backward) (clojure--find-ns-in-direction 'forward)))))) (setq clojure-cached-ns ns) ns))), 1
The same error prevents me doing things like evaluating s-expressions or defns. I am basically dead in the water. Is there any hope anyone might be able to help me troubleshoot this?This is with cider 20230930.751.
The middle of that looks like the doc string and start of the implementation of clojure-find-ns
from clojure-mode.el
but I can’t imagine why that is showing up as an argument to something in the process filter? Whatever that means?
I can’t find the string clojure-mode-abbrev-table
anywhere in my elpa downloads.
Well, after much flailing and pulling out some of my few remaining strands of hair, I was able to figure out how to revert to the melpa-stable version of Cider, which works again.
Can you clarify this? Is there a way to continue using the melpa version of Cider? What clojure-mode does it need?
(If so, Cider should give that instruction instead of crashing in such a horrible and cryptic way.)
All you need to do is to use clojure-mode latest (stable and unstable happen to be the same commit today, for clojure-mode)
You encountered a more cryptic error message than usual, but it's not undecipherable. Either way, it's not on CIDER to work around the nature of Elisp
Thanks, I will give that a try! And please understand I wasn’t trying to insult CIDER here, if it sounded like that, it is because I was extremely tired and fried after being up much later than I should be, trying to get the Clojure development environment I have come to rely on so profoundly to work again so I could help one of my own users. I was wondering whether, if CIDER depends on a particular version of clojure-mode, and that version is not present, there is any way it could give an explicit warning about that, the way it does with cider-nrepl. Otherwise, even someone like myself, who has been using Emacs since 1987, who wrote the chapter on Elisp in the current revision of O’Reilly’s “Learning GNU Emacs,” and who has been living in CIDER for my personal and professional projects for roughly a decade, can be stuck in a panic for a while. Of course, if I had taken a breath, stepped back, and waited until the morning to see if anyone on this channel had advice in response to my messages, you would have saved me from all that. 😄
It's no issue :) CIDER declares its clojure-mode dep in a vanilla fashion: https://github.com/clojure-emacs/cider/blob/9b300bf817e77f611f9c589c9cdd665f19d98c5f/cider.el#L15 Then it's the package manager's concern to take care of transitive deps. I feel that making sure that the package manager did its work properly would exceed what is expected for a package. We cannot reasonably e.g. wrap every defun in a try/catch and try to automatically perform a diagnostic when things go wrong. Probably if we wanted to zap all possible sources of confusion, we could only accept Github issues as a form of support, and place a very stringent form (not template) that makes sure that users have performed all the basic troubleshooting themselves. I took that approach with https://github.com/rm-hull/nvd-clojure/ (try opening an issue there) and issue reports have greatly dropped since. But things are quite good as they are right now.
Agreed, and trying to get the package manager to behave better would probably be as effective as attacking a windmill with a lance. 🙂

And I can confirm that after fighting with the package manager for a bit more—I think I need to remove the lines from my init.el
that require these packages—everything is working with the latest versions. Thanks again!
@alexyakushev Thanks for the response! Watching one of your screencasts for your Clojure profiler and seeing the spinner active in the file buffer is what inspired me to look into this! (It’s not as often that I have a REPL buffer visible, but knowing there’s a longer-running computation is useful feedback.) I want to thank you so much for your tools! I use them everyday. So much so that I have an emacs shortcut wrapping them to run at a key press. Including in case it’s useful to others:
(defun clojurize-last-sexp (f)
(let* ((bounds (cider-last-sexp 'bounds))
(s (cider-last-sexp))
(clojurize (concat "(" f " " s ")")))
(cider-interactive-eval clojurize nil bounds (cider--nrepl-print-request-map))))
(defun clojurize-defun-at-point (f)
(let* ((bounds (cider-defun-at-point 'bounds))
(s (cider-defun-at-point))
(clojurize (concat "(" f " " s ")")))
(cider-interactive-eval clojurize nil bounds (cider--nrepl-print-request-map))))
;; ----------------------------------------------------------------------
(defun clj-quickbench-at-point ()
(interactive)
(clojurize-defun-at-point "criterium.core/quick-bench"))
(defun clj-quickbench-last-sexp ()
(interactive)
(clojurize-last-sexp "criterium.core/quick-bench"))
So, I am able to get the spinner to display in file buffer by modifying two lines in cider-client.el, changing connection
to eval-buffer
and adding (add-hook 'cider-after-eval-done-hook 'spinner-stop)
to my config. Below is the modified function with the original lines commented out:
(defun cider-nrepl-request:eval (input callback &optional ns line column additional-params connection)
"Send the request INPUT and register the CALLBACK as the response handler.
If NS is non-nil, include it in the request. LINE and COLUMN, if non-nil,
define the position of INPUT in its buffer. ADDITIONAL-PARAMS is a plist
to be appended to the request message. CONNECTION is the connection
buffer, defaults to (cider-current-repl)."
(let ((connection (or connection (cider-current-repl nil 'ensure)))
(eval-buffer (current-buffer)))
(run-hooks 'cider-before-eval-hook)
(nrepl-request:eval input
(lambda (response)
(when cider-show-eval-spinner
;; (cider-eval-spinner connection response)
(cider-eval-spinner eval-buffer response)
)
(when (and (buffer-live-p eval-buffer)
(member "done" (nrepl-dict-get response "status")))
(with-current-buffer eval-buffer
(run-hooks 'cider-after-eval-done-hook)))
(funcall callback response))
connection
ns line column additional-params)
;; (cider-spinner-start connection)
(cider-spinner-start eval-buffer)))