mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-23 19:40:24 +10:00
Updating Doom Emacs.
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
;;; tools/magit/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; HACK Magit complains loudly when it can't determine its own version, which is
|
||||
;; the case when magit is built through straight. The warning is harmless,
|
||||
;; however, so we just need it to shut up.
|
||||
;; HACK Magit complains loudly (but harmlessly) when it can't determine its own
|
||||
;; version in a sparse clone. This was fixed upstream in
|
||||
;; magit/magit@b1b2683, but only for macOS and Linux users. Windows doesn't
|
||||
;; support symlinks as unix knows them, so `magit-version' can't resolve
|
||||
;; its own repo's path.
|
||||
;;;###autoload
|
||||
(advice-add #'magit-version :override #'ignore)
|
||||
(when! IS-WINDOWS
|
||||
(defadvice! +magit--ignore-version-a (&optional print-dest)
|
||||
:override #'magit-version
|
||||
(when print-dest
|
||||
(defvar magit-git-debug)
|
||||
(princ (format "Magit (unknown), Git %s, Emacs %s, %s"
|
||||
(or (let ((magit-git-debug
|
||||
(lambda (err)
|
||||
(display-warning '(magit git) err :error))))
|
||||
(magit-git-version t))
|
||||
"(unknown)")
|
||||
emacs-version
|
||||
system-type)
|
||||
print-dest))
|
||||
nil))
|
||||
|
||||
;;;###autoload
|
||||
(defun +magit-display-buffer-fn (buffer)
|
||||
@@ -41,28 +57,42 @@
|
||||
|
||||
|
||||
;;
|
||||
;; Commands
|
||||
;;; Auto-revert
|
||||
|
||||
(defun +magit--refresh-vc-in-buffer (buffer)
|
||||
(defvar +magit--stale-p nil)
|
||||
|
||||
(defun +magit--revert-buffer (buffer)
|
||||
(with-current-buffer buffer
|
||||
(when (and vc-mode (fboundp 'vc-refresh-state))
|
||||
(vc-refresh-state))
|
||||
(when (and (bound-and-true-p git-gutter-mode)
|
||||
(fboundp '+version-control|update-git-gutter))
|
||||
(+version-control|update-git-gutter))
|
||||
(setq +magit--vc-is-stale-p nil)))
|
||||
(kill-local-variable '+magit--stale-p)
|
||||
(when buffer-file-name
|
||||
(if (buffer-modified-p (current-buffer))
|
||||
(when (bound-and-true-p vc-mode)
|
||||
(vc-refresh-state)
|
||||
(force-mode-line-update))
|
||||
(revert-buffer t t)))))
|
||||
|
||||
;;;###autoload
|
||||
(defvar-local +magit--vc-is-stale-p nil)
|
||||
(defun +magit-mark-stale-buffers-h ()
|
||||
"Revert all visible buffers and mark buried buffers as stale.
|
||||
|
||||
Stale buffers are reverted when they are switched to, assuming they haven't been
|
||||
modified."
|
||||
(dolist (buffer (buffer-list))
|
||||
(when (buffer-live-p buffer)
|
||||
(if (get-buffer-window buffer)
|
||||
(+magit--revert-buffer buffer)
|
||||
(with-current-buffer buffer
|
||||
(setq-local +magit--stale-p t))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +magit-refresh-vc-state-maybe-h ()
|
||||
(defun +magit-revert-buffer-maybe-h ()
|
||||
"Update `vc' and `git-gutter' if out of date."
|
||||
(when +magit--vc-is-stale-p
|
||||
(+magit--refresh-vc-in-buffer (current-buffer))))
|
||||
(when +magit--stale-p
|
||||
(+magit--revert-buffer (current-buffer))))
|
||||
|
||||
;;;###autoload
|
||||
(add-hook 'doom-switch-buffer-hook #'+magit-refresh-vc-state-maybe-h)
|
||||
|
||||
;;
|
||||
;;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +magit/quit (&optional kill-buffer)
|
||||
@@ -76,12 +106,7 @@ control in buffers."
|
||||
(eq major-mode 'magit-status-mode)))
|
||||
(window-list)))
|
||||
(mapc #'+magit--kill-buffer (magit-mode-get-buffers))
|
||||
(dolist (buffer (buffer-list))
|
||||
(when (buffer-live-p buffer)
|
||||
(if (get-buffer-window buffer)
|
||||
(+magit--refresh-vc-in-buffer buffer)
|
||||
(with-current-buffer buffer
|
||||
(setq +magit--vc-is-stale-p t)))))))
|
||||
(+magit-mark-stale-buffers-h)))
|
||||
|
||||
(defun +magit--kill-buffer (buf)
|
||||
"TODO"
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
;;; tools/magit/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! magit
|
||||
:commands magit-file-delete
|
||||
:defer-incrementally (dash f s with-editor git-commit package eieio lv transient)
|
||||
:init
|
||||
(setq magit-auto-revert-mode nil) ; we do this ourselves
|
||||
(setq magit-auto-revert-mode nil) ; we do this ourselves further down
|
||||
;; Must be set early to prevent ~/.emacs.d/transient from being created
|
||||
(setq transient-levels-file (concat doom-etc-dir "transient/levels")
|
||||
transient-values-file (concat doom-etc-dir "transient/values")
|
||||
@@ -19,12 +16,27 @@
|
||||
;; Don't autosave repo buffers. This is too magical, and saving can
|
||||
;; trigger a bunch of unwanted side-effects, like save hooks and
|
||||
;; formatters. Trust us to know what we're doing.
|
||||
magit-save-repository-buffers nil)
|
||||
magit-save-repository-buffers nil
|
||||
;; Magit runs git *a lot*. Having to scan your PATH so many times can
|
||||
;; add up with each invokation, especially on Catalina (macOS) or
|
||||
;; Windows, so we resolve it once.
|
||||
magit-git-executable (executable-find magit-git-executable))
|
||||
(add-hook 'magit-process-mode-hook #'goto-address-mode)
|
||||
|
||||
(defadvice! +magit-invalidate-projectile-cache-a (&rest _args)
|
||||
;; We ignore the args to `magit-checkout'.
|
||||
(defadvice! +magit-revert-repo-buffers-deferred-a (&rest _)
|
||||
:after '(magit-checkout magit-branch-and-checkout)
|
||||
(projectile-invalidate-cache nil))
|
||||
;; Since the project likely now contains new files, best we undo the
|
||||
;; projectile cache so it can be regenerated later.
|
||||
(projectile-invalidate-cache nil)
|
||||
;; Use a more efficient strategy to auto-revert buffers whose git state has
|
||||
;; changed: refresh the visible buffers immediately...
|
||||
(+magit-mark-stale-buffers-h))
|
||||
;; ...then refresh the rest only when we switch to them, not all at once.
|
||||
(add-hook 'doom-switch-buffer-hook #'+magit-revert-buffer-maybe-h)
|
||||
|
||||
;; Center the target file, because it's poor UX to have it at the bottom of
|
||||
;; the window after invoking `magit-status-here'.
|
||||
(advice-add #'magit-status-here :after #'doom-recenter-a)
|
||||
|
||||
;; The default location for git-credential-cache is in
|
||||
;; ~/.cache/git/credential. However, if ~/.git-credential-cache/ exists, then
|
||||
@@ -36,6 +48,20 @@
|
||||
"~/.cache/")
|
||||
"git/credential/socket")))
|
||||
|
||||
;; Prevent scrolling when manipulating magit-status hunks. Otherwise you must
|
||||
;; reorient yourself every time you stage/unstage/discard/etc a hunk.
|
||||
;; Especially so on larger projects."
|
||||
(defvar +magit--pos nil)
|
||||
(add-hook! 'magit-pre-refresh-hook
|
||||
(defun +magit--set-window-state-h ()
|
||||
(setq-local +magit--pos (list (current-buffer) (point) (window-start)))))
|
||||
(add-hook! 'magit-post-refresh-hook
|
||||
(defun +magit--restore-window-state-h ()
|
||||
(when (and +magit--pos (eq (current-buffer) (car +magit--pos)))
|
||||
(goto-char (cadr +magit--pos))
|
||||
(set-window-start nil (caddr +magit--pos) t)
|
||||
(kill-local-variable '+magit--pos))))
|
||||
|
||||
;; Magit uses `magit-display-buffer-traditional' to display windows, by
|
||||
;; default, which is a little primitive. `+magit-display-buffer' marries
|
||||
;; `magit-display-buffer-fullcolumn-most-v1' with
|
||||
@@ -50,7 +76,7 @@
|
||||
(set-popup-rule! "^\\(?:\\*magit\\|magit:\\| \\*transient\\*\\)" :ignore t)
|
||||
(add-hook 'magit-popup-mode-hook #'hide-mode-line-mode)
|
||||
|
||||
;; Add --tags switch
|
||||
;; Add additional switches that seem common enough
|
||||
(transient-append-suffix 'magit-fetch "-p"
|
||||
'("-t" "Fetch all tags" ("-t" "--tags")))
|
||||
(transient-append-suffix 'magit-pull "-r"
|
||||
@@ -63,7 +89,8 @@
|
||||
(and (derived-mode-p 'magit-mode)
|
||||
(not (eq major-mode 'magit-process-mode))))))
|
||||
|
||||
;; properly kill leftover magit buffers on quit
|
||||
;; Clean up after magit by killing leftover magit buffers and reverting
|
||||
;; affected buffers (or at least marking them as need-to-be-reverted).
|
||||
(define-key magit-status-mode-map [remap magit-mode-bury-buffer] #'+magit/quit)
|
||||
|
||||
;; Close transient with ESC
|
||||
@@ -71,10 +98,12 @@
|
||||
|
||||
|
||||
(use-package! forge
|
||||
:when (featurep! +forge)
|
||||
;; We defer loading even further because forge's dependencies will try to
|
||||
;; compile emacsql, which is a slow and blocking operation.
|
||||
:after-call magit-status
|
||||
:init
|
||||
:commands forge-create-pullreq forge-create-issue
|
||||
:preface
|
||||
(setq forge-database-file (concat doom-etc-dir "forge/forge-database.sqlite"))
|
||||
:config
|
||||
;; All forge list modes are derived from `forge-topic-list-mode'
|
||||
@@ -101,8 +130,8 @@ ensure it is built when we actually use Forge."
|
||||
(message (concat "Failed to build emacsql; forge may not work correctly.\n"
|
||||
"See *Compile-Log* buffer for details"))
|
||||
;; HACK Due to changes upstream, forge doesn't initialize completely if
|
||||
;; it doesn't find `emacsql-sqlite-executable', so we have to do it
|
||||
;; manually after installing it.
|
||||
;; it doesn't find `emacsql-sqlite-executable', so we have to do it
|
||||
;; manually after installing it.
|
||||
(setq forge--sqlite-available-p t)
|
||||
(magit-add-section-hook 'magit-status-sections-hook 'forge-insert-pullreqs nil t)
|
||||
(magit-add-section-hook 'magit-status-sections-hook 'forge-insert-issues nil t)
|
||||
@@ -142,7 +171,7 @@ ensure it is built when we actually use Forge."
|
||||
(setq evil-magit-state 'normal
|
||||
evil-magit-use-z-for-folds t)
|
||||
:config
|
||||
(unmap! magit-mode-map
|
||||
(undefine-key! magit-mode-map
|
||||
;; Replaced by z1, z2, z3, etc
|
||||
"M-1" "M-2" "M-3" "M-4"
|
||||
"1" "2" "3" "4"
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; tools/magit/packages.el
|
||||
|
||||
(when (package! magit)
|
||||
(package! forge)
|
||||
(package! magit-gitflow)
|
||||
(package! magit-todos)
|
||||
(package! github-review)
|
||||
(when (package! magit :pin "793e387a508984ae2586b93ff78afddf7a1164ac")
|
||||
(when (featurep! +forge)
|
||||
(package! forge :pin "6f299d2d84a0c92a6656a6db03656c2d554d2cac"))
|
||||
(package! magit-gitflow :pin "cc41b561ec6eea947fe9a176349fb4f771ed865b")
|
||||
(package! magit-todos :pin "a0e5d1f3c7dfcb4f18c1b0d57f1746a4872df5c6")
|
||||
(package! github-review :pin "50c6bcc7cf4d7193577b3f74eea4dd72f2b7795b")
|
||||
(when (featurep! :editor evil +everywhere)
|
||||
(package! evil-magit)))
|
||||
(package! evil-magit :pin "88dc26ce59dbf4acb4e2891c79c4bd329553ba56")))
|
||||
|
||||
Reference in New Issue
Block a user