Skip to content

Commit

Permalink
feature: add ability to render commit info in margin overlays (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artawower authored May 28, 2024
1 parent 4cc2e6d commit 281963d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Can accept
- ='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.
**** Overlay popup position
Expand Down
25 changes: 21 additions & 4 deletions blamer.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Artur Yaroshenko <[email protected]>
;; URL: https://github.com/artawower/blamer.el
;; Package-Requires: ((emacs "27.1") (posframe "1.1.7") (async "1.9.8"))
;; Version: 0.8.7
;; Version: 0.9.1

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -118,6 +118,7 @@ Will add additional space for each BLAMER-OFFSET-PER-SYMBOL"
\\='visual - show blame only for current line
\\='selected - show blame only for selected line
\\='both - both of them
\\='margin-overlay - show blame in margin.
This types are used only for single line blame.
\\='overlay-popup - show commit info inside pretty overlay
Expand All @@ -127,6 +128,7 @@ This types are used only for single line blame.
(const :tag "Pretty overlay popup" overlay-popup)
(const :tag "Pretty posframe popup" posframe-popup)
(const :tag "Visual and selected" both)
(const :tag "Margin overlay" margin-overlay)
(const :tag "Selected only" selected)))

(defcustom blamer--overlay-popup-position 'bottom
Expand Down Expand Up @@ -709,8 +711,9 @@ Works only for github right now."
blamer-symbol-count-before-new-line))
text))

(defun blamer--create-popup-msg (commit-info)
"Handle current COMMIT-INFO."
(defun blamer--create-popup-msg (commit-info &optional not-truncate-p)
"Handle current COMMIT-INFO.
Optional disable truncating with NOT-TRUNCATE-P."
(let* ((offset (max (- (or blamer-min-offset 0) (length (thing-at-point 'line))) 0))
(commit-author (plist-get commit-info :commit-author))
(popup-message (blamer--format-commit-info (plist-get commit-info :commit-hash)
Expand All @@ -720,7 +723,7 @@ Works only for github right now."
(plist-get commit-info :commit-time)
offset
commit-info))
(popup-message (blamer--maybe-normalize-truncated-line popup-message)))
(popup-message (if (not not-truncate-p) (blamer--maybe-normalize-truncated-line popup-message) popup-message)))

(when (and commit-author (not (string= commit-author "")))
popup-message)))
Expand Down Expand Up @@ -859,6 +862,18 @@ Return list of strings."
(overlay-put ov 'window (get-buffer-window))
(add-to-list 'blamer--overlays ov)))

(defun blamer--render-margin-overlay (commit-info render-point)
"Render COMMIT-INFO as overlay at RENDER-POINT position in the right overlay."
(when-let* ((ov (progn (move-end-of-line nil)
(make-overlay render-point render-point nil t t)))
(popup-msg (blamer--create-popup-msg commit-info t)))
(overlay-put ov 'priority 65001)
(overlay-put ov 'before-string
(propertize " " 'display `((margin right-margin) ,popup-msg)))
(overlay-put ov 'intangible t)
(overlay-put ov 'window (get-buffer-window))
(add-to-list 'blamer--overlays ov)))

(defun blamer--render-right-overlay (commit-info render-point)
"Render COMMIT-INFO as overlay at RENDER-POINT position."
(when-let ((ov (progn (move-end-of-line nil)
Expand Down Expand Up @@ -925,6 +940,7 @@ when not provided `blamer-type' will be used."
(save-excursion
(cond ((eq (or type blamer-type) 'overlay-popup) (blamer--render-overlay-popup commit-info))
((eq (or type blamer-type) 'posframe-popup) (blamer--render-posframe-popup commit-info))
((eq (or type blamer-type) 'margin-overlay) (blamer--render-margin-overlay commit-info render-point))
(t (blamer--render-right-overlay commit-info render-point))))))

(defun blamer--get-async-blame-info (file-name start-line end-line callback)
Expand Down Expand Up @@ -1071,6 +1087,7 @@ LOCAL-TYPE is force replacement of current `blamer-type' for handle rendering."
(when (and (not long-region-p)
(not blamer--block-render-p)
(or (eq type 'both)
(eq type 'margin-overlay)
(and (eq type 'visual) (not (use-region-p)))
(and (eq type 'overlay-popup) (not (use-region-p)))
(and (eq type 'selected) (use-region-p)))
Expand Down

0 comments on commit 281963d

Please sign in to comment.