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

Neogit disables numbers for new buffers opened #1539

Open
guiltiest-gear opened this issue Nov 3, 2024 · 13 comments
Open

Neogit disables numbers for new buffers opened #1539

guiltiest-gear opened this issue Nov 3, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@guiltiest-gear
Copy link
Contributor

Description

After opening and closing neogit, any new buffers opened after the action now have the number option unset, as well as the foldcolumn being set to 0.

While I do understand that foldcolumn being set to 0 is a feature (as referenced in #1507) rather than a bug. It's rather disruptive to my workflow to have it not be set back properly after I leave neogit.

Neovim version

NVIM v0.10.2
Build type: RelWithDebInfo
LuaJIT 2.1.1727870382
Run "nvim -V1 -v" for more info

Operating system and version

EndeavourOS

Steps to reproduce

  1. Run :set number foldcolumn=1
  2. Open neogit
  3. Close neogit
  4. Open a new buffer

Expected behavior

The new buffer retains the number and signcolumn settings.

Actual behavior

The new buffer no longer has the number and signcolumn setting set.

Minimal config

-- NOTE: See the end of this file if you are reporting an issue, etc. Ignore all the "scary" functions up top, those are
-- used for setup and other operations.
local M = {}

local base_root_path = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") .. "/.min"
function M.root(path)
  return base_root_path .. "/" .. (path or "")
end

function M.load_plugin(plugin_name, plugin_url)
  local package_root = M.root("plugins/")
  local install_destination = package_root .. plugin_name
  vim.opt.runtimepath:append(install_destination)

  if not vim.loop.fs_stat(package_root) then
    vim.fn.mkdir(package_root, "p")
  end

  if not vim.loop.fs_stat(install_destination) then
    print(string.format("> Downloading plugin '%s' to '%s'", plugin_name, install_destination))
    vim.fn.system({
      "git",
      "clone",
      "--depth=1",
      plugin_url,
      install_destination,
    })
    if vim.v.shell_error > 0 then
      error(string.format("> Failed to clone plugin: '%s' in '%s'!", plugin_name, install_destination),
        vim.log.levels.ERROR)
    end
  end
end

---@alias PluginName string The plugin name, will be used as part of the git clone destination
---@alias PluginUrl string The git url at which a plugin is located, can be a path. See https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols for details
---@alias MinPlugins table<PluginName, PluginUrl>

---Do the initial setup. Downloads plugins, ensures the minimal init does not pollute the filesystem by keeping
---everything self contained to the CWD of the minimal init file. Run prior to running tests, reproducing issues, etc.
---@param plugins? table<PluginName, PluginUrl>
function M.setup(plugins)
  vim.opt.packpath = {}                      -- Empty the package path so we use only the plugins specified
  vim.opt.runtimepath:append(M.root(".min")) -- Ensure the runtime detects the root min dir

  -- Install required plugins
  if plugins ~= nil then
    for plugin_name, plugin_url in pairs(plugins) do
      M.load_plugin(plugin_name, plugin_url)
    end
  end

  vim.env.XDG_CONFIG_HOME = M.root("xdg/config")
  vim.env.XDG_DATA_HOME = M.root("xdg/data")
  vim.env.XDG_STATE_HOME = M.root("xdg/state")
  vim.env.XDG_CACHE_HOME = M.root("xdg/cache")

  -- NOTE: Cleanup the xdg cache on exit so new runs of the minimal init doesn't share any previous state, e.g. shada
  vim.api.nvim_create_autocmd("VimLeave", {
    callback = function()
      vim.fn.system({
        "rm",
        "-r",
        "-f",
        M.root("xdg")
      })
    end
  })
end

-- NOTE: If you have additional plugins you need to install to reproduce your issue, include them in the plugins
-- table within the setup call below.
M.setup({
  plenary = "https://github.com/nvim-lua/plenary.nvim.git",
  telescope = "https://github.com/nvim-telescope/telescope.nvim",
  diffview = "https://github.com/sindrets/diffview.nvim",
  neogit = "https://github.com/NeogitOrg/neogit"
})
-- WARN: Do all plugin setup, test runs, reproductions, etc. AFTER calling setup with a list of plugins!
-- Basically, do all that stuff AFTER this line.
require("neogit").setup({}) -- For instance, setup Neogit
@guiltiest-gear guiltiest-gear added the bug Something isn't working label Nov 3, 2024
@guiltiest-gear guiltiest-gear changed the title Neogit disables numbers on new buffers Neogit disables numbers for new buffers opened Nov 3, 2024
@ikhurramraza
Copy link

Facing the same issue.

Neovim version

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1727870382

Operating system and version

macOS Sequoia 15.1

@AlejandroSanchez90
Copy link

yes i opened an issue 3 days ago, it also mess with some keymaps like , my keymaps to go down and up (c-n, c-p), etc

ikhurramraza added a commit to ikhurramraza/archie that referenced this issue Nov 5, 2024
Neogit messes up with the `foldcolumn`, so locking to a version before
it was broken.

NeogitOrg/neogit#1539
@JocelynMeyron-eaton
Copy link

I'm encountering the same issue

@gregoriB
Copy link

Same issue here on the latest

@AlejandroSanchez90
Copy link

AlejandroSanchez90 commented Nov 14, 2024 via email

@CKolkey
Copy link
Member

CKolkey commented Nov 14, 2024

Oops, deleted my comment. As I was saying, I have a guess whats up, but just took home some twin boys so.. not loads of time right now.

@gregoriB
Copy link

Oops, deleted my comment. As I was saying, I have a guess whats up, but just took home some twin boys so.. not loads of time right now.

Congrats! I'm sure twins are a lot of work. I just locked the package to an older commit, so no worries. Thanks for all your work on this great package!

@AlejandroSanchez90
Copy link

AlejandroSanchez90 commented Nov 19, 2024

Oops, deleted my comment. As I was saying, I have a guess whats up, but just took home some twin boys so.. not loads of time right now.

the overwrite for me comes from here

Last set from /nvim/lazy/neogit/lua/neogit/lib/buffer.lua line 413 

@CKolkey
Copy link
Member

CKolkey commented Nov 21, 2024

Some questions:

When you open Neogit, is it as a tabpage? or some other kind?

When you say "open new buffer", could you specify how? Like, via :new or ...?

Seems to work alright for me :\

Screen.Recording.2024-11-21.at.14.50.33.mov

@AlejandroSanchez90
Copy link

AlejandroSanchez90 commented Nov 21, 2024

the issue for me is if I open neogit and use the same window to navigate to another file, for example,
open neogit, while in neogit, open fzflua/nvim-tree and go to another file, or if you are in the diff window (dd) and do "gf," it will bug out

@CKolkey
Copy link
Member

CKolkey commented Nov 21, 2024

Ohh. Yeah, you shouldn't reuse the window. I set a bunch of window options that you almost certainly don't want. All of the "edit file" "open in split" actions first -close- the neogit buffer to avoid exactly this.

So, I think the fix here is to make it so you can't do this, a bit more like how telescope works with its layouts.

@AlejandroSanchez90
Copy link

Ohh. Yeah, you shouldn't reuse the window. I set a bunch of window options that you almost certainly don't want. All of the "edit file" "open in split" actions first -close- the neogit buffer to avoid exactly this.

So, I think the fix here is to make it so you can't do this, a bit more like how telescope works with its layouts.

yeah, now that I'm aware of how it works, I don't do this, but sometimes, when I work for long hours, I forget, it would be nice just to block this window navigation somehow

@kjughx
Copy link
Contributor

kjughx commented Nov 22, 2024

Personally, I find the use-case of

  1. opening a commit to view the changed files
  2. do gf on one of them to open it in a buffer
  3. Work as usual

to be a really compelling one and "fixing" it so that this can't be done seems harsh.

I was about to submit a PR for this change, which only sets the options in "local" scope, and that fixes the issues with options for me at least. However, the new buffer is somehow tied to the other Neogit buffer/window and when I close it (neogit buffer/window), my new window is also closed (the buffer remains though).

@kjughx kjughx mentioned this issue Nov 30, 2024
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

7 participants