nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
14.86k stars 811 forks source link

Prevent Telescope from inheriting events in `autocmds` from `vimrc` #1345

Closed mystilleef closed 2 years ago

mystilleef commented 2 years ago

Description

Telescope is inheriting InsertLeave and InsertEnter events I have set up in autocmds from vimrc.

au! InsertEnter silent! Goyo
au! InsertLeave silent! Goyo!

I've set up these events to toggle Goyo.

Unfortunately, this breaks Telescope when I launch some pickers, especially the built-in buffers picker.

Is there a way to prevent or disable this behavior? I've attached a video showing the issue.

Video

https://user-images.githubusercontent.com/273399/137406447-e75ca4f9-2cb0-49e2-b000-4f9f39600e5a.mp4

Neovim version

NVIM v0.6.0-dev+461-g88e16a7f3 Build type: Release LuaJIT 2.1.0-beta3 Compiled by lateef@bigdaddy

Operating system and version

Fedora 34 Linux (Workstation Edition) x86_64

checkhealth telescope

telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
  - OK: plenary installed.
  - OK: nvim-treesitter installed.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0
  - OK: fd: found fd 8.2.1

## ===== Installed extensions =====

## Telescope Extension: `emoji`
  - INFO: No healthcheck provided

## Telescope Extension: `frecency`
  - INFO: No healthcheck provided

## Telescope Extension: `fzf`
  - INFO: No healthcheck provided

Steps to reproduce

  1. nvim -nu minimal.lua
  2. Open multiple documents with :Explore or :edit
  3. Enter and exit InsertMode to make sure that Goyo is behaving as intended
  4. Use :Telescope buffers to try to navigate to open documents.

Expected behavior

I expected Telescope to show me open buffers that I can navigate to.

Actual behavior

Telescope and Neovim become unusable. It seems Telescope is trying to activate Goyo inside its own buffers.

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
  "junegunn/goyo.vim"
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
vim.cmd ([[
augroup FocusModeAuGroup
  au!
  au InsertEnter * silent! Goyo
  au InsertLeave * silent! Goyo!
augroup end
]])
fdschmidt93 commented 2 years ago

I think the solution here would be to setup the autocmd in the way that it's not triggered when being in a buffer with the TelescopePrompt filetype.

Sorry, I have no belt in vimscript fu, something like this should maybe work?

au! InsertEnter lua if vim.bo.filetype ~= "TelescopePrompt" then vim.cmd[[silent! Goyo]] end
au! InsertLeave lua if vim.bo.filetype ~= "TelescopePrompt" then vim.cmd[[silent! Goyo!]] end
fdschmidt93 commented 2 years ago

I'm assuming from the reaction that this can be closed and I don't think this is an issue that needs or can be principally solved from within Telescope. Please comment if you feel there's more to discuss and then we can reopen this.

mystilleef commented 2 years ago

@fdschmidt93 thanks for the response. Yeah, that's how I'm getting around this issue. I think the Telescope buffers shouldn't inherit all settings in vimrc though. I'm not sure putting Telescope checks allover configuration settings is the way to go. That's a leaky abstraction. Telescope should know about my vimrc but my vimrc should not know about or depend on Telescope. Maybe the buffer should only inherit common “visual” settings and not behavioral ones.

fdschmidt93 commented 2 years ago

Agreed, the buffers picker previewer is a well known issue. We at some point switched to showing actual buffers rather than copies of the files to be able to show highlighted terminal buffers.

This incurred a series of of follow up issues; most likely the issue you are facing is one of these. It's probably fixed for the time being with lua require 'telescope.builtin'.buffers { previewer = false }. We will switch back to showing copies; it's on my todo list for when I have more time than replying to issues :) hope it helps for now

mystilleef commented 2 years ago

@fdschmidt93 Life without a previewer is not worth living. 😊 The checks will do for now.