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/version-control/funcs.el
Maximilian Wolff 25d6364bdb
[version control] Revise git-gutter+ refresh on Magit refresh
It was possible before, that the utility function
`spacemacs//git-gutter+-refresh-in-all-buffers`
was not defined but called in the package file.
2020-09-23 21:42:46 +02:00

157 lines
5 KiB
EmacsLisp

;;; funcs.el --- Version control functions File
;;
;; Copyright (c) 2012-2020 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
(defun spacemacs/diff-mode-revert-hunk ()
(interactive)
(diff-apply-hunk t))
(defun spacemacs/vcs-next-hunk ()
(interactive)
(let ((current-prefix-arg t))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'diff-hl-next-hunk)
(git-gutter 'git-gutter:next-hunk)
(git-gutter+ 'git-gutter+-next-hunk)))))
(defun spacemacs/vcs-previous-hunk ()
(interactive)
(let ((current-prefix-arg t))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'diff-hl-previous-hunk)
(git-gutter 'git-gutter:previous-hunk)
(git-gutter+ 'git-gutter+-previous-hunk)))))
(defun spacemacs/vcs-revert-hunk ()
(interactive)
(let ((current-prefix-arg t)
(inhibit-modification-hooks t))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'diff-hl-revert-hunk)
(git-gutter 'git-gutter:revert-hunk)
(git-gutter+ 'git-gutter+-revert-hunks)))))
(defun spacemacs/vcs-stage-hunk ()
(interactive)
(if (eq 'diff-hl version-control-diff-tool)
(message "Staging not available")
(let ((current-prefix-arg t))
(call-interactively
(cl-case version-control-diff-tool
(git-gutter 'git-gutter:stage-hunk)
(git-gutter+ 'git-gutter+-stage-hunks))))))
(defun spacemacs/vcs-show-hunk ()
(interactive)
(let ((current-prefix-arg t))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'diff-hl-diff-goto-hunk)
(git-gutter 'git-gutter:popup-hunk)
(git-gutter+ 'git-gutter+-show-hunk-inline-at-point)))))
(defun spacemacs/vcs-enable-margin ()
(interactive)
(let ((current-prefix-arg t))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'diff-hl-mode)
(git-gutter 'git-gutter-mode)
(git-gutter+ 'git-gutter+-mode)))))
(defun spacemacs/vcs-disable-margin ()
(interactive)
(let ((current-prefix-arg nil))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'diff-hl-mode)
(git-gutter 'git-gutter-mode)
(git-gutter+ 'git-gutter+-mode)))))
(defun spacemacs/vcs-enable-margin-globally ()
(interactive)
(let ((current-prefix-arg t))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'global-diff-hl-mode)
(git-gutter 'global-git-gutter-mode)
(git-gutter+ 'global-git-gutter+-mode)))))
(defun spacemacs/vcs-disable-margin-globally ()
(interactive)
(let ((current-prefix-arg nil))
(call-interactively
(cl-case version-control-diff-tool
(diff-hl 'global-diff-hl-mode)
(git-gutter 'global-git-gutter-mode)
(git-gutter+ 'global-git-gutter+-mode)))))
(defun spacemacs/vcs-show-help ()
(interactive)
(setq version-control--ms-doc-toggle
(logxor version-control--ms-doc-toggle 1)))
(defun spacemacs/vcs-margin-p ()
(interactive)
(cl-case version-control-diff-tool
(diff-hl diff-hl-mode)
(git-gutter (bound-and-true-p git-gutter-mode))
(git-gutter+ (bound-and-true-p git-gutter+-mode))))
(defun spacemacs/vcs-margin-global-p ()
(interactive)
(cl-case version-control-diff-tool
(diff-hl global-diff-hl-mode)
(git-gutter global-git-gutter-mode)
(git-gutter+ global-git-gutter+-mode)))
(spacemacs|add-toggle version-control-margin
:status (spacemacs/vcs-margin-p)
:on (spacemacs/vcs-enable-margin)
:off (spacemacs/vcs-disable-margin)
:documentation "Enable diff margins."
:evil-leader "Td")
(spacemacs|add-toggle version-control-margin-globally
:status (spacemacs/vcs-margin-global-p)
:on (spacemacs/vcs-enable-margin-globally)
:off (spacemacs/vcs-disable-margin-globally)
:documentation "Enable diff margins globally."
:evil-leader "T C-d")
(defun spacemacs//smerge-ts-hint ()
"Return a hint for the smerge transient state.
Return a string indicating the index of the current conflict and
the number of conflicts detected by `smerge-mode'."
(concat
(cl-loop for ol being the overlays
with pos = (point)
if (eq (overlay-get ol 'smerge) 'conflict)
count ol into total
and if (<= (overlay-start ol) pos)
count ol into idx
finally return (format "conflict [%d/%d]" idx total))
(if spacemacs--smerge-ts-full-hint-toggle
spacemacs--smerge-ts-full-hint
(concat " (["
(propertize "?" 'face 'hydra-face-red)
"] help)"))))
(defun spacemacs//smerge-ts-toggle-hint ()
"Toggle the full hint docstring for the smerge transient state."
(interactive)
(setq spacemacs--smerge-ts-full-hint-toggle
(not spacemacs--smerge-ts-full-hint-toggle)))
(defun spacemacs//git-gutter+-refresh-in-all-buffers ()
(git-gutter+-in-all-buffers (when git-gutter+-mode (git-gutter+-refresh))))