From 095051895a430670b177e9424dc068b8befb60bb Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 29 Dec 2015 23:40:30 -0500 Subject: [PATCH] Add hub browse fallback for browse-at-remote (WIP) --- core/core-vcs.el | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/core/core-vcs.el b/core/core-vcs.el index 6297cece4..cdbc329f4 100644 --- a/core/core-vcs.el +++ b/core/core-vcs.el @@ -49,16 +49,27 @@ :n [tab] 'vc-annotate-toggle-annotation-visibility :n "RET" 'vc-annotate-find-revision-at-line)) -(evil-define-command narf:git-remote-browse (&optional bang file) - "Open the website for the current (or specified) version controlled FILE. If BANG, +(use-package browse-at-remote + :commands (browse-at-remote/browse browse-at-remote/to-clipboard) + :init + (evil-define-command narf:git-remote-browse (&optional bang) + "Open the website for the current (or specified) version controlled FILE. If BANG, then use hub to do it." - (interactive "") - (let ((url (shell-command-to-string "hub browse -u -- "))) - (when url - (setq url (concat (s-trim url) "/" (f-relative (buffer-file-name) (narf/project-root))))) - (if bang - (message "Url copied to clipboard: %s" (kill-new url)) - (browse-url url)))) + (interactive "") + (let (url) + (condition-case err + (setq url (browse-at-remote/get-url)) + (error + (setq url (shell-command-to-string "hub browse -u --")) + (setq url (if url + (concat (s-trim url) "/" (f-relative (buffer-file-name) (narf/project-root)) + (when (use-region-p) (format "#L%s-L%s" + (line-number-at-pos (region-beginning)) + (line-number-at-pos (region-end))))))))) + (when url + (if bang + (message "Url copied to clipboard: %s" (kill-new url)) + (browse-url url)))))) (provide 'core-vcs) ;;; core-vcs.el ends here