From 2b1e07dcf0c5ffce89489c960ef59d204fe8ac3e Mon Sep 17 00:00:00 2001 From: Eyoel Tesfu Date: Tue, 29 Apr 2025 07:04:22 -0500 Subject: [PATCH] fix(vc): better line selection in git-timemachine buffers when browse at remote `+vc/browse-at-remote` on git-timemachine buffers solely depended on the active region to determine highlighted lines in the browser, sometimes returning an error when no region is set, and other times using an implicit/invisible transient mark. The number of lines that get highlighted at remote is also not always consistent. This commit modifies `+vc-support-git-timemachine-a` to correct all the above and have `+vc/browse-at-remote` remain consistent between git-timemachine buffers and non git-timemachine buffers. --- modules/emacs/vc/config.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/emacs/vc/config.el b/modules/emacs/vc/config.el index 2994c2347..fae0c4393 100644 --- a/modules/emacs/vc/config.el +++ b/modules/emacs/vc/config.el @@ -89,8 +89,10 @@ file in your browser at the visited revision." :around #'browse-at-remote-get-url (if git-timemachine-mode - (let* ((start-line (line-number-at-pos (min (region-beginning) (region-end)))) - (end-line (line-number-at-pos (max (region-beginning) (region-end)))) + (let* ((start-line (and (use-region-p) (line-number-at-pos + (min (region-beginning) (region-end))))) + (point-end (and (use-region-p) (max (region-beginning) (region-end)))) + (end-line (and (use-region-p) (line-number-at-pos point-end))) (remote-ref (browse-at-remote--remote-ref buffer-file-name)) (remote (car remote-ref)) (ref (car git-timemachine-revision)) @@ -105,7 +107,8 @@ file in your browser at the visited revision." (error (format "Origin repo parsing failed: %s" repo-url))) (funcall url-formatter repo-url ref relname (if start-line start-line) - (if (and end-line (not (equal start-line end-line))) end-line))) + (when (and end-line (not (equal start-line end-line))) + (if (eq (char-before point-end) ?\n) (- end-line 1) end-line)))) (funcall fn))) (defadvice! +vc-update-header-line-a (revision)