💥 revise advice naming convention (1/2)

This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.

In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.

  doom*shut-up -> doom-shut-up-a
  doom*recenter -> doom-recenter-a
  +evil*static-reindent -> +evil--static-reindent-a

The rationale behind this change is:

1. Elisp's own formatting/indenting tools would occasionally struggle
   with | and * (particularly pp and cl-prettyprint). They have no
   problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
   github markdown) struggle with it, sometimes refusing to highlight
   code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
   intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
   on haphazardly way back when Doom was simply "my private config".

Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.

Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
  macro. The old pair weren't as useful. The new def-advice! saves on a
  lot of space.
- Removed "stage" assertions to make sure you were using the right
  macros in the right place. Turned out to not be necessary, we'll
  employ better checks later.
This commit is contained in:
Henrik Lissner 2019-07-18 15:42:52 +02:00
parent e3a102d05a
commit 51d3b1b424
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
44 changed files with 398 additions and 484 deletions

View file

@ -76,21 +76,6 @@ list is returned as-is."
collect (cadr hook)
else collect (intern (format "%s-hook" (symbol-name hook)))))))
(defun doom--assert-stage-p (stage macro)
(unless (or (bound-and-true-p byte-compile-current-file)
;; Don't complain if we're being evaluated on-the-fly. Since forms
;; are often evaluated (by `eval-region') or expanded (by
;; macroexpand) in a temp buffer in `emacs-lisp-mode'...
(eq major-mode 'emacs-lisp-mode))
(cl-assert (eq stage doom--stage)
nil
"Found %s call in non-%s.el file (%s)"
macro (symbol-name stage)
(let ((path (FILE!)))
(if (file-in-directory-p path doom-emacs-dir)
(file-relative-name path doom-emacs-dir)
(abbreviate-file-name path))))))
;;
;;; Public library
@ -303,32 +288,26 @@ If N and M = 1, there's no benefit to using this macro over `remove-hook'.
(nreverse forms))))
collect `(add-hook ',hook #',fn 'append)))))
(defun advice-add! (symbols where functions)
"Variadic version of `advice-add'.
(defmacro def-advice! (symbol arglist docstring where places &rest body)
"Define an advice called NAME and add it to PLACES.
SYMBOLS and FUNCTIONS can be lists of functions."
(let ((functions (if (functionp functions)
(list functions)
functions)))
(dolist (s (doom-enlist symbols))
(dolist (f (doom-enlist functions))
(advice-add s where f)))))
(defun advice-remove! (symbols where-or-fns &optional functions)
"Variadic version of `advice-remove'.
WHERE-OR-FNS is ignored if FUNCTIONS is provided. This lets you substitute
advice-add with advice-remove and evaluate them without having to modify every
statement."
(unless functions
(setq functions where-or-fns
where-or-fns nil))
(let ((functions (if (functionp functions)
(list functions)
functions)))
(dolist (s (doom-enlist symbols))
(dolist (f (doom-enlist functions))
(advice-remove s f)))))
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 (format "%s advice for %s." where places)))
`(progn
(defun ,symbol ,arglist
,docstring
,@body)
(dolist (target (doom-enlist ,places))
(if (eq ,where :remove)
(advice-remove target #',symbol)
(advice-add target ,where #',symbol)))))
(cl-defmacro associate! (mode &key modes match files when)
"Enables a minor mode if certain conditions are met.