Questions tagged [advice]

is for the Elisp advice feature that changes an existing definition of a function in a way that lets you undo the change easily. This tag applies to both old and new advice features. The old advice feature uses `defadvice`. The new advice feature uses functions and macros such as `advice-add` and `add-function`.

Filter by
Sorted by
Tagged with
52
votes
4answers
4k views

Practical benefits of new advice system in Emacs 24.4

Emacs 24.4 comes with a new advice system. The NEWS file says: ** New package nadvice.el offers lighter-weight advice facilities. It is layered as: *** add-function/remove-function, which ...
29
votes
1answer
3k views

How do I use nadvice?

My config is full of advice, and I keep hearing about the new shiny minimalist nadvice.el package. I've searched the manuals, and I've read the source, but I'll openly admit: I still have no idea ...
3
votes
3answers
160 views

Sort of autoreply for specific messages in minibuffer

Every time when I call M-x projectile-regenate-tags I get bothered with the message Tags file a:/foobar/TAGS has changed, read new contents? (y or n) which is quite cumbersome. Especially when I ...
10
votes
3answers
1k views

How to write a transparent “pass-through” function wrapper?

What I mean by a "transparent 'pass-through' function wrapper" is a function, let's call it wrapper, that returns the result from passing all its argument to some other function, let's call it wrappee....
7
votes
1answer
2k views

Override a function locally, but allow calls to the original function

The advice feature allows modifying the behavior of a function globally. An advice definition can make calls to the original function. (defadvice foo (around foo-bar activate compile) "Always set ...
6
votes
1answer
677 views

Unadvise a function (remove all advice from it)

I cannot find a predefined command in nadvice to easily unadvise a function in Emacs 24.5.1. Something like: (defun advice-unadvice (sym) "Remove all advices from symbol SYM." (interactive "...
14
votes
1answer
630 views

Emacs let-bound advice

I'd like to temporarily override a function in a piece of code. Take, for example, the following: (defun nadvice/load-quiet (args) (cl-destructuring-bind (file &optional noerror ...
10
votes
5answers
1k views

How to enter view-only mode when browsing Emacs source code from help?

When I browse Emacs help for functions via C-h f, I often want to peek into the Elisp/C implementation. I want to enter view-mode automatically when I access source code this way to avoid unnecessary ...
6
votes
3answers
1k views

How to bypass (or disable) a command's “advice”?

In my .emacs I have an expression of the form (defadvice find-file ...) ...which modifies the behavior of the standard find-file command. There are times, however, when I want to bypass this ...
12
votes
2answers
750 views

How to manipulate argument list in nadvice.el?

Following on from an answer to another question about the new advice system: In old-style advice.el, it was possible to manipulate individual members of an advised function's argument list, without ...
2
votes
1answer
378 views

Monkey patching a function

Some context: I'm doing some linux kernel development on a Debian VM so naturally I'm using tramp. I want to use semantic-symref, but the trouble is that: Semantic will eventually call cedet-gnu-...
12
votes
3answers
518 views

How can I remove an unnamed advice?

I was having fun adding some advice to a function: (advice-add 'executable-find :around (lambda (f &rest args) (apply g args))) ;;; ^ Ouch, a typo. ...
5
votes
2answers
495 views

Getting electric-pair mode to behave more nicely around existing strings

Electric-pair-mode always tries to insert a closing delimiter after the opening one if nothing is selected. However, if you're placing delimiters around an existing something that you don't want to ...
4
votes
2answers
220 views

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, ...
2
votes
2answers
113 views

On monkey-patching a third-party function

The following snippet, featuring the "fantasy function" clone-function, illustrates what I'd like to do: (defvar last-enabled-foo nil) ;; hold on to a "clone"/copy of third-party function enable-foo ...
0
votes
1answer
341 views

Run command after each type/insert in particular buffer

I'm implementing a (optional, de-activable) real-time syntax checker. Each time the user types/deletes anything, I want to run my spell-checking funtion : I tried (add-hook 'post-self-insert-hook '...
0
votes
1answer
93 views

How to write this advice for inject code into let-binding?

I want to write an advice on original code. But don't know how to write it in my case. I just did some modification, and do an diff. Hope the you can understand what I need. Here is the diff ...
0
votes
1answer
43 views

What's the most effective way to modify this internal mode config?

markdown-mode defines tab-width using a magic number when loaded, overwriting any global settings I have (namely, 2 spaces): ;;;###autoload (define-derived-mode markdown-mode text-mode "Markdown" "...