Fork me on GitHub
#calva
<
2023-02-13
>
pez10:02:54

OT, TIL (Because I searched for it in the Command Palette). You can compare the content of two editors in VS Code even if they are untitled (VS Code lingo for editor with no filesystem representation). Say you have two chunks of text of something and want to see the diff: 1. Open a new editor (`cmd+n`) 2. Paste chunk 1. 3. Open another new editor. 4. Paste chunk 2. 5. In the Command Palette search and select File: Compare Active File with... 6. A menu of open editors opens. Select the other chunk. 7. 🎉

👍 2
1
1
bringe16:02:19

I’ve done this before. Really handy at times.

noprompt21:02:26

Does anyone know what causes Calva and NeoVim not to play well? It seems like there’s an interference between the killing functions and whatever is killed does not get properly copied to the clipboard (even when that setting is turned off).

pez21:02:32

You’ll need to describe a bit more what you do, what you expect and what happens. Assume we know nothing about Neovim. (A correct assumption in my case.)

noprompt21:02:50

If simply call “Paredit: Kill Sexp Forward” from the command palette the resulting kill does not get copied to my clipboard.

noprompt21:02:21

I tried toggle the setting to do this and, either way, nothing gets copied.

noprompt21:02:00

Sorry, to clarify, it gets copied to my system clipboard.

noprompt21:02:22

But I can’t use something like p to paste it back.

noprompt21:02:40

I don’t think this is necessarily a problem with Calva. I was more or less looking to see if anyone has found a solution to this kind of problem.

noprompt21:02:22

My guess is that I will probably have to call a function in Neovim to do the kill.

dpsutton21:02:46

neovim is a separate editor right? is there also a vim emulation layer in vs code named neovim?

noprompt22:02:14

VS Code has a neovim plugin which uses neovim to do the vim emulation.

noprompt22:02:30

The standard vim emulation for VS Code not great by comparison.

dpsutton22:02:50

ah. i was super confused

pez22:02:43

> But I can’t use something like p to paste it back. Not even from the * yank buffer?

orestis08:02:45

IIRC you need to integrate the system clipboard with the Vim registers. I’ll have a look in a second (I mainly use the vim keybindings so is haven’t ran into this issue)

noprompt21:02:48

@U7PBP4UVA Thanks. I’ll look that up!

noprompt23:02:25

Looks like I needed to add set clipboard=unnamedplus in ~/.config/nvim/init.vim

orestis07:02:03

Not sure if you use neovim for other things, I have a separate init file for vscode

noprompt18:02:18

Yeah. I am currently in the process of writing a thin wrapper around vim-sexp as an alternative to the built-in paredit.

noprompt23:02:02

I ended up writing most of paredit in lua using the treesitter extension. The cool thing is that it applies to more than just Clojure. I’ve tried it out on Lua and VimL too. https://gist.github.com/noprompt/176883f76e7051909a16438c357438dd

pez06:02:48

That’s awesome! I don’t understand why it’s necessary, but it’s way cool, and nice to have it outside Clojure. PR to Calva’s docs welcome.

noprompt17:02:26

@U0ETXRFEW Its necessary because Calva's paredit doesn't play well with neovim. Undo u has issues restoring the previous structure/cursor position, and killing to pasteboard requires extra configuration. Additionally, this can use treesitter/vim for formatting.

noprompt17:02:48

I think investing in treesitter is a good idea and I hope VS Code adds natives support for it like Vim/Emacs. What I'm considering now is building a small rewriting language on top of treesitter and then compile that to Lua, elisp, etc. such that operations can be built symbolically and in a language agnostic way.

clojure-spin 2
orestis05:02:38

Does this work with the neovim plugin in insert mode? I’ve found for some reason I use paredit mainly in insert mode.

noprompt21:03:36

@U7PBP4UVA I don’t see why not. FYI, its still a work in progress.

noprompt21:03:29

There are a couple bugs, formatting is janky, and there are missing features. I’d say this needs to bake for a few months.

sudakatux20:11:01

So i know this is an old thread. but when using neovim plugin. with calva i lost the ability to move between window splits ctrl-h or even create them ctrl-v ctrl-s. how can i have that back?

sudakatux20:11:33

when not in a clojure file everything works

pez20:11:32

Interesting. I don’t think Calva binds those keys…

sudakatux20:11:57

Actually sorry its now working :thinking_face: not sure what happened.

pez20:11:45

