Fork me on GitHub
#spacemacs
<
2020-03-26
>
jr0cket01: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.

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

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

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

jr0cket02:03:39

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

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

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

jr0cket02: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?

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

jr0cket02:03:01

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

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?

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

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

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

jr0cket16:03:21

Its already a PR

zane22:03:18

You're the best!

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

jr0cket07:03:14

Yes, just included for context

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

jr0cket11:03:36

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

thenonameguy11:03:41

here I had it mapped to , e (

thenonameguy11:03:44

but it’s the same fn

thenonameguy11:03:28

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

thenonameguy11:03:33

but I moved the keybind to , e . since it’s more comfortable

jr0cket11:03:57

Is this different to , e l or , e $

thenonameguy11:03:14

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

thenonameguy11:03:32

try invoking them on this example

thenonameguy11:03:43

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

thenonameguy11:03:52

not the surrounding sexp

jr0cket11:03:00

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

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

zane12:03:20

I've been wanting this for ages.

kirill.salykin13:03:47

Thank you so much!

thenonameguy14:03:06

This should be included with the clojure layer IMO

thenonameguy12: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. :slightly_frowning_face:

thenonameguy14:03:41

yes, it would be nice to fix

thenonameguy14:03:44

had this for ages

mario.cordova.86215:03:34

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

jr0cket16:03:02

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

mario.cordova.86216: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.cordova.86216:03:21

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

mario.cordova.86216:03:37

As in find all places where this function is called

plins17:03:02

, r f u -> find usages

mario.cordova.86217: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.cordova.86217: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.cordova.86217:03:16

I am using the dev branch

jr0cket17: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

jr0cket17:03:37

I use this approach to refactor names across a project, eg. https://practicalli.github.io/spacemacs/refactor/within-a-project.html

mario.cordova.86217:03:16

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

jr0cket17: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.cordova.86217: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

jr0cket17: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.cordova.86217: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.

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

jr0cket18: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.cordova.86218:03:02

Yes, I use the silver searcher

jr0cket18: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

thenonameguy18:03:03

also thread-first/thread-last refactorings

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

jr0cket08: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

jr0cket13: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.cordova.86218: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.cordova.86218:03:19

not those specific but all of them in general

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

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