neogit icon indicating copy to clipboard operation
neogit copied to clipboard

Neogit disables numbers for new buffers opened

Open guiltiest-gear opened this issue 1 year ago • 13 comments

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 avatar Nov 03 '24 05:11 guiltiest-gear

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

ikhurramraza avatar Nov 03 '24 16:11 ikhurramraza

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

AlejandroSanchez90 avatar Nov 03 '24 17:11 AlejandroSanchez90

I'm encountering the same issue

JocelynMeyron-eaton avatar Nov 14 '24 07:11 JocelynMeyron-eaton

Same issue here on the latest

gregoriB avatar Nov 14 '24 15:11 gregoriB

Thanks! And gratz for the twins!

On Thu, Nov 14, 2024, 9:50 AM Cameron @.***> wrote:

Hey - I have a guess whats up, but y'all will have to sit tight for a bit. Just had twins, so I'm busy for a while 😉

— Reply to this email directly, view it on GitHub https://github.com/NeogitOrg/neogit/issues/1539#issuecomment-2476763668, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6NKLAVSQUZJBFUBBBJCZET2ATBDXAVCNFSM6AAAAABRCMYXNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINZWG43DGNRWHA . You are receiving this because you commented.Message ID: @.***>

AlejandroSanchez90 avatar Nov 14 '24 16:11 AlejandroSanchez90

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.

CKolkey avatar Nov 14 '24 17:11 CKolkey

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!

gregoriB avatar Nov 15 '24 20:11 gregoriB

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 

AlejandroSanchez90 avatar Nov 19 '24 20:11 AlejandroSanchez90

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 :\

https://github.com/user-attachments/assets/00b35eda-b9dc-4d97-bd5d-200713b89bd0

CKolkey avatar Nov 21 '24 13:11 CKolkey

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

AlejandroSanchez90 avatar Nov 21 '24 16:11 AlejandroSanchez90

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.

CKolkey avatar Nov 21 '24 18:11 CKolkey

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

AlejandroSanchez90 avatar Nov 21 '24 19:11 AlejandroSanchez90

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 avatar Nov 22 '24 07:11 kjughx