💥 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

@ -54,13 +54,13 @@ detected.")
;; Remove hscroll-margin in shells, otherwise it causes jumpiness
(setq-hook! '(eshell-mode-hook term-mode-hook) hscroll-margin 0)
(defun doom*optimize-literal-mode-for-large-files (buffer)
(def-advice! doom--optimize-literal-mode-for-large-files-a (buffer)
:filter-return #'find-file-noselect-1
(with-current-buffer buffer
(when find-file-literally
(setq buffer-read-only t)
(buffer-disable-undo))
buffer))
(advice-add #'find-file-noselect-1 :filter-return #'doom*optimize-literal-mode-for-large-files)
;;
@ -171,11 +171,10 @@ savehist file."
(setq save-place-file (concat doom-cache-dir "saveplace")
save-place-forget-unreadable-files t
save-place-limit 200)
(defun doom*recenter-on-load-saveplace (&rest _)
(def-advice! doom--recenter-on-load-saveplace-a (&rest _)
"Recenter on cursor when loading a saved place."
:after-while #'save-place-find-file-hook
(if buffer-file-name (ignore-errors (recenter))))
(advice-add #'save-place-find-file-hook
:after-while #'doom*recenter-on-load-saveplace)
(save-place-mode +1))
(def-package! server
@ -202,14 +201,14 @@ savehist file."
(better-jumper-mode +1)
(add-hook 'better-jumper-post-jump-hook #'recenter)
(defun doom*set-jump (orig-fn &rest args)
(defun doom-set-jump-a (orig-fn &rest args)
"Set a jump point and ensure ORIG-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)))
(defun doom*set-jump-maybe (orig-fn &rest args)
(defun doom-set-jump-maybe-a (orig-fn &rest args)
"Set a jump point if ORIG-FN returns non-nil."
(let ((origin (point-marker))
(result
@ -261,9 +260,10 @@ savehist file."
(push '(t tab-width) dtrt-indent-hook-generic-mapping-list)
(defvar dtrt-indent-run-after-smie)
(defun doom*fix-broken-smie-modes (orig-fn arg)
(def-advice! doom--fix-broken-smie-modes-a (orig-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
(let ((dtrt-indent-run-after-smie dtrt-indent-run-after-smie))
(cl-letf* ((old-smie-config-guess (symbol-function 'smie-config-guess))
((symbol-function 'smie-config-guess)
@ -273,8 +273,7 @@ savehist file."
(message "[WARNING] Indent detection: %s"
(error-message-string e))
(message "")))))) ; warn silently
(funcall orig-fn arg))))
(advice-add #'dtrt-indent-mode :around #'doom*fix-broken-smie-modes))
(funcall orig-fn arg)))))
(def-package! helpful
@ -354,17 +353,16 @@ savehist file."
`(("." . ,(concat doom-cache-dir "undo-tree-hist/"))))
(when (executable-find "zstd")
(defun doom*undo-tree-make-history-save-file-name (file)
(concat file ".zst"))
(advice-add #'undo-tree-make-history-save-file-name :filter-return
#'doom*undo-tree-make-history-save-file-name))
(def-advice! doom--undo-tree-make-history-save-file-name-a (file)
:filter-return #'undo-tree-make-history-save-file-name
(concat file ".zst")))
(defun doom*strip-text-properties-from-undo-history (&rest _)
(def-advice! doom--undo-tree-strip-text-properties-a (&rest _)
:before #'undo-list-transfer-to-tree
(dolist (item buffer-undo-list)
(and (consp item)
(stringp (car item))
(setcar item (substring-no-properties (car item))))))
(advice-add #'undo-list-transfer-to-tree :before #'doom*strip-text-properties-from-undo-history)
(global-undo-tree-mode +1))