Fork me on GitHub
#emacs
<
2023-03-21
>
borkdude11:03:06

clj2el: a small clojure -> elisp transpiler 😂 clojure-spin emacs-spin https://borkdude.github.io/clj2el/

emacs-spin 26
clojure-spin 10
💯 6
😁 2
ag18:03:31

Coool, I can't wait for it to be able to take Clojure let with destructuring and turn it into pcase-let or something. That would be so awesome. And turning clj maps into elisp alists or hashmaps. Converting (assoc m :foo x) into proper setf, etc. Clojure is awesome, and Elisp is not horrible either, but it can be annoyingly verbose, quirky and nonsensical.

ag18:03:50

I'd donate my pinky or thumb to have proper Clojure maps in Elisp. Maps alone make working with Clojure so much nicer.

borkdude18:03:52

Feel free to post issues with ideas :)

borkdude18:03:12

Also check out #C04V4LQF6V7 for another thing in progress

ag18:03:26

Maan, you're like clj-Midas. Whatever you touch - it becomes Clojure. LOL...

😂 2
teodorlu13:03:35

now with a small babashka CLI ☝️

$ bbin install io.github.borkdude/clj2el --latest-sha
$ echo '(defn foo [x & xs] xs)' | clj2el
(defun foo (x &rest xs) xs)

👏 4
2
borkdude13:03:44

now I'm just waiting for someone to write clj2el.el which shells out to that CLI to convert a region

borkdude13:03:53

(PR welcome)

dpsutton13:03:48

reminder that M-| is shell-command-on-region. If you highlight a region you can use it. If you give it a prefix, it will replace the region with the output of the shell command. I use this often with jet to format edn and jq to format json.

👍 8
borkdude14:03:08

Thanks for the reminder @dpsutton, it works!

dpsutton14:03:01

(I wish someone had posted that reminder years ago. forgot how powerful and useful it is in so many scenarios)

teodorlu14:03:11

https://clojurians.slack.com/archives/C099W16KZ/p1679406764536459 Something like this?

