doomemacs/modules/feature/version-control/autoload.el
Henrik Lissner 9b41423537
feature/version-control: fix git-timemachine headerline
On first invokation of git-timemachine the headerline isn't visible
until you jump to another revision. This fix ensures it's visible from
the start.
2018-02-07 02:27:09 -05:00

60 lines
2.2 KiB
EmacsLisp

;;; feature/version-control/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +vcs-root ()
"Get git url root."
(require 'git-link)
(let ((remote (git-link--select-remote)))
(if (git-link--remote-host remote)
(format "https://%s/%s"
(git-link--remote-host remote)
(git-link--remote-dir remote))
(error "Remote `%s' is unknown or contains an unsupported URL" remote))))
(defvar git-link-open-in-browser)
;;;###autoload
(defun +vcs/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 +vcs/git-browse-issues ()
"Open the github issues page for current repo."
(interactive)
(if-let* ((root (+vcs-root)))
(browse-url (concat root "/issues"))
(user-error "No git root found!")))
;;;###autoload
(defun +vcs*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))))
;;;###autoload
(defun +vcs|enable-smerge-mode-maybe ()
"Auto-enable `smerge-mode' when merge conflict is detected."
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^<<<<<<< " nil :noerror)
(smerge-mode 1)
(when (and (featurep 'hydra)
+vcs-auto-hydra-smerge)
(+hydra-smerge/body)))))