Skip to content

Commit

Permalink
refactor: better convention for advice functions naming
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jan 13, 2024
1 parent 8871df4 commit 569f10b
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 61 deletions.
21 changes: 11 additions & 10 deletions core/me-builtin.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ or file path may exist now."
(let ((x-win-dir (+directory-ensure minemacs-local-dir "x-win/")))
(advice-add
#'emacs-session-filename :filter-return
(defun +emacs-session-filename--in-subdir-a (session-filename)
(defun +emacs-session-filename--in-subdir:filter-return-a (session-filename)
"Put the SESSION-FILENAME in the \"x-win/\" sub-directory."
(concat x-win-dir (file-name-nondirectory session-filename))))

Expand Down Expand Up @@ -698,7 +698,7 @@ Functions are differentiated into \"special forms\", \"built-in functions\" and

;; Taken from:
;; reddit.com/r/emacs/comments/d7x7x8/finally_fixing_indentation_of_quoted_lists
(defun +emacs-lisp--calculate-lisp-indent-a (&optional parse-start)
(defun +emacs-lisp--calculate-lisp-indent:override-a (&optional parse-start)
"Add better indentation for quoted and backquoted lists."
;; The `calculate-lisp-indent-last-sexp' is defined with `defvar' with it's
;; value omitted, marking it special and only defining it locally. So if you
Expand Down Expand Up @@ -857,15 +857,15 @@ Functions are differentiated into \"special forms\", \"built-in functions\" and

;; Override the `calculate-lisp-indent' to indent plists correctly. See:
;; reddit.com/r/emacs/comments/d7x7x8/finally_fixing_indentation_of_quoted_lists/
(advice-add 'calculate-lisp-indent :override #'+emacs-lisp--calculate-lisp-indent-a)
(advice-add 'calculate-lisp-indent :override #'+emacs-lisp--calculate-lisp-indent:override-a)

;; Better fontification for Emacs Lisp code (colorizes functions, ...)
(font-lock-add-keywords 'emacs-lisp-mode '((+emacs-lisp--highlight-vars-and-faces . +emacs-lisp--face)))

;; HACK: Adapted from Doom. Quite a few functions here are called often, and
;; so are especially performance sensitive, so we compile these functions
;; on-demand.
(+compile-functions #'+emacs-lisp--highlight-vars-and-faces #'+emacs-lisp--calculate-lisp-indent-a))
(+compile-functions #'+emacs-lisp--highlight-vars-and-faces #'+emacs-lisp--calculate-lisp-indent:override-a))

(use-package scheme
:custom
Expand Down Expand Up @@ -893,7 +893,7 @@ Functions are differentiated into \"special forms\", \"built-in functions\" and

(advice-add
'gud-display-line :after
(defun +gud--display-overlay-a (true-file _line)
(defun +gud--display-overlay:after-a (true-file _line)
(let* ((overlay +gud-overlay)
(buffer (gud-find-file true-file)))
(with-current-buffer buffer
Expand Down Expand Up @@ -1415,7 +1415,7 @@ current line.")
;; `shell-kill-buffer-on-exit').
(advice-add
'term-sentinel :around
(defun +term--kill-after-exit-a (orig-fn proc msg)
(defun +term--kill-after-exit:around-a (orig-fn proc msg)
(if (memq (process-status proc) '(signal exit))
(let ((buffer (process-buffer proc)))
(apply orig-fn (list proc msg))
Expand Down Expand Up @@ -1617,11 +1617,12 @@ Useful for quickly switching to an open buffer."
:init
;; Add visual pulse when changing focus, like beacon but built-in
;; From: https://karthinks.com/software/batteries-included-with-emacs/
(defun +pulse-line (&rest _)
"Pulse the current line."
(pulse-momentary-highlight-one-line (point)))
(dolist (command '(scroll-up-command scroll-down-command recenter-top-bottom other-window))
(advice-add command :after #'+pulse-line)))
(advice-add
command :after
(defun +pulse--line:after-a (&rest _)
"Pulse the current line."
(pulse-momentary-highlight-one-line (point))))))

(use-package isearch
;; Scroll in isearch history using UP/DOWN or C-j/C-k
Expand Down
2 changes: 1 addition & 1 deletion core/me-core-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
;; Disable previously enabled custom themes before enabling a new one.
(advice-add
'load-theme :before
(defun +theme--disable-previous-themes-a (&rest _)
(defun +theme--disable-previous-themes:before-a (&rest _)
"Disable previously enabled themes before enabling the new one."
(mapc #'disable-theme custom-enabled-themes)))

Expand Down
5 changes: 2 additions & 3 deletions core/me-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@
;; Ask for a buffer when splitting windows
(with-eval-after-load 'consult
(dolist (fn '(evil-window-split evil-window-vsplit))
(advice-add
fn :after
(defun +evil--cunsult-buffer-after-window-split-a (&rest _)
(advice-add fn :after
(defun +evil--cunsult-buffer-after-window-split:after-a (&rest _)
(consult-buffer))))))

(use-package evil-collection
Expand Down
4 changes: 2 additions & 2 deletions core/me-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ value of this method instead of the original alist, to ensure correct results."
(defmacro +fn-inhibit-messages! (fn &optional no-message-log)
"Add an advice around the function FN to suppress messages in echo area.
If NO-MESSAGE-LOG is non-nil, do not print any message to *Messages* buffer."
(let ((advice-fn (make-symbol (format "+%s--inhibit-messages-a" fn))))
(let ((advice-fn (make-symbol (format "+%s--inhibit-messages:around-a" fn))))
`(advice-add
',fn :around
(defun ,advice-fn (origfn &rest args)
Expand Down Expand Up @@ -326,7 +326,7 @@ EXT-REGEXP. When it runs, this function provides a feature named
`minemacs-first-FILETYPE-file' and a run all hooks in
`minemacs-first-FILETYPE-file-hook'."
(let* ((filetype (+unquote filetype))
(fn-name (intern (format "+first-file-%s-h" (if filetype (format "-%s" filetype) ""))))
(fn-name (intern (format "+first-%s-file:after-a" (if filetype (format "-%s" filetype) ""))))
(hook-name (intern (format "minemacs-first%s-file-hook" (if filetype (format "-%s" filetype) ""))))
(feature-name (intern (format "minemacs-first%s-file" (if filetype (format "-%s" filetype) ""))))
(hook-docs (format "This hook will be run after opening the first %s file (files that matches \"%s\").
Expand Down
6 changes: 3 additions & 3 deletions core/me-use-package-extra.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
;; `straight'.
(advice-add
'use-package :around
(defun +use-package--check-if-disabled-a (origfn package &rest args)
(defun +use-package--check-if-disabled:around-a (origfn package &rest args)
(when (and (not (+package-disabled-p package))
(or (not (memq :if args))
(and (memq :if args) (eval (+varplist-get args :if t))))
Expand All @@ -54,7 +54,7 @@
(add-to-list 'minemacs-configured-packages package t)
(apply origfn package args))))

;; If you want to keep the `+use-package--check-if-disabled-a' advice after
;; If you want to keep the `+use-package--check-if-disabled:around-a' advice after
;; loading MinEmacs' modules. You need to set in in your
;; "$MINEMACSDIR/early-config.el"
(defvar +use-package-keep-checking-for-disabled-p nil)
Expand All @@ -66,7 +66,7 @@
'minemacs-after-loading-modules-hook
(defun +use-package--remove-check-if-disabled-advice-h ()
(unless +use-package-keep-checking-for-disabled-p
(advice-remove 'use-package '+use-package--check-if-disabled-a)))))
(advice-remove 'use-package '+use-package--check-if-disabled:around-a)))))


(provide 'me-use-package-extra)
Expand Down
4 changes: 2 additions & 2 deletions core/me-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ of being enabled."

(defcustom minemacs-after-loading-modules-hook nil
"This hook will be run after loading MinEmacs modules.
It is used internally to remove the `+use-package--check-if-disabled-a' advice
we set on `use-package' in `me-bootstrap'."
It is used internally to remove the `+use-package--check-if-disabled:around-a'
advice we set on `use-package' in `me-bootstrap'."
:group 'minemacs-core
:type 'hook)

Expand Down
6 changes: 3 additions & 3 deletions modules/extras/me-eglot-ltex.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
(defvar eglot-ltex-disable-rules
(+deserialize-sym 'eglot-ltex-disable-rules eglot-ltex-user-rules-path))

(defun eglot-ltex--process-client-commands-a (_srv cmd args)
(defun eglot-ltex--process-client-commands:before-a (_srv cmd args)
"Process LTeX-LS client commands."
(cond
((string= cmd "_ltex.addToDictionary")
Expand Down Expand Up @@ -101,12 +101,12 @@ When STORE is non-nil, this will also store the new plist in the directory
(defun eglot-ltex-enable-handling-client-commands ()
"Enable Eglot hack to handle code actions of LTeX-LS."
(interactive)
(advice-add 'eglot-execute-command :before #'eglot-ltex--process-client-commands-a))
(advice-add 'eglot-execute-command :before #'eglot-ltex--process-client-commands:before-a))

(defun eglot-ltex-disable-handling-client-commands ()
"Disable Eglot hack to handle code actions of LTeX-LS."
(interactive)
(advice-remove 'eglot-execute-command #'eglot-ltex--process-client-commands-a))
(advice-remove 'eglot-execute-command #'eglot-ltex--process-client-commands:before-a))


(provide 'me-eglot-ltex)
Expand Down
8 changes: 4 additions & 4 deletions modules/extras/me-gdb.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

(advice-add
'gdb :around
(defun +gdb--set-window-layout-a (origfn &rest args)
(defun +gdb--set-window-layout:around-a (origfn &rest args)
;; Save current buffer
(setq +gdb--old-win-config (current-window-configuration))
(let ((c-buffer (window-buffer (selected-window))))
Expand All @@ -51,15 +51,15 @@

(advice-add
'gdb-reset :after
(defun +gdb--restore-window-layout-a (&rest _)
(defun +gdb--restore-window-layout:after-a (&rest _)
(set-window-configuration +gdb--old-win-config))))

(defun +gdb-reset-layout ()
"Enable custom window layout for gdb."
(interactive)
(setq gdb-many-windows +gdb--many-windows-old)
(advice-remove 'gdb #'+gdb--set-window-layout-a)
(advice-add 'gdb-reset #'+gdb--restore-window-layout-a))
(advice-remove 'gdb #'+gdb--set-window-layout:around-a)
(advice-add 'gdb-reset #'+gdb--restore-window-layout:after-a))

;;;###autoload
(defun +emacs-gdb-enable ()
Expand Down
4 changes: 2 additions & 2 deletions modules/extras/me-mu4e-extras.el
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ If SKIP-HEADERS is set, do not show include message headers."
(mm-destroy-parts parts)))))

(defun +mu4e-extras-locks-setup ()
(advice-add 'mu4e--server-kill :after (defun +mu4e--unlock-h (&rest _) (+unlock 'mu)))
(advice-add 'mu4e--server-start :after (defun +mu4e--lock-h (&rest _) (+lock 'mu))))
(advice-add 'mu4e--server-kill :after (defun +mu4e--unlock:after-a (&rest _) (+unlock 'mu)))
(advice-add 'mu4e--server-start :after (defun +mu4e--lock:after-a (&rest _) (+lock 'mu))))

(defun +mu4e-extras-setup ()
(add-hook 'mu4e-compose-mode-hook '+mu4e--auto-bcc-h)
Expand Down
10 changes: 5 additions & 5 deletions modules/extras/me-mu4e-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(defvar +mu4e-main-bullet "⦿"
"Prefix to use instead of \" *\" in the mu4e main view.
This is enacted by `+mu4e--main-action-str-prettier-a' and
`+mu4e--main-keyval-str-prettier-a'.")
`+mu4e--main-keyval-str-prettier:filter-return-a'.")

(defvar +mu4e-header-colorized-faces
'(nerd-icons-green
Expand Down Expand Up @@ -66,7 +66,7 @@ integer OFFSET."
+mu4e-header-colorized-faces)))
color))

(defun +mu4e--main-action-prettier-a (title cmd &optional bindstr alt)
(defun +mu4e--main-action-prettier:override-a (title cmd &optional bindstr alt)
(let* ((bindstr (or bindstr (mu4e-key-description cmd) (and alt (string alt))
(mu4e-error "No binding for %s" cmd)))
(bindstr (if (and alt (> (length bindstr) 1)) alt bindstr))
Expand Down Expand Up @@ -100,7 +100,7 @@ integer OFFSET."
(- (length title) 1) 'mouse-face 'highlight title)
(propertize title 'keymap map)))

(defun +mu4e--main-keyval-str-prettier-a (str)
(defun +mu4e--main-keyval-str-prettier:filter-return-a (str)
"Replace '*' with `+mu4e-main-bullet' in STR."
(replace-regexp-in-string "\t\\*" (format "\t%s" +mu4e-main-bullet) str))

Expand Down Expand Up @@ -224,8 +224,8 @@ will also be the width of all other printable characters."
(:from-or-to . 25)
(:subject-truncated)))

(advice-add 'mu4e--key-val :filter-return #'+mu4e--main-keyval-str-prettier-a)
(advice-add 'mu4e--main-action :override #'+mu4e--main-action-prettier-a))
(advice-add 'mu4e--key-val :filter-return #'+mu4e--main-keyval-str-prettier:filter-return-a)
(advice-add 'mu4e--main-action :override #'+mu4e--main-action-prettier:override-a))

(defun +mu4e-ui-setup ()
(if (display-graphic-p)
Expand Down
28 changes: 14 additions & 14 deletions modules/extras/me-org-extras.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Return an AST with newlines counts in each level."
(plist-get (car ast) :children)))

;; Adapted from Scimax
(defun +org-extras--renumber-env-a (orig-func &rest args)
(defun +org-extras--renumber-env:around-a (orig-func &rest args)
"An advice function to inject numbers in LaTeX fragment previews."
(let ((counter -1) results)
(setq results (cl-loop
Expand Down Expand Up @@ -100,16 +100,16 @@ Return an AST with newlines counts in each level."
Force enabling when ENABLE is non-nil."
(interactive)
(if (or enable (not (get '+org-extras--renumber-env-a 'enabled)))
(if (or enable (not (get '+org-extras--renumber-env:around-a 'enabled)))
(progn
(advice-add 'org-create-formula-image :around #'+org-extras--renumber-env-a)
(put '+org-extras--renumber-env-a 'enabled t)
(advice-add 'org-create-formula-image :around #'+org-extras--renumber-env:around-a)
(put '+org-extras--renumber-env:around-a 'enabled t)
(message "LaTeX numbering enabled."))
(advice-remove 'org-create-formula-image #'+org-extras--renumber-env-a)
(put '+org-extras--renumber-env-a 'enabled nil)
(advice-remove 'org-create-formula-image #'+org-extras--renumber-env:around-a)
(put '+org-extras--renumber-env:around-a 'enabled nil)
(message "LaTeX numbering disabled.")))

(defun +org-extras-inject-latex-fragment (orig-func &rest args)
(defun +org-extras-inject-latex-fragment:around-a (orig-func &rest args)
"Advice function to inject latex code before and/or after the equation in a latex fragment.
You can use this to set \\mathversion{bold} for example to make it bolder.
The way it works is by defining :latex-fragment-pre-body and/or
Expand All @@ -124,13 +124,13 @@ it is made into an image."
(defun +org-extras-inject-latex-fragments ()
"Toggle whether you can insert latex in fragments."
(interactive)
(if (not (get '+org-extras-inject-latex-fragment 'enabled))
(if (not (get '+org-extras-inject-latex-fragment:around-a 'enabled))
(progn
(advice-add 'org-create-formula-image :around #'+org-extras-inject-latex-fragment)
(put '+org-extras-inject-latex-fragment 'enabled t)
(advice-add 'org-create-formula-image :around #'+org-extras-inject-latex-fragment:around-a)
(put '+org-extras-inject-latex-fragment:around-a 'enabled t)
(message "Inject latex enabled"))
(advice-remove 'org-create-formula-image #'+org-extras-inject-latex-fragment)
(put '+org-extras-inject-latex-fragment 'enabled nil)
(advice-remove 'org-create-formula-image #'+org-extras-inject-latex-fragment:around-a)
(put '+org-extras-inject-latex-fragment:around-a 'enabled nil)
(message "Inject latex disabled")))

;; Adapted from: github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-org.el
Expand Down Expand Up @@ -168,7 +168,7 @@ Example: \"#+TITLE\" -> \"#+title\"
"Enable multi-files documents."
(advice-add
'org-latex-export-to-pdf :around
(defun +org--latex-export-to-pdf-main-file-a (orig-fn &rest orig-args)
(defun +org--latex-export-to-pdf-main-file:around-a (orig-fn &rest orig-args)
(let* ((main-file (and +org-export-to-pdf-main-file
(file-exists-p (expand-file-name +org-export-to-pdf-main-file))))
(out-file (if main-file
Expand Down Expand Up @@ -280,7 +280,7 @@ Example: \"#+TITLE\" -> \"#+title\"
"Fix the font size issue in Org's outline in the echo area."
(advice-add
#'org-format-outline-path :around
(defun +org--strip-properties-from-outline-a (fn &rest args)
(defun +org--strip-properties-from-outline:around-a (fn &rest args)
(let ((org-level-faces
(cl-loop for face in org-level-faces
collect `(:foreground ,(face-foreground face nil t)
Expand Down
2 changes: 1 addition & 1 deletion modules/me-calendar.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:config
(advice-add
'cfw:render-button :override
(defun +cfw:render-button-flat-a (title command &optional state)
(defun +cfw:render-button-flat:override-a (title command &optional state)
"Render a flat button with TITLE, COMMAND and STATE."
(let ((text (concat " " title " "))
(keymap (make-sparse-keymap)))
Expand Down
2 changes: 1 addition & 1 deletion modules/me-checkers.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
;; Automatically generate `backend-load' function to be used as a hook
(advice-add
'flymake-quickdef-backend :after
(defun +flymake-quickdef--make-load-fn (backend &rest _)
(defun +flymake-quickdef--make-load-fn:after-a (backend &rest _)
(let ((fn (intern (format "+%s-load" backend))))
(defalias fn
(lambda () (add-hook 'flymake-diagnostic-functions backend nil t))))))
Expand Down
8 changes: 4 additions & 4 deletions modules/me-emacs-lisp.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
(defvar-local +parinter-rust--was-enabled-p nil)

;; HACK: Disable `parinfer-rust-mode' on some commands.
(defun +parinter-rust--restore-a (&rest _)
(defun +parinter-rust--restore:after-a (&rest _)
(when +parinter-rust--was-enabled-p
(setq +parinter-rust--was-enabled-p nil)
(parinfer-rust-mode 1)))

(defun +parinter-rust--disable-a (&rest _)
(defun +parinter-rust--disable:before-a (&rest _)
(if (and (bound-and-true-p parinfer-rust-mode) (bound-and-true-p parinfer-rust-enabled))
(progn (setq +parinter-rust--was-enabled-p t)
(parinfer-rust-mode -1))
Expand All @@ -40,8 +40,8 @@
;; behave strangely when `parinfer-rust-mode' is enabled, so lets disable when
;; using this command.
(dolist (cmd '(evil-shift-right))
(advice-add cmd :before #'+parinter-rust--disable-a)
(advice-add cmd :after #'+parinter-rust--restore-a)))
(advice-add cmd :before #'+parinter-rust--disable:before-a)
(advice-add cmd :after #'+parinter-rust--restore:after-a)))

(use-package macrostep
:straight t
Expand Down
4 changes: 2 additions & 2 deletions modules/me-email.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
;; Force running update and index in background
(advice-add
'mu4e-update-mail-and-index :around
(defun +mu4e--update-mail-quitely-a (origfn run-in-background)
(defun +mu4e--update-mail-quitely:around-a (origfn run-in-background)
(+info! "Getting new emails")
(apply origfn '(t)))))

Expand Down Expand Up @@ -173,7 +173,7 @@
;; HACK: When adding multiple attachements, I likely need it to remember the directory of the last added attachement.
(advice-add
'org-msg-attach-attach :after
(defun +org-msg-attach-attach--save-default-directory-a (file &rest _)
(defun +org-msg-attach-attach--save-default-directory:after-a (file &rest _)
(when-let ((dir (file-name-directory file)))
(setq-local default-directory dir)))))

Expand Down
2 changes: 1 addition & 1 deletion modules/me-tools.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
;; `multi-vterm' don't get the working directory right, lets fix it!
(advice-add
'multi-vterm-dedicated-open :after
(defun +multi-vterm--remote-change-working-directory-a (&rest _)
(defun +multi-vterm--remote-change-working-directory:after-a (&rest _)
(if-let ((dir (file-remote-p default-directory 'localname)))
(vterm-send-string (format "cd %S\n" dir)))))
(+nvmap!
Expand Down
2 changes: 1 addition & 1 deletion modules/me-workspaces.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
;; Switch to the scratch buffer after creating a new workspace
(advice-add
'tabspaces-switch-or-create-workspace :around
(defun +tabspaces--switch-to-scratch-after-create-a (origfn &rest workspace)
(defun +tabspaces--switch-to-scratch-after-create:around-a (origfn &rest workspace)
(let ((before-list (tabspaces--list-tabspaces)))
(apply origfn workspace)
;; Created a new empty workspace
Expand Down

0 comments on commit 569f10b

Please sign in to comment.