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

@ -357,31 +357,6 @@ If N and M = 1, there's no benefit to using this macro over `remove-hook'.
(cl-loop for (_var _val hook fn) in (doom--setq-hook-fns hooks vars 'singles)
collect `(remove-hook ',hook #',fn))))
(defmacro def-advice! (symbol arglist docstring where places &rest body)
"Define an advice called NAME and add it to PLACES.
ARGLIST is as in `defun'. WHERE is a keyword as passed to `advice-add', and
PLACE is the function to which to add the advice, like in `advice-add'.
DOCSTRING and BODY are as in `defun'."
(declare (doc-string 3) (indent defun))
(unless (stringp docstring)
(push places body)
(setq places where
where docstring
docstring nil))
`(progn
(fset ',symbol (lambda ,arglist ,@body))
(put ',symbol 'function-documentation
(format "%sThis is %s advice for the following functions: %s"
,(if docstring (concat docstring "\n\n") "")
,where
(mapconcat (lambda (p) (format "`%s'" p))
(doom-enlist ,places) ", ")))
(dolist (target (doom-enlist ,places))
(if (eq ,where :remove)
(advice-remove target #',symbol)
(advice-add target ,where #',symbol)))))
(defmacro file-exists-p! (spec &optional directory)
"Returns non-nil if the files in SPEC all exist.
@ -490,5 +465,33 @@ writes to `standard-output'."
(save-silently t))
(prog1 ,@forms (message ""))))))
;;
;;; Definers
(define-obsolete-function-alias 'def-advice! 'defadvice!)
(defmacro defadvice! (symbol arglist &optional docstring &rest body)
"Define an advice called NAME and add it to PLACES.
ARGLIST is as in `defun'. WHERE is a keyword as passed to `advice-add', and
PLACE is the function to which to add the advice, like in `advice-add'.
DOCSTRING and BODY are as in `defun'.
\(fn SYMBOL ARGLIST &optional DOCSTRING &rest [WHERE PLACES...] BODY\)"
(declare (doc-string 3) (indent defun))
(unless (stringp docstring)
(push docstring body)
(setq docstring nil))
(let (where-alist)
(while (keywordp (car body))
(push `(cons ,(pop body) (doom-enlist ,(pop body)))
where-alist))
`(progn
(defun ,symbol ,arglist ,docstring ,@body)
,(when where-alist
`(dolist (targets (list ,@(nreverse where-alist)))
(dolist (target (cdr targets))
(advice-add target (car targets) #',symbol)))))))
(provide 'core-lib)
;;; core-lib.el ends here