(defun clj2el-transpile-region ()
  (interactive)
  (shell-command-on-region (point) (mark) "clj2el" (current-buffer) 't))
1. Select clojure region 2. M-x clj2el-transpile-region 3. you now have Emacs lisp! https://github.com/borkdude/clj2el/pull/2

teodorlu14:03:54

I'm not quite sure about how to provide installation instructions for Emacs distributions other than Doom Emacs, suggestions welcome!

dpsutton14:03:09

look at the docstring on interactive. You can make that region aware i believe

👀 2
brianwitte14:03:23

y'all are really leveling this up, love it

🎉 2
Benjamin15:03:39

Do you know what is kaputt when my cider shadow session does not complete js/ (`js/console.log`)

solf17:03:08

Does auto-completion work for other js objects?

solf17:03:02

The one responsible for auto-completion of js objects is clj-suitable

solf17:03:20

used by cider.nrepl

solf17:03:37

In the browser console you should see

shadow-cljs: load JS cider/nrepl/inlined/deps/suitable/v0v4v1/suitable/js_introspection.cljs

solf17:03:45

only when you first try to auto-complete a js object

Benjamin11:03:13

The issue was fixed when I upgraded shadow from 2.19.0 to 2.22.7

Benjamin12:03:22

nvm. I had it working for 30seconds. Now I am not sure if the version was the difference. Back to it not loading suitable

ag21:03:22

I swear, I feel like I used to know what's needed to make it work. But I've been trying for the past 40 minutes and can't figure it out. What do I need to tweak so evil-ex-search - # or * in Evil-mode worked with Clojure symbols? So when I search for foo/bar, while the cursor is on foo part, it would search for foo and not foo/bar?

tomd21:03:58

evil-symbol-word-search

tomd21:03:02

In your example, foo/bar is one symbol, so setting evil-symbol-word-search to nil would give you the behaviour you want. I realise that's the opposite of how you've stated the problem, but afaik that's how it's always worked

ag21:03:24

yeah, but then it doesn't work for things like foo-bar/zap-zop - when the cursor at foo-bar, pressing # I'd expect it to find previous mention of foo-bar, but it'd be looking for foo

tomd21:03:29

Yes, no doubt. I'm not sure this has ever worked as you want, and if it has, it's not an evil setting. It will be what clojure-mode defines as a symbol, most likely

tomd21:03:56

Evil, after all, defers to the syntax (defined by major mode usually) to decide what is a symbol

ag21:03:28

I need to figure out how to make emacs recognize (thing-at-point 'word) for foo-bar as foo-bar and not foo

tomd21:03:17

I think the simplest (dumb?) approach is

(modify-syntax-entry ?- "w" clojure-mode-syntax-table)
But someone has probably made a package that is smarter about this. Something like superword-mode is probably in that area (I haven't used it myself)

ag21:03:11

Ya, so doing modify-syntax-entry makes it recognize the whole symbol as the word. so thing-at-point 'word now returns the whole foo-bar/zap-zop... Now you probably understand why I spent almost an hour and still can't figure it out 🙂

tomd21:03:52

not if evil-symbol-word-search is nil, no?

ag22:03:50

Additionally, I realized that unlike in Vim, evil-ex-start-word-search doesn't respect the region, i.e., when I select a portion of the symbol/word I should expect it to search only for that part. IMO That's a legit bug.

tomd22:03:38

Are you looking for visual-star functionality?

tomd22:03:27

https://github.com/bronson/vim-visual-star-search is a plugin, not default vim behaviour. Maybe I'm not understanding

ag22:03:37

see here: https://github.com/emacs-evil/evil/blob/master/evil-search.el#L1166 it should respect region if (use-region-p)

tomd22:03:44

Yeah I know where the code is 🙂 - I just want to check what behaviour you're expecting

tomd22:03:58

I can make (and work on) an evil issue if it's a bug

tomd22:03:18

(I'm the maintainer of evil btw, that's probably not obvious)

ag22:03:13

I'm not sure about Vim, I checked in nvim, #|* respects the region (if there's one)

tomd22:03:00

so, just to make sure I understand you, by "respects the region" do you mean "search within the region" or "search within the whole buffer for what is selected by the region"?

ag22:03:15

So I have foo-bar/zap-zop. Cursor is at f. I mark a region from f to -, selecting foo-. When I press # I expect it to search backwards for the previous occurrence of foo-

tomd22:03:36

ok, so the second thing

tomd22:03:47

yeah, that's not default vim behaviour, hence vim-visual-star-search plugin. it may have been added to neovim (it's the sort of thing I'd expect they would add) and it's not evil's official policy to mimic neovim (although sometimes we do if we fancy)

tomd22:03:44

yeah, it's a "default mapping" according to their docs: https://neovim.io/doc/user/vim_diff.html#default-mappings

tomd22:03:07

the line between "bug" and "feature" is fuzzy in Evil, even by optimistic developer standards, so file it either way on evil's github and one of us may take a look soon

ag22:03:37

Yeah, this should be trivial to make it work with an advise. Please don't waste your energy trying to fix something that's not broken 😉

🙂 2
ag22:03:09

I'll try to fix it locally and if that works I'll try to make a documentation PR

ag22:03:15

Thank you for your help, Tom!

tomd22:03:05

no probs. sorry I couldn't help on the syntax-table / word-thing stuff

ag22:03:21

nah, don't sweat it. It's not hugely important. I'm just having my emacs tantrum moment. I often want something badly. Would spend hours to make it work only two days later to realize I never needed that shit. Like some monkey that finds a stick, carries it like the most precious thing in the whole world and then drops it without any philosophical remorse. That's me. I'm an Emacs monkey.

😆 2
ag23:03:01

Oy vey... took me forever to make it work. I did not expect it to be so non-trivial. This is what I had to do to make visual-star-search in evil:

(defun evil-ex-start-word-search-a (fn unbounded direction count &optional symbol)
  (if (use-region-p)
      (let* ((beg (region-beginning))
             (end (1+ (region-end)))
             (delta (- end beg 1))
             (s (buffer-substring beg end))
             (evil-ex-search-pattern s)
             (evil-ex-search-offset 0))
        (deactivate-mark)
        (if (eq direction 'forward)
            (goto-char end)
          (goto-char beg))
        (when (evil-ex-search-full-pattern s count direction)
          (let ((p (progn (when (eq direction 'forward)
                            (backward-char))
                          (point))))
            (set-mark p)
            (goto-char (if (eq direction 'forward)
                           (- p delta)
                         (+ p delta))))))
    (funcall fn unbounded direction count symbol)))

(advice-add #'evil-ex-start-word-search :around #'evil-ex-start-word-search-a)

ag23:03:44

I'm an idiot with no respect for the notion of Time. It already exists. https://github.com/bling/evil-visualstar

tomd23:03:32

Heh yes I almost posted that earlier but got distracted. Often better to work it out yourself first anyway eh 😉