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.87k stars 227 forks source link

About the verbose version of `SlimeSend` that always prompt the users for the output pane. #370

Closed nyngwang closed 1 year ago

nyngwang commented 1 year ago

Moved from comments started here of #268:

@jpalardy Neovim user here. It seems that setting vim.g.slime_dont_ask_default to either 0, false, nil all still fallback to use the default config. Could you help me check this? What I want to achieve is that it always shows me the prompt even if I'm calling '<,'>:SlimeSend on the same buffer.

,

@nyngwang

you want to be prompted every time you press ctrl-c, ctrl-c?

,

@jpalardy Yes! This might sound silly to you at first, but I want to be able to send different lines of the same buffer to different tmux-panes so that I can categorize the output. It's OK for me to check it every time as you already did a good job pre-filling the prompt so I just need to press enter twice.

To be more specific about my requirements, as a reference I also provide my current config below:

  • I have provided slime_default_config, I'm happy that these fields are always pre-filled when the prompt appears.
  • I have set slime_dont_ask_default = false, it will be great to provide something like slime_verbose_mode = true to prompt for the config (with pre-fills for sure!) everytime one call :SlimeSend.
use {
  'jpalardy/vim-slime',
  init = function ()
    -- NOTE: put in init to make sure all globals are applied every time `nvim` is called.
    vim.g.slime_target = 'tmux'
    vim.g.slime_no_mappings = true
    vim.g.slime_dont_ask_default = false
    vim.g.slime_preserve_curpos = false
    vim.g.slime_default_config = {
      socket_name = vim.split(vim.fn.getenv('TMUX'), ',')[1],
      target_pane = ':',
    }
  end,
  config = function ()
  end
}
jpalardy commented 1 year ago

Hi @nyngwang

A few ideas:

The simplest way, for now, would be to delete b:slime_config before calling whatever vim-slime function or binding. For example:

nmap <c-c><c-c> :if exists("b:slime_config") \| unlet b:slime_config \| endif<cr><Plug>SlimeParagraphSend

Another way is to take over configuration -- like this

Let me know how that goes for you.

nyngwang commented 1 year ago

Well, I somehow made it work, but it's a little bit tricky on the Lua side. Fortunately, this problem just reminded me of a syntax I thought I would never use when I was maintaining one of my plugins. (my <C-c> has been used for other things so I prefer : and type the command manually, but I got what you mean)

Still, it will be great if you can create an option for it natively.

vim.api.nvim_del_user_command('SlimeSend')
vim.api.nvim_create_user_command('SlimeSend', function (opts)
  local backup = vim.b.slime_config
  vim.b.slime_config = nil
  vim.fn['slime#send_range'](opts.line1, opts.line2)
  vim.b.slime_config = backup
end, { range = true })

(in fact, it's not precise to just unset b:slime_config as the other commands might want to remember the config. So instead, I created a backup to accept a one-shot state only when this new command is called.)

jpalardy commented 1 year ago

Hi @nyngwang

Glad you have a workaround for now šŸ‘

I realized a while ago that it's hard to support everything that vim-slime users want to do only with flags. That's why I opted for that "override" option.

I've also been experimenting with making vim-slime itself a "framework" of components you can snap together: https://github.com/jpalardy/vim-slime-ext-plugins ā€” it's not ready, but it's something I've been thinking about.

nyngwang commented 1 year ago

I realized a while ago that it's hard to support everything that vim-slime users want to do only with flags.

Good point. I should not ignore this aspect. Then feel free to close this issue as my original requirement was resolved.

I've also been experimenting with making vim-slime itself a "framework" [...]

Nice idea! I will take it into consideration when making plugins. Thanks for the reference!