summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2023-06-04 17:03:43 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2023-06-04 18:24:08 +0200
commitd0f1731bab471ad2a7de685a85b7c3e571e292da (patch)
tree28d2869a63e7d45520f079a1241676aede944c87
parent11fcabc479b8a401c2189bed8f500db9af08cd47 (diff)
downloaddotfiles-d0f1731bab471ad2a7de685a85b7c3e571e292da.tar.xz
Convert diff-hl tweaks to use-package
Puzzled by this problem I have with :hook. "(use-package) Hooks" suggests that if package X defines function X-foo to be used by package Y in Y-bar-hook, then the idiomatic thing to do is… (use-package X :hook ((Y-bar . X-foo))) … but empirically, if Y.el contains… (defcustom Y-bar-hook '(Y-quux Y-corge)) (add-hook 'Y-bar-hook #'Y-grault) … then Y-bar-hook will be set to '(X-foo Y-grault): it will be missing the functions added in the defcustom form. Since add-hook does this: (or (boundp hook) (set hook nil)) I am assuming that the problem happens when use-package runs X's :hook additions before Y is loaded. No idea (a) if I can reproduce from -Q (b) if this is a SNAFU from setting always-defer (c) if this could be solved by sprinkling :after or :requires.
-rw-r--r--.emacs39
-rw-r--r--.emacs-custom.el4
2 files changed, 33 insertions, 10 deletions
diff --git a/.emacs b/.emacs
index 545218b..af613f3 100644
--- a/.emacs
+++ b/.emacs
@@ -387,9 +387,6 @@
;;; Version control.
-(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
-(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
-
(add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell)
(setq magit-process-finish-apply-ansi-colors t)
@@ -456,8 +453,6 @@
(setq truncate-lines nil)
(setq-local recenter-positions '(top middle bottom)))
-(add-hook 'dired-mode-hook 'diff-hl-dired-mode-unless-remote)
-
(add-to-list 'ibuffer-saved-filter-groups
'("my/ibuffer-groups"
("REPL"
@@ -683,6 +678,34 @@
(my/list-update package-archives
'(("melpa" . "https://melpa.org/packages/")))))
+(use-package diff-hl
+ :custom
+ (diff-hl-flydiff-mode t)
+ (global-diff-hl-mode t)
+
+ ;; FIXME: Adding to these hooks _here_ clobbers them, i.e. they end
+ ;; up containing (a) the diff-hl functions (b) whatever functions
+ ;; their libraries add dynamically (c) *none* of the functions
+ ;; included in the defcustom's default value.
+ ;;
+ ;; Therefore, set these hooks up in the :config form _for the
+ ;; libraries that define these hooks_, so that (presumably) the
+ ;; default values for these hooks are loaded *before* adding the
+ ;; diff-hl functions.
+ ;;
+ ;; :hook
+ ;; ((dired-mode . diff-hl-dired-mode-unless-remote)
+ ;; (magit-pre-refresh . diff-hl-magit-pre-refresh)
+ ;; (magit-post-refresh . diff-hl-magit-post-refresh))
+ )
+
+(use-package dired
+ :custom
+ (dired-kill-when-opening-new-dired-buffer t)
+ (dired-listing-switches "-al -Fhv --group-directories-first")
+ :config
+ (add-hook 'dired-mode-hook 'diff-hl-dired-mode-unless-remote))
+
(use-package ediff
:custom
(ediff-merge-split-window-function 'split-window-vertically)
@@ -738,7 +761,11 @@
(magit-define-global-key-bindings nil)
(magit-diff-refine-hunk t)
(magit-ediff-dwim-show-on-hunks t)
- (magit-revision-show-gravatars t))
+ (magit-revision-show-gravatars t)
+ :config
+ ;; See `diff-hl' form for rationale.
+ (add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
+ (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh))
(use-package magit-blame
:delight "👉")
diff --git a/.emacs-custom.el b/.emacs-custom.el
index 8d3b619..11bfaf4 100644
--- a/.emacs-custom.el
+++ b/.emacs-custom.el
@@ -14,9 +14,6 @@
'(delete-selection-mode t)
'(describe-bindings-outline t)
'(diff-default-read-only t)
- '(diff-hl-flydiff-mode t)
- '(dired-kill-when-opening-new-dired-buffer t)
- '(dired-listing-switches "-al -Fhv --group-directories-first")
'(electric-pair-mode t)
'(enable-recursive-minibuffers t)
'(epg-pinentry-mode 'loopback)
@@ -29,7 +26,6 @@
'(gdb-many-windows t)
'(generic-extras-enable-list
'(ansible-inventory-generic-mode etc-fstab-generic-mode etc-modules-conf-generic-mode etc-passwd-generic-mode etc-services-generic-mode etc-sudoers-generic-mode hosts-generic-mode java-manifest-generic-mode java-properties-generic-mode pkginfo-generic-mode prototype-generic-mode resolve-conf-generic-mode x-resource-generic-mode xmodmap-generic-mode))
- '(global-diff-hl-mode t)
'(global-page-break-lines-mode t nil (page-break-lines))
'(gnus-cloud-method "nnimap:gmail")
'(highlight-nonselected-windows t)