2017-06-08 11:47:56 +02:00
|
|
|
;;; feature/version-control/autoload.el -*- lexical-binding: t; -*-
|
2017-02-03 20:29:09 -05:00
|
|
|
|
|
|
|
;;;###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-10-18 20:30:20 +02:00
|
|
|
(require 'git-link)
|
2017-05-07 00:49:18 +02:00
|
|
|
(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))))
|
2017-02-03 20:29:09 -05:00
|
|
|
|
2017-07-14 18:19:08 +02:00
|
|
|
(defvar git-link-open-in-browser)
|
2017-02-03 20:29:09 -05:00
|
|
|
;;;###autoload
|
|
|
|
(defun +vcs/git-browse ()
|
2017-04-22 21:27:54 -04:00
|
|
|
"Open the website for the current version controlled file. Fallback to
|
|
|
|
repository root."
|
2017-02-03 20:29:09 -05:00
|
|
|
(interactive)
|
2017-06-09 13:59:23 +02:00
|
|
|
(require 'git-link)
|
2017-06-25 02:04:50 +02:00
|
|
|
(cl-destructuring-bind (beg end)
|
2017-06-09 13:59:23 +02:00
|
|
|
(if buffer-file-name (git-link--get-region))
|
|
|
|
(let ((git-link-open-in-browser t))
|
|
|
|
(git-link (git-link--select-remote) beg end))))
|
2017-02-03 20:29:09 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +vcs/git-browse-issues ()
|
|
|
|
"Open the github issues page for current repo."
|
|
|
|
(interactive)
|
2017-12-10 14:49:52 -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!")))
|
2017-06-10 11:52:07 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +vcs|init-header-line ()
|
|
|
|
"Toggle the git-timemachine header-line on activate. Use this on
|
|
|
|
`git-timemachine-mode-hook'."
|
|
|
|
(if git-timemachine-mode
|
|
|
|
(+vcs*update-header-line)
|
|
|
|
(setq-local header-line-format nil)))
|
|
|
|
|
2017-07-02 16:29:46 +02:00
|
|
|
;;;###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)
|
2017-08-09 11:56:12 -04:00
|
|
|
(when (and (featurep 'hydra)
|
|
|
|
+vcs-auto-hydra-smerge)
|
|
|
|
(+hydra-smerge/body)))))
|
2017-07-02 16:29:46 +02:00
|
|
|
|
2017-06-10 11:52:07 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defun +vcs*update-header-line (&rest _)
|
|
|
|
"Show revision details in the header-line, instead of the minibuffer.
|
|
|
|
|
|
|
|
Sometimes I forget `git-timemachine' is enabled in a buffer. Putting info into,
|
|
|
|
putting them in `header-line-format' has better visibility."
|
|
|
|
(when (and git-timemachine-mode git-timemachine-revision)
|
|
|
|
(let* ((revision git-timemachine-revision)
|
|
|
|
(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-local
|
|
|
|
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)))))
|