sindrets

sindrets

Member Since 9 years ago

Experience Points
14
follower
Lessons Completed
7
follow
Lessons Completed
111
stars
Best Reply Awards
27
repos

355 contributions in the last year

Pinned
⚡ Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
⚡ A file explorer tree for neovim written in lua
⚡ Rearrange your windows with ease.
⚡ Adds an alternative, theme-aware title bar and application menu that is more inline with Atom's UI design.
⚡ A test framework for java.
⚡ Convert images to braille ascii-art.
Activity
Dec
2
1 day ago
Activity icon
issue

sindrets issue comment sindrets/dotfiles

sindrets
sindrets

[Question] How do you get such pretty looking diff views?

Hey @sindrets, I thought this would be an appropriate place for my question.

Your diffview, in the screenshot posted on the diffview repo, your diff looks really nice.

https://user-images.githubusercontent.com/2786478/131269942-e34100dd-cbb9-48fe-af31-6e518ce06e9e.png

This is what mine looks like: image

Just speculation, i think I might know why my colors are so off. Im using font colors for the highlights rather than bg colors. As for the diff listchar, i'm not so sure how you got yours to be offset on every line to match up so nicely.

Sorry to clutter your dotfiles repo, but, I just had to ask!

EDIT: I think I'm going to clone your config and use it as a base for mine. I've been wanting to clean up and re-do my config anyways. It's clear that you've put a ton of work into yours!

sindrets
sindrets

Sorry to clutter your dotfiles repo, but, I just had to ask!

@marwan38 No worries! Since you're asking here instead of the diffview repo I can go into more detail about how I go about generating diff highlights etc.

Just speculation, i think I might know why my colors are so off. Im using font colors for the highlights rather than bg colors.

Yes, you're right about that. I personally don't like how most themes define their diff highlights, so I have a little setup for dynamically generating diff colors based on other colors from the theme.

The function is defined here.

function M.generate_diff_colors()
  local bg = vim.o.bg
  local hl_bg_normal = hl.get_bg("Normal") or (bg == "dark" and "#111111" or "#eeeeee")

  local bg_normal = Color.from_hex(hl_bg_normal)

  local base_add = Color.from_hex(hl.get_fg("diffAdded") or "#b7ce42")
  local base_del = Color.from_hex(hl.get_fg("diffRemoved") or "#e84f4f")
  local base_mod = Color.from_hex(hl.get_fg("diffChanged") or "#51afef")

  local bg_add = base_add:blend(bg_normal, 0.85):mod_saturation(0.05)
  local bg_del = base_del:blend(bg_normal, 0.85):mod_saturation(0.05)
  local bg_mod = base_mod:blend(bg_normal, 0.85):mod_saturation(0.05)
  local bg_mod_text = base_mod:blend(bg_normal, 0.7):mod_saturation(0.05)

  hi("DiffAdd", { bg = bg_add:to_css(), fg = "NONE", gui = "NONE" })
  hi("DiffDelete", { bg = bg_del:to_css(), fg = "NONE", gui = "NONE" })
  hi("DiffChange", { bg = bg_mod:to_css(), fg = "NONE", gui = "NONE" })
  hi("DiffText", { bg = bg_mod_text:to_css(), fg = "NONE", gui = "NONE" })
end

If you're interested in incorporating this into your own config: it depends on my Color class and my highlight utils. The function works by using the foreground colors for diffAdded, diffRemoved and diffChanged as a base and then blends these with the background color for Normal as well as adjusting saturation and lightness. These highlights are almost always defined for most themes. diffChanged is sometimes missing, but it's trivial to define that in the case that it is.

The following custom command is very useful for inspecting and working with highlights. On calling it, it will bring all currently defined highlights into a new buffer (depends on norcalli/nvim-colorizer.lua for showing the colors):

command! -bar HiShow exe 'redir=>a | silent hi | redir END | exe "e " . tempname() . "/Highlights" '
            \ . '| call setline(1, split(g:a, "\n")) | setl buftype=nofile | ColorizerAttachToBuffer'

image

It doesn't show exactly how the highlight looks as opposed to :so $VIMRUNTIME/syntax/hitest.vim, but it's a lot faster.

As for the diff listchar, i'm not so sure how you got yours to be offset on every line to match up so nicely.

