-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add ability to render commit info in margin overlays (#69)
- Loading branch information
Showing
2 changed files
with
22 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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))) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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))) | ||
|