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`.

While the tag is properly spelled as the noun , the Emacs manuals and Stack Exchange questions also use advise(the verb form) and advising. Try these alternate spellings when searching.

Useful Link:

99 questions
55
votes
4 answers

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 can be used to add/remove code on any function-carrying…
itsjeyd
  • 14,586
  • 3
  • 58
  • 87
31
votes
1 answer

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 how to actually use it. Can anyone here point me to…
PythonNut
  • 10,243
  • 2
  • 29
  • 75
18
votes
3 answers

before-save-hook for cc-mode

I want to customize cc-mode to execute a function before saving. One solution would be to modify cc-mode keymap to bind C-x C-s to a function which performs the work I need and then saves it. My question is whether there is a hook I could customize…
Pradhan
  • 2,330
  • 14
  • 28
14
votes
1 answer

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 nomessage nosuffix must-suffix) args (list file…
PythonNut
  • 10,243
  • 2
  • 29
  • 75
12
votes
3 answers

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 making any assertions regarding those members not…
Aaron Miller
  • 552
  • 2
  • 12
12
votes
3 answers

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. How is this done in Emacs Lisp? NB: The ideal…
kjo
  • 3,145
  • 14
  • 42
11
votes
5 answers

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 modification. Is there a hook or function I can…
rationalrevolt
  • 213
  • 1
  • 4
11
votes
3 answers

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. Fixed it and evaluated above code again. But now I have…
Daniel Jour
  • 415
  • 2
  • 10
11
votes
1 answer

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 "aFunction symbol:") (advice-mapc `(lambda (fun props)…
Tobias
  • 32,569
  • 1
  • 34
  • 75
9
votes
2 answers

List advice for functions

I had a look over the weekend, and I cannot see an easy way to check whether a function is advised. I must be missing something. HELP! :)
Realraptor
  • 1,253
  • 6
  • 17
9
votes
1 answer

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 `qux' to t when running `foo'." (let ((qux t)) …
8
votes
2 answers

Change focus to *Help* buffer after running describe-mode

When I type C-h m for describe-mode the frame splits into two windows with the current buffer on top and the *Help* buffer below. But the focus stays in the current buffer, so I usually have to type C-x o to move focus to the *Help* buffer, and then…
Håkon Hægland
  • 3,608
  • 1
  • 20
  • 51
7
votes
3 answers

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 customized behavior altogether, and run the original,…
kjo
  • 3,145
  • 14
  • 42
6
votes
1 answer

Is there a "switch to buffer" hook?

I'm running emacs 26.3. I want to run a hook every time I switch to a buffer. However, I have not been able to find any kind of "buffer switch hook". If I want to always run a function when switching to a buffer, do I have to do something like…
HippoMan
  • 582
  • 2
  • 11
6
votes
1 answer

How to automatically kill a shell buffer when the shell process exits

In shell-mode when you exit the shell process (e.g. by typing exit) the buffer still hangs around (with the message "Process shell<1> finished"). How can I automatically kill the shell buffer when the shell process exits? (1) Is there a package…
halloleo
  • 1,215
  • 9
  • 23
1
2 3 4 5 6 7