@ordoflammae , e p
will pretty print into a new buffer, The contents could then be copied into your source code buffer and put in as a comment. Select the expression and press g c
to comment it.
You can also do SPC SPC cider-pprint-eval-defn-to-comment
and same for last-sexp. If I can think of good keybindings, I can add them...
OK, that last function was what I was asking for. I can just assign that to some keybinding.
Thanks.
What keybinding in the Clojure major mode menu would make sense in your opinion? I would like to add it to Spacemacs.
Probably , e p ;
. I'm not super experienced with Spacemacs, but that seems natural.
which would you use more, cider-pprint-eval-defn-to-comment
or last-sexp version ??
I don't know. I'm trying to research the difference.
I don't understand the difference between the eval-defn
family of commands and the last-sexp
family.
I tend to prefer defun, that is what , e ;
uses for the non pprint version
defn evaluates the top level expression (the parent form), last-sexp evaluates the expression/form before the cursor (or on the previous line).
I find last-sexp most useful for evaluating expressions nested inside other expressions
Ah. I'd probably use the defn
version then.
thanks, good to get some feedback before making changes π
The cider docs don't seem to be very informative on the different functions, do you have any suggestions on where I can go to find information on the different cider functions in emacs?
Well you could read my book π One day it will be finished, but hopefully has enough to help you https://practicalli.github.io/spacemacs/
Yeah, that's where I've gotten all the information I have.
I am updating it fairly regularly at the moment, often from questions posed here
I've also been having trouble with CIDER putting the result-comments on the same line as the expression sometimes, do you know how to fix that?
It seems to do that when no new line is below the code you are evaluating, i.e. at the end of the file.
Either create a new line or use C-j
as the start of the comment to move it to the next line
OK, thanks for the help.
Hello everyone, I am considering a pull request to add some more pprint keybindings. Feedback is appreciated
"e;" 'cider-eval-defun-to-comment
"ep;" 'cider-pprint-eval-defun-to-comment
"epf" 'cider-pprint-eval-defun-at-point
"epe" 'cider-pprint-eval-last-sexp
"epE" 'cider-pprint-eval-last-sexp-to-comment
Thank youI would absolutely love this.
Its already a PR
You're the best!
The PR is https://github.com/syl20bnr/spacemacs/pull/13421 (I had to push an amended commit, so it may take a few days to be cherry picked into Spacemacs)
Isn't , e ;
already implemented?
I believe , e ;
currently runs cider-eval-defun-to-comment
. It looks like he's proposing moving that to e;
and replacing it with cider-pprint-eval-defun-to-comment
. Emphasis on the pprint
.
Yes, just included for context
This function is pretty useful to me, might be worth adding:
(defun cider-eval-parent-sexp ()
"Evaluate the immediate parent sexp"
(interactive)
(save-excursion
(sp-end-of-sexp)
(evil-jump-item)
(cider-eval-sexp-at-point)))
(spacemacs|forall-clojure-modes m
(spacemacs/set-leader-keys-for-major-mode m
"e." 'cider-eval-parent-sexp))
@thenonameguy could you provide some examples of when you would use this function?
here I had it mapped to , e (
but itβs the same fn
essentially, you can evaluate the surrounding sexp, without having to navigate to the end/beginning
but I moved the keybind to , e .
since itβs more comfortable
Is this different to , e l
or , e $
yes, because those operate on lines, this operates on the AST
try invoking them on this example
and you would get +
evaled and (+ 2 .2)
evaled
not the surrounding sexp
Okay, thanks. I will give it a try on my own setup.
Cheers, it reduced my navigation by quite a bit
Alternative: setting C-c C-c
to evaluate toplevel expressions inside comments.
Thoughts on what would be most sane to use?
(setq clojure-toplevel-inside-comment-form 't)
that actually makes a lot of sense
I've been wanting this for ages.
Thank you so much!
Anyone else have an issue where , t t
doesn't always show the results in the minibuffer?
I'm finding that sometimes the test result gets hidden by what looks like an evaluation result.
So I have to , t b
to see the test result. π
yes, it would be nice to fix
had this for ages
This should be included with the clojure layer IMO
+1
+ 1
Any idea why Spacemacs becomes awfully slow when setting (set! *warn-on-reflection* true)
?
Is it Emacs or is it adding more overhead for Clojure? Are you actually getting reflection warnings?
I am getting reflection warnings but I think this has more to do with CIDER than anything. Once I close the repl everything is fast again.
Also is there an "inverse" for the go-to definition function?
As in find all places where this function is called
, r f u -> find usages
@plins I dont have those key mapping
you need to enable clj-refactor
are you using master or development branch? o the dev branch it comes with the clojure layer already (if Im not mistaken)
on .spacemacs
at dotspacemacs-configuration-layers
change the clojure layer to this config and the bindings should show up
(clojure :variables
clojure-enable-linters '(clj-kondo)
clojure-enable-clj-refactor t)
if you are not using clj-kondo
(its a linter, no related to your question but any way..) I strongly advise you to do so, once again, its very easy to setup, just install it on your machine , add that line to .spacemacs
and should be working
clj-refactor
was causing issues so I had uninstalled it. But let me give it a go and see if its still wonky
I am using the dev branch
@mario.cordova.862 or you could use the Emacs tools, eg. SPC s p
followed by C-c C-e
to put all the results in a buffer
I use this approach to refactor names across a project, eg. https://practicalli.github.io/spacemacs/refactor/within-a-project.html
Would this catch instances of calling a function with a namespace prefix such (my-ns/function-name args)
?
Yes, its a text search, so it will match what ever you search for. It doesn't rely on the REPL or static analysis.
Ah, well I could just use SPC /
this works relatively well. Although for some odd reason its returning results for files that should be ignored
With either keybinding you can pass arguments to the search. If you have ripgrep binary installed, they you can pass search arguments `-g*.clj` to just search *.clj files, or `-g!*.md` to exclude searching *.md files
I was under the assumption that SPC /
will search all files in project but will ignore files that are set in the .gitignore
file.
Yes, it should do, although I stopped using that keybinding as it has a few annoyances (weird vim things if you forget to press RTN, have to clear the search highlighting by deleting it).
Here are some examples of using the option with a search https://practicalli.github.io/spacemacs/working-with-projects/searching-projects.html
I recommend installing ripgrep or at least silver-searcher (ag) if you havent already, they are much faster and more reliable than grep.
Yes, I use the silver searcher
Thanks @jr0cket
I think clj-refactor is a bit more reliable than it used to be, however, I found I haven't missed it over the last year. It's good to have options π
Threading refactoring is already part of clojure-mode, so clj-refactor is not needed for that. In fact I just used thread-last refactor yesterday thanks to your reminder about it.
@plins could you clarify what clear the namespace does? I assume you mean remove (undefine) the definitions in the current namespace. I thought that was part of CIDER itself (I could be wrong).
https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-clean-ns
I think its part of CLJR, also besides removing the unused requires/definitions I think it also sort the requires in alphabetical order
Oh yes, I looked at the link. That refactor command does more than I would want it too personally. I prefer to group dependencies and requires by their purpose rather than how they are spelt. For unused requirements, then clj-kondo has that covered and is my preferred approach, as I prefer to learn by making those changes myself. However, thats just my approach and its interesting to know how others work.
I never really used it. I need to discipline myself to use more of the structural editing. starting getting into the habit of using spc k r, spc k t, spc k c
. These keybindings are powerful
not those specific but all of them in general
for it would be worth it just for the clear namespace function
does ag have the same -g
options for specifying patters? I know it can do the same, just cant remember if the option names are the same.
It does actually
If SPC /
is not working as expected, you could always rebind it to another command, e.g in dotspacemacs/user-config
addd this expression to use helm swoop (evil-leader/set-key "/" 'helm-swoop)
also thread-first/thread-last refactorings
SPC k r
is one of my most-used keybindings in Lisp languages.
I still struggle to find a use for SPC k c
. π