summaryrefslogtreecommitdiffstats
path: root/lisp/init-git.el
blob: b598dc5b099a365fd5d49bfcda92e4c3eb0fceea (plain) (blame)
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
;;; init-git.el --- configure git and forge integration  -*- lexical-binding:t -*-
;;; Commentary:
;;; Code:

(defun mpolden/magit-visit-file-other-window (&optional noselect)
  "Visit current file in another window.
If NOSELECT is non-nil, do not select the window."
  (interactive)
  (let ((current-window (selected-window)))
    (call-interactively 'magit-diff-visit-file-other-window)
    (when noselect
      (select-window current-window))))

(defun mpolden/magit-visit-file-other-window-noselect ()
  "Visit current file in another window, but don't select it."
  (interactive)
  (mpolden/magit-visit-file-other-window t))

(defun mpolden/vc-git-grep ()
  "Run git grep interactively in the current VC tree."
  (interactive)
  (vc-git-grep (grep-read-regexp) "" (vc-root-dir)))

(use-package magit
  :ensure t
  :init
  ;; disable gravatars
  (setq magit-revision-show-gravatars nil)

  ;; hide recent commits in magit-status
  (setq magit-log-section-commit-count 0)

  :bind (("C-x m" . magit-status)
         ("C-c b" . magit-blame)
         :map magit-status-mode-map
         ;; make C-o and o behave as in dired
         ("o" . mpolden/magit-visit-file-other-window)
         ("C-o" . mpolden/magit-visit-file-other-window-noselect)))

(use-package forge
  :ensure t
  :after magit
  :init
  ;; limit number of topics listed in status buffer
  (setq forge-topic-list-limit '(10 . 0))
  :bind (;; killing in pullreq or issue section copies the url at point
         :map forge-pullreq-section-map
         ([remap magit-delete-thing] . forge-copy-url-at-point-as-kill)
         :map forge-issue-section-map
         ([remap magit-delete-thing] . forge-copy-url-at-point-as-kill)))

(use-package git-commit
  :ensure t
  :after markdown-mode
  :init
  ;; use gfm-mode as major mode
  (setq git-commit-major-mode 'gfm-mode))

(use-package smerge-mode
  ;; vc-git-find-file-hook calls this command
  :commands smerge-start-session
  :init
  (setq smerge-command-prefix (kbd "C-c x")))

(use-package vc-git
  :commands vc-git-grep
  :bind (;; C-c g runs git grep in current vc tree
         ("C-c g" . mpolden/vc-git-grep)))

;; follow symlinks to files under version control
(setq vc-follow-symlinks t)

;; limit vc backends as this may speed up some operations, e.g. tramp
(setq vc-handled-backends '(Git))

(provide 'init-git)

;;; init-git.el ends here