From 87e48cbc9002cca192f33e4c4a2190d7a2169ddb Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 10 May 2021 16:55:54 -0400 Subject: [PATCH] Add git-timemachine support to browse-at-remote browse-at-remote commands will now open the current file at the active revision on that project's git forge in your browser. --- modules/emacs/vc/config.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/emacs/vc/config.el b/modules/emacs/vc/config.el index d5ef38dc9..cd81bd26f 100644 --- a/modules/emacs/vc/config.el +++ b/modules/emacs/vc/config.el @@ -48,6 +48,31 @@ ;; `header-line-format', which has better visibility. (setq git-timemachine-show-minibuffer-details t) + ;; TODO PR this to `git-timemachine' + (defadvice! +vc-support-git-timemachine-a (orig-fn) + "Allow `browse-at-remote' commands in git-timemachine buffers to open that +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)))) + (remote-ref (browse-at-remote--remote-ref buffer-file-name)) + (remote (car remote-ref)) + (ref (car git-timemachine-revision)) + (relname + (file-relative-name + buffer-file-name (expand-file-name (vc-git-root buffer-file-name)))) + (target-repo (browse-at-remote--get-url-from-remote remote)) + (remote-type (browse-at-remote--get-remote-type target-repo)) + (repo-url (cdr target-repo)) + (url-formatter (browse-at-remote--get-formatter 'region-url remote-type))) + (unless url-formatter + (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))) + (funcall orig-fn))) + (defadvice! +vc-update-header-line-a (revision) "Show revision details in the header-line, instead of the minibuffer.