Skip to content

A simple, fast, asynchronous, customizable display, view of git blame commit in Emacs.

Notifications You must be signed in to change notification settings

ISouthRain/emsg-blame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

emsg-blame

Repository status

Under active maintenance

If you see no commit information for a long time, it proves that the package is stable and don’t worry that the repository has been abandoned.

Overview

A simple, fast, asynchronous, customizable display, highlight all lines with the same commit information, view of git blame in Emacs.

emsg-blame is a minor mode for Emacs that displays Git blame information in the Emacs message area. This package provides detailed information about the last commit that affected the current line, including the author, date, and summary of the commit. It supports multiple languages for time descriptions and allows customization of how and when the blame information is displayed.

Preview for message display && highlight commit background.

There are many more ways to display it. ./attach/preview.gif

Installation

To install emsg-blame , place the following in your Emacs configuration file (.emacs or init.el):

;; Example configuration.
(add-to-list 'load-path "/path/to/emsg-blame")
(require 'emsg-blame)
(setq emsg-blame-background t)
(global-emsg-blame-mode)

Custom Display output

default

./attach/README/20240907_142428.png

message

(defun my--emsg-blame-display ()
  (message " 👽%s 📅%s 🗨️%s" emsg-blame--commit-author emsg-blame--commit-date emsg-blame--commit-summary))
(setq emsg-blame-display #'my--emsg-blame-display)

./attach/README//20240907_125302.png

posframe

(defun my--emsg-blame-display ()
  (posframe-show "*emgs-blame-posframe*"
                 :string (format " 👽%s\n 📅%s\n 🗨️%s " emsg-blame--commit-author emsg-blame--commit-date emsg-blame--commit-summary)
                 :timeout 5
                 :max-width 30
                 :left-fringe 5
                 :right-fringe 5
                 :position (point)
                 :poshandler #'posframe-poshandler-frame-top-right-corner
                 :border-width 5;; 外边框大小
                 :border-color "#ed98cc" ;; 边框颜色
                 )
  )
(setq emsg-blame-display #'my--emsg-blame-display)

./attach/README/20240907_142546.png

right-aligned, propertized

If you already use the echo area to display similar messages (e.g., eldoc), you can display the blame information right-aligned, and preserve the existing messages as long as there is enough space. The function below also propertizes the blame message with Magit-style faces for the commit author and date.

(defun my--emsg-blame-display ()
  "Display git blame message, right-aligned with Magit-style faces.
If another message is already being displayed, display both messages unless they
do not both fit in the echo area."
  (let* ((message-log-max nil) ; prevent messages from being logged to *Messages*
         (cur-msg (or (current-message) ""))
	 (blm-msg (format "%s %s %s "
			  emsg-blame--commit-summary
			  (propertize emsg-blame--commit-author 'face 'error)
			  (propertize emsg-blame--commit-date 'face 'warning)))
	 (available-width (max 0 (- (frame-width) (string-width cur-msg) 1)))
	 (blm-msg-width (string-width blm-msg))
	 (padding (max 0 (- available-width blm-msg-width)))
	 (rev-blm-msg (concat (make-string padding ?\s) blm-msg)))
    (if (> blm-msg-width available-width)
	(message blm-msg)
      (message (concat cur-msg rev-blm-msg)))))

(setq emsg-blame-display #'my--emsg-blame-display)

./attach/README/20240909_091135.png

More display Method

I think you already understand!

commit info variable:

  • emsg-blame–commit-author
  • emsg-blame–commit-date
  • emsg-blame–commit-summary
  • emsg-blame–commit-head

Customization

The behavior of emsg-blame can be customized using the following variables:

emsg-blame-background Type: boolean

Default: t

Description: Toggle highlight all lines with the same commit information use `overlay` background color.

emsg-blame-background-color Default: nil , It is recommended to keep the default nil.

Description: If set to a color value (e.g., hex code or color name), it will be used as the background color for overlays that highlight differences. If set to nil, the default `hl-line` background color will be used instead.

emsg-blame-idle-time Type: number

Default: 0.5

Description: Specifies the time in seconds of idle before showing Git blame information. Adjust this to control how quickly the blame information is displayed after the cursor is idle.

emsg-blame-date-format Type: string

Default: “%Y-*%m-%d”

Description: Defines the format for displaying the commit date. You can customize this using standard format-time-string patterns.

emsg-blame-data-pretty Type: boolean

Default: t

Description: Toggle between pretty (relative) time display and absolute time display. When set to t, relative time (e.g., “5 minutes ago”) is shown. When set to nil, the exact commit date is displayed.

emsg-blame-display Type: function or nil

Default: #’emsg-blame–display-message

Description: Function used to display the blame information. You can provide a custom function to handle the display of the blame information, or set this to nil to use the default display function.

i18n local language

(setq emsg-blame-i18n-date-now "当前"
      emsg-blame-i18n-date-min "%s 分钟前"
      ;; hour, day, month, year
      ;; .......
      )

./attach/README/20240907_141309.png

(setq emsg-blame-i18n-date-now "à l'instant"
      emsg-blame-i18n-date-min "il y a %d minutes"
      ;; hour, day, month, year
      ;; .......
      )

./attach/README/20240907_141415.png

Notes

The emsg-blame package requires Git to be installed and accessible from Emacs.

Non-ASCII filenames are supported, but filenames with non-ASCII characters may not be handled correctly in all environments.

For more information and updates, please visit the project repository.

CONTRIBUTE

Pull requests are welcome.

If you want to add new features, please discuss them in issues first to avoid wasting your precious time.

Similar packages

ChangLog

0.2

feat: Add support highlight all lines with the same commit information.

About

A simple, fast, asynchronous, customizable display, view of git blame commit in Emacs.

Resources

Stars

Watchers

Forks

Packages

No packages published