This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+source-control/git/packages.el

283 lines
9.7 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- Git Layer packages File for Spacemacs
;;
2018-01-04 07:00:25 +00:00
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq git-packages
'(
2015-11-06 23:24:51 +00:00
evil-magit
fill-column-indicator
gitattributes-mode
gitconfig-mode
gitignore-mode
2018-06-15 20:36:48 +00:00
gitignore-templates
git-commit
git-link
git-messenger
git-timemachine
golden-ratio
2018-03-27 01:19:04 +00:00
(helm-git-grep :requires helm)
2017-07-03 07:52:54 +00:00
(helm-gitignore :requires helm)
magit
2019-02-18 17:56:45 +00:00
magit-gitflow
2018-04-22 15:49:51 +00:00
magit-svn
2017-07-03 07:52:54 +00:00
(orgit :requires org)
smeargle
transient
))
(defun git/pre-init-golden-ratio ()
(spacemacs|use-package-add-hook golden-ratio
:post-config
(add-to-list 'golden-ratio-exclude-buffer-names " *transient*")))
(defun git/pre-init-evil-magit ()
(spacemacs|use-package-add-hook magit
:post-config
(when (spacemacs//support-evilified-buffer-p dotspacemacs-editing-style)
(evil-magit-init))
Use evil in holy-mode Motivation While disabling Evil in holy-mode makes its implementation shorter and sounds elegant on the paper, in practice it puts a big burden on the configuration parts which need to know if Evil is enable or not. This is a bad separation of concerns and the bunch of fixes that we were forced to do in the past weeks shows this issue. Those fixes were about removing the knowledge of the activation of Evil by implementing new dispatching functions to be used by layers, this is cumbersome and makes Spacemacs layer configuration more subtle which is not good. There was additional bad consequences of the removal of Evil state like the impossibility to use Evil lisp state or iedit states, or we would have been forced to implement a temporary activation of Evil which is awkward. Instead I reintroduce Evil as the central piece of Spacemacs design thus Evil is now re-enabled in holy-mode. It provides the abstraction we need to isolate editing styles and be able to grow the Spacemacs configuration coverage sanely. Layers don't need to check whether the holy mode is active or not and they don't need to know if Evil is available (it is always available). We also don't need to write additional dispatching functions, this is the job of Evil, and I think it provides everything for this. Ideally configuration layer should be implemented with only Evil in mind and the holy-mode (and hybrid-mode) should magically make it work for Emacs style users, for instance we can freely use `evil-insert-state` anywhere in the code without any guard. Evil is now even more part of Spacemacs, we can really say that Spacemacs is Emacs+Evil which is now an indivisible pair. Spacemacs needed this stable API to continue on the right track. While these changes should be rather transparent to the user, I'm sorry for this experimental period, I failed to see all the implications of such a change, I was just excited about the possibility to make Evil optional. The reality is that Spacemacs has to embrace it and keep its strong position on being Emacs+Evil at the core. Implementation - insert, motion and normal states are forced to emacs state using an advice on `evil-insert-state`, `evil-motion-state` and `evil-normal-state` respectively. These functions can be used freely in the layer configuration. - A new general hook `spacemacs-editing-style-hook` allow to hook any code that need to be configured based on the editing style. Functions hooked to this hook takes the current style as parameter, this basically generalize the hook used to setup hjkl navigation bindings. - ESC has been removed from the emacs state map. - Revert unneeded changes - Revert "evil: enter insert-state only from normal-state" commit bdd702dfbe302206bbc989c7a0832daba087a781. - Revert "avoid being evil in deft with emacs editing style" commit f3a16f49ed27cc8cf05f23f93b006d6e04235381. Additional changes All editing style packages have been moved to a layer called `spacemacs-editing-styles` Notes I did not have time to attack hybrid mode, I should be able to do it later.
2016-03-13 23:41:18 +00:00
(evil-define-key 'motion magit-mode-map
(kbd dotspacemacs-leader-key) spacemacs-default-map)))
(defun git/init-evil-magit ()
(use-package evil-magit
:defer t
:init (add-hook 'spacemacs-editing-style-hook
'spacemacs//magit-evil-magit-bindings)))
(defun git/post-init-fill-column-indicator ()
(add-hook 'git-commit-mode-hook 'fci-mode))
2018-03-27 01:19:04 +00:00
(defun git/init-helm-git-grep ()
(use-package helm-git-grep
:defer t
:init (spacemacs/set-leader-keys
"g/" 'helm-git-grep
"g*" 'helm-git-grep-at-point)))
(defun git/init-helm-gitignore ()
(use-package helm-gitignore
:defer t
:init (spacemacs/set-leader-keys "gI" 'helm-gitignore)))
2015-05-18 02:43:42 +00:00
(defun git/init-git-commit ()
2015-07-26 05:03:30 +00:00
(use-package git-commit
:defer t))
(defun git/init-git-link ()
(use-package git-link
:defer t
:init
(progn
2016-07-05 03:17:14 +00:00
(spacemacs/declare-prefix "gl" "links")
(spacemacs/set-leader-keys
"gll" 'spacemacs/git-link
"glL" 'spacemacs/git-link-copy-url-only
"glc" 'spacemacs/git-link-commit
"glC" 'spacemacs/git-link-commit-copy-url-only)
;; default is to open the generated link
(setq git-link-open-in-browser t))))
2014-12-14 04:59:02 +00:00
(defun git/init-git-messenger ()
(use-package git-messenger
:defer t
:init (spacemacs/set-leader-keys "gM" 'git-messenger:popup-message)
:config (define-key git-messenger-map [escape] 'git-messenger:popup-close)))
2014-12-14 04:59:02 +00:00
(defun git/init-git-timemachine ()
(use-package git-timemachine
:defer t
2016-01-20 02:55:38 +00:00
:commands spacemacs/time-machine-transient-state/body
2014-12-14 04:59:02 +00:00
:init
(spacemacs/set-leader-keys
2016-01-20 02:55:38 +00:00
"gt" 'spacemacs/time-machine-transient-state/body)
:config
(progn
2016-01-20 02:55:38 +00:00
(spacemacs|define-transient-state time-machine
:title "Git Timemachine Transient State"
:doc "
[_p_/_N_] previous [_n_] next [_c_] current [_g_] goto nth rev [_Y_] copy hash [_q_] quit"
:on-enter (let (golden-ratio-mode)
(unless (bound-and-true-p git-timemachine-mode)
(call-interactively 'git-timemachine)))
:on-exit (when (bound-and-true-p git-timemachine-mode)
(git-timemachine-quit))
:foreign-keys run
:bindings
("c" git-timemachine-show-current-revision)
("g" git-timemachine-show-nth-revision)
("p" git-timemachine-show-previous-revision)
("n" git-timemachine-show-next-revision)
("N" git-timemachine-show-previous-revision)
("Y" git-timemachine-kill-revision)
("q" nil :exit t)))))
2014-12-14 04:59:02 +00:00
2015-03-26 16:10:54 +00:00
(defun git/init-gitattributes-mode ()
(use-package gitattributes-mode
:defer t))
2015-03-26 16:10:54 +00:00
(defun git/init-gitconfig-mode ()
(use-package gitconfig-mode
:defer t))
2015-03-26 16:10:54 +00:00
(defun git/init-gitignore-mode ()
(use-package gitignore-mode
:defer t))
2015-03-26 16:10:54 +00:00
2018-06-15 20:36:48 +00:00
(defun git/init-gitignore-templates ()
(use-package gitignore-templates
:defer t
:init
(spacemacs/set-leader-keys-for-major-mode 'gitignore-mode
"i" 'gitignore-templates-insert)
(spacemacs/set-leader-keys
"gfi" 'gitignore-templates-new-file)))
2014-12-14 04:59:02 +00:00
(defun git/init-magit ()
(use-package magit
2018-03-31 04:55:59 +00:00
:defer (spacemacs/defer)
2014-12-14 04:59:02 +00:00
:init
(progn
2018-10-25 12:59:11 +00:00
(push "magit: .*" spacemacs-useless-buffers-regexp)
(push "magit-.*: .*" spacemacs-useless-buffers-regexp)
2018-03-31 04:55:59 +00:00
(spacemacs|require 'magit)
(setq magit-completing-read-function
(if (configuration-layer/layer-used-p 'ivy)
'ivy-completing-read
'magit-builtin-completing-read))
(setq magit-revision-show-gravatars '("^Author: " . "^Commit: "))
;; On Windows, we must use Git GUI to enter username and password
;; See: https://github.com/magit/magit/wiki/FAQ#windows-cannot-push-via-https
(when (eq window-system 'w32)
(setenv "GIT_ASKPASS" "git-gui--askpass"))
;; key bindings
(spacemacs/declare-prefix "gf" "file")
(spacemacs/set-leader-keys
"gb" 'spacemacs/git-blame-micro-state
"gc" 'magit-clone
"gff" 'magit-find-file
"gfl" 'magit-log-buffer-file
"gfd" 'magit-diff
"gi" 'magit-init
2016-09-12 14:54:26 +00:00
"gL" 'magit-list-repositories
"gm" 'magit-dispatch
"gs" 'magit-status
"gS" 'magit-stage-file
"gU" 'magit-unstage-file)
;; transient state
;; TODO use transient state instead of old micro-state, IIRC we continue
;; to use micro-state because of the re-entry keyword :on-enter which is
;; not available in transient state
(spacemacs|define-micro-state git-blame
2016-01-20 02:55:38 +00:00
:title "Git Blame Transient State"
2016-01-21 21:06:15 +00:00
:doc "
Press [_b_] again to blame further in the history, [_q_] to go up or quit."
:on-enter (let (golden-ratio-mode)
(unless (bound-and-true-p magit-blame-mode)
(call-interactively 'magit-blame-addition)))
:foreign-keys run
2015-10-19 03:36:03 +00:00
:bindings
("b" magit-blame-addition)
2015-10-19 03:36:03 +00:00
;; here we use the :exit keyword because we should exit the
;; micro-state only if the magit-blame-quit effectively disable
;; the magit-blame mode.
("q" nil :exit (progn (when (bound-and-true-p magit-blame-mode)
(magit-blame-quit))
(not (bound-and-true-p magit-blame-mode))))))
2014-12-14 04:59:02 +00:00
:config
(progn
;; seems to be necessary at the time of release
(require 'git-rebase)
;; bind function keys
;; (define-key magit-mode-map (kbd "<tab>") 'magit-section-toggle)
2016-09-12 14:54:26 +00:00
(evilified-state-evilify-map magit-repolist-mode-map
:mode magit-repolist-mode
:bindings
(kbd "gr") 'magit-list-repositories
(kbd "RET") 'magit-repolist-status)
;; confirm/abort
(when dotspacemacs-major-mode-leader-key
(add-hook 'with-editor-mode-hook 'evil-normalize-keymaps)
(let ((mm-key dotspacemacs-major-mode-leader-key))
(dolist (state '(normal motion))
(evil-define-key state with-editor-mode-map
(concat mm-key mm-key) 'with-editor-finish
(concat mm-key "a") 'with-editor-cancel
(concat mm-key "c") 'with-editor-finish
(concat mm-key "k") 'with-editor-cancel)
(evil-define-key state magit-log-select-mode-map
(concat mm-key mm-key) 'magit-log-select-pick
(concat mm-key "a") 'magit-log-select-quit
(concat mm-key "c") 'magit-log-select-pick
(concat mm-key "k") 'magit-log-select-quit))))
;; whitespace
(define-key magit-status-mode-map (kbd "C-S-w")
'spacemacs/magit-toggle-whitespace)
;; full screen magit-status
(when git-magit-status-fullscreen
(setq magit-display-buffer-function
'magit-display-buffer-fullframe-status-v1))
(spacemacs|hide-lighter with-editor-mode))))
2014-12-14 04:59:02 +00:00
(defun git/init-magit-gitflow ()
(use-package magit-gitflow
2019-02-18 17:56:45 +00:00
:defer t
:init (add-hook 'magit-mode-hook 'turn-on-magit-gitflow)
:config
(progn
(spacemacs|diminish magit-gitflow-mode "Flow")
(define-key magit-mode-map "%" 'magit-gitflow-popup))))
2014-12-14 04:59:02 +00:00
2015-01-27 05:17:51 +00:00
(defun git/init-magit-svn ()
(use-package magit-svn
2018-05-24 16:21:40 +00:00
:if git-enable-magit-svn-plugin
2015-01-27 05:17:51 +00:00
:commands turn-on-magit-svn
2018-05-24 16:21:40 +00:00
:init (add-hook 'magit-mode-hook 'turn-on-magit-svn)
:config (progn
(spacemacs|diminish magit-svn-mode "SVN")
(define-key magit-mode-map "~" 'magit-svn))))
2015-01-27 05:17:51 +00:00
2018-11-29 13:03:26 +00:00
(defun git/init-orgit ()
(use-package orgit
:defer t))
2014-12-14 04:59:02 +00:00
(defun git/init-smeargle ()
(use-package smeargle
:defer t
2014-12-14 04:59:02 +00:00
:init
(progn
(spacemacs/declare-prefix "gH" "highlight")
(when (configuration-layer/package-used-p 'which-key)
;; TODO abstract this to a function
(let ((descr
'(("smeargle" . "highlight by last update time")
("smeargle-commits" . "highlight by age of changes")
("smeargle-clear" . "clear"))))
(dolist (nd descr)
;; ensure the target matches the whole string
(push (cons (cons nil (concat "\\`" (car nd) "\\'"))
(cons nil (cdr nd)))
which-key-replacement-alist))))
(spacemacs/set-leader-keys
"gHc" 'smeargle-clear
"gHh" 'smeargle-commits
"gHt" 'smeargle))))
(defun git/init-transient ()
(use-package transient
:defer t
:init
(setq
transient-levels-file
(expand-file-name "transient/levels.el" spacemacs-cache-directory)
transient-values-file
(expand-file-name "transient/values.el" spacemacs-cache-directory)
transient-history-file
(expand-file-name "transient/history.el" spacemacs-cache-directory))))