Skip to content

Opening .org files via Telescope causes foldmethod=expr to persist in other buffers #3485

Open
@jp887

Description

@jp887

Description

After installing orgmode.nvim I found that when I open a .org file with telescope find_file, then another file type (.lua for example), the .lua file would unexpectedly contain folds on opening. This behaviour does not occur if the .org file is opened without telescope (:e /path/to/some/file.org).

I suspect the issue might be caused by this line promoting orgmode.nvim's window folding behaviour to other file types. If I run :set foldmethod? in a .lua file it usually returns foldmethod="manual", but after first opening a .org file with telescope running :set foldmethod? in a different non-org file returns foldmethod="expr".

Neovim version

NVIM v0.11.2
Build type: Release
LuaJIT 2.1.1741730670

Operating system and version

Ubuntu 24.04.2

Telescope version / branch / rev

telescope 0.1.8

checkhealth telescope

==============================================================================
telescope:                                                                  ✅

Checking for required plugins ~
- ✅ OK plenary installed.
- ✅ OK nvim-treesitter installed.

Checking external dependencies ~
- ✅ OK rg: found ripgrep 14.1.0
- ✅ OK fd: found fdfind 9.0.0

===== Installed extensions ===== ~

Telescope Extension: `fzf` ~
- ✅ OK lib working as expected
- ✅ OK file_sorter correctly configured
- ✅ OK generic_sorter correctly configured

Telescope Extension: `ui-select` ~
- No healthcheck provided

Steps to reproduce

  1. nvim -nu minimal.lua
  2. :Telescope find_file
  3. Open any '.org' file from the telescope picker
  4. Now open a .lua file such as minimal.lua (doesn't have to be with telescope)
  5. Some lines are already folded when the file opens, and :set foldmethod? returns foldmethod=expr

Expected behavior

orgmode.nvim sets vim.opt_local.foldmethod in it's ftplugin for .org files so it's folding behaviour should only affect .org files.

Actual behavior

orgmode.nvim's folding behaviour is leaking to other file types when opened with Telescope find_file.

Minimal config

local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs { 'config', 'data', 'state', 'cache' } do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system {
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    'nvim-telescope/telescope.nvim',
    dependencies = {
      'nvim-lua/plenary.nvim',
    },
    config = function()
      -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
      require('telescope').setup {}
    end,
  },
  {
   'nvim-orgmode/orgmode',
   event = 'VeryLazy',
   config = function()
      require('orgmode').setup({org_agenda_files = '~/org/**/*',})
   end
  }
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions