A git blame plugin for emacs inspired by VS Code’s GitLens plugin and Vim plugin
Emacs 27.1 is required.
(use-package blamer
:ensure t
:bind (("s-i" . blamer-show-commit-info)
("C-c i" . blamer-show-posframe-commit-info))
:defer 20
:custom
(blamer-idle-time 0.3)
(blamer-min-offset 70)
:custom-face
(blamer-face ((t :foreground "#7a88cf"
:background nil
:height 140
:italic t)))
:config
(global-blamer-mode 1))
(use-package blamer
:quelpa ((blamer :fetcher github :repo "artawower/blamer.el") :upgrade t)
:bind (("s-i" . blamer-show-commit-info)
("C-c i" . blamer-show-posframe-commit-info))
:custom
(blamer-idle-time 0.3)
(blamer-min-offset 70)
:custom-face
(blamer-face ((t :foreground "#7a88cf"
:background nil
:height 140
:italic t)))
:config
(global-blamer-mode 1))
(use-package blamer
:straight (:host github :repo "artawower/blamer.el")
:bind (("s-i" . blamer-show-commit-info))
:custom
(blamer-idle-time 0.3)
(blamer-min-offset 70)
:custom-face
(blamer-face ((t :foreground "#7a88cf"
:background nil
:height 140
:italic t)))
:config
(global-blamer-mode 1))
packages.el
(package! blamer)
;; or
(package! blamer :recipe (:host github :repo "artawower/blamer.el"))
config.el
(use-package blamer
:bind (("s-i" . blamer-show-commit-info))
:defer 20
:custom
(blamer-idle-time 0.3)
(blamer-min-offset 70)
:custom-face
(blamer-face ((t :foreground "#7a88cf"
:background nil
:height 140
:italic t)))
:config
(global-blamer-mode 1))
Current style for blame messages, now can be overlay
and overlay-right
.
(setq blamer-view 'overlay)
(setq blamer-author-formatter " ✎ %s ")
(setq blamer-datetime-formatter "[%s]")
(setq blamer-commit-formatter " ● %s")
All formatters can be nil.
If your would like to wrap whole message, or add special prefix before blame text you can use
(setq blamer-entire-formatter "<%>")
(setq blamer-idle-time 0.5)
(setq blamer-min-offset 40)
(setq blamer-prettify-time-p t)
Will format time line (2 days ago/1 week ago/Yesterday etc)
(setq blamer-type 'both)
Can accept
'selected
- blamer will show commit info for every selected line.'visual
- blamer will show info only about one line.'both
- works with both states.'overlay-popup
- nice overlay popup (see images/blamer-pretty-popup-dark.jpg)'margin-overlay
- show commit info in the margin'posframe-popup
- posframe popup (see images/posframe.png) Warning The ‘overlay-popup feature highly dependent on you custom fonts, it may have worse alignment.
blamer--overlay-popup-position
- is position for the overlay popup, it could be:
'bottom
'top
'smart
- will choose the better popup position, in most cases it will prefer center
If more then 30 lines will selected, blamer will not try to execute git commands.
(setq blamer-max-lines 30)
(setq blamer-uncommitted-changes-message "NO COMMITTED")
If line has length more then this value, text will be truncated
(setq blamer-max-commit-message-length 10)
If you want to disable automatic background detection you can always use blamer face
(setq blamer-smart-background-p nil)
You can turn on a tooltip when hovering over a commit, by settings blamer-tooltip-function
This variably can apply default functions
(setq blamer-tooltip-function 'blamer-tooltip-keybindings)
- will show keybindings for current commit message
(setq blamer-tooltip-function 'blamer-tooltip-commit-message)
- show commit message about current line
(it could be helpfull when blamer-commit-formatter is empty)
(setq blamer-tooltip-function 'blamer-tooltip-author-info)
- show information about author
Also you can write own function with first argumens as commit-info
plist, or set this variable to null, that mean tooltip is disabled
For example, you can write function for showing commit datetime inside tooltip:
(defun my-blamer-tooltip-func (commit-info)
(let ((commit-date (plist-get commit-info :commit-date))
(commit-time (plist-get commit-info :commit-time)))
(message "%s" commit-info)
(format "%s - %s" commit-date commit-time)))
(setq blamer-tooltip-function 'my-blamer-tooltip-func)
Available in the posframe for github and gitlab only!
blamer-show-avatar-p
- if you want to show the user avatar in the posframe popup, you can set this variable to t.
If you have an incorrect view of the avatar or line breaks, try to play with these variables.
blamer-avatar-size
- size of the avatar, default is 96px.
blamer-avatar-ratio
- the ratio of the avatar, default is 3x3.
blamer-default-avatar-url
- default fallback URL for not found avatars or users.
blamer-avatar-folder
- folder for saving avatars, default is ~/.blamer/avatars/
blamer-avatar-regexps-uploaders-alist
- list of regexp patterns as car, and API URL and uploader fn as cdr.
Useful for self-hosted Gitlab or GitHub instances.
You can bind the mouse click event and pass custom handler. Where the handler is callback function with commit-info arg. commit-info consist of:
:commit-hash
- hash of clicked commit
:commit-author
- author name after formatting
:raw-commit-author
- raw author username if exist.
:commit-date
- date of commit. (string field)
:commit-time
- commit’s time. (string field)
:commit-message
- message of commit. If not exist will be get from blamer-uncommitted-changes-message
:raw-commit-message
- full message of commit.
For example, if we want to open magit diff by left click, and browse remote by right click we can use this code (magit and forge have to be installed):
(defun blamer-callback-show-commit-diff (commit-info)
(interactive)
(let ((commit-hash (plist-get commit-info :commit-hash)))
(when commit-hash
(magit-show-commit commit-hash))))
(defun blamer-callback-open-remote (commit-info)
(interactive)
(let ((commit-hash (plist-get commit-info :commit-hash)))
(when commit-hash
(message commit-hash)
(forge-browse-commit commit-hash))))
(setq blamer-bindings '(("<mouse-3>" . blamer-callback-open-remote)
("<mouse-1>" . blamer-callback-show-commit-diff)))
Also, you can use timemachine or select the commit in the magit log:
(defun blamer-callback-magit-log-file (commit-info)
(interactive)
(magit-log-buffer-file)
(let ((commit-hash (plist-get commit-info :commit-hash)))
(when commit-hash
(run-with-idle-timer 1 nil (lambda (commit-hash)
(goto-char (point-min))
(search-forward (substring commit-hash 0 7))
(set-mark (point-at-bol))
(goto-char (point-at-eol)))
commit-hash))))
(defun blamer-callback-timemachine (commit-info)
(interactive)
(git-timemachine))
Run before push
eldev prepare && eldev -p -dtT -C test
For more information check this repo