Skip to main content

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
1 answer
29 views

How do I write an advice to override an org-roam function?

I have an issue with org-roam graph https://github.com/org-roam/org-roam/issues/2427 . How do I write my config so that I do not have to patch the org roam code each time the org-roam gets update or I ...
ruby_object's user avatar
1 vote
2 answers
44 views

How to create an independent copy of a function's definition?

I want to create a modified copy of re-search-forward and advise this copy to be sensitive to isearch-filter-predicate. I tried: (defun make-search-sensitive-to-ifpmod-advice (orig-fun &rest args) ...
Gabriele's user avatar
  • 1,662
0 votes
0 answers
32 views

Eager macro-expansion failure: (wrong-type-argument integer-or-marker-p nil)

I have this code: (defun make-search-sensitive-to-ifpmod-advice (orig-fun &rest args) "Temporary advice the search functions to make them sensitive to `isearch-filter-predicate'" (...
Gabriele's user avatar
  • 1,662
1 vote
1 answer
37 views

Can I override a function in a function using a closure?

I want to build a modified version of the occur command that obeys to isearch-filter-predicate. I made some tests and I found that I can do it using a modified version of re-search-forward that I ...
Gabriele's user avatar
  • 1,662
0 votes
1 answer
45 views

Calling a function interactively without adding it to the command history

In some cases, I often run the same command, say my-common-fun, which I call subsequently with M-x M-p RET, and occasionally run another command, such as my-occasional-fun. I want to call the latter ...
emonigma's user avatar
  • 1,907
1 vote
2 answers
121 views

Translating `defadvice` to `advice-add` for modification of modes

With Emacs 30.1 defadvice has become obsolete, and one should use advice-add or define-advice instead. The Emacs-manual outlines how to transition from defadvice here. I understand the principle of ...
Alexander Praehauser's user avatar
0 votes
1 answer
26 views

browse-url: replace \% with % in the url argument

Short version: how can I make sure that \% strings are replaced by %, in the url argument of browse-url? Long version: In LaTeX, URLs that appear in \url{} macros need to have any % character escaped ...
pglpm's user avatar
  • 325
0 votes
1 answer
54 views

Using advice-add to redefine a function call within another function

The function outshine-cycle (part of Outshine) calls the function indent-relative. I would like that instead, it called the function indent-for-tab-command. To do this, I want to advise the function ...
scaramouche's user avatar
  • 1,754
0 votes
1 answer
58 views

use keyboard in org calendar

I want to use keyboard when selecting a date in calendar (while setting deadline or schedule in org mode). The cursor is set to nil and it's not visible where the cursor is. I've tracked down the code ...
eugene's user avatar
  • 499
6 votes
2 answers
224 views

Call function without calling advice defined on it

I sometimes want to bypass the advice I have defined on some function. Something like: (call-without-advice #'fn ...)
HappyFace's user avatar
  • 830
0 votes
2 answers
78 views

How do you handle an error in the scope of current-buffer with condition-case?

I would like to create headings and subheadings with org-capture if they don't exist with file+olp in my templates. The problem is that I get this message Heading not found on level 1. I'm not sure ...
Rick's user avatar
  • 25
2 votes
1 answer
235 views

How to override a function in a function only in that function?

I used (advice-add 'yas-new-snippet :override 'my/yas-new-snippet ) but I was wondering if there was something like this which would allow me to override a function in a function only in that function:...
ritchie's user avatar
  • 169
0 votes
2 answers
26 views

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-...
John Graham's user avatar
3 votes
0 answers
71 views

How to advise a CL method?

I am familiar with setting advice on a function: (advice-add 'some-tag :before 'function-being-advised (lambda (arg) (message "In advice with arg: %s" arg))) How do you advise a ...
Troy Daniels's user avatar
0 votes
0 answers
105 views

How can I advise a cl-defgeneric method?

There's a bug in eglot.el where initialisation options aren't handled, so I can't set the initialisation parameters for a given server; that is causing me problems because the language server I'm ...
cl-defgeneric's user avatar
0 votes
1 answer
35 views

`ido-find-file` always trigger `ido-reread-directory`

Tried following this answer, but did not work on Emacs27 (defadvice ido-find-file (before auto-refresh-ido nil activate) (setq ido-rescan t)) Also tried but did not work because when ido-reread-...
phoxd's user avatar
  • 231
6 votes
1 answer
2k views

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 ...
HippoMan's user avatar
  • 616
1 vote
2 answers
390 views

Using defadvice to add an interactive argument to a non-interactive function?

Is there a way to wrap a non-interactive function within defadvice so that the new function can accept an interactive argument which can alter the way that the wrapped function gets called? In other ...
HippoMan's user avatar
  • 616
1 vote
1 answer
275 views

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 ...
Alex028502's user avatar
4 votes
1 answer
104 views

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 ...
Gauthier's user avatar
  • 509
5 votes
1 answer
138 views

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) (...
alper's user avatar
  • 1,400
0 votes
1 answer
45 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 ...
PRouleau's user avatar
  • 831
0 votes
1 answer
98 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 ...
Tyler's user avatar
  • 22.4k
0 votes
0 answers
82 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. ...
Wilder's user avatar
  • 95
4 votes
2 answers
185 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 (...
Flux's user avatar
  • 603
0 votes
1 answer
164 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 ...
Flux's user avatar
  • 603
0 votes
1 answer
461 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 ...
Paul Gowder's user avatar
3 votes
1 answer
101 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!&...
Daniel Vartanov's user avatar
1 vote
1 answer
66 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 ...
Saddle Point's user avatar
0 votes
0 answers
48 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 ...
Aleksandar Dimitrov's user avatar
0 votes
2 answers
559 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 ...
Adam's user avatar
  • 1,907
1 vote
2 answers
234 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....
GreenLlama's user avatar
3 votes
1 answer
585 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) (...
Tohiko's user avatar
  • 1,649
0 votes
3 answers
85 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) "...
Lorem Ipsum's user avatar
  • 4,527
1 vote
0 answers
63 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? ...
scaramouche's user avatar
  • 1,754
1 vote
1 answer
94 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) #+...
extremeaxe5's user avatar
3 votes
1 answer
300 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 ...
ideasman42's user avatar
  • 8,846
3 votes
1 answer
198 views

How does one "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 ...
not-just-yeti's user avatar
2 votes
1 answer
461 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 ...
kdb's user avatar
  • 1,571
0 votes
2 answers
203 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 ...
Aquaactress's user avatar
  • 1,453
1 vote
0 answers
37 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) ...
Aquaactress's user avatar
  • 1,453
6 votes
2 answers
3k 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, ...
iLemming's user avatar
  • 1,273
6 votes
1 answer
823 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 ...
halloleo's user avatar
  • 1,345
3 votes
1 answer
411 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) (...
nalzok's user avatar
  • 675
2 votes
1 answer
195 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 ...
nalzok's user avatar
  • 675
1 vote
2 answers
110 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 ...
FalkH.'s user avatar
  • 11
1 vote
1 answer
79 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 ...
Toothrot's user avatar
  • 3,274
0 votes
2 answers
682 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) ...
Realraptor's user avatar
  • 1,293
1 vote
1 answer
102 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 ...
YuriAlbuquerque's user avatar
2 votes
1 answer
172 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 ...
std_answ's user avatar
  • 191