Fork me on GitHub
#emacs
<
2023-08-16
>
tianshu05:08:38

Have a question about indentation in clojure-mode . both clojure-mode and clojure-lsp has its own config for indentation. I want to stick with clojure-lsp, how I can apply it to line indent(i.g. the indent behavior each time I press RET )?

jasonjckn05:08:50

not your exact question, but you could apply clojure lsp indent on file save with https://github.com/radian-software/apheleia

jasonjckn05:08:42

in general the var Indent-line-function controls that happens when you push RET

jasonjckn05:08:03

also sometimes var lisp-indent-function does to in clojure mode

tianshu05:08:59

For one time format I can do lsp-format-buffer without problem. But it's annoying that the format is different during the typing. I guess lsp only has formatting for whole buffer, there's no line based format?

jasonjckn05:08:52

i’ll defer to someone else, not sure

vemv06:08:48

If you use CIDER: cider alters clojure-mode indentation rules dynamically. And it's possible for CIDER to read .cljfmt.edn dynamically (I have a wip https://github.com/clojure-emacs/cider-nrepl/pull/754) So that would be a possible solution. It technically doesn't use clojure-lsp, but both solutions would essentially use cljfmt and .cljfmt.edn. So the result would be the same. I'm highly interested in formatting being less of a mess (i.e. have most tools follow the same basic rule) so I might look into this again soon.

❤️ 2
ericdallo11:08:50

I'd be interesting in a feature like that @U0NBGRGD6 as well without the need of a REPL on, I think we could achive this making some minor changes in https://github.com/emacs-lsp/lsp-mode/blob/master/clients/lsp-clojure.el, like after lsp started, request clojure/serverInfo which will bring cljfmt settings, and then convert to indent config like cider does :)

ericdallo12:08:09

Should be a nice contribution and not hard to do, LMK if you have interest in contributing :)

tianshu12:08:17

I have two questions, Does clojure-lsp provide a way to query cljfmt config? How could clojure-mode handle those rules specified with regexp?

ericdallo12:08:13

Yes, that's how calva does ATM, it requests clojure/serverInfo which contains the cljfmt setting being used there, there is already a function in lsp-clojure.el requesting that. Good question, maybe check how cider does?

lukasz17:08:27

Anybody tried the treesitter mode for Clojure? Any advantages over good old clojure-mode ?

🍿 4
practicalli-johnny18:08:31

I tried and failed to get Treesitter working with Emacs (didn't have much time), although Treemacs is excellent with Neovim and Clojure. Very fast. In theory, a Clojure-mode on top of Treesitter should be very perfomant and potentially simplify the code in Clojure-mode (or reduce the codebase). But I've only had a cursory glance...

👍 1
lukasz20:08:17

I see - I just followed this guide from Mastering Emacs https://www.masteringemacs.org/article/how-to-get-started-tree-sitter - seems to work out of the box with tsx-/elisp-/makefile- modes. Although I'm on 29.1 version so maybe I why I didn't run into any issues so far

practicalli-johnny20:08:21

I'm interested to know what difference treesitter makes for Clojure development and if https://github.com/clojure-emacs/clojure-ts-mode helps, as it seems to be an eventual successor to clojure-mode

lukasz21:08:59

I'll try it out and see if I notice anything

lukasz21:08:27

one thing that is annoying right now is that major mode hooks have to be updated, e.g. despite instructing emacs to use clojure-ts-mode when clojure-mode is requested, it doesn't know that for clojue-mode-hooks, you have to update all your configuration to use clojure-ts-mode-hooks. You can follow along as I'm updating my config 😉 https://github.com/lukaszkorecki/command-center/pull/3/files

nivekuil03:08:35

can you just call clojure-mode-hooks from clojure-ts-mode-hook?

Roma09:08:47

Another option is (add-to-list 'major-mode-remap-alist '(clojure-mode . clojure-ts-mode))

Roma09:08:34

But I guess it won't fix hooks

lukasz14:08:38

It won’t, and other major modes that depend on Clojure-mode explicitly (Monroe) seem to break, at least that’s how I’m experiencing it. Gonna wait until tree sitter modes are the default

jasonjckn22:08:35

im daily driving clojure-ts-mode, works great, i love it, although for the moment i set indent functions back to clojure-mode, but that’ll be improved shortly.

jasonjckn22:08:09

if you’re interested in the general ecosystem surrounding treesit, ts-fold, combobulate, DIY stuff, etc there’s advantages , otherwise for now best case scenario you’ll notice no real difference (feature parity is current goal), maybe a slight performance increase

jasonjckn23:08:50

if you’re interested in any non lisp languages, treesit makes it possible to manipulate languages as if they were lisps , in terms of the editing experience you’re probably use to in clojure/paredit/etc

lukasz23:08:38

So far I installed a bunch of modes for non-Clojure languages and things seem to work... a bit faster I guess?

lukasz23:08:56

couldn't make it work as a replacement for clojure-mode, too many things didn't work for me

lukasz23:08:34

not that I'm in desperate need, I don't even use parinfer or similar things 🤷

jasonjckn00:08:48

@U0JEFEZH6 no parinfer? that’s like running with scissors

jasonjckn00:08:16

i’d probably be one of those people ranting about parentheses if not for smartparens + cleverparens, etc

lukasz00:08:36

C-M-f & C-M-b is all I need 😉

2