doomemacs/modules/feature/version-control/autoload.el

36 lines
1.3 KiB
EmacsLisp
Raw Normal View History

2017-02-03 20:29:09 -05:00
;;; feature/version-control/autoload.el
;;;###autoload
2017-02-11 06:51:59 -05:00
(defun +vcs-root ()
2017-02-03 20:29:09 -05:00
"Get git url root."
2017-02-19 18:39:54 -05:00
(when-let (url (car-safe (browse-at-remote--remote-ref buffer-file-name)))
2017-02-03 20:29:09 -05:00
(cdr (browse-at-remote--get-url-from-remote url))))
;;;###autoload
(defun +vcs/git-browse ()
"Open the website for the current (or specified) version controlled FILE.
Fallback to repository root."
(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
2017-04-17 02:18:25 -04:00
(concat (string-trim url) "/"
2017-02-19 18:39:54 -05:00
(file-relative-name (buffer-file-name)
(doom-project-root))
(when (use-region-p)
(format "#L%s-L%s"
(line-number-at-pos (region-beginning))
(line-number-at-pos (region-end)))))))))
2017-02-03 20:29:09 -05:00
(when url (browse-url url))))
;;;###autoload
(defun +vcs/git-browse-issues ()
"Open the github issues page for current repo."
(interactive)
2017-02-11 06:51:59 -05:00
(if-let (root (+vcs-root))
2017-02-03 20:29:09 -05:00
(browse-url (concat root "/issues"))
(user-error "No git root found!")))