Artawower / blamer.el

A git blame plugin for emacs inspired by VS Code's GitLens plugin
GNU General Public License v3.0
430 stars 15 forks source link

Author name with parens truncated #45

Closed jasonmj closed 9 months ago

jasonmj commented 1 year ago

I noticed that the author name is not getting formatted correctly when it includes parenthesis, like: Tom Bombadil (he/him). Instead, only he/him) gets printed. I suspect this is related to blamer--regexp-info.

jasonmj commented 1 year ago

I did a little digging into this issue and I'm not sure the regex is actually the problem. Instead, I think it's the way that the captures are being accessed with match-string. Since there's a set of parens in the author capture, it doesn't return the correct value. I'll continue to look into this later, just wanted to provide an update.

Artawower commented 1 year ago

I think the problem with the regexp, it doesn't catch the first bracket, i'll speculate about it

image

Artawower commented 1 year ago
(setq blamer--regexp-info
  (concat "^(?\\(?1:[^ ]*\\).*[[:blank:]]\(\\(?2:[^\n]+\\)"
          "\s\\(?3:[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)"
          "\s\\(?4:[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)"))

Can you try to use this regexp ?

jasonmj commented 1 year ago

Hmm, that did not seem to help.

Annoyingly, I did manage to fix it at one point with some testing I did in a scratch buffer, but I lost that work. I'll try to give it another go later... might be next week for me though. Busy times! Thanks for your response and attempt to fix 🙏

jasonmj commented 1 year ago

This is working for me:

(setq blamer--regexp-info
     (concat "^(?\\(?1:[^ ]*\\) [^ ]*[[:blank:]]?\(\\(?2:.*\\)"
         "\s\\(?3:[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)"
         "\s\\(?4:[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)"))
Artawower commented 1 year ago

Unfortunately, It doesn't work with the author's name without spaces, for example

(^3130q6ze (TomBombadil(he/him) 2020-12-16 16:28:09 +0800 4) $tooltip-border-radius: 2px;)

Could you try this one?

(concat "(\\(?1:[^ ]*\\) (\\(?2:.*\\)"
            "\s\\(?3:[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)"
            "\s\\(?4:[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)")
jasonmj commented 1 year ago

Hmm, your blame message looks different than what I typically have. Here's what I've been testing with:

(setq blamer--regexp-info
  (concat "^(?\\(?1:[^ ]*\\) [^ ]*[[:blank:]]?\(\\(?2:.*\\)"
          "\s\\(?3:[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)"
          "\s\\(?4:[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)"))

(setq-local blame-msg "3b90f8b82 lib/project_web/live/installation_live/show.html.heex (TomBombadil(he/him) 2023-03-16 08:08:26 -0500 25)     <div class=\"flex justify-between gap-4\">")

(string-match blamer--regexp-info blame-msg)
(message "%s" (match-string 2 blame-msg))

The latest regex you posted did not work with my blame-msg.

Artawower commented 1 year ago

Oh, i got it, my tests were wrong. Sorry for the inconvenience, I try to find a silver bullet for this problem. Can you check this regexp please?

(concat "^\\(?1:[^ ]*\\) \\(?5:[^ ]* \\)?(\\(?2:.*\\)"
            "\s\\(?3:[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)"
            "\s\\(?4:[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\)")

before image after

image

jasonmj commented 1 year ago

It's working for me :tada:

Thanks for your help here. It's been nice working with you.