refactor: rename orig-fn arg in advice to fn

A minor tweak to our naming conventions for the first argument of an
:around advice.
This commit is contained in:
Henrik Lissner 2021-08-04 01:18:06 -04:00
parent 12732be155
commit 06392a723f
51 changed files with 223 additions and 229 deletions

View file

@ -64,9 +64,9 @@
doom-emacs-dir ,doom-emacs-dir
doom-cache-dir ,(expand-file-name "cache/" doom-sandbox-dir)
doom-etc-dir ,(expand-file-name "etc/" doom-sandbox-dir))
(defun doom--write-to-etc-dir-a (orig-fn &rest args)
(defun doom--write-to-etc-dir-a (fn &rest args)
(let ((user-emacs-directory doom-etc-dir))
(apply orig-fn args)))
(apply fn args)))
(advice-add #'locate-user-emacs-file :around #'doom--write-to-etc-dir-a)
;; emacs essential variables
(setq before-init-time (current-time)

View file

@ -32,24 +32,24 @@ are open."
(recenter))
;;;###autoload
(defun doom-preserve-window-position-a (orig-fn &rest args)
(defun doom-preserve-window-position-a (fn &rest args)
"Generic advice for preserving cursor position on screen after scrolling."
(let ((row (cdr (posn-col-row (posn-at-point)))))
(prog1 (apply orig-fn args)
(prog1 (apply fn args)
(save-excursion
(let ((target-row (- (line-number-at-pos) row)))
(unless (< target-row 0)
(evil-scroll-line-to-top target-row)))))))
;;;###autoload
(defun doom-shut-up-a (orig-fn &rest args)
(defun doom-shut-up-a (fn &rest args)
"Generic advisor for silencing noisy functions.
In interactive Emacs, this just inhibits messages from appearing in the
minibuffer. They are still logged to *Messages*.
In tty Emacs, messages are suppressed completely."
(quiet! (apply orig-fn args)))
(quiet! (apply fn args)))
;;

View file

@ -36,11 +36,11 @@ original state.")
;; HACK Replace GUI popup prompts (which hang indefinitely in tty Emacs) with
;; simple prompts.
(defadvice! doom--straight-fallback-to-y-or-n-prompt-a (orig-fn &optional prompt)
(defadvice! doom--straight-fallback-to-y-or-n-prompt-a (fn &optional prompt)
:around #'straight-are-you-sure
(or doom-auto-accept
(if doom-interactive-p
(funcall orig-fn prompt)
(funcall fn prompt)
(y-or-n-p (format! "%s" (or prompt ""))))))
(defun doom--straight-recommended-option-p (prompt option)
@ -48,11 +48,11 @@ original state.")
if (string-match-p prompt-re prompt)
return (string-match-p opt-re option)))
(defadvice! doom--straight-fallback-to-tty-prompt-a (orig-fn prompt actions)
(defadvice! doom--straight-fallback-to-tty-prompt-a (fn prompt actions)
"Modifies straight to prompt on the terminal when in noninteractive sessions."
:around #'straight--popup-raw
(if doom-interactive-p
(funcall orig-fn prompt actions)
(funcall fn prompt actions)
(let ((doom--straight-auto-options doom--straight-auto-options))
;; We can't intercept C-g, so no point displaying any options for this key
;; when C-c is the proper way to abort batch Emacs.

View file

@ -142,7 +142,7 @@ tell you about it. Very annoying. This prevents that."
;; filesystem will murder your family. To appease it, I compress
;; `buffer-file-name' to a stable 40 characters.
;; TODO PR this upstream; should be a universal issue!
(defadvice! doom-make-hashed-auto-save-file-name-a (orig-fn)
(defadvice! doom-make-hashed-auto-save-file-name-a (fn)
"Compress the auto-save file name so paths don't get too long."
:around #'make-auto-save-file-name
(let ((buffer-file-name
@ -157,11 +157,11 @@ tell you about it. Very annoying. This prevents that."
'make-auto-save-file-name))
buffer-file-name
(sha1 buffer-file-name))))
(funcall orig-fn)))
(funcall fn)))
;; HACK Does the same for Emacs backup files, but also packages that use
;; `make-backup-file-name-1' directly (like undo-tree).
(defadvice! doom-make-hashed-backup-file-name-a (orig-fn file)
(defadvice! doom-make-hashed-backup-file-name-a (fn file)
"A few places use the backup file name so paths don't get too long."
:around #'make-backup-file-name-1
(let ((alist backup-directory-alist)
@ -171,7 +171,7 @@ tell you about it. Very annoying. This prevents that."
(if (string-match (car elt) file)
(setq backup-directory (cdr elt)
alist nil))))
(let ((file (funcall orig-fn file)))
(let ((file (funcall fn file)))
(if (or (null backup-directory)
(not (file-name-absolute-p backup-directory)))
file
@ -385,17 +385,17 @@ the unwritable tidbits."
:after-while #'save-place-find-file-hook
(if buffer-file-name (ignore-errors (recenter))))
(defadvice! doom--inhibit-saveplace-in-long-files-a (orig-fn &rest args)
(defadvice! doom--inhibit-saveplace-in-long-files-a (fn &rest args)
:around #'save-place-to-alist
(unless doom-large-file-p
(apply orig-fn args)))
(apply fn args)))
(defadvice! doom--dont-prettify-saveplace-cache-a (orig-fn)
(defadvice! doom--dont-prettify-saveplace-cache-a (fn)
"`save-place-alist-to-file' uses `pp' to prettify the contents of its cache.
`pp' can be expensive for longer lists, and there's no reason to prettify cache
files, so this replace calls to `pp' with the much faster `prin1'."
:around #'save-place-alist-to-file
(letf! ((#'pp #'prin1)) (funcall orig-fn))))
(letf! ((#'pp #'prin1)) (funcall fn))))
(use-package! server
@ -426,20 +426,20 @@ files, so this replace calls to `pp' with the much faster `prin1'."
(global-set-key [remap evil-jump-backward] #'better-jumper-jump-backward)
(global-set-key [remap xref-pop-marker-stack] #'better-jumper-jump-backward)
:config
(defun doom-set-jump-a (orig-fn &rest args)
"Set a jump point and ensure ORIG-FN doesn't set any new jump points."
(defun doom-set-jump-a (fn &rest args)
"Set a jump point and ensure fn doesn't set any new jump points."
(better-jumper-set-jump (if (markerp (car args)) (car args)))
(let ((evil--jumps-jumping t)
(better-jumper--jumping t))
(apply orig-fn args)))
(apply fn args)))
(defun doom-set-jump-maybe-a (orig-fn &rest args)
"Set a jump point if ORIG-FN returns non-nil."
(defun doom-set-jump-maybe-a (fn &rest args)
"Set a jump point if fn returns non-nil."
(let ((origin (point-marker))
(result
(let* ((evil--jumps-jumping t)
(better-jumper--jumping t))
(apply orig-fn args))))
(apply fn args))))
(unless result
(with-current-buffer (marker-buffer origin)
(better-jumper-set-jump
@ -489,7 +489,7 @@ files, so this replace calls to `pp' with the much faster `prin1'."
(push '(t tab-width) dtrt-indent-hook-generic-mapping-list)
(defvar dtrt-indent-run-after-smie)
(defadvice! doom--fix-broken-smie-modes-a (orig-fn arg)
(defadvice! doom--fix-broken-smie-modes-a (fn arg)
"Some smie modes throw errors when trying to guess their indentation, like
`nim-mode'. This prevents them from leaving Emacs in a broken state."
:around #'dtrt-indent-mode
@ -502,7 +502,7 @@ files, so this replace calls to `pp' with the much faster `prin1'."
(message "[WARNING] Indent detection: %s"
(error-message-string e))
(message ""))))) ; warn silently
(funcall orig-fn arg)))))
(funcall fn arg)))))
(use-package! helpful
;; a better *help* buffer
@ -517,11 +517,11 @@ files, so this replace calls to `pp' with the much faster `prin1'."
(global-set-key [remap describe-key] #'helpful-key)
(global-set-key [remap describe-symbol] #'helpful-symbol)
(defun doom-use-helpful-a (orig-fn &rest args)
"Force ORIG-FN to use helpful instead of the old describe-* commands."
(defun doom-use-helpful-a (fn &rest args)
"Force FN to use helpful instead of the old describe-* commands."
(letf! ((#'describe-function #'helpful-function)
(#'describe-variable #'helpful-variable))
(apply orig-fn args)))
(apply fn args)))
(after! apropos
;; patch apropos buttons to call helpful instead of help

View file

@ -367,13 +367,13 @@ This value is cached. If REFRESH-P, then don't use the cached value."
;; HACK Fix `:load-path' so it resolves relative paths to the containing file,
;; rather than `user-emacs-directory'. This is a done as a convenience
;; for users, wanting to specify a local directory.
(defadvice! doom--resolve-load-path-from-containg-file-a (orig-fn label arg &optional recursed)
(defadvice! doom--resolve-load-path-from-containg-file-a (fn label arg &optional recursed)
"Resolve :load-path from the current directory."
:around #'use-package-normalize-paths
;; `use-package-normalize-paths' resolves paths relative to
;; `user-emacs-directory', so we change that.
(let ((user-emacs-directory (if (stringp arg) (dir!))))
(funcall orig-fn label arg recursed)))
(funcall fn label arg recursed)))
;; Adds two keywords to `use-package' to expand its lazy-loading capabilities:
;;

View file

@ -102,10 +102,10 @@ uses a straight or package.el command directly).")
;; `let-alist' is built into Emacs 26 and onwards
(add-to-list 'straight-built-in-pseudo-packages 'let-alist))
(defadvice! doom--read-pinned-packages-a (orig-fn &rest args)
(defadvice! doom--read-pinned-packages-a (fn &rest args)
"Read `:pin's in `doom-packages' on top of straight's lockfiles."
:around #'straight--lockfile-read-all
(append (apply orig-fn args) ; lockfiles still take priority
(append (apply fn args) ; lockfiles still take priority
(doom-package-pinned-list)))

View file

@ -181,7 +181,7 @@ And if it's a function, evaluate it."
(if IS-WINDOWS " --path-separator=/")))
("find . -type f -print0"))))
(defadvice! doom--projectile-default-generic-command-a (orig-fn &rest args)
(defadvice! doom--projectile-default-generic-command-a (fn &rest args)
"If projectile can't tell what kind of project you're in, it issues an error
when using many of projectile's command, e.g. `projectile-compile-command',
`projectile-run-project', `projectile-test-project', and
@ -190,7 +190,7 @@ when using many of projectile's command, e.g. `projectile-compile-command',
This suppresses the error so these commands will still run, but prompt you for
the command instead."
:around #'projectile-default-generic-command
(ignore-errors (apply orig-fn args))))
(ignore-errors (apply fn args))))
;;

View file

@ -103,30 +103,30 @@ font to that size. It's rarely a good idea to do so!")
(run-hooks 'doom-switch-frame-hook)
(setq doom--last-frame (selected-frame)))))
(defun doom-run-switch-buffer-hooks-a (orig-fn buffer-or-name &rest args)
(defun doom-run-switch-buffer-hooks-a (fn buffer-or-name &rest args)
(if (or doom-inhibit-switch-buffer-hooks
(and buffer-or-name
(eq (current-buffer)
(get-buffer buffer-or-name)))
(and (eq orig-fn #'switch-to-buffer) (car args)))
(apply orig-fn buffer-or-name args)
(and (eq fn #'switch-to-buffer) (car args)))
(apply fn buffer-or-name args)
(let ((gc-cons-threshold most-positive-fixnum)
(doom-inhibit-switch-buffer-hooks t)
(inhibit-redisplay t))
(when-let (buffer (apply orig-fn buffer-or-name args))
(when-let (buffer (apply fn buffer-or-name args))
(with-current-buffer (if (windowp buffer)
(window-buffer buffer)
buffer)
(run-hooks 'doom-switch-buffer-hook))
buffer))))
(defun doom-run-switch-to-next-prev-buffer-hooks-a (orig-fn &rest args)
(defun doom-run-switch-to-next-prev-buffer-hooks-a (fn &rest args)
(if doom-inhibit-switch-buffer-hooks
(apply orig-fn args)
(apply fn args)
(let ((gc-cons-threshold most-positive-fixnum)
(doom-inhibit-switch-buffer-hooks t)
(inhibit-redisplay t))
(when-let (buffer (apply orig-fn args))
(when-let (buffer (apply fn args))
(with-current-buffer buffer
(run-hooks 'doom-switch-buffer-hook))
buffer))))
@ -499,13 +499,13 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(set-fontset-font t 'unicode font nil 'append)))))
:config
(cond ((daemonp)
(defadvice! doom--disable-all-the-icons-in-tty-a (orig-fn &rest args)
(defadvice! doom--disable-all-the-icons-in-tty-a (fn &rest args)
"Return a blank string in tty Emacs, which doesn't support multiple fonts."
:around '(all-the-icons-octicon all-the-icons-material
all-the-icons-faicon all-the-icons-fileicon
all-the-icons-wicon all-the-icons-alltheicon)
(if (or (not after-init-time) (display-multi-font-p))
(apply orig-fn args)
(apply fn args)
"")))
((not (display-graphic-p))
(defadvice! doom--disable-all-the-icons-in-tty-a (&rest _)
@ -617,7 +617,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(with-selected-frame (or frame (selected-frame))
(load-theme doom-theme t))))
(defadvice! doom--load-theme-a (orig-fn theme &optional no-confirm no-enable)
(defadvice! doom--load-theme-a (fn theme &optional no-confirm no-enable)
"Record `doom-theme', disable old themes, and trigger `doom-load-theme-hook'."
:around #'load-theme
;; Run `load-theme' from an estranged buffer, where we can ensure that
@ -628,7 +628,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
;; Disable previous themes so there are no conflicts. If you truly want
;; multiple themes enabled, then use `enable-theme' instead.
(mapc #'disable-theme custom-enabled-themes)
(prog1 (funcall orig-fn theme no-confirm no-enable)
(prog1 (funcall fn theme no-confirm no-enable)
(when (and (not no-enable) (custom-theme-enabled-p theme))
(setq doom-theme theme)
(put 'doom-theme 'previous-themes (or last-themes 'none))

View file

@ -243,20 +243,15 @@ users).")
request-storage-directory (concat doom-cache-dir "request")
shared-game-score-directory (concat doom-etc-dir "shared-game-score/"))
(defadvice! doom--write-to-etc-dir-a (orig-fn &rest args)
"Resolve Emacs storage directory to `doom-etc-dir', to keep local files from
polluting `doom-emacs-dir'."
:around #'locate-user-emacs-file
(let ((user-emacs-directory doom-etc-dir))
(apply orig-fn args)))
(defadvice! doom--write-enabled-commands-to-doomdir-a (orig-fn &rest args)
(defadvice! doom--write-to-sane-paths-a (fn &rest args)
"When enabling a disabled command, the `put' call is written to
~/.emacs.d/init.el, which causes issues for Doom, so write it to the user's
config.el instead."
:around #'en/disable-command
(let ((user-init-file custom-file))
(apply orig-fn args)))
:around #'locate-user-emacs-file
(let ((user-emacs-directory doom-etc-dir)
(user-init-file custom-file))
(apply fn args)))
;;