Fork me on GitHub
#spacemacs
<
2020-03-26
>
practicalli-johnny01:03:32

@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.

practicalli-johnny01:03:01

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...

OrdoFlammae02:03:29

OK, that last function was what I was asking for. I can just assign that to some keybinding.

practicalli-johnny02:03:26

What keybinding in the Clojure major mode menu would make sense in your opinion? I would like to add it to Spacemacs.

OrdoFlammae02:03:50

Probably , e p ;. I'm not super experienced with Spacemacs, but that seems natural.

practicalli-johnny02:03:20

which would you use more, cider-pprint-eval-defn-to-comment or last-sexp version ??

OrdoFlammae02:03:53

I don't know. I'm trying to research the difference.

OrdoFlammae02:03:27

I don't understand the difference between the eval-defn family of commands and the last-sexp family.

practicalli-johnny02:03:39

I tend to prefer defun, that is what , e ; uses for the non pprint version

practicalli-johnny02:03:39

defn evaluates the top level expression (the parent form), last-sexp evaluates the expression/form before the cursor (or on the previous line).

practicalli-johnny02:03:09

I find last-sexp most useful for evaluating expressions nested inside other expressions

OrdoFlammae02:03:31

Ah. I'd probably use the defn version then.

practicalli-johnny02:03:47

thanks, good to get some feedback before making changes 馃檪

OrdoFlammae02:03:10

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?

practicalli-johnny02:03:14

Well you could read my book 馃檪 One day it will be finished, but hopefully has enough to help you https://practicalli.github.io/spacemacs/

OrdoFlammae02:03:29

Yeah, that's where I've gotten all the information I have.

practicalli-johnny02:03:01

I am updating it fairly regularly at the moment, often from questions posed here

馃挌 4
OrdoFlammae02:03:07

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?

practicalli-johnny02:03:02

It seems to do that when no new line is below the code you are evaluating, i.e. at the end of the file.

practicalli-johnny02:03:52

Either create a new line or use C-j as the start of the comment to move it to the next line

OrdoFlammae02:03:20

OK, thanks for the help.

practicalli-johnny02:03:11

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 you

zane12:03:23

I would absolutely love this.

zane22:03:18

You're the best!

practicalli-johnny11:03:42

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)

OrdoFlammae02:03:04

Isn't , e ; already implemented?

zane12:03:07

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.

practicalli-johnny07:03:14

Yes, just included for context

kszabo10:03:17

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))

practicalli-johnny11:03:36

@thenonameguy could you provide some examples of when you would use this function?

kszabo11:03:41

here I had it mapped to , e (

kszabo11:03:44

but it鈥檚 the same fn

kszabo11:03:28

essentially, you can evaluate the surrounding sexp, without having to navigate to the end/beginning

kszabo11:03:33

but I moved the keybind to , e . since it鈥檚 more comfortable

practicalli-johnny11:03:57

Is this different to , e l or , e $

kszabo11:03:14

yes, because those operate on lines, this operates on the AST

kszabo11:03:32

try invoking them on this example

kszabo11:03:43

and you would get + evaled and (+ 2 .2) evaled

kszabo11:03:52

not the surrounding sexp

practicalli-johnny11:03:00

Okay, thanks. I will give it a try on my own setup.

kszabo11:03:59

Cheers, it reduced my navigation by quite a bit

teodorlu12:03:16

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)

16
zane12:03:20

I've been wanting this for ages.

kirill.salykin13:03:47

Thank you so much!

kszabo14:03:06

This should be included with the clojure layer IMO

kszabo12:03:55

that actually makes a lot of sense

zane13:03:36

Anyone else have an issue where , t t doesn't always show the results in the minibuffer?

zane13:03:11

I'm finding that sometimes the test result gets hidden by what looks like an evaluation result.

zane13:03:20

So I have to , t b to see the test result. 馃檨

kszabo14:03:41

yes, it would be nice to fix

kszabo14:03:44

had this for ages

Mario C.15:03:34

Any idea why Spacemacs becomes awfully slow when setting (set! *warn-on-reflection* true) ?

4
practicalli-johnny16:03:02

Is it Emacs or is it adding more overhead for Clojure? Are you actually getting reflection warnings?

Mario C.16:03:18

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.

Mario C.16:03:21

Also is there an "inverse" for the go-to definition function?

Mario C.16:03:37

As in find all places where this function is called

plins17:03:02

, r f u -> find usages

Mario C.17:03:42

@plins I dont have those key mapping

plins17:03:05

you need to enable clj-refactor

plins17:03:27

are you using master or development branch? o the dev branch it comes with the clojure layer already (if Im not mistaken)

plins17:03:40

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)

plins17:03:32

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

Mario C.17:03:10

clj-refactor was causing issues so I had uninstalled it. But let me give it a go and see if its still wonky

Mario C.17:03:16

I am using the dev branch

practicalli-johnny17:03:35

@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

Mario C.17:03:16

Would this catch instances of calling a function with a namespace prefix such (my-ns/function-name args) ?

practicalli-johnny17:03:53

Yes, its a text search, so it will match what ever you search for. It doesn't rely on the REPL or static analysis.

Mario C.17:03:58

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

practicalli-johnny17:03:12

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

Mario C.17:03:36

I was under the assumption that SPC / will search all files in project but will ignore files that are set in the .gitignore file.

practicalli-johnny18:03:16

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).

practicalli-johnny18:03:53

I recommend installing ripgrep or at least silver-searcher (ag) if you havent already, they are much faster and more reliable than grep.

Mario C.18:03:02

Yes, I use the silver searcher

practicalli-johnny18:03:39

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 馃榿

plins18:03:56

for it would be worth it just for the clear namespace function

馃憤 4
kszabo18:03:03

also thread-first/thread-last refactorings

practicalli-johnny08:03:24

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.

馃憤 4
practicalli-johnny08:03:54

@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).

plins11:03:19

I think its part of CLJR, also besides removing the unused requires/definitions I think it also sort the requires in alphabetical order

practicalli-johnny13:03:37

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.

Mario C.18:03:10

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

zane22:03:13

SPC k r is one of my most-used keybindings in Lisp languages.

zane22:03:27

I still struggle to find a use for SPC k c. 馃檪

Mario C.18:03:19

not those specific but all of them in general

practicalli-johnny18:03:54

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.

Mario C.18:03:47

It does actually

馃憤 4
practicalli-johnny18:03:23

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)