jpalardy / vim-slime

A vim plugin to give you some slime. (Emacs)
http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/
MIT License
1.83k stars 223 forks source link

Can SlimeConfig apply to all vim buffers #407

Closed Praful closed 6 months ago

Praful commented 6 months ago

I switched to this from a Jupyter Console vim plugin, which was temperamental. So far, Slime works well (I use ptpython in ipython mode from Kitty) and has the bonus of sending text to the terminal or whatever app is open in it.

When SlimeConfig is called for a buffer, the settings apply only to that buffer. For other buffers you must enter the settings again. It helps that "Kitty listen on" socket is pre-filled. (For some reason, the Window ID is always 0 even if I launch gvim from Kitty where KITTY_WINDOW_ID is defined.)

Is it possible to have Slime remember when the window id and socket have been provided and not ask again for other buffers?

I'm using gvim 9, Linux Mint 21.2, Kitty 0.21.2.

jpalardy commented 6 months ago

Hi @Praful

Since I use g:slime_dont_ask_default, I forgot that's how it works 😅

Having each buffer ask you is more a feature than a bug, since it's not automatic that you would want every buffer to send to the same target.

That being said:

Give that a try and let me know how it goes 👍

Praful commented 6 months ago

Hi @jpalardy

Thanks for replying.

With kitty, the socket name changes every time it's launched (it consists of a basic stem and a port is appended). Similarly, the window id varies for each kitty tab. I could fix which id I send to from vim but I'm not sure how to get around the varying socket name. That was the rationale for suggesting to prompt once and not thereafter.

Suggestions?!

jpalardy commented 6 months ago

Hi @Praful

Sorry, what I meant was: after the first prompt, try:

let g:slime_default_config = b:slime_config

and it will populate the next prompt. (combine with let g:slime_dont_ask_default = 1 to skip the prompt)

You can put it on a mapping, so you don't have to type it.

Praful commented 6 months ago

@jpalardy ah thanks - I misunderstood.

Setting the two variables manually after running :SlimConfig does the trick.

I tried to put it in a function:

function! CustomSlimConfig()
  :SlimConfig
  let g:slime_default_config = b:slime_config
  let g:slime_dont_ask_default = 1

  " Display a message (optional)
  echo "SlimConfig executed"
endfunction

" Map F2 to the custom function
nnoremap <F2> :call CustomSlimConfig()<CR>

but it didn't work! My VimScript isn't good enough to find the bug. Could you help please?

jpalardy commented 6 months ago

it's close ^

how about:

function! CustomSlimeConfig()
  call SlimeConfig()
  let g:slime_default_config = b:slime_config
  let g:slime_dont_ask_default = 1

  " Display a message (optional)
  echo "SlimeConfig executed"
endfunction

" Map F2 to the custom function
nnoremap <F2> :call CustomSlimeConfig()<CR>
Praful commented 6 months ago

Thanks again. I've changed to your corrected version, but the two global variables are still not being set and the echo message is not appearing.

Does this work for you?!

jpalardy commented 6 months ago

SlimeConfig isn't a function after all

function! CustomSlimeConfig()
  SlimeConfig
  let g:slime_default_config = b:slime_config
  let g:slime_dont_ask_default = 1

  " Display a message (optional)
  echo "SlimeConfig executed"
endfunction

" Map F2 to the custom function
nnoremap <F2> :call CustomSlimeConfig()<CR>
Praful commented 6 months ago

Still no joy! Same result: the two variables are not being set. Very strange!

Praful commented 6 months ago

Sorry - user error. I had an old F2 mapping to :SlimeConfig, which was overriding the new F2. All working now.

Thank you for taking the time to resolve this.

jpalardy commented 6 months ago

Good times — I'm happy that worked out for you 👍