This is gonna depend on your terminal emulator. First of all, make sure you use the proper box-drawing char and not a normal forward slash. The char I use is (code point: U+2571). As for the terminal, I use kitty. Kitty uses a lot of really nice rendering tricks. Among other things, it replaces all box-drawing chars with its own such that they always look nice regardless of line height, column width etc. There are other terminals that do similar things, like i.e. WezTerm.

I think I'm going to clone your config and use it as a base for mine. I've been wanting to clean up and re-do my config anyways. It's clear that you've put a ton of work into yours!

That's very nice to hear! I will warn you though: my config is very personal. I have things set up in a way that works very well for me and my workflow, but it won't be right for everyone. But If you find parts of the config useful, that's great!

Just let me know if you have any other questions about the setup.

Nov
30
3 days ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

Callback for ftplugin style setup when opening diffview.nvim

I want to add some <buffer> keymaps that are only active in the diffview. I know that we can bind any maps in setup.key_bindings, but I also want to add which-key.nvim entries for description. I think a more flexible method is to be able to register a callback that is run when opening a new diffview buffer (like ftplugin)

sindrets
sindrets

This should be resolved now as I've implemented both autocommands as well as a lua API for hooking into events emitted from Diffview. But just let me know if there are any problems.

Activity icon
delete

sindrets in sindrets/diffview.nvim delete branch feat/hooks

deleted time in 3 days ago
push

sindrets push sindrets/diffview.nvim

sindrets
sindrets

feat: Hooks (#99)

  • feat: Implemented hooks.

Hooks let you define event callbacks that will be called when the related events are emitted from Diffview. These are the currently implemented hooks:

  • 'diff_buff_read'
  • 'view_opened'
  • 'view_closed'

See ':h diffview-config-hooks'

  • doc: Update README.

  • feat: Implement all hooks as autocmds as well.

commit sha: 2c0f5af509a9e0f42430c0b561ab7e49aec84f72

push time in 3 days ago
pull request

sindrets pull request sindrets/diffview.nvim

sindrets
sindrets

feat: Hooks

Resolves #75.

The hooks table in the config allows you to define callbacks for various events emitted from Diffview. The available hooks are documented in detail in :h diffview-config-hooks.

The hook events are also available as User autocommands. See :h diffview-user-autocmds for more details.

hooks                                                  *diffview-config-hooks*
        Type: `table<string, function>`, Default: `{}`

        This is a table of event names mapped to callback functions. The
        callbacks are called when the related events are emitted from
        Diffview.

        Available Events:~
                {view_opened} (`fun(view: View)`)
                        Emitted after a new view has been opened. It's called
                        after initializing the layout in the new tabpage (all
                        windows are ready).

                        Callback Parameters:~
                                {view} (`View`)
                                        The `View` instance that was opened.

                {view_closed} (`fun(view: View)`)
                        Emitted after closing a view.

                        Callback Parameters:~
                                {view} (`View`)
                                        The `View` instance that was closed.

                {diff_buf_read} (`fun(bufnr: integer)`)
                        Emitted after a new diff buffer is ready (the first
                        time it's created and loaded into a window). Diff
                        buffers are all buffers with |diff-mode| enabled. That
                        includes buffers of local files (not created from
                        git).

                        This is always called with the new buffer as the
                        current buffer and the correct diff window as the
                        current window such that |:setlocal| will apply
                        settings to the relevant buffer / window.

                        Callback Parameters:~
                                {bufnr} (`integer`)
                                        The buffer number of the new buffer.

        Examples: >
                hooks = {
                  diff_buf_read = function(bufnr)
                    -- Change local options in diff buffers
                    vim.opt_local.wrap = false
                    vim.opt_local.list = false
                    vim.opt_local.colorcolumn = { 80 }
                  end,
                  view_opened = function(view)
                    print(
                      ("A new %s was opened on tab page %d!")
                      :format(view:class():name(), view.tabpage)
                    )
                  end,
                }

User Autocommands

  • DiffviewViewOpened
  • DiffviewViewClosed
  • DiffviewViewDiffBufRead
Activity icon
issue

sindrets issue sindrets/diffview.nvim

sindrets
sindrets

Callback for ftplugin style setup when opening diffview.nvim

I want to add some <buffer> keymaps that are only active in the diffview. I know that we can bind any maps in setup.key_bindings, but I also want to add which-key.nvim entries for description. I think a more flexible method is to be able to register a callback that is run when opening a new diffview buffer (like ftplugin)

Nov
29
4 days ago
push

sindrets push sindrets/diffview.nvim

sindrets
sindrets

feat: Implement all hooks as autocmds as well.

commit sha: 7237798d8a936c1ff04cbb89caadbb5cd200c746

push time in 3 days ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

Callback for ftplugin style setup when opening diffview.nvim

I want to add some <buffer> keymaps that are only active in the diffview. I know that we can bind any maps in setup.key_bindings, but I also want to add which-key.nvim entries for description. I think a more flexible method is to be able to register a callback that is run when opening a new diffview buffer (like ftplugin)

pull request

sindrets pull request sindrets/diffview.nvim

sindrets
sindrets

feat: Hooks

Related #75.

The hooks table in the config allows you to define callbacks for various events emitted from Diffview. The available hooks are documented in detail in :h diffview-config-hooks.

hooks                                                  *diffview-config-hooks*
        Type: `table<string, function>`, Default: `{}`

        This is a table of event names mapped to callback functions. The
        callbacks are called when the related events are emitted from
        Diffview.

        Available Events:~
                {view_opened} (`fun(view: View)`)
                        Emitted after a new view has been opened. It's called
                        after initializing the layout in the new tabpage (all
                        windows are ready).

                        Callback Parameters:~
                                {view} (`View`)
                                        The `View` instance that was opened.

                {view_closed} (`fun(view: View)`)
                        Emitted after closing a view.

                        Callback Parameters:~
                                {view} (`View`)
                                        The `View` instance that was closed.

                {diff_buf_read} (`fun(bufnr: integer)`)
                        Emitted after a new diff buffer is ready (the first
                        time it's created and loaded into a window). Diff
                        buffers are all buffers with |diff-mode| enabled. That
                        includes buffers of local files (not created from
                        git).

                        This is always called with the new buffer as the
                        current buffer and the correct diff window as the
                        current window such that |:setlocal| will apply
                        settings to the relevant buffer / window.

                        Callback Parameters:~
                                {bufnr} (`integer`)
                                        The buffer number of the new buffer.

        Examples: >
                hooks = {
                  diff_buf_read = function(bufnr)
                    -- Change local options in diff buffers
                    vim.opt_local.wrap = false
                    vim.opt_local.list = false
                    vim.opt_local.colorcolumn = { 80 }
                  end,
                  view_opened = function(view)
                    print(
                      ("A new %s was opened on tab page %d!")
                      :format(view:class():name(), view.tabpage)
                    )
                  end,
                }
Activity icon
created branch

sindrets in sindrets/diffview.nvim create branch feat/hooks

createdAt 3 days ago
Nov
27
6 days ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

Auto open files

Hey 👋 Is there any way to enable automatic opening files (or commits in the history)

For example: I have two files with changes. I use j k to select them in the tree. I would like them to open automatically without when I select one of them? I mean without o or enter etc.

sindrets
sindrets

Yes. Just change the mappings for j and k to map to the select_next_entry and select_prev_entry callbacks instead. I'll note that <tab> and <s-tab> already have these mappings by default.

Nov
26
1 week ago
push

sindrets push sindrets/diffview.nvim

sindrets
sindrets

fix(file-history): Don't try to get path when there are no entries.

commit sha: f92d27b22bd5bfa47903ac91de5077263ce816ea

push time in 6 days ago
Nov
25
1 week ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

scrollopt gets reset after `:DiffviewOpen`

I have scrollopt set to ver,hor,jump but after opening diffview it gets reset to ver,jump

(I want to use horizontal scrollbind with nowrap)

sindrets
sindrets

The culprit was :diffoff which resets this option. Should be fixed now.

push

sindrets push sindrets/diffview.nvim

sindrets
sindrets

feat: Create diff buffers asynchronously.

  • More detailed logging of failed jobs.
  • Added ':DiffviewLog'.
sindrets
sindrets

fix: diff views weren't subscribed to the 'close' event.

(closes #96)

sindrets
sindrets

feat: Save and restore winopts of diff buffers.

(closes #97)

commit sha: 00c2f2390f0b52b3ed115094a248b1f1523c6d4c

push time in 1 week ago
Activity icon
issue

sindrets issue sindrets/diffview.nvim

sindrets
sindrets

scrollopt gets reset after `:DiffviewOpen`

I have scrollopt set to ver,hor,jump but after opening diffview it gets reset to ver,jump

(I want to use horizontal scrollbind with nowrap)

Activity icon
issue

sindrets issue sindrets/diffview.nvim

sindrets
sindrets

cb("close") keybinding doesn't work in `:DiffviewOpen`

My setup:

  local cb = (require("diffview.config")).diffview_callback
  require("diffview")).setup({
    enhanced_diff_hl = true,
    key_bindings = {
      file_history_panel = { q = cb("close") },
      file_panel = { q = cb("close") },
      view = { q = cb("close") },
    },
  }

However, when i press q in the diff buffer nothing happens. Note that it doesn't start recording macros when I press another letter after q, so atleast it is taking over keybindings

The mapping works in :DiffviewFileHistory

Nov
24
1 week ago
push

sindrets push sindrets/diffview.nvim

sindrets
sindrets

Update '(left|right)_ready' based on buffer state.

commit sha: df94eeee90f2483e3c30b1b368b2e6e0c487aa7b

push time in 1 week ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

scrollopt gets reset after `:DiffviewOpen`

I have scrollopt set to ver,hor,jump but after opening diffview it gets reset to ver,jump

(I want to use horizontal scrollbind with nowrap)

sindrets
sindrets

I never adjust scrollopt anywhere in the code, so I don't know what this is about, but I'll have a closer look soon.

Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

cb("close") keybinding doesn't work in `:DiffviewOpen`

My setup:

  local cb = (require("diffview.config")).diffview_callback
  require("diffview")).setup({
    enhanced_diff_hl = true,
    key_bindings = {
      file_history_panel = { q = cb("close") },
      file_panel = { q = cb("close") },
      view = { q = cb("close") },
    },
  }

However, when i press q in the diff buffer nothing happens. Note that it doesn't start recording macros when I press another letter after q, so atleast it is taking over keybindings

The mapping works in :DiffviewFileHistory

sindrets
sindrets

Diff views aren't subscribed to the close event. This is an oversight. I added the close event when I added file history, and I forgot to also have diff views subscribed to the event. I'll fix this soon.

Nov
23
1 week ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

[feature] File history view showing difference between commit and current verision

It would be great to extend file history view ( invoked by :DiffviewFileHistory <FILE_NAME>) with possibility to show diff not only before and after particular commit, but also to have difference between particular commit and current (HEAD) version of a file.

The current version should be editable, so one could navigate through history of commits and be able to pick up particular changes into current version.

Maybe it can be additional option to file history view, that switched between modes

  • when true - current diff behaviour, showing differences caused by a single commit.
  • when false - then show differene from a commit to current version, with editable buffer of current file version.
sindrets
sindrets

Okay, the only way I see this being properly useful is if we can specify any base rev to diff against. Something like: :DiffviewFileHistory --base=<REV> <PATHS>

Nov
22
1 week ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

[feature] File history view showing difference between commit and current verision

It would be great to extend file history view ( invoked by :DiffviewFileHistory <FILE_NAME>) with possibility to show diff not only before and after particular commit, but also to have difference between particular commit and current (HEAD) version of a file.

The current version should be editable, so one could navigate through history of commits and be able to pick up particular changes into current version.

Maybe it can be additional option to file history view, that switched between modes

  • when true - current diff behaviour, showing differences caused by a single commit.
  • when false - then show differene from a commit to current version, with editable buffer of current file version.
sindrets
sindrets

It sounds like this use-case is already covered by features that already exist. See:

  • :h diffview-maps-goto_file
  • :h diffview-maps-goto_file_split
  • :h diffview-maps-goto_file_tab

Using these mappings you can quickly bring up the local version of a file.

Another way to solve this would be to use the y mapping from the file history panel to copy the commit hash for the entry under the cursor. Then you can open a full diffview for that commit with :DiffviewOpen <commit-SHA>.

Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

Error when trying :DiffviewOpen

Hey, I just installed this plugin (nice plugin btw) I when I tried to run :DiffviewOpen I got this error :

E5108: Error executing lua ...ck\packer\start\diffview.nvim\lua\diffview/git/utils.lua:42: attempt to index local 'name' (a nil value)

:version:

NVIM v0.6.0-dev+205-g9695691ee
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilé par [email protected]

Features: -acl +iconv +tui
See ":help feature-compile"

         fichier vimrc système : "$VIM\sysinit.vim"
               $VIM par défaut : "C:/Program Files/nvim/share/nvim"

Run :checkhealth for more info

Configuration:

use {
        'sindrets/diffview.nvim',
        requires = 'nvim-lua/plenary.nvim'
    }

I'm on Windows 10, have a nice day! (:

sindrets
sindrets

@vzytoi I can't reproduce this. You're probably gonna have to do some debugging on your own. I can only make guesses as to what might be causing the problem here:

  • Outdated Git.
  • Your :h 'shell' configuration in nvim and the configuration for your shell. I'm in the process of refactoring to use jobs, but currently this plugin relies on the :h system() functions (which will use your configured shell).

I'm sorry that I can't help you directly as I'm unable to reproduce this from my testing on Windows, but I can give you some pointers as to what you need to investigate.

  • Check that the system() functions work for you in vim. Try calling :echo system('git diff --name-status') and check the output.
  • In the code:
    • You can use vim.inspect() to inspect tables. I would start looking here, as this is where your error was coming from:
diff --git a/lua/diffview/git/utils.lua b/lua/diffview/git/utils.lua
index ee9d441..e4bd34b 100644
--- a/lua/diffview/git/utils.lua
+++ b/lua/diffview/git/utils.lua
@@ -33,6 +33,9 @@ local function tracked_files(git_root, left, right, args, kind)
   cmd = "git -C " .. vim.fn.shellescape(git_root) .. " diff --numstat " .. args
   local stat_data = vim.fn.systemlist(cmd)
 
+  print("name-status:", vim.inspect(names))
+  print("numstat:", vim.inspect(stat_data))
+
   if not utils.shell_error() then
     for i, s in ipairs(names) do
       local status = s:sub(1, 1):gsub("%s", " ")

Let me know if you figure something out, or need more pointers for as to where / what / how to debug further.

Nov
21
1 week ago
push

sindrets push sindrets/diffview.nvim

sindrets
sindrets

feat: More detailed logging of failed jobs. Added ':DiffviewLog'.

  • Fixed 'enhanced_diff_hl'

commit sha: bef106d593dd19d431717f9a990855d73c03f74e

push time in 1 week ago
Nov
20
1 week ago
Activity icon
created branch

sindrets in sindrets/diffview.nvim create branch feat/async-buf-creation

createdAt 1 week ago
Nov
19
2 weeks ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

Error when trying :DiffviewOpen

Hey, I just installed this plugin (nice plugin btw) I when I tried to run :DiffviewOpen I got this error :

E5108: Error executing lua ...ck\packer\start\diffview.nvim\lua\diffview/git/utils.lua:42: attempt to index local 'name' (a nil value)

:version:

NVIM v0.6.0-dev+205-g9695691ee
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilé par [email protected]

Features: -acl +iconv +tui
See ":help feature-compile"

         fichier vimrc système : "$VIM\sysinit.vim"
               $VIM par défaut : "C:/Program Files/nvim/share/nvim"

Run :checkhealth for more info

Configuration:

use {
        'sindrets/diffview.nvim',
        requires = 'nvim-lua/plenary.nvim'
    }

I'm on Windows 10, have a nice day! (:

sindrets
sindrets

I have honestly never even tested the plugin on windows before now. But it seems to work almost fine aside from some non-breaking problems regarding path separators.

The issue seems to be that something is going wrong during parsing of git's output. This could maybe be related to your git config, or there's something wrong in my parser. It would help if you could share the output of git diff --name-status from the repo you were having problems with. You can censor the paths if that is sensitive information, but please don't change the formatting in any other way.

Also, have you tried with different repos? If the problem only occurs in one / some of your repos it's probably some git output I've not accounted for in my parser, but if the problem happens with all repos it's more likely to be related to your config.

Nov
18
2 weeks ago
Activity icon
issue

sindrets issue comment sindrets/diffview.nvim

sindrets
sindrets

theme

What theme vim do you use image screenshot?

Previous