💥 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

@ -27,8 +27,9 @@
;; Allow users to switch between backends on the fly. E.g. C-x C-s followed
;; by C-x C-n, will switch from `company-yasnippet' to
;; `company-dabbrev-code'.
(defun +company*abort-previous (&rest _) (company-abort))
(advice-add #'company-begin-backend :before #'+company*abort-previous))
(def-advice! +company--abort-previous-a (&rest _)
:before #'company-begin-backend
(company-abort)))
(add-hook 'company-mode-hook #'+company|init-backends)
(global-company-mode +1))

View file

@ -60,7 +60,3 @@ bottom, which is easier on the eyes on big displays."
;;
(posframe-delete +helm--posframe-buffer))
;;;###autoload
(defun +helm*fix-get-font-height (orig-fn position)
(ignore-errors (funcall orig-fn position)))

View file

@ -83,9 +83,11 @@ be negative.")
:init
(when (and EMACS26+ (featurep! +childframe))
(setq helm-display-function #'+helm-posframe-display)
;; Fix "Specified window is not displaying the current buffer" error
(advice-add #'posframe--get-font-height :around #'+helm*fix-get-font-height))
(setq helm-display-function #'+helm-posframe-display-fn)
(def-advice! +helm--fix-get-font-height-a (orig-fn position)
"Fix \"Specified window is not displaying the current buffer\" error."
:around #'posframe--get-font-height
(ignore-errors (funcall orig-fn position))))
(let ((fuzzy (featurep! +fuzzy)))
(setq helm-M-x-fuzzy-match fuzzy
@ -119,15 +121,9 @@ be negative.")
(advice-add #'helm-display-mode-line :override #'+helm|hide-mode-line)
(advice-add #'helm-ag-show-status-default-mode-line :override #'ignore)
;; TODO Find a better way
(defun +helm*use-helpful (orig-fn arg)
(cl-letf (((symbol-function #'describe-function)
(symbol-function #'helpful-callable))
((symbol-function #'describe-variable)
(symbol-function #'helpful-variable)))
(funcall orig-fn arg)))
(advice-add #'helm-describe-variable :around #'+helm*use-helpful)
(advice-add #'helm-describe-function :around #'+helm*use-helpful))
;; Use helpful instead of describe-* to display documentation
(dolist (fn '(helm-describe-variable helm-describe-function))
(advice-add fn :around #'doom-use-helpful-a)))
(def-package! helm-flx
@ -142,9 +138,9 @@ be negative.")
(define-key helm-ag-edit-map [remap quit-window] #'helm-ag--edit-abort)
(set-popup-rule! "^\\*helm-ag-edit" :size 0.35 :ttl 0 :quit nil)
;; Recenter after jumping to match
(advice-add #'helm-ag--find-file-action :after-while #'doom*recenter)
(advice-add #'helm-ag--find-file-action :after-while #'doom-recenter-a)
;; And record position before jumping
(advice-add #'helm-ag--find-file-action :around #'doom*set-jump-maybe))
(advice-add #'helm-ag--find-file-action :around #'doom-set-jump-maybe-a))
;;;###package helm-bookmark

View file

@ -28,7 +28,7 @@
(insert "~/")
(call-interactively #'self-insert-command))))
(defun +ido*sort-mtime ()
(defun +ido--sort-mtime-a ()
"Sort ido filelist by mtime instead of alphabetically."
(setq ido-temp-list
(sort ido-temp-list
@ -40,8 +40,8 @@
(cl-loop for x in ido-temp-list
if (char-equal (string-to-char x) ?.)
collect x)))
(advice-add #'ido-sort-mtime :override #'+ido*sort-mtime)
(add-hook! (ido-make-file-list ido-make-dir-list) #'+ido*sort-mtime)
(advice-add #'ido-sort-mtime :override #'+ido--sort-mtime-a)
(add-hook! (ido-make-file-list ido-make-dir-list) #'ido-sort-mtime)
;;
(ido-mode 1)

View file

@ -94,12 +94,12 @@ immediately runs it on the current candidate (ending the ivy session)."
(after! yasnippet
(add-to-list 'yas-prompt-functions #'+ivy-yas-prompt nil #'eq))
(defun +ivy*inhibit-ivy-in-evil-ex (orig-fn &rest args)
(def-advice! +ivy--inhibit-ivy-in-evil-ex-a (orig-fn &rest args)
"`ivy-completion-in-region' struggles with completing certain
evil-ex-specific constructs, so we disable it solely in evil-ex."
:around #'evil-ex
(let ((completion-in-region-function #'completion--in-region))
(apply orig-fn args)))
(advice-add #'evil-ex :around #'+ivy*inhibit-ivy-in-evil-ex)
(define-key! ivy-mode-map
[remap switch-to-buffer] #'+ivy/switch-buffer

View file

@ -12,12 +12,11 @@
(def-package! expand-region
:commands (er/contract-region er/mark-symbol er/mark-word)
:config
(defun doom*quit-expand-region ()
(def-advice! doom--quit-expand-region-a ()
"Properly abort an expand-region region."
:before '(evil-escape doom/escape)
(when (memq last-command '(er/expand-region er/contract-region))
(er/contract-region 0)))
(advice-add #'evil-escape :before #'doom*quit-expand-region)
(advice-add #'doom/escape :before #'doom*quit-expand-region))
(er/contract-region 0))))
;;

View file

@ -17,7 +17,7 @@
If BANG is non-nil, open compilation output in a comint buffer.
If BANG, then run ARGUMENTS as a full command. This command understands vim file
modifiers (like %:p:h). See `+evil*resolve-vim-path' for details."
modifiers (like %:p:h). See `+evil-resolve-vim-path-a' for details."
(interactive "<sh><!>")
(+evil:compile (format "make %s"
(evil-ex-replace-special-filenames
@ -29,7 +29,7 @@ modifiers (like %:p:h). See `+evil*resolve-vim-path' for details."
If BANG is non-nil, open compilation output in a comint buffer.
This command understands vim file modifiers (like %:p:h). See
`+evil*resolve-vim-path' for details."
`+evil-resolve-vim-path-a' for details."
(interactive "<sh><!>")
(compile (evil-ex-replace-special-filenames
(format "%s %s"

View file

@ -1,76 +1,13 @@
;;; editor/evil/autoload/advice.el -*- lexical-binding: t; -*-
(defun +evil--insert-newline (&optional above _noextranewline)
(let ((pos (save-excursion (beginning-of-line-text) (point)))
comment-auto-fill-only-comments)
(require 'smartparens)
(evil-narrow-to-field
(if above
(if (save-excursion (nth 4 (sp--syntax-ppss pos)))
(evil-save-goal-column
(setq evil-auto-indent nil)
(goto-char pos)
(let ((ws (abs (skip-chars-backward " \t"))))
;; FIXME oh god why
(save-excursion
(if comment-line-break-function
(funcall comment-line-break-function)
(comment-indent-new-line))
(when (and (derived-mode-p 'c-mode 'c++-mode 'objc-mode 'java-mode 'js2-mode)
(eq (char-after) ?/))
(insert "*"))
(insert
(make-string (max 0 (+ ws (skip-chars-backward " \t")))
32)))
(insert (make-string (max 1 ws) 32))))
(evil-move-beginning-of-line)
(insert (if use-hard-newlines hard-newline "\n"))
(forward-line -1)
(back-to-indentation))
(evil-move-end-of-line)
(cond ((sp-point-in-comment pos)
(setq evil-auto-indent nil)
(if comment-line-break-function
(funcall comment-line-break-function)
(comment-indent-new-line)))
;; TODO Find a better way to do this
((and (eq major-mode 'haskell-mode)
(fboundp 'haskell-indentation-newline-and-indent))
(setq evil-auto-indent nil)
(haskell-indentation-newline-and-indent))
(t
(insert (if use-hard-newlines hard-newline "\n"))
(back-to-indentation)))))))
;;;###autoload
(defun +evil-escape-a (&rest _)
"Call `doom/escape' if `evil-force-normal-state' is called interactively."
(when (called-interactively-p 'any)
(call-interactively #'doom/escape)))
;;;###autoload
(defun +evil*insert-newline-below-and-respect-comments (orig-fn count)
(if (or (not +evil-want-o/O-to-continue-comments)
(not (eq this-command 'evil-open-below))
(evil-insert-state-p))
(funcall orig-fn count)
(cl-letf (((symbol-function 'evil-insert-newline-below)
(lambda () (+evil--insert-newline))))
(let ((evil-auto-indent evil-auto-indent))
(funcall orig-fn count)))))
;;;###autoload
(defun +evil*insert-newline-above-and-respect-comments (orig-fn count)
(if (or (not +evil-want-o/O-to-continue-comments)
(not (eq this-command 'evil-open-above))
(evil-insert-state-p))
(funcall orig-fn count)
(cl-letf (((symbol-function 'evil-insert-newline-above)
(lambda () (+evil--insert-newline 'above))))
(let ((evil-auto-indent evil-auto-indent))
(funcall orig-fn count)))))
;;;###autoload
(defun +evil*static-reindent (orig-fn &rest args)
"Don't move cursor on indent."
(save-excursion (apply orig-fn args)))
;;;###autoload
(defun +evil*resolve-vim-path (file-name)
(defun +evil-resolve-vim-path-a (file-name)
"Take a path and resolve any vim-like filename modifiers in it. This adds
support for most vim file modifiers, as well as:
@ -148,8 +85,77 @@ more information on modifiers."
path file-name t t 1))))
(replace-regexp-in-string regexp "\\1" file-name t)))
;;;###autoload (autoload '+evil*window-split "editor/evil/autoload/advice" nil t)
(evil-define-command +evil*window-split (&optional count file)
(defun +evil--insert-newline (&optional above _noextranewline)
(let ((pos (save-excursion (beginning-of-line-text) (point)))
comment-auto-fill-only-comments)
(require 'smartparens)
(evil-narrow-to-field
(if above
(if (save-excursion (nth 4 (sp--syntax-ppss pos)))
(evil-save-goal-column
(setq evil-auto-indent nil)
(goto-char pos)
(let ((ws (abs (skip-chars-backward " \t"))))
;; FIXME oh god why
(save-excursion
(if comment-line-break-function
(funcall comment-line-break-function)
(comment-indent-new-line))
(when (and (derived-mode-p 'c-mode 'c++-mode 'objc-mode 'java-mode 'js2-mode)
(eq (char-after) ?/))
(insert "*"))
(insert
(make-string (max 0 (+ ws (skip-chars-backward " \t")))
32)))
(insert (make-string (max 1 ws) 32))))
(evil-move-beginning-of-line)
(insert (if use-hard-newlines hard-newline "\n"))
(forward-line -1)
(back-to-indentation))
(evil-move-end-of-line)
(cond ((sp-point-in-comment pos)
(setq evil-auto-indent nil)
(if comment-line-break-function
(funcall comment-line-break-function)
(comment-indent-new-line)))
;; TODO Find a better way to do this
((and (eq major-mode 'haskell-mode)
(fboundp 'haskell-indentation-newline-and-indent))
(setq evil-auto-indent nil)
(haskell-indentation-newline-and-indent))
(t
(insert (if use-hard-newlines hard-newline "\n"))
(back-to-indentation)))))))
;;;###autoload
(defun +evil--insert-newline-below-and-respect-comments-a (orig-fn count)
(if (or (not +evil-want-o/O-to-continue-comments)
(not (eq this-command 'evil-open-below))
(evil-insert-state-p))
(funcall orig-fn count)
(cl-letf (((symbol-function 'evil-insert-newline-below)
(lambda () (+evil--insert-newline))))
(let ((evil-auto-indent evil-auto-indent))
(funcall orig-fn count)))))
;;;###autoload
(defun +evil--insert-newline-above-and-respect-comments-a (orig-fn count)
(if (or (not +evil-want-o/O-to-continue-comments)
(not (eq this-command 'evil-open-above))
(evil-insert-state-p))
(funcall orig-fn count)
(cl-letf (((symbol-function 'evil-insert-newline-above)
(lambda () (+evil--insert-newline 'above))))
(let ((evil-auto-indent evil-auto-indent))
(funcall orig-fn count)))))
;;;###autoload
(defun +evil--static-reindent-a (orig-fn &rest args)
"Don't move cursor on indent."
(save-excursion (apply orig-fn args)))
;;;###autoload (autoload '+evil-window-split-a "editor/evil/autoload/advice" nil t)
(evil-define-command +evil-window-split-a (&optional count file)
"Same as `evil-window-split', but focuses (and recenters) the new split."
:repeat nil
(interactive "P<f>")
@ -164,8 +170,8 @@ more information on modifiers."
(balance-windows (window-parent)))
(if file (evil-edit file)))
;;;###autoload (autoload '+evil*window-vsplit "editor/evil/autoload/advice" nil t)
(evil-define-command +evil*window-vsplit (&optional count file)
;;;###autoload (autoload '+evil-window-vsplit-a "editor/evil/autoload/advice" nil t)
(evil-define-command +evil-window-vsplit-a (&optional count file)
"Same as `evil-window-vsplit', but focuses (and recenters) the new split."
:repeat nil
(interactive "P<f>")
@ -181,13 +187,7 @@ more information on modifiers."
(if file (evil-edit file)))
;;;###autoload
(defun +evil*escape (&rest _)
"Call `doom/escape' if `evil-force-normal-state' is called interactively."
(when (called-interactively-p 'any)
(call-interactively #'doom/escape)))
;;;###autoload
(defun +evil*make-numbered-markers-global (orig-fn char)
(defun +evil--make-numbered-markers-global-a (orig-fn char)
(or (and (>= char ?2) (<= char ?9))
(funcall orig-fn char)))

View file

@ -107,36 +107,36 @@ directives. By default, this only recognizes C directives.")
(setq save-silently t)
(add-hook 'after-save-hook #'+evil|display-vimlike-save-message))
;; Make ESC (from normal mode) the universal escaper. See `doom-escape-hook'.
(advice-add #'evil-force-normal-state :after #'+evil*escape)
(advice-add #'evil-force-normal-state :after #'+evil-escape-a)
;; Don't move cursor when indenting
(advice-add #'evil-indent :around #'+evil*static-reindent)
(advice-add #'evil-indent :around #'+evil--static-reindent-a)
;; monkey patch `evil-ex-replace-special-filenames' to improve support for
;; file modifiers like %:p:h. This adds support for most of vim's modifiers,
;; and one custom one: %:P (expand to the project root).
(advice-add #'evil-ex-replace-special-filenames :override #'+evil*resolve-vim-path)
(advice-add #'evil-ex-replace-special-filenames :override #'+evil-resolve-vim-path-a)
;; make `try-expand-dabbrev' (from `hippie-expand') work in minibuffer
(add-hook 'minibuffer-inactive-mode-hook #'+evil*fix-dabbrev-in-minibuffer)
(add-hook 'minibuffer-inactive-mode-hook #'+evil--fix-dabbrev-in-minibuffer-a)
;; Focus and recenter new splits
(advice-add #'evil-window-split :override #'+evil*window-split)
(advice-add #'evil-window-vsplit :override #'+evil*window-vsplit)
(advice-add #'evil-window-split :override #'+evil-window-split-a)
(advice-add #'evil-window-vsplit :override #'+evil-window-vsplit-a)
;; In evil, registers 2-9 are buffer-local. In vim, they're global, so...
(advice-add #'evil-global-marker-p :around #'+evil*make-numbered-markers-global)
(advice-add #'evil-global-marker-p :around #'+evil--make-numbered-markers-global-a)
;; Make o/O continue comments (see `+evil-want-o/O-to-continue-comments')
(advice-add #'evil-open-above :around #'+evil*insert-newline-above-and-respect-comments)
(advice-add #'evil-open-below :around #'+evil*insert-newline-below-and-respect-comments)
(advice-add #'evil-open-above :around #'+evil--insert-newline-above-and-respect-comments-a)
(advice-add #'evil-open-below :around #'+evil--insert-newline-below-and-respect-comments-a)
;; Recenter screen after most searches
(advice-add! '(evil-visualstar/begin-search-forward
evil-visualstar/begin-search-backward
evil-ex-search-word-backward
evil-ex-search-word-backward
evil-ex-search-forward
evil-ex-search-backward)
:after #'doom*recenter)
(dolist (fn '(evil-visualstar/begin-search-forward
evil-visualstar/begin-search-backward
evil-ex-search-word-backward
evil-ex-search-word-backward
evil-ex-search-forward
evil-ex-search-backward))
(advice-add fn :after #'doom-recenter-a))
;; --- custom interactive codes -----------
;; These arg types will highlight matches in the current buffer

View file

@ -10,10 +10,10 @@
(after-all
(unload-feature 'evil t))
(before-each
(fset 'resv #'+evil*resolve-vim-path)
(fset 'resv #'+evil-resolve-vim-path-a)
(spy-on 'doom-project-root :and-call-fake (lambda () project-root)))
;; `evil-ex-replace-special-filenames' / `+evil*resolve-vim-path'
;; `evil-ex-replace-special-filenames' / `+evil-resolve-vim-path-a'
(describe "file modifiers"
(it "supports basic vim file modifiers"
(let ((buffer-file-name "~/.emacs.d/test/modules/feature/test-evil.el")

View file

@ -24,14 +24,11 @@
;; Nicer code-folding overlays (with fringe indicators)
hs-set-up-overlay #'+fold-hideshow-set-up-overlay)
(defun +fold-hideshow*ensure-mode (&rest _)
(def-advice! +fold-hideshow*ensure-mode (&rest _)
"Ensure `hs-minor-mode' is enabled."
:before '(hs-toggle-hiding hs-hide-block hs-hide-level hs-show-all hs-hide-all)
(unless (bound-and-true-p hs-minor-mode)
(hs-minor-mode +1)))
(advice-add! '(hs-toggle-hiding
hs-hide-block hs-hide-level
hs-show-all hs-hide-all)
:before #'+fold-hideshow*ensure-mode)
;; extra folding support for more languages
(unless (assq 't hs-special-modes-alist)

View file

@ -96,15 +96,15 @@
(setq +mc--compat-mark-was-active nil))))
(add-hook 'multiple-cursors-mode-disabled-hook #'+multiple-cursors|compat-back-to-previous-state)
;; When running edit-lines, point will return (position + 1) as a
;; result of how evil deals with regions
(defun +multiple-cursors*adjust-mark-for-evil (&rest _)
;; When running edit-lines, point will return (position + 1) as a result of
;; how evil deals with regions
(def-advice! +multiple-cursors-adjust-mark-for-evil-a (&rest _)
:before #'mc/edit-lines
(when (and (bound-and-true-p evil-mode)
(not (memq evil-state '(insert emacs))))
(if (> (point) (mark))
(goto-char (1- (point)))
(push-mark (1- (mark))))))
(advice-add #'mc/edit-lines :before #'+multiple-cursors*adjust-mark-for-evil)
(defun +multiple-cursors|evil-compat-rect-switch-state ()
(if rectangular-region-mode

View file

@ -5,7 +5,9 @@
(after! git-timemachine
;; HACK Waiting for https://gitlab.com/pidu/git-timemachine/issues/77
(defun +vc*git-timemachine-show-commit ()
(def-advice! +vc--git-timemachine-show-commit-a ()
"Fix `git-timemachine-show-commit'."
:override #'git-timemachine-show-commit
(interactive)
(let ((rev (car git-timemachine-revision)))
(if (fboundp 'magit-revision-mode)
@ -17,7 +19,6 @@
(magit-buffer-diff-args nil)
(magit-buffer-diff-files nil))))
(message "You need to install magit to show commit"))))
(advice-add #'git-timemachine-show-commit :override #'+vc*git-timemachine-show-commit)
;; Sometimes I forget `git-timemachine' is enabled in a buffer, so instead of
;; showing revision details in the minibuffer, show them in

View file

@ -31,9 +31,10 @@
;;
;;; Hacks
(defun +chinese*org-html-paragraph (paragraph contents info)
(def-advice! +chinese--org-html-paragraph-a (paragraph contents info)
"Join consecutive Chinese lines into a single long line without unwanted space
when exporting org-mode to html."
:filter-args #'org-html-paragraph
(let* ((fix-regexp "[[:multibyte:]]")
(origin-contents contents)
(fixed-contents
@ -42,4 +43,3 @@ when exporting org-mode to html."
"\\1\\2"
origin-contents)))
(list paragraph fixed-contents info)))
(advice-add #'org-html-paragraph :filter-args #'+chinese*org-html-paragraph)

View file

@ -41,9 +41,10 @@
;;
;;; Hacks
(defun +japanese*org-html-paragraph (paragraph contents info)
(def-advice! +japanese--org-html-paragraph-a (paragraph contents info)
"Join consecutive Japanese lines into a single long line without unwanted space
when exporting org-mode to html."
:filter-args #'org-html-paragraph
(let* ((fix-regexp "[[:multibyte:]]")
(origin-contents contents)
(fixed-contents
@ -52,4 +53,3 @@ when exporting org-mode to html."
"\\1\\2"
origin-contents)))
(list paragraph fixed-contents info)))
(advice-add #'org-html-paragraph :filter-args #'+japanese*org-html-paragraph)

View file

@ -68,7 +68,7 @@ This marks a foldable marker for `outline-minor-mode' in elisp buffers.")
`((+emacs-lisp-highlight-vars-and-faces . +emacs-lisp--face)))))
;; Recenter window after following definition
(advice-add #'elisp-def :after #'doom*recenter)
(advice-add #'elisp-def :after #'doom-recenter-a)
(map! :localleader
:map emacs-lisp-mode-map

View file

@ -12,24 +12,24 @@ nimsuggest isn't installed."
(when IS-WINDOWS
;; TODO File PR/report upstream (https://github.com/nim-lang/nim-mode)
(defun doom*nimsuggest--get-dirty-dir ()
(def-advice! +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
`nimsuggest--make-tempdir' tries to use it."
:override #'nimsuggest--get-dirty-dir
(let* ((frame-str (format "%s" (selected-frame)))
(frame-num-str (if (string-match " \\(0x[0-9a-z]+\\)>$" frame-str)
(match-string 1 frame-str))))
(file-name-as-directory (concat nimsuggest-dirty-directory frame-num-str))))
(advice-add #'nimsuggest--get-dirty-dir :override #'doom*nimsuggest--get-dirty-dir)
;; TODO File PR/report upstream (https://github.com/nim-lang/nim-mode)
(defun doom*nimsuggest--get-temp-file-name (path)
(def-advice! +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."
(replace-regexp-in-string "[* |<>\"?*]" "" path))
(advice-add #'nimsuggest--get-temp-file-name :filter-return #'doom*nimsuggest--get-temp-file-name))
:filter-return #'nimsuggest--get-temp-file-name
(replace-regexp-in-string "[* |<>\"?*]" "" path)))
(map! :localleader
:map nim-mode-map

View file

@ -842,7 +842,7 @@ compelling reason, so..."
(if (featurep! +present) (load! "contrib/present"))
:config
(add-hook 'org-open-at-point-functions #'doom|set-jump)
(add-hook 'org-open-at-point-functions #'doom-set-jump-h)
;;; Packages
(after! toc-org

View file

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

View file

@ -29,7 +29,7 @@
(nil "^\\s-*\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*()" 1)))
;; `sh-set-shell' is chatty about setting up indentation rules
(advice-add #'sh-set-shell :around #'doom*shut-up)
(advice-add #'sh-set-shell :around #'doom-shut-up-a)
;; 1. Fontifies variables in double quotes
;; 2. Fontify command substitution in double quotes

View file

@ -6,7 +6,7 @@
"TODO"
(interactive "<fsh><!>")
(let ((buffer (+eshell-last-buffer))
(command (+evil*resolve-vim-path command)))
(command (+evil-resolve-vim-path-a command)))
(cond (buffer
(select-window (get-buffer-window buffer))
(+eshell-run-command command buffer))

View file

@ -27,12 +27,18 @@ buffer/window/frame switch, which is less expensive."
(0 font-lock-keyword-face)))))
(add-hook 'direnv-envrc-mode-hook #'+direnv|envrc-fontify-keywords)
(defun +direnv*update (&rest _)
(def-advice! +direnv--update-a (&rest _)
"Update direnv. Useful to advise functions that may run
environment-sensitive logic like `flycheck-default-executable-find'. This fixes
flycheck issues with direnv and on nix."
(direnv-update-environment default-directory))
(advice-add #'flycheck-default-executable-find :before #'+direnv*update)
:before #'flycheck-default-executable-find
(direnv--maybe-update-environment))
(when (executable-find "direnv")
(direnv-mode +1)))
(def-advice! +direnv--fail-gracefully-a (orig-fn)
"Don't try to update direnv if the executable isn't present."
:around #'direnv--maybe-update-environment
(if (executable-find "direnv")
(funcall orig-fn)
(doom-log "Couldn't find direnv executable")))
(direnv-mode +1))

View file

@ -12,7 +12,7 @@
(perl-mode . "pl")
(php-mode . "php"))
"An alist mapping major modes to extensions. Used by
`doom*editorconfig-smart-detection' to give editorconfig filetype hints.")
`doom--editorconfig-smart-detection-a' to give editorconfig filetype hints.")
;; Handles whitespace (tabs/spaces) settings externally. This way projects can
@ -20,7 +20,7 @@
(def-package! editorconfig
:after-call (doom-switch-buffer-hook after-find-file)
:config
(defun doom*editorconfig-smart-detection (orig-fn)
(defun doom--editorconfig-smart-detection-a (orig-fn)
"Retrieve the properties for the current file. If it doesn't have an
extension, try to guess one."
(let ((buffer-file-name
@ -32,7 +32,7 @@ extension, try to guess one."
(concat "." ext)
"")))))
(funcall orig-fn)))
(advice-add #'editorconfig-call-editorconfig-exec :around #'doom*editorconfig-smart-detection)
(advice-add #'editorconfig-call-editorconfig-exec :around #'doom--editorconfig-smart-detection-a)
(defun +editorconfig|disable-ws-butler-maybe (props)
"Disable `ws-butler-mode' if trim_trailing_whitespace is true."

View file

@ -114,7 +114,7 @@ this list.")
(advice-add #'projectile-find-tag :around #'+lookup*projectile-find-tag)
;; Use `better-jumper' instead of xref's marker stack
(advice-add #'xref-push-marker-stack :around #'doom*set-jump)
(advice-add #'xref-push-marker-stack :around #'doom-set-jump-a)
(def-package! ivy-xref
:when (featurep! :completion ivy)

View file

@ -123,18 +123,3 @@ control in buffers."
(url-or-repo))
dir
nil))
;;
;; Advice
;;;###autoload
(defun +magit*hub-settings--format-magithub.enabled ()
"Change the setting to display 'false' as its default."
(magit--format-popup-variable:choices "magithub.enabled" '("true" "false") "false"))
;;;###autoload
(defun +magit*hub-enabled-p ()
"Disables magithub by default."
(magithub-settings--value-or "magithub.enabled" nil
#'magit-get-boolean))

View file

@ -71,7 +71,7 @@ It is passed a user and repository name.")
:config
(setq magit-todos-keyword-suffix "\\(?:([^)]+)\\)?:?")
(define-key magit-todos-section-map "j" nil)
(advice-add #'magit-todos-mode :around #'doom*shut-up)
(advice-add #'magit-todos-mode :around #'doom-shut-up-a)
(magit-todos-mode +1))

View file

@ -86,10 +86,10 @@
(set-window-fringes (minibuffer-window) 0 0 nil))
(add-hook 'solaire-mode-hook #'+doom|disable-fringes-in-minibuffer)
(defun doom*no-fringes-in-which-key-buffer (&rest _)
(+doom|disable-fringes-in-minibuffer)
(def-advice! +doom--no-fringes-in-which-key-buffer-a (&rest _)
:after 'which-key--show-buffer-side-window
(+doom--disable-fringes-in-minibuffer-h)
(set-window-fringes (get-buffer-window which-key--buffer) 0 0 nil))
(advice-add 'which-key--show-buffer-side-window :after #'doom*no-fringes-in-which-key-buffer)
(add-hook! '(minibuffer-setup-hook window-configuration-change-hook)
#'+doom|disable-fringes-in-minibuffer)

View file

@ -58,10 +58,10 @@
'(misc-info mu4e github debug fancy-battery " " major-mode process))
;; Some functions modify the buffer, causing the modeline to show a false
;; modified state, so we try to force them to behave.
(defun +modeline*inhibit-modification-hooks (orig-fn &rest args)
(with-silent-modifications (apply orig-fn args)))
(advice-add #'ws-butler-after-save :around #'+modeline*inhibit-modification-hooks))
;; modified state, so force them to behave.
(def-advice! +modeline--inhibit-modification-hooks-a (orig-fn &rest args)
:around #'ws-butler-after-save
(with-silent-modifications (apply orig-fn args))))
;;

View file

@ -36,7 +36,7 @@ for `org-follow-link-hook')."
(defalias '+nav-flash|blink-cursor-maybe #'+nav-flash-blink-cursor-maybe)
;;;###autoload
(defalias '+nav-flash*blink-cursor #'+nav-flash-blink-cursor-maybe)
(defalias '+nav-flash-blink-cursor-a #'+nav-flash-blink-cursor-maybe)
;;;###autoload
(defun +nav-flash/blink-cursor (&rest _)

View file

@ -21,10 +21,9 @@
(add-hook 'org-follow-link-hook #'+nav-flash|delayed-blink-cursor)
;; `saveplace'
(advice-add #'save-place-find-file-hook :after #'+nav-flash*blink-cursor)
(advice-add #'save-place-find-file-hook :after #'+nav-flash-blink-cursor-a)
;; `evil'
(advice-add #'evil-window-top :after #'+nav-flash*blink-cursor)
(advice-add #'evil-window-middle :after #'+nav-flash*blink-cursor)
(advice-add #'evil-window-bottom :after #'+nav-flash*blink-cursor))
(advice-add #'evil-window-top :after #'+nav-flash-blink-cursor-a)
(advice-add #'evil-window-middle :after #'+nav-flash-blink-cursor-a)
(advice-add #'evil-window-bottom :after #'+nav-flash-blink-cursor-a))

View file

@ -50,8 +50,7 @@
(+neotree*indent-cursor)))
(add-hook 'neo-enter-hook #'+neotree*fix-cursor)
(defun +neotree*indent-cursor (&rest _)
(def-advice! +neotree--indent-cursor-a (&rest _)
:after '(neotree-next-line neotree-previous-line)
(beginning-of-line)
(skip-chars-forward " \t\r"))
(advice-add #'neotree-next-line :after #'+neotree*indent-cursor)
(advice-add #'neotree-previous-line :after #'+neotree*indent-cursor))
(skip-chars-forward " \t\r")))

View file

@ -38,11 +38,10 @@
;;;###package company
(progn
(defun +popup*dont-select-me (orig-fn &rest args)
(let ((+popup--inhibit-select t))
(apply orig-fn args)))
(advice-add #'company-show-doc-buffer :around #'+popup*dont-select-me))
(def-advice! +popup--dont-select-me-a (orig-fn &rest args)
:around #'company-show-doc-buffer
(let ((+popup--inhibit-select t))
(apply orig-fn args)))
;;;###package eshell
@ -51,21 +50,22 @@
;; When eshell runs a visual command (see `eshell-visual-commands'), it spawns
;; a term buffer to run it in, but where it spawns it is the problem...
(defun +popup*eshell-undedicate-popup (orig-fn &rest args)
(def-advice! +popup--eshell-undedicate-popup (&rest _)
"Force spawned term buffer to share with the eshell popup (if necessary)."
:before #'eshell-exec-visual
(when (+popup-window-p)
(set-window-dedicated-p nil nil)
(add-transient-hook! #'eshell-query-kill-processes :after
(set-window-dedicated-p nil t)))
(apply orig-fn args))
(advice-add #'eshell-exec-visual :around #'+popup*eshell-undedicate-popup))
(set-window-dedicated-p nil t)))))
;;;###package evil
(progn
(defun +popup*evil-command-window (hist cmd-key execute-fn)
;; Make evil-mode cooperate with popups
(def-advice! +popup--evil-command-window-a (hist cmd-key execute-fn)
"Monkey patch the evil command window to use `pop-to-buffer' instead of
`switch-to-buffer', allowing the popup manager to handle it."
:override #'evil-command-window
(when (eq major-mode 'evil-command-window-mode)
(user-error "Cannot recursively open command line window"))
(dolist (win (window-list))
@ -81,9 +81,10 @@
(evil-command-window-mode)
(evil-command-window-insert-commands hist)))
(defun +popup*evil-command-window-execute ()
(def-advice! +popup--evil-command-window-execute-a ()
"Execute the command under the cursor in the appropriate buffer, rather than
the command buffer."
:override #'evil-command-window-execute
(interactive)
(let ((result (buffer-substring (line-beginning-position)
(line-end-position)))
@ -98,10 +99,6 @@ the command buffer."
(funcall execute-fn result)
(setq evil-command-window-current-buffer nil)))
;; Make evil-mode cooperate with popups
(advice-add #'evil-command-window :override #'+popup*evil-command-window)
(advice-add #'evil-command-window-execute :override #'+popup*evil-command-window-execute)
;; Don't mess with popups
(advice-add #'+evil--window-swap :around #'+popup*save)
(advice-add #'evil-window-move-very-bottom :around #'+popup*save)
@ -153,21 +150,20 @@ the command buffer."
;;;###package helpful
(progn
(defun +popup*helpful-open-in-origin-window (button)
"Open links in non-popup, originating window rather than helpful's window."
(let ((path (substring-no-properties (button-get button 'path)))
enable-local-variables
origin)
(save-popups!
(find-file path)
(when-let (pos (get-text-property button 'position
(marker-buffer button)))
(goto-char pos))
(setq origin (selected-window))
(recenter))
(select-window origin)))
(advice-add #'helpful--navigate :override #'+popup*helpful-open-in-origin-window))
(def-advice! +popup--helpful-open-in-origin-window-a (button)
"Open links in non-popup, originating window rather than helpful's window."
:override #'helpful--navigate
(let ((path (substring-no-properties (button-get button 'path)))
enable-local-variables
origin)
(save-popups!
(find-file path)
(when-let (pos (get-text-property button 'position
(marker-buffer button)))
(goto-char pos))
(setq origin (selected-window))
(recenter))
(select-window origin)))
;;;###package helm
@ -176,7 +172,8 @@ the command buffer."
(setq helm-default-display-buffer-functions '(+popup-display-buffer-stacked-side-window))
;; Fix #897: "cannot open side window" error when TAB-completing file links
(defun +popup*hide-org-links-popup (orig-fn &rest args)
(def-advice! +popup--helm-hide-org-links-popup-a (orig-fn &rest args)
:around #'org-insert-link
(cl-letf* ((old-org-completing-read (symbol-function 'org-completing-read))
((symbol-function 'org-completing-read)
(lambda (&rest args)
@ -192,23 +189,22 @@ the command buffer."
(get-buffer-create "*Org Links*"))
(apply old-org-completing-read args))))
(apply orig-fn args)))
(advice-add #'org-insert-link :around #'+popup*hide-org-links-popup)
;; Fix left-over popup window when closing persistent help for `helm-M-x'
(defun +popup*helm-elisp--persistent-help (candidate _fun &optional _name)
(def-advice! +popup--helm-elisp--persistent-help-a (candidate _fun &optional _name)
:before #'helm-elisp--persistent-help
(let (win)
(when (and (helm-attr 'help-running-p)
(string= candidate (helm-attr 'help-current-symbol))
(setq win (get-buffer-window (get-buffer (help-buffer)))))
(delete-window win))))
(advice-add #'helm-elisp--persistent-help :before #'+popup*helm-elisp--persistent-help)
;; `helm-ag'
(defun +helm*pop-to-buffer (orig-fn &rest args)
(def-advice! +popup--helm-pop-to-buffer-a (orig-fn &rest args)
:around #'helm-ag--edit
(pop-to-buffer
(save-window-excursion (apply orig-fn args)
(current-buffer))))
(advice-add #'helm-ag--edit :around #'+helm*pop-to-buffer))
(current-buffer)))))
;;;###package ibuffer
@ -216,11 +212,11 @@ the command buffer."
;;;###package Info
(defun +popup*switch-to-info-window (&rest _)
(def-advice! +popup--switch-to-info-window-a (&rest _)
:after #'info-lookup-symbol
(when-let (win (get-buffer-window "*info*"))
(when (+popup-window-p win)
(select-window win))))
(advice-add #'info-lookup-symbol :after #'+popup*switch-to-info-window)
;;;###package multi-term
@ -235,26 +231,26 @@ the command buffer."
;;;###package org
(after! org
(defvar +popup--disable-internal nil)
;; Org has a scorched-earth window management policy I'm not fond of. i.e. it
;; kills all other windows just so it can monopolize the frame. No thanks. We
;; can do better ourselves.
(defun +popup*suppress-delete-other-windows (orig-fn &rest args)
(def-advice! +popup-suppress-delete-other-windows-a (orig-fn &rest args)
:around '(org-add-log-note
org-capture-place-template
org-export--dispatch-ui
org-agenda-get-restriction-and-command
org-fast-tag-selection)
(if +popup-mode
(cl-letf (((symbol-function 'delete-other-windows)
(symbol-function 'ignore)))
(apply orig-fn args))
(apply orig-fn args)))
(advice-add #'org-add-log-note :around #'+popup*suppress-delete-other-windows)
(advice-add #'org-capture-place-template :around #'+popup*suppress-delete-other-windows)
(advice-add #'org-export--dispatch-ui :around #'+popup*suppress-delete-other-windows)
(advice-add #'org-agenda-get-restriction-and-command :around #'+popup*suppress-delete-other-windows)
(advice-add #'org-fast-tag-selection :around #'+popup*suppress-delete-other-windows)
(defun +popup*fix-tags-window (orig-fn &rest args)
(def-advice! +popup--org-fix-tags-window-a (orig-fn &rest args)
"Hides the mode-line in *Org tags* buffer so you can actually see its
content and displays it in a side window without deleting all other windows.
Ugh, such an ugly hack."
:around #'org-fast-tag-selection
(if +popup-mode
(cl-letf* ((old-fit-buffer-fn (symbol-function 'org-fit-window-to-buffer))
((symbol-function 'org-fit-window-to-buffer)
@ -268,31 +264,31 @@ Ugh, such an ugly hack."
(funcall old-fit-buffer-fn window max-height min-height shrink-only))))
(apply orig-fn args))
(apply orig-fn args)))
(advice-add #'org-fast-tag-selection :around #'+popup*fix-tags-window)
(defun +popup*org-src-pop-to-buffer (orig-fn buffer context)
(def-advice! +popup-org-src-pop-to-buffer-a (orig-fn buffer context)
"Hand off the src-block window to the popup system by using `display-buffer'
instead of switch-to-buffer-*."
:around #'org-src-switch-to-buffer
(if (and (eq org-src-window-setup 'popup-window)
+popup-mode)
(pop-to-buffer buffer)
(funcall orig-fn buffer context)))
(advice-add #'org-src-switch-to-buffer :around #'+popup*org-src-pop-to-buffer)
(setq org-src-window-setup 'popup-window)
;; Ensure todo, agenda, and other minor popups are delegated to the popup system.
(defun +popup*org-pop-to-buffer (orig-fn buf &optional norecord)
(def-advice! +popup-org-pop-to-buffer-a (orig-fn buf &optional norecord)
"Use `pop-to-buffer' instead of `switch-to-buffer' to open buffer.'"
:around #'org-switch-to-buffer-other-window
(if +popup-mode
(pop-to-buffer buf nil norecord)
(funcall orig-fn buf norecord)))
(advice-add #'org-switch-to-buffer-other-window :around #'+popup*org-pop-to-buffer)
;; `org-agenda'
(setq org-agenda-window-setup 'popup-window
org-agenda-restore-windows-after-quit nil)
;; Don't monopolize the frame!
(defun +popup*org-agenda-suppress-delete-other-windows (orig-fn &rest args)
(def-advice! +popup-org-agenda-suppress-delete-other-windows-a (orig-fn &rest args)
:around #'org-agenda-prepare-window
(cond ((not +popup-mode)
(apply orig-fn args))
((eq org-agenda-window-setup 'popup-window)
@ -307,18 +303,16 @@ instead of switch-to-buffer-*."
(symbol-function 'ignore)))
(apply orig-fn args))))
((with-popup-rules! nil
(apply orig-fn args)))))
(advice-add #'org-agenda-prepare-window :around #'+popup*org-agenda-suppress-delete-other-windows))
(apply orig-fn args))))))
;;;###package persp-mode
(progn
(defun +popup*persp-mode-restore-popups (&rest _)
"Restore popup windows when loading a perspective from file."
(dolist (window (window-list))
(when (+popup-parameter 'popup window)
(+popup--init window nil))))
(advice-add #'persp-load-state-from-file :after #'+popup*persp-mode-restore-popups))
(def-advice! +popup--persp-mode-restore-popups-a (&rest _)
"Restore popup windows when loading a perspective from file."
:after #'persp-load-state-from-file
(dolist (window (window-list))
(when (+popup-parameter 'popup window)
(+popup--init window nil))))
;;;###package pdf-tools
@ -340,11 +334,11 @@ instead of switch-to-buffer-*."
;;;###package profiler
(defun doom*profiler-report-find-entry-in-other-window (orig-fn function)
(def-advice! +popup--profiler-report-find-entry-in-other-window-a (orig-fn function)
:around #'profiler-report-find-entry
(cl-letf (((symbol-function 'find-function)
(symbol-function 'find-function-other-window)))
(funcall orig-fn function)))
(advice-add #'profiler-report-find-entry :around #'doom*profiler-report-find-entry-in-other-window)
;;;###package wgrep
@ -370,17 +364,13 @@ instead of switch-to-buffer-*."
;;;###package windmove
(progn
;; Users should be able to hop into popups easily, but Elisp shouldn't.
(defun doom*ignore-window-parameters (orig-fn &rest args)
"Allow *interactive* window moving commands to traverse popups."
(cl-letf (((symbol-function #'windmove-find-other-window)
(lambda (dir &optional arg window)
(window-in-direction
(pcase dir (`up 'above) (`down 'below) (_ dir))
window (bound-and-true-p +popup-mode) arg windmove-wrap-around t))))
(apply orig-fn args)))
(advice-add #'windmove-up :around #'doom*ignore-window-parameters)
(advice-add #'windmove-down :around #'doom*ignore-window-parameters)
(advice-add #'windmove-left :around #'doom*ignore-window-parameters)
(advice-add #'windmove-right :around #'doom*ignore-window-parameters))
;; Users should be able to hop into popups easily, but Elisp shouldn't.
(def-advice! doom--ignore-window-parameters-a (orig-fn &rest args)
"Allow *interactive* window moving commands to traverse popups."
:around '(windmove-up windmove-down windmove-left windmove-right)
(cl-letf (((symbol-function #'windmove-find-other-window)
(lambda (dir &optional arg window)
(window-in-direction
(pcase dir (`up 'above) (`down 'below) (_ dir))
window (bound-and-true-p +popup-mode) arg windmove-wrap-around t))))
(apply orig-fn args)))