Questions tagged [defadvice]

defadvice is a macro defined in ELisp. It provides a mechanism to wrap existing functions and have the wrapper called instead of the original function.

defadvice provides a mechanism for the user to define a function to be called before, after or around an existing function; instead of that existing function. It is analogous to the CLOS method combination system.

Multiple advices can be placed upon a function and they will combine to all be called. First all before methods are called, then all around methods, then all after methods. Methods are called in the order of the defadvice. Around methods can decide to terminate and not call any other methods - thus circumventing the original method and any other advice.

29 questions
7
votes
3 answers

Emacs - Skip whitespace kills

I'm trying to make the kill ring essentially ignore whitespace only entries (tabs, newlines, just spaces, etC), I'm fairly new to elisp and I'm pretty sure the way to do is by doing defadvice but I have a few questions. Would it better to stop…
user652650
  • 648
  • 6
  • 18
6
votes
5 answers

Emacs/Emacs Lisp: can I insert advice before interactive form? or how to intelligently pre-set the compile-command?

What I'd like to do is intelligently pre-set a buffer-local default value for the string argument to the compile function. Right now compile.el defaults to using "make" as the command. I can set this by setting compile-command. I can even make…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
6
votes
5 answers

Advising an emacs interactive function: before

I want to before-advice some function, which uses interactive arguments, e.g. find-dired: (defadvice find-dired (before eab-find-dired activate) (message "before!") (setq find-args '("-iname '**'" . 10))) But emacs executes this advice only…
artscan
  • 2,340
  • 15
  • 26
6
votes
2 answers

how to change variables for specific fundamental-mode buffers

Goal: I want to have show-trailing-whitespace enabled for all buffers save a few. Exceptions posing a problem are *Shell Command Output* and its cousin *Async Shell Command*. I usually have show-trailing-whitespace customized to t. Therefore it is…
Moritz Bunkus
  • 11,592
  • 3
  • 37
  • 49
6
votes
4 answers

emacs: How to use the mark-ring?

When I do a C-u C-SPC, emacs takes me to "where I was before". Subsequent C-u C-SPC presses go back up previous places. That is damn great, and I use it a lot. But something always bugged me : The only mark missing from the mark-ring is…
yPhil
  • 8,049
  • 4
  • 57
  • 83
5
votes
4 answers

Emacs defadvice on python-mode function

In python-mode, there is a function called py-execute-region which sends a highlighted region of code to the Python buffer for evaluation. After evaluation, the cursor is in the Python buffer, but I would prefer that it remain in the script buffer…
hatmatrix
  • 42,883
  • 45
  • 137
  • 231
5
votes
1 answer

Emacs Lisp, how to mapcar a macro, and evaluate one of the arguments

Bob Glickstein describes in "Writing GNU Emacs Extensions", chapter 3, a way to advise scroll functions. (He suggests to make them reversible, so we have to save the state before scrolling.) E.g. for scroll-up-command this advising is done like…
Falko
  • 1,028
  • 1
  • 12
  • 24
5
votes
1 answer

What does ad-activate do?

In an answer, I noticed: ;; Align with spaces only (defadvice align-regexp (around align-regexp-with-spaces) "Never use tabs for alignment." (let ((indent-tabs-mode nil)) ad-do-it)) (ad-activate 'align-regexp) This sounds promising, but...…
Michel de Ruiter
  • 7,131
  • 5
  • 49
  • 74
4
votes
1 answer

How to advise primitives in Emacs

I was trying to answer another SO question when I hit upon some very odd behavior. Here's my little test case: (make-variable-buffer-local (defvar my-override-mode-on-save nil "Can be set to automatically ignore read-only mode of a file when…
Joe Casadonte
  • 15,888
  • 11
  • 45
  • 57
4
votes
1 answer

Emacs cursor movement advice

I have written a minor mode that highlights various parts of the buffer as the cursor moves around the buffer. I do this by advising the movement functions like this. ... (defadvice next-line (after showcss/advise-main) "Advice around cursor…
Sheldon
  • 43
  • 3
4
votes
1 answer

How can I locate the defadvice for an advised function in Emacs?

When I view documentation for beginning-of-defun, there is a note: This function is advised. Around-advice `senator': Move backward to the beginning of a defun. If semantic tags are available, use them to navigate. However I can't find in which…
Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
3
votes
2 answers

Org-mode get the content of src block during export

Here's what I'm trying to do: I have a snippet of JavaScript code that I want to both display in the HTML generated from an org document and I want that code to be executed in the HTML page. For a simplistic example, let it be something like …
user797257
3
votes
2 answers

Write-only buffer?

I would like to imitate the way how most consoles work in a buffer, is there any way to do that? I.e. only allow appending text to the buffer, but not deleting? Probably I could disable or advise some built-in functions which delete characters, but…
user797257
3
votes
5 answers

trigger advice on a function only when called from a certain other function

I am trying to work around the restriction that dired-do-shell-command (bound to !) cannot be called on current and parent directories . and ..'. The stack-trace is pasted at the bottom. I can define an advice as below to bypass this…
Miserable Variable
  • 28,432
  • 15
  • 72
  • 133
2
votes
2 answers

How do I advise py-execute-buffer in emacs to run py-shell before the function?

I'd like to be editing a buffer or file, hit C-c C-c and have the file sent to an IPython session. I can accomplish this now if I first run M-x py-shell before running py-execute-buffer via C-c C-c. But if I try to advise the function…
aresnick
  • 1,635
  • 12
  • 24
1
2