Questions tagged [nadvice]
15 questions
5
votes
1 answer
How to suppress `Wrote /home/user/.emacs.d/recentf` message in minibuffer
In the minibuffer I keep seeing:
Wrote /home/user/.emacs.d/recentf
Would it be possible to suppress this message? (Only for file name recentf file)
my minimal.el:
(setq recentf-max-saved-items 50)
(setq recentf-max-menu-items 50)
(setq…

alper
- 1,238
- 11
- 30
5
votes
2 answers
define-advice vs advice-add vs other (?)
Can someone explain and show the right/preferred way of advising functions in Emacs these days.
Official documentation says to use advice-add, but I've seen people using define-advice and I checked, they are both part of nadvice.el (which is as I…

iLemming
- 1,223
- 9
- 14
4
votes
1 answer
Adding a function call after a builtin runs
I always want to run reposition-window after c-beginning-of-defun.
I've tried this:
(advice-add 'c-beginning-of-defun :after #'reposition-window)
it results in this at execution:
Variable binding depth exceeds max-specpdl-size
I've considered…

Gauthier
- 499
- 2
- 13
3
votes
1 answer
Why advice won't work if the function is called from another compiled function?
Let's consider a minimal example, I take org-narrow-to-subtree as a compiled function, under the hood it calls narrow-to-region, I add simple advice to it:
(defun bark (START END) (message "Bark!"))
(advice-add 'narrow-to-region :before #'bark)
If…

Daniel Vartanov
- 33
- 6
3
votes
1 answer
Rewriting `defadvice' as `advice-add' makes advice ineffective
I am trying to make undo-tree auto compress the history save file. The document suggests adding the following advice
(defadvice undo-tree-make-history-save-file-name
(after undo-tree activate)
(setq ad-return-value (concat ad-return-value…

nalzok
- 665
- 6
- 18
2
votes
1 answer
Can "advice-add ... :filter-args" detect if the advised function was called interactively?
Using advice-add from nadvice.el, I am trying to add a :filter-args advice to an interactive function. Is it somehow possible for it to detect, whether the advised function has been called interactively?
I was trying to use called-interactively-p,…

kdb
- 1,561
- 12
- 21
2
votes
1 answer
Add multiple predicates to isearch-filter-predicate
I wrote a set of predicates to filter matches in my ìsearch-* and query-replace* routines. I also wrote a macro to bind the isearch-filter-predicate variable to multiple predicates:
(defmacro with-ifp-predicates (PREDICATES &rest body)
(declare…

Gabriele Nicolardi
- 1,199
- 8
- 17
1
vote
1 answer
redefine a function as wrapper for the old definition
I am trying to modify a package by redefining a function in it. However, I would like to call the original definition in the new definition. (kind of like extending a constructor in a subclass now that I think of it)
let's say we have this…

Alex028502
- 137
- 5
1
vote
1 answer
Prevent dired recenter buffer when reverting buffer
When a directory contains many files, more than the visible lines of the window, use end-of-buffer to go to end of buffer, then press g to revert-buffer, one can see the last line is recentered to the middle of the window.
How I can prevent this?

Saddle Point
- 481
- 7
- 23
1
vote
1 answer
Creating a local advice for a function
I want to slightly modify the behaviour of a function, old-function whose source I cannot modify.
I can do that simply by
(defun my-new-function (old-fn a b c)
(if (evaluate-my-condition)
(funcall old-fun (my-transform a) b c)
(funcall…

Tohiko
- 1,589
- 1
- 10
- 22
0
votes
2 answers
Save before running tests? (Prepend function?)
How can I prepend a function call in Elisp?
E.g. I have a key binding (C-c C-c C-t) that runs some tests (command rustic-cargo-test) and it always asks me if I want to save - I'd like to run (save-some-buffers 'no-prompt) each time before this, so…

John Graham
- 21
- 2
0
votes
1 answer
How to prevent copy-directory from choking on Unix socket files?
I need to copy a directory tree that holds Unix socket files somewhere inside. As Unix sockets cannot be copied, when I use copy-directory, the copy-file function used by copy-directory throws an error because it cannot copy the Unix socket…

PRouleau
- 744
- 3
- 10
0
votes
3 answers
Convert old advise ad-set-arg to new advice
How would I convert the following old style advice to a new style advice?
(setq python--pdb-breakpoint-string "import pdb; pdb.set_trace()")
(defadvice compile (before ad-compile-smart activate)
"Advises `compile' so it sets the argument COMINT…

Lorem Ipsum
- 4,327
- 2
- 14
- 35
0
votes
2 answers
Unusual behavior when overriding `calculate-lisp-indent'
I've modified calculate-lisp-indent as a better solution to the indentation questions here, here and here. By "modified" I mean I overrode the function with advice. After doing this when I restarted emacs and I tried to indent a lisp form, I'd get…

Aquaactress
- 1,393
- 8
- 11
0
votes
2 answers
Adding advice to interactive functions
I want to add advice to `describe-function'. However, when I try to do so, I get an error due to wrong number of arguments. Function:
(defun describe-function-advice (function) …

Realraptor
- 1,253
- 6
- 17