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
1
vote
1answer
24 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, ...
4
votes
1answer
78 views

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 ...
2
votes
1answer
39 views

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) (...
1
vote
1answer
24 views

“void-variable” error when adding advice to `kill-ring-save`

I am trying to add an advice to kill-ring-save and kill-region, so that when I call them with no active regions, instead of throwing an error, the line the point is currently on would be marked ...
1
vote
2answers
26 views

advice-add FOR function dired-do-copy

I got a problem for an advice-add inside Dired's copy function (dired-do-copy). My object is it to filter all marked files/directories in Dired, which should be copied to an other location within ...
0
votes
1answer
22 views

Hooking on to abbreviation expansion

I don't know exactly how abbrev-mode works, but I suppose certain keys --spaces and stops-- cause an examination of the word before point, and a replacement of it in some cases. My question is how ...
0
votes
1answer
99 views

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) ...
1
vote
1answer
46 views

Using an advice to set default parameters in a interactive function

I'm not sure if this is possible or if there's a workaround for it, but I want M-x erc to set the password after I try to call it, but before I input the actual parameters. What I originally had in ...
1
vote
1answer
85 views

Using advice to run function before tag symbol lookup

I use xref-find-definition to look up the definition of a symbol name. When I call xref-find-definition, I want to Emacs to automatically find and load an appropriately named etags file. For this ...
0
votes
1answer
69 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 ...
1
vote
0answers
67 views

advise around org-add-note behaves differnt in Windows and macOS

I have the following in my init.el file: (defun my::with-no-drawer (func &rest args) (interactive "P") (let ((org-log-into-drawer (car args))) (funcall-interactively func args))) ...
2
votes
1answer
296 views

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! :)
1
vote
2answers
122 views

Adding advice to an autoloaded function

I want to add advice to an alias to a function in an internal elisp package at work, gating the logic on a variable. Both the function and the alias is marked autoload. Conceptually: ;;;###autoload ...
2
votes
1answer
207 views

buffer-local advice