Aha, I wondered why that other post was deleted while I was commenting. 😃 Great to hear that it works! Let’s hope it stays working.

sudakatux20:11:10

Ha thanks 🙂

noprompt22:02:35

Another question I have is about Cider :style/indent meta: is there a way to get the Calva formatter to use it? https://docs.cider.mx/cider/indent_spec.html

pez22:02:54

Calva uses cljfmt. So it is cljfmt can support it, then I think Calva could. I remember discussions about this some years ago, but don’t know if support was ever added.

noprompt22:02:32

So this might be a case where I could use joyride to ditch cljfmt and do my own formatting or something, right?

pez22:02:36

I don’t think Joyride is necessary or sufficient. It’s interpreted. I think you need more performance for a task like formatting.

pez22:02:35

That said, we did add rewrite-clj to Joyride yesterday.

Taylor Allred23:02:40

Hi! Is there a way to evaluate a form in the buffer and have it recursively evaluate identifiers that form refers to? (Eg. in the situation where you redefined a function and didn't evaluate it yet)

pez23:02:00

I don’t think it is…

seancorfield23:02:07

No. It's a good habit to eval top-level form every time you change code (you don't even need to save the file) so that your REPL always stays up-to-date...

seancorfield23:02:36

(I'm always pressing alt+enter, way more than I press ctrl+s 🙂 )

4
Taylor Allred23:02:26

I see. I was thinking this would be nice in case I forget, but I'm sure it's no problem to get in the habit of evaluating after any change. Thank you!

pez23:02:39

CIDER shows you what top level forms are evaluated. I think Calva should too.

seancorfield23:02:39

Calva shows a green bar in the right gutter for each top-level form you eval.

seancorfield23:02:58

(and a green highlight over the code too)

pez23:02:13

But it doesn’t stick when you edit the file. At the time when I added those decorations I didn’t know how to make them stick reliably. But I think I do today. Not sure I would solve the need to see what has been evaluate that way, but the same strategy could be used to visualize it in others ways.

1
dpsutton23:02:17

i use inf-clojure but i have a handy keybinding to require :reload the current namespace. and then i can put forms into a key so i can easily send that form to the repl. has been a great workflow

seancorfield00:02:57

If you edit the file, you might invalid the section that was previously eval'd so I think the current behavior is fine, TBH.

seancorfield00:02:04

There are lots of eval options so you can pick the command most suitable to the changes you made or the behavior you need. ctrl+alt+shift+enter is a good option to ensure everything in a namespace up to the current top-level form is eval'd / up-to-date (e.g., if you edited a function in a way that LSP decided to auto-insert some new requires for you, you might want to eval a bunch of code above the fn being edited).

seancorfield00:02:55

I remember someone posted a snippet they use with Joyride to eval the ns form in the current file and jump the cursor back to the current position, which is also a tempting option...

pez09:02:54

You don't need to jump away with the cursor. The Calva API docs might be a bit unclear about it, but you can give the ranges commands an editor and a position. So this Joyride code evaluates the first form in the current document, using the current REPL connection:

(require '["$v0" :as calva])
  (let [p (-> vscode/window.activeTextEditor
              .-document
              (.positionAt 0))
        ns-form (-> (calva/ranges.currentForm vscode/window.activeTextEditor p)
                    second)]
    (-> (calva/repl.evaluateCode (calva/repl.currentSessionKey) ns-form)
        (.then #(println %))))

seancorfield18:02:45

I ended up with this:

(ns javadoc
  (:require ["$v0" :as calva]
            ["vscode" :as vscode]
            [clojure.string :as str]
            [promesa.core :as p]))

(p/let [p (-> vscode/window.activeTextEditor
              .-document
              (.positionAt 0))
        ns-form (-> (calva/ranges.currentForm vscode/window.activeTextEditor p)
                    second)]
  (-> (calva/repl.evaluateCode (calva/repl.currentSessionKey) ns-form)
      (.then #(calva/repl.evaluateCode
               "clj"
               (str "(clojure.core/tap> \""
                    (.-ns %)
                    " evaluated\")")))))

metal 2
skylize22:02:28

When working on a new function, I often start out with

(let [foo (fn [...] ...)]
  (foo ...))
so I can eval the function and a call to the function in one go. Then I move it to a defn after it gets semi-stable.

🙏 2
2
pez06:02:30

You are always welcome to post tips like that in the channel, @U90R0EPHA (and of course @U04V70XH6, and everyone!).

2