def-advice!->defadvice! & conform to new advice conventions

This commit does two things:

- Renames def-advice! to defadvice!, in the spirit of naming convenience
  macros after the function/macro they enhance or replace.
- Correct the names of advice functions to indicate visibility and
  intent. A public advice function like doom-set-jump-a is meant to be
  used elsewhere. A private one like +dired--cleanup-header-line-a
  shouldn't -- it likely won't work anywhere but the function(s) it was
  made to advise.
This commit is contained in:
Henrik Lissner 2019-07-23 17:24:56 +02:00
parent 8aa7772e4e
commit 82ae3a73f3
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
43 changed files with 126 additions and 121 deletions

View file

@ -114,7 +114,7 @@ This marks a foldable marker for `outline-minor-mode' in elisp buffers.")
(advice-add 'describe-function-1 :after #'elisp-demos-advice-describe-function-1)
(advice-add 'helpful-update :after #'elisp-demos-advice-helpful-update)
:config
(def-advice! +emacs-lisp-elisp-demos--search-a (orig-fn symbol)
(defadvice! +emacs-lisp--add-doom-elisp-demos-a (orig-fn symbol)
"Add Doom's own demos to help buffers."
:around #'elisp-demos--search
(or (funcall orig-fn symbol)

View file

@ -19,15 +19,16 @@
(set-company-backend! 'dante-mode #'dante-company)
(defun +haskell*restore-modified-state (orig-fn &rest args)
"Dante quietly saves the current buffer (without triggering save hooks) before
(defadvice! +haskell--restore-modified-state-a (orig-fn &rest args)
"Marks the buffer as falsely modified.
Dante quietly saves the current buffer (without triggering save hooks) before
invoking flycheck, unexpectedly leaving the buffer in an unmodified state. This
is annoying if we depend on save hooks to do work on the buffer (like
reformatting), so we restore a (false) modified state."
reformatting)."
:around #'dante-async-load-current-buffer
(let ((modified-p (buffer-modified-p)))
(apply orig-fn args)
(if modified-p (set-buffer-modified-p t))))
(advice-add #'dante-async-load-current-buffer :around #'+haskell*restore-modified-state)
(when (featurep 'evil)
(add-hook 'dante-mode-hook #'evil-normalize-keymaps))

View file

@ -12,7 +12,7 @@ nimsuggest isn't installed."
(when IS-WINDOWS
;; TODO File PR/report upstream (https://github.com/nim-lang/nim-mode)
(def-advice! +nim--suggest-get-dirty-dir-a ()
(defadvice! +nim--suggest-get-dirty-dir-a ()
"The original `nimsuggest--get-dirty-dir' incorrectly extracts the frame
number from the string representation of `selected-frame', which can contain
characters that are illegal on Windows, causing invalid argument errors when
@ -24,7 +24,7 @@ characters that are illegal on Windows, causing invalid argument errors when
(file-name-as-directory (concat nimsuggest-dirty-directory frame-num-str))))
;; TODO File PR/report upstream (https://github.com/nim-lang/nim-mode)
(def-advice! +nim--suggest-get-temp-file-name-a (path)
(defadvice! +nim--suggest-get-temp-file-name-a (path)
"Removes invalid characters from the temp file path, including the unicode
character that colon is replaced with, which is known to cause issues on
windows."

View file

@ -137,14 +137,14 @@ when executed.")
take one argument (the language specified in the src block, as a string). Stops
at the first function to return non-nil.")
(def-advice! +org--src-lazy-load-library-a (lang)
(defadvice! +org--src-lazy-load-library-a (lang)
"Lazy load a babel package to ensure syntax highlighting."
:before #'org-src--get-lang-mode
(or (cdr (assoc lang org-src-lang-modes))
(fboundp (intern-soft (format "%s-mode" lang)))
(require (intern-soft (format "ob-%s" lang)) nil t)))
(def-advice! +org--babel-lazy-load-library-a (info)
(defadvice! +org--babel-lazy-load-library-a (info)
"Load babel libraries lazily when babel blocks are executed."
:after-while #'org-babel-confirm-evaluate
(let* ((lang (nth 0 info))
@ -218,7 +218,7 @@ Is relative to `org-directory', unless it is absolute. Is used in Doom's default
(file+headline +org-capture-project-notes-file "Unreleased")
"* TODO %?\n%i\n%a" :prepend t :kill-buffer t)))
(def-advice! +org-capture-expand-variable-file-a (file)
(defadvice! +org--capture-expand-variable-file-a (file)
"If a variable is used for a file path in `org-capture-template', it is used
as is, and expanded relative to `default-directory'. This changes it to be
relative to `org-directory', unless it is an absolute path."
@ -227,7 +227,7 @@ relative to `org-directory', unless it is an absolute path."
(expand-file-name (symbol-value file) org-directory)
file))
(def-advice! +org--prevent-save-prompts-when-refiling-a (&rest _)
(defadvice! +org--prevent-save-prompts-when-refiling-a (&rest _)
"Fix #462: when refiling from org-capture, Emacs prompts to kill the
underlying, modified buffer. This fixes that."
:after 'org-refile
@ -314,7 +314,7 @@ path too.")
;; place, and I want to be able to refer back to old exports if needed.
(setq +org-export-directory (expand-file-name +org-export-directory org-directory))
(def-advice! +org--export-output-file-name-a (args)
(defadvice! +org--export-output-file-name-a (args)
"Return a centralized export location unless one is provided or the current
file isn't in `org-directory'."
:filter-args #'org-export-output-file-name
@ -445,7 +445,7 @@ file isn't in `org-directory'."
conditions where a window's buffer hasn't changed at the time this hook is run."
(run-at-time 0.1 nil #'recenter)))
(def-advice! +org--strip-properties-from-outline-a (orig-fn path &optional width prefix separator)
(defadvice! +org--strip-properties-from-outline-a (orig-fn path &optional width prefix separator)
"Remove link syntax and fix variable height text (e.g. org headings) in the
eldoc string."
:around #'org-format-outline-path
@ -471,7 +471,7 @@ the current workspace."
(get-current-persp)
nil)))))
(def-advice! +org--exclude-agenda-buffers-from-recentf-a (orig-fn file)
(defadvice! +org--exclude-agenda-buffers-from-recentf-a (orig-fn file)
"Prevent temporarily opened agenda buffers from polluting recentf."
:around #'org-get-agenda-file-buffer
(let ((recentf-exclude (list (lambda (_file) t))))
@ -719,7 +719,7 @@ between the two."
browsers) can invoke specialized behavior from Emacs. Normally you'd simply
require `org-protocol' and use it, but the package loads all of org for no
compelling reason, so..."
(def-advice! +org--server-visit-files-a (args)
(defadvice! +org--server-visit-files-a (args)
"Advise `server-visit-flist' to invoke `org-protocol' lazily."
:filter-args #'server-visit-files
(cl-destructuring-bind (files proc &optional nowait) args
@ -853,7 +853,7 @@ compelling reason, so..."
;;; Packages
(after! toc-org
(setq toc-org-hrefify-default "gh")
(def-advice! +org-unfold-toc-a (&rest _)
(defadvice! +org--unfold-toc-a (&rest _)
:before #'toc-org-insert-toc
(save-excursion
(when (re-search-forward toc-org-toc-org-regexp (point-max) t)
@ -882,7 +882,8 @@ compelling reason, so..."
:commands org-clock-save
:init
(setq org-clock-persist t)
(def-advice! +org-clock-load-a (&rest _)
(defadvice! +org--clock-load-a (&rest _)
"Lazy load org-clock until its commands are used."
:before '(org-clock-in
org-clock-out
org-clock-in-last

View file

@ -22,7 +22,7 @@
;; Handle non-image files a little differently. Images should be inserted
;; as-is, as image previews. Other files, like pdfs or zips, should be linked
;; to, with an icon indicating the type of file.
(def-advice! +org-dragndrop-insert-link-a (_link filename)
(defadvice! +org--dragndrop-insert-link-a (_link filename)
"Produces and inserts a link to FILENAME into the document.
If FILENAME is an image, produce an attach:%s path, otherwise use file:%s (with
@ -50,7 +50,7 @@ an file icon produced by `+org-attach--icon')."
(file-name-nondirectory (directory-file-name filename)))))))
(advice-add #'org-download--dir-2 :override #'ignore)
(def-advice! +org-dragndrop-download-fullname-a (path)
(defadvice! +org--dragndrop-download-fullname-a (path)
"Write PATH relative to current file."
:filter-return #'org-download--fullname
(let ((dir (or (if buffer-file-name (file-name-directory buffer-file-name))

View file

@ -54,7 +54,7 @@
;; `rustic-setup-rls' uses `package-installed-p' unnecessarily, which breaks
;; because Doom lazy loads package.el.
(def-advice! +rust--disable-package-call-a (orig-fn &rest args)
(defadvice! +rust--disable-package-call-a (orig-fn &rest args)
:around #'rustic-setup-rls
(cl-letf (((symbol-function 'package-installed-p)
(symbol-function 'ignore)))