doomemacs/modules/emacs/vc/autoload.el
Henrik Lissner 60779c9aed
feature/version-control => ui/vc-gutter, emacs/vc
Reorganize vcs functionality. Moves the custom fringe bitmaps into :ui
vc-gutter.
2018-06-22 01:49:20 +02:00

53 lines
2.0 KiB
EmacsLisp

;;; emacs/vc/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +vc-git-root-url ()
"Return the root git repo URL for the current file."
(require 'git-link)
(let* ((remote (git-link--select-remote))
(remote-url (git-link--remote-url remote))
(remote-info (if remote-url (git-link--parse-remote remote-url))))
(if remote-info
(format "https://%s/%s" (car remote-info) (cadr remote-info))
(error "Remote `%s' is unknown or contains an unsupported URL" remote))))
(defvar git-link-open-in-browser)
;;;###autoload
(defun +vc/git-browse ()
"Open the website for the current version controlled file. Fallback to
repository root."
(interactive)
(require 'git-link)
(cl-destructuring-bind (beg end)
(if buffer-file-name (git-link--get-region))
(let ((git-link-open-in-browser t))
(git-link (git-link--select-remote) beg end))))
;;;###autoload
(defun +vc/git-browse-issues ()
"Open the issues page for current repo."
(interactive)
(browse-url (format "%s/issues" (+vc-git-root-url))))
;;;###autoload
(defun +vc/git-browse-pulls ()
"Open the pull requests page for current repo."
(interactive)
(browse-url (format "%s/pulls" (+vc-git-root-url))))
;;;###autoload
(defun +vc*update-header-line (revision)
"Show revision details in the header-line, instead of the minibuffer.
Sometimes I forget `git-timemachine' is enabled in a buffer. Putting revision
info in the `header-line-format' is a good indication."
(let* ((date-relative (nth 3 revision))
(date-full (nth 4 revision))
(author (if git-timemachine-show-author (concat (nth 6 revision) ": ") ""))
(sha-or-subject (if (eq git-timemachine-minibuffer-detail 'commit) (car revision) (nth 5 revision))))
(setq header-line-format
(format "%s%s [%s (%s)]"
(propertize author 'face 'git-timemachine-minibuffer-author-face)
(propertize sha-or-subject 'face 'git-timemachine-minibuffer-detail-face)
date-full date-relative))))