This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-18
Channels
- # announcements (2)
- # asami (20)
- # aws (4)
- # babashka (35)
- # beginners (47)
- # calva (65)
- # cider (19)
- # clj-kondo (63)
- # clojure (177)
- # clojure-austin (2)
- # clojure-europe (27)
- # clojure-nl (1)
- # clojure-uk (4)
- # clojurescript (13)
- # community-development (5)
- # conjure (5)
- # css (2)
- # data-oriented-programming (9)
- # datalevin (13)
- # datascript (15)
- # datomic (4)
- # devcards (6)
- # duct (4)
- # emacs (8)
- # funcool (1)
- # gratitude (2)
- # helix (3)
- # hyperfiddle (3)
- # introduce-yourself (1)
- # jobs (4)
- # jobs-discuss (26)
- # lambdaisland (2)
- # lsp (20)
- # malli (2)
- # meander (2)
- # mid-cities-meetup (5)
- # missionary (15)
- # music (4)
- # off-topic (37)
- # reagent (3)
- # reitit (2)
- # releases (2)
- # ring (18)
- # shadow-cljs (70)
- # specter (4)
- # sql (20)
- # timbre (3)
- # tools-build (43)
- # tools-deps (11)
- # vim (29)
- # xtdb (61)
How would I go about making a keybinding that does a "def a let expression" action? GIF in thread: 🧵
A couple of ideas would be: • a normal vim macro • maybe there's some API in Conjure?
if you've got vim-sexp which has various motions and text objects for s-exprs then something like this might work. Use it with the cursor on the name of the binding. It selects the first element moves to the end of the next, yanks them then pastes them into a command line using :ConjureEval. Clunky but works mostly.
nmap <leader>cdl vie<m-e>y:ConjureEval (def <c-r>")<cr>
@U02EP7NKPAL That worked like a charm! Thank you! Now I feel a hacker in the movies
@U02EP7NKPAL Very nice, I never knew I needed this! It also works with IcedEval
for vim-iced.
This is slightly different but works for me
(nvim.set_keymap :n :<leader>cdl "vi]y:ConjureEval (def <c-r>\")<cr>" {:noremap true})
What’s an example of a multi line let? Vim-sexp motions should work fine across lines
So this works on a let with one line, like (let [a 1])
(nvim.set_keymap :n :<leader>cdl "vi]y:ConjureEval (def <c-r>\")<cr>" {:noremap true})
But if I run it on the two line one, it will go until the ending ]
and then get an error like this:
; eval (command): (def a :b b :c)
; (err) Syntax error compiling def at (src/analysis/core.clj:1:1).
; (err) Too many arguments to def
If I naively try and bind the same binding that worked great in vimscript, translated to this:
(nvim.set_keymap :n :<leader>cdl "vie<m-e>y:ConjureEval (def <c-r>\")<cr>" {:noremap true})
I end up in visual mode - so I don't know if it's able to interpret the <m-e>
string correctly
That vi]
will select everything in square brackets, so every binding in the let which won't work if there is more than one.
Looks like it works if you set noremap to false (not really sure what difference that makes!)
(nvim.set_keymap :n :<leader>cdl "vie<m-e>y:ConjureEval (def <c-r>\")<cr>" {:noremap false})
Ah yes, of course. noremap means interpret the mapping as using default mappings (not any mapping that other plugins or you might have set). Usually that's what you want but in this case we do want to use a plugin's mappings so we need noremap=false. That's why the original mapping I posted used nmap, not nnoremap.
btw - an easy way to use vim script mappings in lua is to use vim.cmd to run vimscript, eg. vim.cmd[[ nmap <leader>cdl vie<m-e>y:ConjureEval (def <c-r>")<cr> ]]