Refactor browse-at-remote commands

This commit is contained in:
Henrik Lissner 2020-01-11 17:29:16 -05:00
parent 0c9f1b1a9c
commit 5802bd7047
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -3,15 +3,18 @@
(autoload 'browse-at-remote-get-url "browse-at-remote") (autoload 'browse-at-remote-get-url "browse-at-remote")
(autoload 'browse-at-remote--file-url "browse-at-remote") (autoload 'browse-at-remote--file-url "browse-at-remote")
(defun +vc--remote-file-or-region-link ()
(if (or (doom-region-active-p) (not buffer-file-name))
(browse-at-remote-get-url)
(browse-at-remote--file-url (buffer-file-name))))
;;;###autoload ;;;###autoload
(defun +vc/browse-at-remote-file-or-region () (defun +vc/browse-at-remote-file-or-region ()
"Open the current file at remote in your browser. "Open the current file at remote in your browser.
If a selection is active, highlight them. Otherwise omits the #L<N> suffix in If a selection is active, highlight them. Otherwise omits the #L<N> suffix in
the URL." the URL."
(interactive) (interactive)
(if (or (doom-region-active-p) (not buffer-file-name)) (browse-url (+vc--remote-file-or-region-link)))
(browse-at-remote)
(browse-url (browse-at-remote--file-url (buffer-file-name)))))
;;;###autoload ;;;###autoload
(defun +vc/browse-at-remote-kill-file-or-region () (defun +vc/browse-at-remote-kill-file-or-region ()
@ -19,10 +22,7 @@ the URL."
If a selection is active, highlight them. Otherwise omits the #L<N> suffix in If a selection is active, highlight them. Otherwise omits the #L<N> suffix in
the URL." the URL."
(interactive) (interactive)
(let ((url (let ((url (+vc--remote-file-or-region-link)))
(if (or (doom-region-active-p) (not buffer-file-name))
(browse-at-remote-get-url)
(browse-at-remote--file-url (buffer-file-name)))))
(kill-new url) (kill-new url)
(message "Copied to clipboard: %S" url))) (message "Copied to clipboard: %S" url)))