spacemacs

Spacemacs docs: http://develop.spacemacs.org/doc/DOCUMENTATION.html http://develop.spacemacs.org/layers/+lang/clojure/README.html https://practicalli.github.io/spacemacs/
practicalli-john 2020-03-26T01:49:32.004800Z

@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-john 2020-03-26T01:51:01.006400Z

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

OrdoFlammae 2020-03-26T02:06:29.006800Z

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

OrdoFlammae 2020-03-26T02:06:38.007Z

Thanks.

practicalli-john 2020-03-26T02:09:26.008Z

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

OrdoFlammae 2020-03-26T02:10:50.008700Z

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

practicalli-john 2020-03-26T02:12:20.009400Z

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

OrdoFlammae 2020-03-26T02:13:53.009800Z

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

OrdoFlammae 2020-03-26T02:14:27.010800Z

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

practicalli-john 2020-03-26T02:14:39.011Z

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

practicalli-john 2020-03-26T02:15:39.012100Z

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

practicalli-john 2020-03-26T02:16:09.012700Z

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

OrdoFlammae 2020-03-26T02:16:31.013100Z

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

practicalli-john 2020-03-26T02:16:47.013900Z

thanks, good to get some feedback before making changes πŸ™‚

OrdoFlammae 2020-03-26T02:17:10.014400Z

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-john 2020-03-26T02:18:14.015100Z

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

OrdoFlammae 2020-03-26T02:18:29.015400Z

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

practicalli-john 2020-03-26T02:19:01.016700Z

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

πŸ’š 1
OrdoFlammae 2020-03-26T02:19:07.017Z

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-john 2020-03-26T02:20:02.018200Z

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-john 2020-03-26T02:20:52.019200Z

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

OrdoFlammae 2020-03-26T02:21:20.019400Z

OK, thanks for the help.

practicalli-john 2020-03-26T02:28:11.021400Z

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

zane 2020-03-26T12:44:23.032300Z

I would absolutely love this.

practicalli-john 2020-03-26T16:23:21.038500Z

Its already a PR

zane 2020-03-26T22:27:18.064500Z

You're the best!

practicalli-john 2020-03-27T11:46:42.065300Z

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)

OrdoFlammae 2020-03-26T02:30:04.022200Z

Isn't , e ; already implemented?

zane 2020-03-26T12:46:07.032500Z

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-john 2020-03-26T07:57:14.023Z

Yes, just included for context

kszabo 2020-03-26T10:46:17.023900Z

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-john 2020-03-26T11:17:36.025100Z

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

kszabo 2020-03-26T11:18:38.025400Z

kszabo 2020-03-26T11:18:41.025800Z

here I had it mapped to , e (

kszabo 2020-03-26T11:18:44.026Z

but it’s the same fn

kszabo 2020-03-26T11:19:28.026800Z

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

kszabo 2020-03-26T11:20:33.027200Z

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

practicalli-john 2020-03-26T11:20:57.027600Z

Is this different to , e l or , e $

kszabo 2020-03-26T11:21:14.028Z

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

kszabo 2020-03-26T11:21:32.028300Z

try invoking them on this example

kszabo 2020-03-26T11:21:43.028700Z

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

kszabo 2020-03-26T11:21:52.029Z

not the surrounding sexp

practicalli-john 2020-03-26T11:25:00.029600Z

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

kszabo 2020-03-26T11:26:59.030100Z

Cheers, it reduced my navigation by quite a bit

teodorlu 2020-03-26T12:02:16.031700Z

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)

4
kszabo 2020-03-26T12:02:55.032100Z

that actually makes a lot of sense

zane 2020-03-26T12:47:20.033Z

I've been wanting this for ages.

kirill.salykin 2020-03-26T13:26:47.033300Z

Thank you so much!

zane 2020-03-26T13:48:36.033700Z

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

zane 2020-03-26T13:49:11.034200Z

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

zane 2020-03-26T13:49:20.034500Z

So I have to , t b to see the test result. πŸ™

kszabo 2020-03-26T14:14:41.034800Z

yes, it would be nice to fix

kszabo 2020-03-26T14:14:44.035100Z

had this for ages

kszabo 2020-03-26T14:15:06.035300Z

This should be included with the clojure layer IMO

kirill.salykin 2020-03-26T14:48:36.035600Z

+1

plins 2020-03-26T15:22:14.036Z

+ 1

Mario C. 2020-03-26T15:37:34.037500Z

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

1
practicalli-john 2020-03-26T16:23:02.038400Z

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

Mario C. 2020-03-26T16:24:18.039300Z

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. 2020-03-26T16:29:21.039900Z

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

Mario C. 2020-03-26T16:29:37.040300Z

As in find all places where this function is called

plins 2020-03-26T17:04:02.040600Z

, r f u -> find usages

Mario C. 2020-03-26T17:18:42.041Z

@plins I dont have those key mapping

plins 2020-03-26T17:19:05.041400Z

you need to enable clj-refactor

plins 2020-03-26T17:19:27.042Z

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

plins 2020-03-26T17:20:40.042900Z

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)

plins 2020-03-26T17:21:32.043900Z

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. 2020-03-26T17:36:10.044700Z

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. 2020-03-26T17:36:16.044900Z

I am using the dev branch

practicalli-john 2020-03-26T17:46:35.045700Z

@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

practicalli-john 2020-03-26T17:48:37.046500Z

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

Mario C. 2020-03-26T17:50:16.047700Z

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

practicalli-john 2020-03-26T17:52:53.049600Z

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. 2020-03-26T17:53:58.050600Z

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-john 2020-03-26T17:56:12.053Z

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. 2020-03-26T17:57:36.053900Z

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-john 2020-03-26T18:00:16.055200Z

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-john 2020-03-26T18:00:43.055600Z

Here are some examples of using the option with a search https://practicalli.github.io/spacemacs/working-with-projects/searching-projects.html

practicalli-john 2020-03-26T18:01:53.056600Z

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. 2020-03-26T18:23:02.056800Z

Yes, I use the silver searcher

Mario C. 2020-03-26T18:23:07.057100Z

Thanks @jr0cket

practicalli-john 2020-03-26T18:24:39.059300Z

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 😁

practicalli-john 2020-03-29T08:20:24.065700Z

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.

πŸ‘ 1
practicalli-john 2020-03-29T08:22:54.065900Z

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

plins 2020-03-30T11:54:19.069800Z

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

practicalli-john 2020-03-30T13:01:37.070100Z

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. 2020-03-26T18:30:10.060600Z

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

Mario C. 2020-03-26T18:30:19.060900Z

not those specific but all of them in general

plins 2020-03-26T18:33:56.061100Z

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

πŸ‘ 1
practicalli-john 2020-03-26T18:35:54.062100Z

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. 2020-03-26T18:38:47.062300Z

It does actually

πŸ‘ 1
practicalli-john 2020-03-26T18:45:23.064100Z

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)

kszabo 2020-03-26T18:57:03.064300Z

also thread-first/thread-last refactorings

zane 2020-03-26T22:29:13.064700Z

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

zane 2020-03-26T22:29:27.064900Z

I still struggle to find a use for SPC k c. πŸ™‚