Commands are functions that can be invoked interactively either through `M-x` or by a key binding.
Questions tagged [commands]
167 questions
43
votes
1 answer
What is the difference between a function and a command?
When posting questions and answers here, people sometimes use the terms "function" and "command" interchangeably. In other cases, people only use one of the two terms to discuss specific pieces of code. As their posts usually focus on other topics,…

itsjeyd
- 14,586
- 3
- 58
- 87
20
votes
2 answers
How to find out what command I just accidentally ran with a keyboard shortcut?
Is there a place where emacs stores commands the user has recently executed, in particular via keyboard shortcuts, and if not, would it be possible to tell it to store them somewhere? I sometimes type the wrong keyboard shortcut by accident and I…

Zorgoth
- 810
- 6
- 14
18
votes
2 answers
How can I test and use a Perl regular expression interactively?
Say I have a buffer with text. I would like to test a regular expression (ideally Perl type) against my buffer and have Emacs highlight the matches on it.
For example, the following regexp (taken from Wikipedia):
(?<=\.) {2,}(?=[A-Z])
would match…

Amelio Vazquez-Reina
- 5,157
- 4
- 32
- 47
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
14
votes
1 answer
Turning active M-! into M-& (a'ka emacs equiv to bash Ctrl-Z)
From time to time I happen to M-! some_command just to find that the command runs longer than I expected and keeps my emacs frozen for long seconds. So I glaze at my frozen emacs and kick myself for not using M-& some_command and promise myself to…

Mekk
- 1,017
- 7
- 14
13
votes
1 answer
How to use 'interactive' arguments when calling the command from code
I have a command called test which simply takes an input from the user and echoes it back:
(defun test (input)
(interactive "MInput: ")
(message "%s" input))
I want to write another function which would call it. The following fails:
(defun…

Pradhan
- 2,330
- 14
- 28
12
votes
4 answers
Get output of external command in the buffer
How do I get the output of (shell-command "df") (or some other more complex command, that I don't want to retype often) in the current buffer?
I run it by typing C-c p after it, but then it opens another buffer and sends the output there.

Yiang Xin
- 129
- 1
- 3
8
votes
3 answers
How can I customize the compile command?
In one of my projects I need to run make package install when building instead of make. It remembers the last compile command I used, but resets to make -k every time emacs starts up. How can I customize M-x compile to default to make package…

Connor
- 1,591
- 1
- 19
- 26
8
votes
2 answers
Exit minibuffer and execute a command afterwards?
I am trying to bind a key in minibuffer-local-map to a command which uses
abort-recursive-edit or exit-minibuffer and then proceeds executing more elisp code. So I want to exit the minibuffer and then continue from the context before. The only…

clemera
- 3,401
- 13
- 40
8
votes
2 answers
How to see which functions are executed
When I do something inside Emacs, with the buffer *Messages* you get some idea what happened. But it's only if that function is echoing a message for the minibuffer. Then *Messages* keeps a record of messages that are echoed.
I remember there was a…

ReneFroger
- 3,855
- 22
- 63
8
votes
1 answer
Is there a column equivalent of `C-l`?
The command C-l scrolls the current line to center, top, bottom. Is there an analogous command that scrolls the current column to center, left, and right?

Brian Fitzpatrick
- 2,265
- 1
- 17
- 40
8
votes
3 answers
Swap default behavior of command with C-u behavior
Many Emacs commands alter their behavior when called with one or more C-u prefixes. In some cases the default behavior of a command is less useful to me than the behavior I get when prefixing it with C-u. At the same time, I do not want to get rid…

itsjeyd
- 14,586
- 3
- 58
- 87
8
votes
5 answers
Sum numbers in region
How can I sum a set of numbers interspersed with text in the region (not a rectangular region). For example, if the region contains this text:
Widgets 234
Sprockets 44
Nubbins 12
Fork handles 4
4 Candles
I'm looking for a command that will report…

Croad Langshan
- 3,192
- 14
- 42
7
votes
1 answer
Getting the key binding for the current command
this-command-keys and this-command-keys-vector return the entire key sequence that fired the current command. However, such sequence will contain any prefix argument, too. Is there a function or variable - let's call it this-command-key-binding -…

Eleno
- 1,428
- 11
- 17
7
votes
3 answers
lazy find/search for commands within emacs
Is there a way to do a lazy find/search within EMACS, for commands using their description?
Something in the lines of:
Say I am looking for how to add indent to org mode
I suspect there is a commands for it
I would like to type "org" and "indent"…

Pandian Le
- 260
- 3
- 13