💥 revise hook/var fns naming convention (2/2)

This is second of three big naming convention changes. In this commit,
we change the naming conventions for hook functions and variable
functions:

1. Replace the bar | to indicate a hook function with a -h suffix, e.g.

     doom|init-ui -> doom-init-ui-h
     doom|run-local-var-hooks -> doom-run-local-var-hooks-h

2. And add a -fn suffix for functions meant to be set on variables,
   e.g.

     (setq magit-display-buffer-function #'+magit-display-buffer-fn)

See ccf327f8 for the reasoning behind these changes.
This commit is contained in:
Henrik Lissner 2019-07-18 15:27:20 +02:00
parent 51d3b1b424
commit 149b2617b0
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
58 changed files with 521 additions and 517 deletions

View file

@ -102,7 +102,7 @@ PLIST can have the following properties:
;;
;;; Bootstrap
(defun +doom-dashboard|init ()
(defun +doom-dashboard-init-h ()
"Initializes Doom's dashboard."
(unless noninteractive
;; Ensure the dashboard becomes Emacs' go-to buffer when there's nothing
@ -112,19 +112,19 @@ PLIST can have the following properties:
(when (equal (buffer-name) "*scratch*")
(set-window-buffer nil (doom-fallback-buffer))
(if (daemonp)
(add-hook 'after-make-frame-functions #'+doom-dashboard|reload-frame)
(add-hook 'after-make-frame-functions #'+doom-dashboard-reload-frame-h)
(+doom-dashboard-reload)))
;; Ensure the dashboard is up-to-date whenever it is switched to or resized.
(add-hook 'window-configuration-change-hook #'+doom-dashboard|resize)
(add-hook 'window-size-change-functions #'+doom-dashboard|resize)
(add-hook 'doom-switch-buffer-hook #'+doom-dashboard|reload-maybe)
(add-hook 'delete-frame-functions #'+doom-dashboard|reload-frame)
(add-hook 'window-configuration-change-hook #'+doom-dashboard-resize-h)
(add-hook 'window-size-change-functions #'+doom-dashboard-resize-h)
(add-hook 'doom-switch-buffer-hook #'+doom-dashboard-reload-maybe-h)
(add-hook 'delete-frame-functions #'+doom-dashboard-reload-frame-h)
;; `persp-mode' integration: update `default-directory' when switching perspectives
(add-hook 'persp-created-functions #'+doom-dashboard|record-project)
(add-hook 'persp-activated-functions #'+doom-dashboard|detect-project)
(add-hook 'persp-before-switch-functions #'+doom-dashboard|record-project)))
(add-hook 'persp-created-functions #'+doom-dashboard--persp-record-project-h)
(add-hook 'persp-activated-functions #'+doom-dashboard--persp-detect-project-h)
(add-hook 'persp-before-switch-functions #'+doom-dashboard--persp-record-project-h)))
(add-hook 'doom-init-ui-hook #'+doom-dashboard|init)
(add-hook 'doom-init-ui-hook #'+doom-dashboard-init-h)
;;
@ -148,7 +148,7 @@ PLIST can have the following properties:
collect (cons car nil) into alist
finally do (setq fringe-indicator-alist alist))
;; Ensure point is always on a button
(add-hook 'post-command-hook #'+doom-dashboard|reposition-point nil t))
(add-hook 'post-command-hook #'+doom-dashboard-reposition-point-h nil t))
(define-key! +doom-dashboard-mode-map
[left-margin mouse-1] #'ignore
@ -185,7 +185,7 @@ PLIST can have the following properties:
;;
;;; Hooks
(defun +doom-dashboard|reposition-point ()
(defun +doom-dashboard-reposition-point-h ()
"Trap the point in the buttons."
(when (region-active-p)
(setq deactivate-mark t)
@ -198,7 +198,7 @@ PLIST can have the following properties:
(progn (goto-char (point-min))
(forward-button 1))))
(defun +doom-dashboard|reload-maybe ()
(defun +doom-dashboard-reload-maybe-h ()
"Reload the dashboard or its state.
If this isn't a dashboard buffer, move along, but record its `default-directory'
@ -214,14 +214,14 @@ If this is the dashboard buffer, reload it completely."
(setq +doom-dashboard--last-cwd default-directory)
(+doom-dashboard-update-pwd))))
(defun +doom-dashboard|reload-frame (_frame)
(defun +doom-dashboard-reload-frame-h (_frame)
"Reload the dashboard after a brief pause. This is necessary for new frames,
whose dimensions may not be fully initialized by the time this is run."
(when (timerp +doom-dashboard--reload-timer)
(cancel-timer +doom-dashboard--reload-timer)) ; in case this function is run rapidly
(setq +doom-dashboard--reload-timer (run-with-timer 0.1 nil #'+doom-dashboard-reload t)))
(defun +doom-dashboard|resize (&rest _)
(defun +doom-dashboard-resize-h (&rest _)
"Recenter the dashboard, and reset its margins and fringes."
(let (buffer-list-update-hook
window-configuration-change-hook
@ -247,20 +247,20 @@ whose dimensions may not be fully initialized by the time this is run."
2))))
?\n)))))))))
(defun +doom-dashboard|detect-project (&rest _)
(defun +doom-dashboard--persp-detect-project-h (&rest _)
"Check for a `last-project-root' parameter in the perspective, and set the
dashboard's `default-directory' to it if it exists.
This and `+doom-dashboard|record-project' provides `persp-mode' integration with
This and `+doom-dashboard--persp-record-project-h' provides `persp-mode' integration with
the Doom dashboard. It ensures that the dashboard is always in the correct
project (which may be different across perspective)."
(when (bound-and-true-p persp-mode)
(when-let (pwd (persp-parameter 'last-project-root))
(+doom-dashboard-update-pwd pwd))))
(defun +doom-dashboard|record-project (&optional persp &rest _)
(defun +doom-dashboard--persp-record-project-h (&optional persp &rest _)
"Record the last `doom-project-root' for the current perspective. See
`+doom-dashboard|detect-project' for more information."
`+doom-dashboard--persp-detect-project-h' for more information."
(when (bound-and-true-p persp-mode)
(set-persp-parameter
'last-project-root (doom-project-root)
@ -305,9 +305,9 @@ controlled by `+doom-dashboard-pwd-policy'."
(erase-buffer)
(run-hooks '+doom-dashboard-functions)
(goto-char pt)
(+doom-dashboard|reposition-point))
(+doom-dashboard|resize)
(+doom-dashboard|detect-project)
(+doom-dashboard-reposition-point-h))
(+doom-dashboard-resize-h)
(+doom-dashboard--persp-detect-project-h)
(+doom-dashboard-update-pwd)
(current-buffer)))))
@ -387,7 +387,7 @@ controlled by `+doom-dashboard-pwd-policy'."
(propertize
(+doom-dashboard--center
+doom-dashboard--width
(doom|display-benchmark 'return))
(doom-display-benchmark-h 'return))
'face 'font-lock-comment-face)
"\n"))

View file

@ -22,11 +22,11 @@
"A list of quit messages, picked randomly by `+doom-quit'. Taken from
http://doom.wikia.com/wiki/Quit_messages and elsewhere.")
(defun +doom-quit (&rest _)
(defun +doom-quit-fn (&rest _)
(doom-quit-p
(format "%s Quit?"
(nth (random (length +doom-quit-messages))
+doom-quit-messages))))
;;
(setq confirm-kill-emacs #'+doom-quit)
(setq confirm-kill-emacs #'+doom-quit-fn)

View file

@ -44,15 +44,16 @@
(def-package! solaire-mode
:defer t
:init
(defun +doom|solaire-mode-swap-bg-maybe ()
(when-let (rule (assq doom-theme +doom-solaire-themes))
(require 'solaire-mode)
(when (cdr rule)
(solaire-mode-swap-bg)
(with-eval-after-load 'ansi-color
(when-let (color (face-background 'default))
(setf (aref ansi-color-names-vector 0) color))))))
(add-hook 'doom-load-theme-hook #'+doom|solaire-mode-swap-bg-maybe t)
(add-hook 'doom-load-theme-hook
(defun +doom--solaire-mode-swap-bg-maybe-h ()
(when-let (rule (assq doom-theme +doom-solaire-themes))
(require 'solaire-mode)
(when (cdr rule)
(solaire-mode-swap-bg)
(with-eval-after-load 'ansi-color
(when-let (color (face-background 'default))
(setf (aref ansi-color-names-vector 0) color))))))
'append)
:config
;; fringe can become unstyled when deleting or focusing frames
(add-hook 'focus-in-hook #'solaire-mode-reset)
@ -67,7 +68,7 @@
;; the hl-line face, hl-line's highlight bleeds into the rest of the window
;; after eob.
(when EMACS26+
(defun +doom--line-range ()
(defun +doom--line-range-fn ()
(cons (line-beginning-position)
(cond ((let ((eol (line-end-position)))
(and (= eol (point-max))
@ -77,21 +78,21 @@
(= (line-end-position 2) (point-max)))
(line-end-position))
((line-beginning-position 2)))))
(setq hl-line-range-function #'+doom--line-range))
(setq hl-line-range-function #'+doom--line-range-fn))
;; Because fringes can't be given a buffer-local face, they can look odd, so
;; we remove them in the minibuffer and which-key popups (they serve no
;; purpose there anyway).
(defun +doom|disable-fringes-in-minibuffer (&rest _)
(set-window-fringes (minibuffer-window) 0 0 nil))
(add-hook 'solaire-mode-hook #'+doom|disable-fringes-in-minibuffer)
(add-hook 'solaire-mode-hook
(defun +doom-disable-fringes-in-minibuffer-h (&rest _)
(set-window-fringes (minibuffer-window) 0 0 nil)))
(def-advice! +doom--no-fringes-in-which-key-buffer-a (&rest _)
:after 'which-key--show-buffer-side-window
(+doom--disable-fringes-in-minibuffer-h)
(+doom-disable-fringes-in-minibuffer-h)
(set-window-fringes (get-buffer-window which-key--buffer) 0 0 nil))
(add-hook! '(minibuffer-setup-hook window-configuration-change-hook)
#'+doom|disable-fringes-in-minibuffer)
#'+doom-disable-fringes-in-minibuffer-h)
(solaire-global-mode +1))

View file

@ -10,6 +10,15 @@
;; Use a more primitive todo-keyword detection method in major modes that
;; don't use/have a valid syntax table entry for comments.
(add-hook!
(pug-mode haml-mode)
#'+hl-todo|use-face-detection))
(add-hook! '(pug-mode-hook haml-mode-hook)
(defun +hl-todo--use-face-detection-h ()
"Use a different, more primitive method of locating todo keywords."
(set (make-local-variable 'hl-todo-keywords)
'(((lambda (limit)
(let (case-fold-search)
(and (re-search-forward hl-todo-regexp limit t)
(memq 'font-lock-comment-face (doom-enlist (get-text-property (point) 'face))))))
(1 (hl-todo-get-face) t t))))
(when hl-todo-mode
(hl-todo-mode -1)
(hl-todo-mode +1)))))

View file

@ -6,10 +6,8 @@
(setq highlight-indent-guides-method 'character)
:config
(add-hook 'focus-in-hook #'highlight-indent-guides-auto-set-faces)
(defun +indent-guides|disable-maybe ()
(when highlight-indent-guides-mode
(highlight-indent-guides-mode -1)))
;; `highlight-indent-guides' breaks in these modes
(add-hook 'visual-line-mode-hook #'+indent-guides|disable-maybe)
(add-hook 'org-indent-mode-hook #'+indent-guides|disable-maybe))
(add-hook! '(visual-line-mode-hook org-indent-mode-hook)
(defun +indent-guides-disable-maybe-h ()
(when highlight-indent-guides-mode
(highlight-indent-guides-mode -1)))))

View file

@ -12,7 +12,7 @@
(defvar +modeline--old-bar-height nil)
;;;###autoload
(defun +modeline|resize-for-font ()
(defun +modeline--resize-for-font-h ()
"Adjust the modeline's height when the font size is changed by
`doom/increase-font-size' or `doom/decrease-font-size'.
@ -33,7 +33,7 @@ Meant for `doom-change-font-size-hook'."
(unless EMACS26+ (doom-modeline-refresh-bars))))
;;;###autoload
(defun +modeline|update-env-in-all-windows (&rest _)
(defun +modeline-update-env-in-all-windows-h (&rest _)
"Update version strings in all buffers."
(dolist (window (window-list))
(with-selected-window window
@ -41,7 +41,7 @@ Meant for `doom-change-font-size-hook'."
(force-mode-line-update))))
;;;###autoload
(defun +modeline|clear-env-in-all-windows (&rest _)
(defun +modeline-clear-env-in-all-windows-h (&rest _)
"Blank out version strings in all buffers."
(dolist (buffer (buffer-list))
(with-current-buffer buffer

View file

@ -32,17 +32,17 @@
(add-hook 'doom-modeline-mode-hook #'size-indication-mode) ; filesize in modeline
(add-hook 'doom-modeline-mode-hook #'column-number-mode) ; cursor column in modeline
(add-hook 'doom-change-font-size-hook #'+modeline|resize-for-font)
(add-hook 'doom-change-font-size-hook #'+modeline--resize-for-font-h)
(add-hook 'doom-load-theme-hook #'doom-modeline-refresh-bars)
(add-hook '+doom-dashboard-mode-hook #'doom-modeline-set-project-modeline)
(defun +modeline|hide-in-non-status-buffer ()
"Show minimal modeline in magit-status buffer, no modeline elsewhere."
(if (eq major-mode 'magit-status-mode)
(doom-modeline-set-project-modeline)
(hide-mode-line-mode)))
(add-hook 'magit-mode-hook #'+modeline|hide-in-non-status-buffer)
(add-hook 'magit-mode-hook
(defun +modeline--hide-in-non-status-buffer-h ()
"Show minimal modeline in magit-status buffer, no modeline elsewhere."
(if (eq major-mode 'magit-status-mode)
(doom-modeline-set-project-modeline)
(hide-mode-line-mode))))
;; Remove unused segments & extra padding
(doom-modeline-def-modeline 'main

View file

@ -24,17 +24,16 @@ or triggered from one of `+nav-flash-exclude-commands'."
(setq +nav-flash--last-point (cons (point-marker) (selected-window)))))
;;;###autoload
(defun +nav-flash|delayed-blink-cursor (&rest _)
(defun +nav-flash-delayed-blink-cursor-h (&rest _)
"Like `+nav-flash-blink-cursor', but links after a tiny pause, in case it
isn't clear at run-time if the point will be in the correct window/buffer (like
for `org-follow-link-hook')."
(run-at-time 0.1 nil #'+nav-flash|blink-cursor))
(run-at-time 0.1 nil #'+nav-flash-blink-cursor-h))
;;;###autoload
(defalias '+nav-flash|blink-cursor #'+nav-flash-blink-cursor)
(defalias '+nav-flash-blink-cursor-h #'+nav-flash-blink-cursor)
;;;###autoload
(defalias '+nav-flash|blink-cursor-maybe #'+nav-flash-blink-cursor-maybe)
(defalias '+nav-flash-blink-cursor-maybe-h #'+nav-flash-blink-cursor-maybe)
;;;###autoload
(defalias '+nav-flash-blink-cursor-a #'+nav-flash-blink-cursor-maybe)

View file

@ -13,12 +13,12 @@
(add-hook!
'(imenu-after-jump-hook better-jumper-post-jump-hook
counsel-grep-post-action-hook dumb-jump-after-jump-hook)
#'+nav-flash|blink-cursor-maybe)
#'+nav-flash-blink-cursor-maybe-h)
(add-hook 'doom-switch-window-hook #'+nav-flash|blink-cursor-maybe)
(add-hook 'doom-switch-window-hook #'+nav-flash-blink-cursor-maybe-h)
;; `org'
(add-hook 'org-follow-link-hook #'+nav-flash|delayed-blink-cursor)
(add-hook 'org-follow-link-hook #'+nav-flash-delayed-blink-cursor-h)
;; `saveplace'
(advice-add #'save-place-find-file-hook :after #'+nav-flash-blink-cursor-a)

View file

@ -42,14 +42,13 @@
(after! winner
(add-to-list 'winner-boring-buffers neo-buffer-name))
;; The cursor always sits at bol. `+neotree*fix-cursor' and
;; `+neotree*indent-cursor' change that behavior, so that the cursor is always
;; on the first non-blank character on the line, in the neo buffer.
(defun +neotree*fix-cursor (&rest _)
(with-current-buffer neo-global--buffer
(+neotree*indent-cursor)))
(add-hook 'neo-enter-hook #'+neotree*fix-cursor)
;; The cursor always sits at bol. `+neotree--fix-cursor-h' and
;; `+neotree--indent-cursor-a' change that behavior so that the cursor is
;; always on the first non-blank character on the line, in the neo buffer.
(add-hook 'neo-enter-hook
(defun +neotree--fix-cursor-h (&rest _)
(with-current-buffer neo-global--buffer
(+neotree*indent-cursor))))
(def-advice! +neotree--indent-cursor-a (&rest _)
:after '(neotree-next-line neotree-previous-line)
(beginning-of-line)

View file

@ -22,34 +22,34 @@ to the right fringe.")
(def-package! git-gutter
:commands (git-gutter:revert-hunk git-gutter:stage-hunk)
:init
(defun +vc-gutter|init-maybe ()
"Enable `git-gutter-mode' in the current buffer.
(add-hook! '(text-mode-hook prog-mode-hook conf-mode-hook)
(defun +vc-gutter-init-maybe-h ()
"Enable `git-gutter-mode' in the current buffer.
If the buffer doesn't represent an existing file, `git-gutter-mode's activation
is deferred until the file is saved. Respects `git-gutter:disabled-modes'."
(when (or +vc-gutter-in-remote-files
(not (file-remote-p (or buffer-file-name default-directory))))
(if (not buffer-file-name)
(add-hook 'after-save-hook #'+vc-gutter|init-maybe nil t)
(when (and (vc-backend buffer-file-name)
(progn
(require 'git-gutter)
(not (memq major-mode git-gutter:disabled-modes))))
(if (and (display-graphic-p)
(require 'git-gutter-fringe nil t))
(progn
(setq-local git-gutter:init-function #'git-gutter-fr:init)
(setq-local git-gutter:view-diff-function #'git-gutter-fr:view-diff-infos)
(setq-local git-gutter:clear-function #'git-gutter-fr:clear)
(setq-local git-gutter:window-width -1))
(setq-local git-gutter:init-function 'nil)
(setq-local git-gutter:view-diff-function #'git-gutter:view-diff-infos)
(setq-local git-gutter:clear-function #'git-gutter:clear-diff-infos)
(setq-local git-gutter:window-width 1))
(git-gutter-mode +1)
(remove-hook 'after-save-hook #'+vc-gutter|init-maybe t)))))
(add-hook! (text-mode prog-mode conf-mode)
#'+vc-gutter|init-maybe)
(when (or +vc-gutter-in-remote-files
(not (file-remote-p (or buffer-file-name default-directory))))
(if (not buffer-file-name)
(add-hook 'after-save-hook #'+vc-gutter-init-maybe-h nil t)
(when (and (vc-backend buffer-file-name)
(progn
(require 'git-gutter)
(not (memq major-mode git-gutter:disabled-modes))))
(if (and (display-graphic-p)
(require 'git-gutter-fringe nil t))
(progn
(setq-local git-gutter:init-function #'git-gutter-fr:init)
(setq-local git-gutter:view-diff-function #'git-gutter-fr:view-diff-infos)
(setq-local git-gutter:clear-function #'git-gutter-fr:clear)
(setq-local git-gutter:window-width -1))
(setq-local git-gutter:init-function 'nil)
(setq-local git-gutter:view-diff-function #'git-gutter:view-diff-infos)
(setq-local git-gutter:clear-function #'git-gutter:clear-diff-infos)
(setq-local git-gutter:window-width 1))
(git-gutter-mode +1)
(remove-hook 'after-save-hook #'+vc-gutter-init-maybe-h t))))))
;; standardize default fringe width
(if (fboundp 'fringe-mode) (fringe-mode '4))
:config
@ -58,16 +58,15 @@ is deferred until the file is saved. Respects `git-gutter:disabled-modes'."
;; Update git-gutter on focus (in case I was using git externally)
(add-hook 'focus-in-hook #'git-gutter:update-all-windows)
(defun +vc-gutter|update (&rest _)
"Refresh git-gutter on ESC. Return nil to prevent shadowing other
(add-hook! :append '(doom-escape-hook doom-switch-window-hook)
(defun +vc-gutter-update-h (&rest _)
"Refresh git-gutter on ESC. Return nil to prevent shadowing other
`doom-escape-hook' hooks."
(when git-gutter-mode
(ignore (git-gutter))))
(add-hook 'doom-escape-hook #'+vc-gutter|update t)
(when git-gutter-mode
(ignore (git-gutter)))))
;; update git-gutter when using magit commands
(advice-add #'magit-stage-file :after #'+vc-gutter|update)
(advice-add #'magit-unstage-file :after #'+vc-gutter|update))
(advice-add #'magit-stage-file :after #'+vc-gutter-update-h)
(advice-add #'magit-unstage-file :after #'+vc-gutter-update-h))
;; subtle diff indicators in the fringe