forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-git.el
100 lines (72 loc) · 3.18 KB
/
init-git.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; init-git.el --- Git SCM support -*- lexical-binding: t -*-
;;; Commentary:
;; See also init-github.el.
;;; Code:
;; TODO: link commits from vc-log to magit-show-commit
;; TODO: smerge-mode
(require-package 'git-blamed)
(require-package 'git-modes)
(when (maybe-require-package 'git-timemachine)
(global-set-key (kbd "C-x v t") 'git-timemachine-toggle))
(require-package 'git-link)
(when (maybe-require-package 'magit)
(setq-default magit-diff-refine-hunk 'all)
;; Hint: customize `magit-repository-directories' so that you can use C-u M-F12 to
;; quickly open magit on any one of your projects.
(global-set-key [(meta f12)] 'magit-status)
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-x M-g") 'magit-dispatch)
(defun sanityinc/magit-or-vc-log-file (&optional prompt)
(interactive "P")
(if (and (buffer-file-name)
(eq 'Git (vc-backend (buffer-file-name))))
(if prompt
(magit-log-buffer-file-popup)
(magit-log-buffer-file t))
(vc-print-log)))
(with-eval-after-load 'vc
(define-key vc-prefix-map (kbd "l") 'sanityinc/magit-or-vc-log-file)))
(with-eval-after-load 'magit
(define-key magit-status-mode-map (kbd "C-M-<up>") 'magit-section-up))
(maybe-require-package 'magit-todos)
(require-package 'fullframe)
(with-eval-after-load 'magit
(fullframe magit-status magit-mode-quit-window))
(when (maybe-require-package 'git-commit)
(add-hook 'git-commit-mode-hook 'goto-address-mode))
(when *is-a-mac*
(with-eval-after-load 'magit
(add-hook 'magit-mode-hook (lambda () (local-unset-key [(meta h)])))))
;; Convenient binding for vc-git-grep
(with-eval-after-load 'vc
(define-key vc-prefix-map (kbd "f") 'vc-git-grep))
;;; git-svn support
;; (when (maybe-require-package 'magit-svn)
;; (require-package 'magit-svn)
;; (autoload 'magit-svn-enabled "magit-svn")
;; (defun sanityinc/maybe-enable-magit-svn-mode ()
;; (when (magit-svn-enabled)
;; (magit-svn-mode)))
;; (add-hook 'magit-status-mode-hook #'sanityinc/maybe-enable-magit-svn-mode))
(with-eval-after-load 'compile
(dolist (defn (list '(git-svn-updated "^\t[A-Z]\t\\(.*\\)$" 1 nil nil 0 1)
'(git-svn-needs-update "^\\(.*\\): needs update$" 1 nil nil 2 1)))
(add-to-list 'compilation-error-regexp-alist-alist defn)
(add-to-list 'compilation-error-regexp-alist (car defn))))
(defvar git-svn--available-commands nil "Cached list of git svn subcommands")
(defun git-svn--available-commands ()
(or git-svn--available-commands
(setq git-svn--available-commands
(sanityinc/string-all-matches
"^ \\([a-z\\-]+\\) +"
(shell-command-to-string "git svn help") 1))))
(autoload 'vc-git-root "vc-git")
(defun git-svn (dir command)
"Run a git svn subcommand in DIR."
(interactive (list (read-directory-name "Directory: ")
(completing-read "git-svn command: " (git-svn--available-commands) nil t nil nil (git-svn--available-commands))))
(let* ((default-directory (vc-git-root dir))
(compilation-buffer-name-function (lambda (major-mode-name) "*git-svn*")))
(compile (concat "git svn " command))))
(provide 'init-git)
;;; init-git.el ends here