Questions tagged [interactive]

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

Emacs-Lisp functions are made interactive (i.e., commands, which are invocable usingM-x or a key binding) by placing an interactive spec (a special form) in the function definition. The spec provides the actual arguments to the command. The argument to the spec is either a literal string with predefined codes) or a sexp that is evaluated to return the list of actual arguments.

144 questions
25
votes
1 answer

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 ? Also, can there be two separate code path for doing…
Sibi
  • 3,603
  • 2
  • 22
  • 35
16
votes
1 answer

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, I get the error: [no match] in the…
Tyler
  • 21,719
  • 1
  • 52
  • 92
15
votes
3 answers

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/file followed by M-x R to launch an R…
David LeBauer
  • 433
  • 2
  • 10
13
votes
1 answer

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 recognizes the universal argument. More specifically, I…
kjo
  • 3,145
  • 14
  • 42
12
votes
4 answers

How can I read a single character from the minibuffer?

When part of a defun, (interactive "c(C)hoose (A)n (O)ption") will prompt the user for a single character; RET is not required. How can I replicate this reading behavior without the need for interactive?
Sean Allred
  • 6,861
  • 16
  • 85
12
votes
3 answers

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 "P") do?
11
votes
1 answer

Is it possible to read user input from STDIN while tangling a source block?

Is it possible to read user input from STDIN while tangling a source block with org-babel-tangle? I am aware of this: Org Mode Babel - Interactive code block evaluation. That doesn't help solve this particular use-case, as it still doesn't allow…
gsl
  • 1,742
  • 17
  • 34
9
votes
1 answer

ielm, bound to a certain buffer

Is there a way to run ielm, but with variables bound to a certain buffer? I know about M-:, but having a shell like ielm to inspect things would be much easier.
ustun
  • 193
  • 4
9
votes
1 answer

call interactive function from elisp code without worrying about arguments

So, I want to do (ispell-change-dictionary) inside a function I'm writing, but doing a test throws this error: (wrong-number-of-arguments #[(dict &optional arg) I was told that M-x calls the function without arguments. Well, I did the same but for…
shackra
  • 2,702
  • 18
  • 47
8
votes
1 answer

Default argument for interactive function?

Using (interactive "sPROMPT: ") one can set a prompt for, e.g., a string function. Question: Is it possible to also supplement a default argument to the function? Say (interactive "sPROMPT: default") so that the users can supply "default" as the…
George
  • 879
  • 5
  • 17
8
votes
1 answer

Insert character by its Unicode name

From the documentation of insert-char, I cannot see why (insert-char "GREEK SMALL LETTER EPSILON") doesn't work. Is there a non-interactive way to insert a character given its Unicode name?
Toothrot
  • 3,204
  • 1
  • 12
  • 30
7
votes
3 answers

Near-identical commands on multiple keys

Visual Studio has this nice feature where you can put the point on something, press C-f3 and it'll both find the next instance of the thing under the point and it'll remember it. You can then press f3 to find the next instance, and S-f3 to search…
MikeTheTall
  • 659
  • 4
  • 11
7
votes
3 answers

How to search for lines not containing some text?

In a large file, I want to find which lines which do not contain a given string, grep -v basically. M-x grep helps, but it forces to protect special characters, is not interactive nor incremental, and doesn't let me edit the file at matches. How to…
Nikana Reklawyks
  • 322
  • 4
  • 15
6
votes
1 answer

Why does multiple cursors use the same char for all cursors with zap-to-char but not with zap-up-to-char?

This a follow up to my earlier question Why does multiple-cursors use the same char for all cursors with iy-go-to-char, but not with zap-up-to-char?. As I describe in that question, for some commands that prompt for a character in the mini-buffer…
Omar
  • 4,732
  • 1
  • 17
  • 32
5
votes
1 answer

Combine two interactive functions

For example, I want to sort a file, then remove the duplicate lines. I run M-x sort followed by M-x delete-duplicate-lines. I wanted to combine them into a single interactive function. Here is an attempt at solving this. (defun sort-and-dedup () …
nomad
  • 247
  • 1
  • 6
1
2 3
9 10