Fork me on GitHub
#calva
<
2021-01-23
>
plexus10:01:51

Has anyone figured out how to get the equivalent of emacs' aggressive-indent-mode? I've set "editor.autoIndent": "full" but that doesn't seem to be enough. For example:

(foo)
(bar)

;; slurp
(foo
 (bar))

;; barf, oh no!
(foo)
 (bar)

plexus10:01:28

I'd like it to always always always auto indent no matter what I do, so it's impossible for indentation and code structure to differ

pez10:01:09

That looks like an issue with the Calva formatter. It focuses on the enclosing form, and runs into troubles at the top level. File it on GitHub, I don't think we ever did that.

borkdude10:01:35

funny, I recently asked how to make Calva indenting less aggressive like I'm used to in clojure-mode in emacs :)

😂 3
plexus10:01:55

ok! I'll make an issue

borkdude10:01:21

In general you can find some options here: https://calva.io/formatting/#configuration (@plexus)

borkdude10:01:44

btw, pez, the docs are pretty!

❤️ 3
pez10:01:03

@plexus, to verify that I have understood the problem correctly you can try the same procedure with fully enclosed forms.

plexus10:01:29

for me this is really the holy grail, paredit + aggressive-indent, makes me feel like I'm actually manipulating a syntax tree instead of a text file

plexus10:01:52

@pez you mean with something around it like

(do
  (foo)
  (bar))
?

pez10:01:36

I also want to have one more notch of aggressiveness of the indentation to kick in. I have this feeling it might make parinfer less missed.

clyfe11:01:07

On a similar note I'd like paredit.deleteBackward in the formation " <space> (|)" to delete just the parens first, and on second key press to delete the space; not both at once. Or maybe I'll get used to and will prefer the current beavior.

plexus11:01:40

sorry, got called away for a second. Works fine when it's not at the top level @pez

(do
  (foo
   (bar)))

(do
  (foo)
  (bar))

pez11:01:40

Great. Then it’s not a regression at least. I’m at my computer now and could verify that as well.

plexus11:01:30

