From 281963da789fe9e47ce9efc4f7a9c4d19bf3a405 Mon Sep 17 00:00:00 2001 From: Art Date: Tue, 28 May 2024 10:54:13 +0400 Subject: [PATCH] feature: add ability to render commit info in margin overlays (#69) --- README.org | 1 + blamer.el | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.org b/README.org index d8a918c..f4782a7 100644 --- a/README.org +++ b/README.org @@ -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 diff --git a/blamer.el b/blamer.el index 9649930..5231f11 100644 --- a/blamer.el +++ b/blamer.el @@ -5,7 +5,7 @@ ;; Author: Artur Yaroshenko ;; 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)))