Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The org_global_cycle keybinding affects non-org buffers #863

Open
ficcdaf opened this issue Jan 19, 2025 · 0 comments
Open

The org_global_cycle keybinding affects non-org buffers #863

ficcdaf opened this issue Jan 19, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ficcdaf
Copy link

ficcdaf commented Jan 19, 2025

Describe the bug

Kindly note that I have org_cycle bound to Tab and org_global_cycle bound to S-Tab and every orgmode setting is the defaults.

When opening an org file, headings are folded (as per my org_startup_folded default setting). When I press S-Tab to cycle the folds on all the headlines, it seems to modify Neovim's foldlevel. Then, when I open a new buffer to a non-org file, that foldlevel persists, and the contents of that file are folded. This behavior persists after all org buffers are closed. The behavior also persists when opening the new buffers in split windows.

I observed this only happens with the global cycle command. org_cycle does not cause this behavior.

Steps to reproduce

Note that my foldlevel is set to 99 in my Neovim config.

  1. Open an org file in a buffer.
  2. Press org_global_cycle (S-tab) an arbitrary number of times.
  3. Open a non-org file (such as a lua file) in another buffer.
  4. Observe that the file is displayed with folding.
  5. Close the org buffer.
  6. Open another non-org file.
  7. Observe that the file is still displayed with folding.

Screenshots:

Image

Observation at step 4.

Expected behavior

The org global cycle keybind should only affect org buffers.

Emacs functionality

No response

Minimal init.lua

With the minimal init, you can do :e /tmp/test.org and then :e /tmp/test.lua to reproduce the issue. In the minimal init, the Lua file doesn't fold automatically, but you can observe that set foldlevel does not return 99 after opening test.lua, and it is the foldlevel which is the problem here.

local org = io.open("/tmp/test.org", "w")
if not org then
	error("failed open org")
end
local orgc = [[
* A headline is here.
** TODO This is a task.
]]
local lua = io.open("/tmp/test.lua", "w")
local luac = [[
-- a file from my config that has a lot of folds in it
-- this is the file on which I noticed the bug
return {
  "folke/snacks.nvim",
  opts = {
    toggle = {
      notify = false,
    },
    bigfile = {
      notify = true, -- show notification when big file detected
      size = 1.5 * 1024 * 1024, -- 1.5MB
      -- Enable or disable features when big file detected
      ---@param ctx {buf: number, ft:string}
      setup = function(ctx)
        -- Snacks.util.wo(0, { foldmethod = "manual", statuscolumn = "", conceallevel = 0 })
        -- vim.b.minianimate_disable = true
        vim.schedule(function()
          vim.bo[ctx.buf].syntax = ctx.ft
        end)
      end,
    },
    zen = {
      notify = false,
      toggles = {
        dim = false,
        git_signs = false,
        mini_diff_signs = false,
        diagnostics = true,
        inlay_hints = true,
      },
      win = {
        backdrop = {
          transparent = false,
          blend = 20,
        },
      },
    },
  },
  keys = {
    {
      "<leader>z",
      function()
        Snacks.zen({
          win = {
            backdrop = {
              transparent = false,
              blend = 10,
            },
          },
        })
      end,
      desc = "Toggle Zen Mode",
    },
    {
      "<leader>Z",
      function()
        Snacks.zen({
          win = {
            backdrop = {
              transparent = false,
            },
          },
        })
      end,
      desc = "Toggle Zen Mode (no backdrop)",
    },
  },
}
]]
org:write(orgc)
lua:write(luac)

local tmp_dir = vim.env.TMPDIR or vim.env.TMP or vim.env.TEMP or "/tmp"
local nvim_root = tmp_dir .. "/nvim_orgmode"
local lazy_root = nvim_root .. "/lazy"
local lazypath = lazy_root .. "/lazy.nvim"

for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = nvim_root .. "/" .. name
end

-- Install lazy.nvim if not already installed
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable", -- latest stable release
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"nvim-orgmode/orgmode",
		event = "VeryLazy",
		ft = { "org" },
		config = function()
			require("orgmode").setup()
		end,
	},
}, {
	root = lazy_root,
	lockfile = nvim_root .. "/lazy.json",
	install = {
		missing = false,
	},
})

require("lazy").sync({
	wait = true,
	show = false,
})

vim.o.foldlevel = 99

Screenshots and recordings

No response

OS / Distro

Arch Linux

Neovim version/commit

NVIM v0.11.0-dev-1589+g71507281fb Build type: RelWithDebInfo LuaJIT 2.1.1736781742

Additional context

No response

@ficcdaf ficcdaf added the bug Something isn't working label Jan 19, 2025
@ficcdaf ficcdaf changed the title The org_global_cycle keybinding affects non-org buffers while an org buffer is open The org_global_cycle keybinding affects non-org buffers Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant