f-person / git-blame.nvim

Git Blame plugin for Neovim written in Lua
GNU General Public License v3.0
884 stars 43 forks source link

Configurable EOL offset #104

Open lougreenwood opened 12 months ago

lougreenwood commented 12 months ago

Currently the EOL offset for the message template or not committed template requires prepending with spaces, additionally the virtual_text_column will default to the EOL when the line is longer than this setting.

However, the need to prepend spaces is both visually messy and adds a (small, but not invisible) layer of maintenance cost now that there are multiple templates. It also requires overriding the default templates even if the only thing a user wants to configure is the offset.

Did you consider adding something like an eol_offset config to allow something like

      message_template = "<author>, <date> • <summary>",
      message_when_not_committed = "<author>, <date> • Uncommitted changes",
      eol_offset = 5, -- offset the message by 5 cols from the EOL
      virtual_text_column = 40,

So that all messages are consistently offset by 5 cols from the end of the line and messages.

f-person commented 12 months ago

Hi! I never considered this since we had a single template until recently, but I see how this could be useful.

additionally the virtual_text_column will default to the EOL when the line is longer than this setting.

Are you suggesting changing the behavior with the introduction of eol_offset somehow?

lougreenwood commented 12 months ago

Hi! I never considered this since we had a single template until recently, but I see how this could be useful.

Yep, I figured it would be something like this 😄 👍.

Are you suggesting changing the behavior with the introduction of eol_offset somehow?

Not necessarily in a breaking way, only that virtual_text_column will also use the eol_offset value if the line length is longer than the virtual_text_column.

Or thinking about this some more, just always use eol_offset value with virtual_text_column, but internally we'd calculate the effective virtual_text_column as virtual_text_column -= eol_offset so that if say a line is 99 chars long and the user-defined virtual_text_column = 100 we still get an eol_offset of +5 from end of the line (so starting at col 104 - essentially ensuring that all places where the templates have a minimum offset of what is defined by eol_offset).

Something like:

-- line_length = 99
-- eol_offset = 5
-- virtual_text_column = 100

virtual_text_column -= eol_offset
local template_column = nil
if virtual_text_column > line_length

  -- if the line length was 50, then we'd render the template at col 100 ((100 - 5) + 5), matching the user defined value.
  return virtual_text_column + eol_offset
else
  -- if the line length is 99, then we'd render the template at col 104 (99 + 5)
  return line_length + eol_offset
end