Skip to content

Commit

Permalink
refactor: use use-package's :hook as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jun 1, 2023
1 parent b9f673c commit e31ca12
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 75 deletions.
5 changes: 2 additions & 3 deletions modules/me-docs.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
(use-package nov
:straight t
:mode ("\\.epub\\'" . nov-mode)
:hook (nov-mode . +nov-mode-setup)
:custom
(nov-save-place-file (concat minemacs-local-dir "nov/save-place.el"))
:config
Expand Down Expand Up @@ -82,9 +83,7 @@
(format-mode-line
(cons ""
'(:eval (doom-modeline-segment--major-mode))))))))))
(:eval (doom-modeline-segment--major-mode)))))

(add-hook 'nov-mode-hook #'+nov-mode-setup))
(:eval (doom-modeline-segment--major-mode))))))

(use-package crdt
:straight t
Expand Down
13 changes: 6 additions & 7 deletions modules/me-natural-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
(defconst +aspell-available-p (executable-find "aspell"))
:when +aspell-available-p
:hook (text-mode . spell-fu-mode)
:hook (spell-fu-mode . +spell-fu--init-excluded-faces-h)
:custom
(spell-fu-directory (+directory-ensure minemacs-local-dir "spell-fu/"))
:init
Expand Down Expand Up @@ -67,13 +68,11 @@
"Faces in certain major modes that spell-fu will not spellcheck."
:group 'minemacs-ui
:type '(repeat (cons symbol (repeat face))))

(add-hook
'spell-fu-mode-hook
(defun +spell-fu--init-excluded-faces-h ()
"Set `spell-fu-faces-exclude' according to `+spell-excluded-faces-alist'."
(when-let (excluded (cdr (cl-find-if #'derived-mode-p +spell-excluded-faces-alist :key #'car)))
(setq-local spell-fu-faces-exclude excluded)))))
:config
(defun +spell-fu--init-excluded-faces-h ()
"Set `spell-fu-faces-exclude' according to `+spell-excluded-faces-alist'."
(when-let (excluded (cdr (cl-find-if #'derived-mode-p +spell-excluded-faces-alist :key #'car)))
(setq-local spell-fu-faces-exclude excluded))))

(use-package go-translate
:straight (:host github :repo "lorniu/go-translate")
Expand Down
78 changes: 38 additions & 40 deletions modules/me-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@
:straight t
:init
(+map! "oP" :keymaps 'org-mode-map #'org-present)
:hook (org-present-mode . +org-present--on-h)
:hook (org-present-mode-quit . +org-present--off-h)
:config
(setq org-present-text-scale 2.5)

Expand All @@ -266,46 +268,42 @@
:center-text nil)
"Variable to hold `visual-fill-column-mode' parameters")

(add-hook
'org-present-mode-hook
(defun +org-present--on-h ()
(setq-local
face-remapping-alist
'((default (:height 1.5) variable-pitch)
(header-line (:height 2.0) variable-pitch)
(org-document-title (:height 2.0) org-document-title)
(org-code (:height 1.55) org-code)
(org-verbatim (:height 1.55) org-verbatim)
(org-block (:height 1.25) org-block)
(org-block-begin-line (:height 0.7) org-block)))
;; (org-present-big)
(org-display-inline-images)
(org-present-hide-cursor)
(org-present-read-only)
(when (bound-and-true-p visual-fill-column-mode)
(+plist-push! +org-present--vcm-params
:enabled visual-fill-column-mode
:width visual-fill-column-width
:center-text visual-fill-column-center-text))
(setq-local visual-fill-column-width 120
visual-fill-column-center-text t)
(visual-fill-column-mode 1)))

(add-hook
'org-present-mode-quit-hook
(defun +org-present--off-h ()
(setq-local
face-remapping-alist
'((default default default)))
;; (org-present-small)
(org-remove-inline-images)
(org-present-show-cursor)
(org-present-read-write)
(visual-fill-column-mode -1)
(unless (plist-get +org-present--vcm-params :enabled)
(setq-local visual-fill-column-width (plist-get +org-present--vcm-params :width)
visual-fill-column-center-text (plist-get +org-present--vcm-params :center-text))
(visual-fill-column-mode 1)))))
(defun +org-present--on-h ()
(setq-local
face-remapping-alist
'((default (:height 1.5) variable-pitch)
(header-line (:height 2.0) variable-pitch)
(org-document-title (:height 2.0) org-document-title)
(org-code (:height 1.55) org-code)
(org-verbatim (:height 1.55) org-verbatim)
(org-block (:height 1.25) org-block)
(org-block-begin-line (:height 0.7) org-block)))
;; (org-present-big)
(org-display-inline-images)
(org-present-hide-cursor)
(org-present-read-only)
(when (bound-and-true-p visual-fill-column-mode)
(+plist-push! +org-present--vcm-params
:enabled visual-fill-column-mode
:width visual-fill-column-width
:center-text visual-fill-column-center-text))
(setq-local visual-fill-column-width 120
visual-fill-column-center-text t)
(visual-fill-column-mode 1))

(defun +org-present--off-h ()
(setq-local
face-remapping-alist
'((default default default)))
;; (org-present-small)
(org-remove-inline-images)
(org-present-show-cursor)
(org-present-read-write)
(visual-fill-column-mode -1)
(unless (plist-get +org-present--vcm-params :enabled)
(setq-local visual-fill-column-width (plist-get +org-present--vcm-params :width)
visual-fill-column-center-text (plist-get +org-present--vcm-params :center-text))
(visual-fill-column-mode 1))))

(use-package evil-org
:straight t
Expand Down
42 changes: 20 additions & 22 deletions modules/me-vc.el
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@
:hook (dired-mode . diff-hl-dired-mode)
:hook (vc-dir-mode . diff-hl-dir-mode)
:hook (diff-hl-mode . diff-hl-flydiff-mode)
:hook (magit-pre-refresh . diff-hl-magit-pre-refresh)
:hook (magit-post-refresh . diff-hl-magit-post-refresh)
:init
(+map! "gs" #'diff-hl-stage-current-hunk)
:custom
(diff-hl-draw-borders nil)
:config
(add-hook 'magit-pre-refresh-hook #'diff-hl-magit-pre-refresh)
(add-hook 'magit-post-refresh-hook #'diff-hl-magit-post-refresh))
(diff-hl-draw-borders nil))

(use-package git-timemachine
:straight t
Expand All @@ -113,23 +112,23 @@
(use-package git-commit
:after magit
:demand t
:hook (git-commit-mode . +git-gommit--set-fill-column-h)
:hook (git-commit-setup . +git-commit--enter-evil-insert-state-maybe-h)
:custom
(git-commit-summary-max-length 50)
(git-commit-style-convention-checks '(overlong-summary-line non-empty-second-line))
:config
(add-hook
'git-commit-mode-hook
(defun +git-gommit--set-fill-column-h ()
(setq-local fill-column 72)))
(add-hook
'git-commit-setup-hook
;; Enter evil-insert-state for new commits
(defun +git-commit--enter-evil-insert-state-maybe-h ()
(when (and (bound-and-true-p evil-mode)
(not (evil-emacs-state-p))
(bobp)
(eolp))
(evil-insert-state))))
(defun +git-gommit--set-fill-column-h ()
(setq-local fill-column 72))

;; Enter evil-insert-state for new commits (hooked to `git-commit-setup-hook')
(defun +git-commit--enter-evil-insert-state-maybe-h ()
(when (and (bound-and-true-p evil-mode)
(not (evil-emacs-state-p))
(bobp)
(eolp))
(evil-insert-state)))

(global-git-commit-mode 1))

(use-package git-modes
Expand All @@ -139,6 +138,7 @@

(use-package ediff
:straight (:type built-in)
:hook (ediff-before-setup . +ediff--save-window-config-h)
:custom
;; Split horizontally
(ediff-split-window-function #'split-window-horizontally)
Expand All @@ -147,11 +147,9 @@
:config
(defvar +ediff--saved-window-config nil)

;; Save the current window configuration
(add-hook
'ediff-before-setup-hook
(defun +ediff--save-window-config-h ()
(setq +ediff--saved-window-config (current-window-configuration))))
;; Save the current window configuration (hooked to `ediff-before-setup-hook')
(defun +ediff--save-window-config-h ()
(setq +ediff--saved-window-config (current-window-configuration)))

;; Restore the saved window configuration on quit or suspend
(dolist (hook '(ediff-quit-hook ediff-suspend-hook))
Expand Down
5 changes: 2 additions & 3 deletions modules/me-workspaces.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
(use-package tabspaces
:straight t
:hook (minemacs-after-startup . tabspaces-mode)
:hook (tabspaces-mode . +consult-tabspaces-setup)
:custom
(tabspaces-use-filtered-buffers-as-default t)
(tabspaces-include-buffers '("*scratch*"))
Expand All @@ -38,7 +39,7 @@
"R" #'tabspaces-remove-selected-buffer
"k" #'(tabspaces-kill-buffers-close-workspace :wk "Kill buffers & close WS"))
:config
(defun +consult-tabspaces ()
(defun +consult-tabspaces-setup ()
"Deactivate isolated buffers when not using tabspaces."
(require 'consult)
(cond (tabspaces-mode
Expand All @@ -50,8 +51,6 @@
(consult-customize consult--source-buffer :hidden nil :default t)
(setq consult-buffer-sources (remove #'+consult--source-workspace consult-buffer-sources)))))

(add-hook 'tabspaces-mode-hook #'+consult-tabspaces)

(with-eval-after-load 'consult
;; Hide full buffer list (still available with "b" prefix)
(consult-customize consult--source-buffer :hidden t :default nil)
Expand Down

0 comments on commit e31ca12

Please sign in to comment.