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
0
votes
1answer
30 views

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 ...
0
votes
1answer
11 views

ESS: start R in current directory conflicts with ivy-mode

I use ivy-mode for completion. I don't usually want to see the dot files ("./" and "../") when selecting files/directories, so I've set (setq ivy-extra-directories nil). I also ...
0
votes
0answers
20 views

How to properly advise macros used by functions if earlier byte-compilation is present?

I am trying to customize the looks of org-agenda and, in order to do so, I would like to advice the macro org-agenda--insert-overriding-header; this macro appears to be used in several functions. ...
4
votes
2answers
108 views

How do I use an advice to change the definition of goto-char within a function?

Suppose a third-party plugin contains the following function: (defun example-function () (interactive) ;; ... do many things ... (goto-char (point-max)) ;; ... do many things ... (goto-char (...
0
votes
1answer
50 views

What does “Making browse-url-browser-function local to *eww* while let-bound!” mean?

I am using SLIME (which includes hyperspec.el). I wanted to view the HyperSpec using Emacs' EWW instead of the desktop web browser (e.g. Firefox, Chromium, etc.). To do this, I added an advice to set ...
0
votes
1answer
76 views

does advice :around always have to pass a list of args?

I'm new to elisp, and I'm struggling to figure out how to do advice. I got my code working, but I'm not sure why. This is from a real problem that I had digging into markdown mode to add an extra ...
3
votes
1answer
54 views

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!&...
1
vote
1answer
34 views

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 ...
0
votes
0answers
25 views

How do I stop checkdoc from flagging header/footer in org-src-edit buffers?

When editing Emacs Lisp source blocks in org-mode via org-src-edit, if flycheck is enabled (which I'd like to keep that way) checkdoc rather annoyingly remarks that I'm missing headers and footers and ...
0
votes
2answers
235 views

Add-advice :before org-edit-special

I want to advise org-edit-special so that a function runs before Emacs enters org-src-mode. I am not particularly tied to org-edit-special. If there is a hook like org-src-mode-hook (but that triggers ...
1
vote
2answers
134 views

Help with function advice: Unknown add-function location ‘asm-calculate-indentation’

I'm trying to modify how asm-mode does its automatic indentation. I thought I would use the following: (defun yasm-calculate-indentation (oldfun) "Add the formatting for a few other keywords I like....
1
vote
1answer
148 views

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) (...
0
votes
3answers
51 views

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) "...
1
vote
0answers
32 views

Get time since last keystroke

I would like to know how many seconds have passed since the last keystroke (or character that showed up in the screen, whatever is easier). Is there a timer that is associated to self-insert-command? ...
1
vote
1answer
33 views

Byte compilation still happening when `no-byte-compile` is t on adding advice

In org-mode, I have the following: #+BEGIN_SRC emacs-lisp :results scalar (setq no-byte-compile t) (defun f ()) (defun g ()) (add-function :before (symbol-function 'f) 'g) (symbol-function 'f) #+...
3
votes
1answer
130 views

How to add a locally override the message function?

I would like to add a suffix to a message reported by a function called in some source I don't maintain. Is there a way to locally override the message function so I can manipulate it before it's ...
2
votes
0answers
60 views

how to “extend” an existing function?

What I want to do: have the function evil-delete do one more task after its usual code. (I'm presuming that evil-delete is the underlying workhorse that is called by evil-delete-line and about five ...
2
votes
1answer
147 views

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 ...
0
votes
2answers
114 views

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 ...
1
vote
0answers
33 views

Why doesn't the window begin and end update after `outline-show-all`?

I'm using this test code. (defun +outline~show-all (orig-fn &rest args) "Show all." (let ((beg1 (window-start)) (end1 (window-end)) (beg2) (end2)) (apply orig-fn args) ...
5
votes
2answers
776 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, ...
5
votes
1answer
364 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 ...
3
votes
1answer
270 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) (...
2
votes
1answer
139 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
70 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
41 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
2answers
304 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
76 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 ...
2
votes
1answer
131 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
125 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
86 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))) ...
7
votes
1answer
763 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
278 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 ...
3
votes
1answer
541 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
82 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
211 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
44 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 ...
3
votes
0answers
349 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
65 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
124 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
384 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
326 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
344 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-...
11
votes
3answers
651 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
37 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
818 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
671 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
63 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
295 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
84 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<...