> it might make parinfer less missed exactly, I always thought parinfer got it backwards. why manipulate structure via whitespace when you can just manipulate the structure and let the whitespace take care of itself (I'm aware many people will disagree with this sentiment 🙂 )

pez11:01:27

Parinfer does both, though? Especially if you are furtunate enough to be using an editor that can handle smart mode.

pez11:01:25

I think the Parinfer preference has a lot to do with personal, yeah, preferences. I was “forced” to think about Clojure code from te structural angle, because I learnt my first Clojure by pair programming with people who were using Emacs and shunned Parinfer. It stuck with me, even with my Python background. Paredit is my buddy. But for some it seems to be second nature (or quickly become at least) to indent their way to structure. I have a new colleague who belongs to that latter category, @anthony-galea. When we pair program I often notice that he accepts quite a lot of work to avoid Paredit. 😃

plexus11:01:55

I have accepted that for some people parinfer works really well, I try to avoid getting into arguments about it, but I can't say I get it. And I strongly resist promoting parinfer for newcomers. If people figure out it works for them ok great, but it's clearly not a great fit for everyone. I've seen too many people (e.g. at clojurebridge workshops) just confuse themselves, accidentally ending up with some weird unexpected structure, and just having no clue how to come back from it.

roelof11:01:55

Yep, I have seen a lot of these problems when learning clojure @plexus

pez11:01:24

I also avoid promoting Parinfer to newcomers. Of course somewhat because Calva’s auto-formatter does not play well with it, but mostly because I think Paredit is quite easy to learn and learning it helps in figuring out the structured nature of the code. But, yeah, arguing about this is boring. 😃 And, since the VS Code team does not get Parinfer either, Smartmode is not likely to become an option in this editor anytime soon.

roelof11:01:47

but still I find calva very good to work with as a beginner

roelof11:01:57

made even my first web project with it

pez11:01:03

I saw that. 😃 Noticed that you have commited a lot of tempfiles produced by Calva, clojure-lsp and clj-kondo. Which reminds me that Calva should help with avoiding that.

roelof11:01:30

now im stuck because I thought of a way to use pre-loading but get a error message which do not tell where the error is

pez11:01:54

pre-loading of what?

roelof11:01:57

that I find a bummer about clojure. the error messages that are nor clear

roelof11:01:09

pre-loading of some images from a external api

roelof11:01:50

but this is off-topic of this channel

pez11:01:36

Since we’re in a thread we can go off-topic, me thinks. 😃 Not sure if this is useful to you, but in my Advent of Code util.clj I cache my input data using memoize:

(defn- fetch-input' [day]
  (try
    (let [cookie (slurp ".aoc-session")]
      (:body (client/get
              (str "" day "/input")
              {:cookies {"session" {:value cookie}}})))
    (catch Exception e
      (println "Ho, ho, ho! Did you forget to populate `.aoc-session` with your AOC session cookie?")
      (throw e))))

(def fetch-input
  (memoize fetch-input'))
Maybe images are not something that should be memoized.

roelof12:01:02

it worked before

pez12:01:23

Agree about error messages and stack traces often being less helpful than we have in other languages. But you will get better at recognizing the patterns, so the problem will not remain this big for you.

roelof12:01:31

but I think this line mess things up

(future (memo-display-data (inc page))

roelof12:01:18

but to get more info, I begin a question on the beginners question where you can find all the data

pez12:01:13

Yeah #beginners is the place for this. I don’t have much experience with futures anyway. 😃

roelof12:01:47

maybe someone else can see what is wrong

roelof12:01:01

Im just a beginner which have to learn a lot

pez12:01:11

I think I saw an API key in your repo, btw. You might want to not have that public.

roelof12:01:43

yep, I still have to learn how to hide it

roelof12:01:59

but is a key from a company which do not exist anymore

pez12:01:16

One way is the way I do it in the util code I posted above. Then I have .aoc-session in .gitignore.

roelof12:01:27

so like this :

{:cookies {"session" {:value cookie}}})))```

roelof12:01:49

I have to think well how I can make that work

pez12:01:03

It’s is rather this:

(let [cookie (slurp ".aoc-session")]

roelof12:01:34

and in the file .aoc-session I can put the key?

roelof12:01:18

easy fix then , which I would do after I get this working again

pez12:01:52

Yes, put the key in some file that is gitignored, then read it in. You can make a memoized function that does the reading, so that the server doesn’t read the file every time.

pez12:01:08

Also, you might want to use to predictably find the file: https://clojuredocs.org/clojure.java.io/resource

roelof12:01:43

oke, fix on my list

roelof12:01:00

like I said first I want to make the site running again

pez12:01:02

Also put on that list to change the key. 😃

roelof12:01:37

and then practice more with 4clojure and exercism

roelof12:01:05

and learn re-frame so that I can make the next idea I have for this site

roelof12:01:15

so enoughh to learn this year

roelof12:01:54

and maybe even try some AOC challenges after exercism and 4clojure

pez12:01:18

Good plan! I think Exercism should suit you very well, since you like getting feedback. It helped me tons and tons. There’s #exercism , btw.

pez11:01:38

The aspects I am interested in is mainly when Parinfer speeds up an operation. When I watch it being used I notice both that it is slower and that is faster than Paredit. I haven’t quite wrapped my head around it, but when I do I will try to use the understanding to make Calva editing more efficient.

pez12:01:13

I’ve commented on the issue with top level formatting. Could be interesting reading for anyone who is curious about the innards of Calva structural editing: https://github.com/BetterThanTomorrow/calva/issues/982

pez12:01:45

I think there are a lot of quite interesting things with Calva structural editing that I could write some articles about, btw. I might even start that soon. 😃

pez17:01:05

Here’s a VSIX with a fix for the ; line comment bug that hits some of you. It might also fix the issue that @agold had with auto-closing quotes. Please try it out, Calva friends.

👍 10
😀 3
agold21:01:19

@pez Worked like a charm! Many thanks!

❤️ 7
vlad_poh19:01:34

what's the shortcut key for closing a tab in calva (ctrl w is taken)

pez19:01:05

You'll have to assign a shortcut, @kbosompem . At least until we update the Calva shortcut.

👍 3
clyfe20:01:58

Toying with https://nextjournal.github.io/clojure-mode/ Nifty how modifier key highlights the form to be repl-sent.

❤️ 3
pez21:01:50

Don't think it's possible with vscode, but would be so sweet!

Janne Sauvala23:01:21

Hi 👋:skin-tone-2: is it possible to define keybindings for certain repl-commands? I would like to have a keybinding that would tap> the form I’m evaluating. I noticed there is setting for calva.customREPLCommandSnippets but I think I cannot pass args to those snippets

bringe01:01:19

I don't think it's possible currently. I think this may be best done with a new Calva command. Feel free to file an issue for a feature request.

pez11:01:04

I think it should be solved with those command snippets. We recently pulled a PR that adds some editor variables to those snippets. Sounds like if we add variables for the current form and current top level form, we would handle this case. You think so too, @UJZ6S8YR2 ?

Janne Sauvala14:01:28

Yes, that could work. I got the idea from Sean Corfield’s setup with vscode+Clover. And your suggestion could be how Clover handles custom command integration with the editor 👍:skin-tone-2:

bringe19:01:01

I guess allowing params would make it way more extensible. Also if it seems many users are using the same custom command, maybe it's a candidate for a built-in command.

bringe21:01:16

I just re-read what @pez said and I'm not sure it hit me the first time. That sounds like a great idea. simple_smile

calva 3
Janne Sauvala13:01:06

I finally made an issue for tracking purposes https://github.com/BetterThanTomorrow/calva/issues/986

❤️ 6