conjure

:neovim:+:clj: https://github.com/Olical/conjure - If you're enjoying Conjure and want to say thanks: https://github.com/users/Olical/sponsorship :smile: (alt https://conjure.fun/discord)
dave 2021-06-11T13:13:22.137300Z

I've noticed recently that when I open a .clj file on load (i.e. vim /path/to/something.clj) I am immediately in insert mode. Is it possible that Conjure is doing this somehow?

Olical 2021-06-11T13:16:16.137400Z

Shouldn't be, I never attempt to put you in insert mode :thinking_face:

Olical 2021-06-11T13:16:24.137600Z

Try rolling back one or two versions?

Olical 2021-06-11T13:16:28.137800Z

Just to confirm

Olical 2021-06-11T13:42:42.141100Z

I wonder if @dave and @rafaeldelboni's issues are related and both related to the auto repl / babashka functionality :thinking_face: obviously "works on my machine" but maybe there's a setting to do with unsaved buffers or something that's confusing things when I swap to the bb REPL buffer and back.

dave 2021-06-11T13:48:51.141700Z

I temporarily took bb out of my PATH and the problem went away.

dave 2021-06-11T13:49:03.142100Z

So it does seem related to the auto bb REPL.

emilaasa 2021-06-11T15:12:35.142600Z

The beautiful auto-bb ! Surely it's not to blame its so precious

Olical 2021-06-11T15:22:32.143800Z

Haha, it's probably just the way I'm creating the terminal. I create a new buffer or window and open a terminal running bb inside that new one. Then close it or swap back to what was there before, I can't remember the process exactly. I'm guessing there's some vim setting that makes this behave weirdly in some setups though...

Olical 2021-06-11T15:22:52.144400Z

Maybe I can do something simpler :thinking_face: like rephrasing the operation may be enough to fix it.

Olical 2021-06-11T15:25:29.145300Z

I haven't had the time or energy to do another batch of fix-y/feature work, but should get a window this weekend! I need to do short sprints where I fix a few things and add a few features then release it the same day I think.

dave 2021-06-11T15:26:28.145700Z

Aha! I think I do have a hack in place that puts me directly into insert mode when a terminal buffer opens.

dave 2021-06-11T15:26:45.145900Z

Yep:

" When I open a terminal buffer, I want it to feel like I'm in the terminal. I
" don't want to still be in normal mode.
autocmd TermOpen * startinsert

Olical 2021-06-11T15:27:26.146500Z

Oooo yeah! That'll do it! Still doesn't explain why @rafaeldelboni's Clojure highlighting vanished... that one has me stumped.

Olical 2021-06-11T15:27:42.146900Z

I'll see if I can somehow open the term without causing any autocmds maybe? Although not sure how I get around that.

dave 2021-06-11T15:28:09.147400Z

I'm wondering what the right solution is. Maybe there is something I can do on my side. :thinking_face:

dave 2021-06-11T15:28:39.147900Z

Would it make sense for you to switch back to normal mode explicitly when you move back away from the terminal buffer?

Olical 2021-06-11T15:29:43.149100Z

:thinking_face: I mean, you shouldn't be in normal mode after that, it's your custom autocmd that does that. So I'd like to find a way to say "just open a terminal but don't trigger anything custom since it's a background process". Patching around the insert mode part seems too narrow to me tbh, I'd like to find a broader fix.

Olical 2021-06-11T15:30:56.150300Z

I could maybe not open a terminal and just start the process completely hidden not attached to a buffer. But then you can't interact with it to <c-c> it or type into it. Which will be useful with some REPL setups (not bb sadly, you can't have nREPL and stdio because single thread)

dave 2021-06-11T15:31:47.151100Z

I think I agree. It might actually be worse to switch to normal mode explicitly because maybe someone else's weird setup relies on you putting them back into whatever mode they were in before :man-shrugging:

Olical 2021-06-11T15:32:01.151300Z

Yep 🙂

Olical 2021-06-11T15:32:16.152Z

So I will see if there's anything I can set to say "just open a buffer, don't do anything clever"

dave 2021-06-11T15:32:19.152100Z

Maybe there is a TermLeave event or something that I can respond to by putting me back into normal mode.

dave 2021-06-11T15:33:01.152300Z

Yeah! There is a TermLeave. Trying it.

dave 2021-06-11T15:34:13.152500Z

Didn't work 😑

Olical 2021-06-11T15:35:14.153200Z

If you condition your autocmd to say "only do this if the current window is a terminal" then you'll only run i when you actually have the terminal in focus, rather than a sort of background thing

💡 1
Olical 2021-06-11T15:35:18.153500Z

But maybe that's a bit much

Olical 2021-06-11T15:35:28.153700Z

We should probably thread, sorry everyone

❤️ 1
➕ 1
dave 2021-06-11T15:41:42.154Z

I took a stab at this:

" When I open a terminal buffer, I want it to feel like I'm in the terminal. I
" don't want to still be in normal mode.
autocmd TermOpen * if &amp;buftype ==# 'terminal'
      \ | startinsert
      \ | endif
Doesn't seem to have any effect, sadly.

dave 2021-06-11T15:57:31.154300Z

OK, I've solved it! 😄

" When I open a terminal buffer, I want it to feel like I'm in the terminal. I
" don't want to still be in normal mode.
autocmd TermOpen * startinsert

" This doesn't play nice with Conjure, which will sometimes open a terminal
" buffer to start a REPL server and then switch back to the previous
" buffer.
"
" As a workaround, I explicitly switch to normal mode when entering any
" Clojure buffer.
autocmd BufEnter *.clj,*.cljs,*.edn stopinsert
" (This doesn't work, for some reason.)
" autocmd FileType clojure stopinsert

Olical 2021-06-11T16:05:00.154500Z

Haha, well I'm glad you have something but sorry you had to do extra things! Not sure how I can avoid triggering autocmds like this 😞

dave 2021-06-11T17:04:01.154700Z

Don't feel bad about it. I realize that I'm probably an outlier here in that I'm monkeying with the default behavior of terminal buffers.