I am trying to create a buffer local advice to run some code when a minor mode is disabled. I looked through the documentation for add-function and saw this If PLACE is a symbol, its `default-value' ...
3
votes
1answer
58 views

Should the sharp quote should be used for the first argument of advice-add?

... when a symbol referencing a function is actually used? Documentation states: Like ‘add-function’ but for the function named SYMBOL. Contrary to ‘add-function’, this will properly handle the ...
0
votes
1answer
129 views

Error when trying to advice python-shell-send-string

I'm trying to write advice such that each time I eval a python snippet, it automatically output the exception time in the emacs python shell (defun python-send-with-time-record (orig-func string &...
1
vote
1answer
39 views

Creating a new function based off exisiting one

I apologize if this is a duplicate, but the essence of the question is whether it is possible to create "around" advice for an existing function and bind that to a new one. In my case, I'm trying to ...
2
votes
0answers
182 views

How to set the colors for pdf-tools annotations individually?

I would like to be able to set the annotation colors to be different (e.g. strike-out "black" while keeping highlight "yellow"). I asked about this as an issue at the github page for pdftools and was ...
2
votes
0answers
47 views

How to find out what advice has been defined for a function?

I accidentally added a lambda function that wasn't done being written to the advice of a function, and the function doesn't work. I don't know the exact text of the lambda function. Obviously, I could ...
2
votes
2answers
78 views

Monkey patch and restore builtin set-window-dedicated-p during advice

I would like to make set-window-dedicated-p a NOP when called from xref--show-pos-in-buf. Below is an attempt to do so using advice. It doesn't work, I think because fset is not really copying the ...
0
votes
1answer
269 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 '...
1
vote
1answer
147 views

Argument Access in Advice

In the documentation, two ways are suggested for accessing arguments in an advice: by the name of the argument in the original function and by using special functions. I cannot get the second way to ...
1
vote
1answer
113 views

How to indicate if narrow-to-region is currently in effect

I have advised the narrow and widen functions so that the fringe color indicates if narrowing is active: (advice-add 'narrow-to-region :after '(lambda (&rest args) (set-...
10
votes
3answers
385 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. ...
1
vote
0answers
35 views

How to eliminate all advice from function? [duplicate]

Is there a way to remove all advice added to a function with advice-add? advice-remove requires the original function to be passed in. Sometimes, when experimenting w/ advice, I'll add several ...
1
vote
2answers
474 views

After-advice for disabling evil-mode in ansi-term has no effect

I'm using evil-mode and trying to make sure that it gets disabled after invoking an ansi-term. I've tried using before and after advice to advise the ansi-term function, as well as adding a hook to ...
3
votes
0answers
398 views

mu4e without mu server process

Occasionally I get error from mu4e error in process sentinel: Database is locked by another process. To solve this issue I usually end up to kill the process in list-process or sometimes pkill emacs ...
0
votes
0answers
44 views

Using advices to flatten a single subfolder

One of Github's features i like is that it "flattens" path if a folder contains only one subfolder, i.e you have a src folder which has only main folder, so by clicking on src you go to the content of ...
2
votes
0answers
169 views

Faces not set immediately after load-theme

I'm trying to set the faces of highlight-indent-guides automatically whenever a new theme is loaded by making small adjustments to the background color of the default face. I have everything working ...
2
votes
1answer
69 views

Constructing an advice around org-html--wrap-image

This is a follow-up question from a previous thread The function org-html--wrap-image adds a <p> tag around its contents, as you can see here: ELISP> (org-html--wrap-image "bla" t) "\n<...
2
votes
1answer
33 views

Which function should I advise to do something when a user-error is unhandled?

I need to advise emacs to do something when any error dings to the user. I can't find any documentation on which function I actually need to advise. Which function do I need to advise to do ...
2
votes
2answers
212 views

Trace calls to a function with the parameters

I need to track the calls to org-tags-view to discover the params passed to it. I tried an advice: (defun his-tracing-function (orig-fun &rest args) (message "org-tags-view called with args %S" ...
0
votes
1answer
70 views

What is the best way to redefine the indentation rules of a major mode

I am using js-mode in emacs 25.1. There are some indentation rules that are not editable through the provided customization variables. The specific one I have issue with is the indentation of arrow ...
1
vote
1answer
145 views

Can you intercept a function and return your own value using advice?

Is it possible to use advice to not only run your function first, but also prevent the advised function from running at all? For example, say a command ordinarily calls read-from-minibuffer to get a ...
2
votes
1answer
114 views

How to automatically select an option in a specific prompt?

When I'm programming Python, I will use rope to rename variables (using ropemacs). rope-rename pops up a dialogue after you provide a new variable name, where you can preview the change, cancel, or ...
3
votes
2answers
188 views

One-time advice

I've been trying to a macro to put one-time advice on a function. What I mean by one-time advice is advice which removes itself after it is called – so that when you add the advice and run the ...
0
votes
0answers
34 views

Updating advice in function

I've noticed that if function f is used to advise function g through advice-add, and function f is then redefined, function g's advice is not updated. After digging into advice-add a bit, it is clear ...
4
votes
1answer
446 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 "...
5
votes
2answers
133 views

Shallowly override functions within a target function

I'm exploring options for monkey-patching and I'm wondering if the following is within reason. I would like to override a particular function within some target function so that calls within the ...
1
vote
0answers
105 views

Find where advice is defined (defadvice)

When a function documentation page tells me that a function has advice, is there any way to find out where that piece of advice is defined? This is advice that was created using the defadvice ...
0
votes
1answer
47 views

Problem about `evil-visual-state` and advising `read-key-sequence` with `call-process`

In Evil mode, after I enter visual-state, I can use f to expand the selection by jumping to a character. Now if I've pressed f after entering visual-state, Emacs asks me to input a character to jump ...
3
votes
1answer
288 views

Defining advice for cider-interactive-eval for evil compatibility

Cider offers very useful debugger for clojure code. Once you enter the debugger, you can step through it with keys like (n)ext, (o)ut, etc., like so. Using evil, the problem is that if I enter this ...
4
votes
3answers
414 views

Call a function before a specific major mode starts

I have a setup function that I want to run before I use pdb/gud to debug a Python script. I know about gud-mode-hook which runs after the debugger starts (too late) and change-major-mode-hook which, ...
2
votes
2answers
100 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 ...
12
votes
2answers
616 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 ...
10
votes
3answers
854 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....
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 ...
3
votes
0answers
49 views

Passing advice to mode line

I'd like to advise format-mode-line to collapse whitespace across the whole string. The following attempt does not work for me. (advice-add 'format-mode-line :filter-return 'collapse-whitespace) ...
2
votes
2answers
93 views

in org-mode, how to move point to next checkbox when it's marked completed?

I work with org-mode checkboxes, marking them as completed as I go. * TODO clean kitchen - [X] sink - [ ] stove - [ ] floors I want org to move point to the next checkbox when when it gets marked - ...
7
votes
1answer
1k 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 ...