Questions tagged [interactive]

`interactive` spec of an Emacs-Lisp command (function invocable using `M-x` or a key binding)

Filter by
Sorted by
Tagged with
13
votes
1answer
2k views

Why can't I bind my function to a key or call it with M-x?

I wrote a function, and I want to call it via M-x, and bind it to a key. This is my function: (defun my-function () (message "This is a great function")) If I try to call it with M-x my-function,...
9
votes
1answer
2k views

How to apply `call-interactively` to an interactive command that accepts the universal argument?

I've read the documentation on how to make interactive calls from within Elisp, but I still can't figure out how to pass the universal argument when using call-interactively on a command that ...
9
votes
3answers
2k views

What is a raw prefix argument? (capital P in interactive)

And what can they be used for? (interactive "p") takes a numerical argument from the universal argument right? And the universal argument is just an int either way, so what does capital (interactive "...
22
votes
1answer
2k views

Elisp for applying command to only the selected region

Say, I have some code like this: (defun some-function () (interactive) ;; do something ) Now I want some-function to operate only on the selected region in the buffer ? How can I do that ? ...
12
votes
2answers
918 views

Can Emacs use tramp to run in an interactive session on a remote HPC node?

I have been using Emacs with ESS and tramp to load remote files and run remote R processes on HPC computers. With ssh keys, tramp makes this easy with C-x C-f to find file at /ssh:myserver:/path/to/...
4
votes
2answers
234 views

Custom C-arrow cursor movement

I was not satisfied with the behavior of standard C-arrow and C-S-arrow, so I wrote this functions to replace standard ones. (setq separators-regexp "[\-'\"();:,.\\/?!@#%&*+=]") (defun forward-...
5
votes
1answer
449 views

log keystrokes with timestamp and other metadata?

If I evaluate this form: (open-dribble-file "/home/joe/keys.log") then type something, Emacs saves what I type to the keys.log file: <return>hellow<backspace> keyloggi<down-mouse-5&...
3
votes
4answers
864 views

How can I determine which function was called interactively in the stack?

Say I have two functions (defun tmp:a () (interactive) (tmp:b)) (defun tmp:b () (message "called from %S" "?")) If I call M-x tmp:a, how can I determine this from tmp:b?
2
votes
1answer
551 views

“Invalid use of '\' in replacement text” with non-interactive calls

It seems that replace-regexp has a different behavior if called interactively and not, but I do not understand why, and how to get the wanted behavior. What I want is the non-interactive equivalent ...
1
vote
1answer
77 views

Reuse other command's “interactive” form

Example, I want to define a package-open-homepage command, which reuses C-h P (describe-package)'s "interactive" form. I don't want to copy-and-paste because it is too long. The following (eval `(...
5
votes
1answer
314 views

Helm and custom commands

If I write a command that calls (interactive "f"), Emacs will prompt the user to select a file when the command is run interactively. With Helm enabled, this selection is done through Helm with no ...
5
votes
2answers
201 views

How to repeat a command immediately after calling it?

I've just called an interactive function (i.e., a command). I want to call it again, with the same arguments. I know that I can call a keyboard macro again by using e right after running it the ...
3
votes
1answer
269 views

How can I use an interactive function in a script?

I'm using virtualenvwrapper.el to load Python virtualenvs during emacs sessions. I would like emacs to start with a default one, so I don't have to load it manually every time. To load it manually, I ...
2
votes
1answer
286 views

how to parameterize prompt for interactive/command?

background I had elisp code (in this very small git repo) like (defun bulk-replace-file (filepath) (interactive "FPath to file to bulk-replace: ") (bulk-replace-file-non-interactive filepath) ) ...
0
votes
1answer
43 views

Prompt for command to reset variable to 1 or any other number

I have a command that semi-automates the insertion of numbered chapter headings in an org-mode file. (defun reset-counter () (interactive) (setq n 1)) (defun insert-numbered-chapter-headings () ...