Questions tagged [commands]

Commands are functions that can be invoked interactively either through `M-x` or by a key binding.

Filter by
Sorted by
Tagged with
38
votes
1answer
3k views

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 ...
16
votes
2answers
2k views

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 ...
16
votes
2answers
796 views

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 ...
15
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,...
14
votes
1answer
157 views

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 ...
13
votes
1answer
2k views

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 ...
8
votes
4answers
1k views

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 ...
8
votes
2answers
1k views

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 ...
8
votes
1answer
77 views

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?
7
votes
4answers
5k views

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 ...
7
votes
2answers
456 views

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 ...
7
votes
1answer
205 views

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 ...
7
votes
3answers
4k views

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 ...
7
votes
3answers
210 views

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 ...
6
votes
2answers
1k views

Run shell commands in emacs by something similar to M-x …?

I have a program which can run as a command in bash. Can I run the program in emacs, in some way similar to run emacs' command (i.e.M-x , e.g. M-x occur), instead of first explicitly running a shell ...
6
votes
4answers
2k views

Repeating a command n times

For posting code to stackexchange I repeatedly have to do indentation in emacs. I mark a piece of text and then do M-X indent-rigidly four times. Is there an elegant way to do this indentation of text ...
6
votes
1answer
1k views

Display corresponding key binding of command during M-x completion

As an example, when I use M-x save-buffer Emacs says in the minibuffer: You can run the command ‘save-buffer’ with C-x C-s I'm using Swiper/Ivy; I want to know if there is a way to instruct Ivy to ...
6
votes
3answers
334 views

Is there a way to make the “o” keypress of other-window <C-x><C-o> repeatable?

Question is as stated in the title. Instead of using various packages for switching windows, it might be simpler to make <C-x><C-o> behave like <C-x><C-+>, such that repeated ...
6
votes
3answers
2k views

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 ...
6
votes
1answer
2k views

How can I change which shell script mode I'm in?

Occasionally, emacs opens a file in shell-script[fish] when I want it to open in shell-script[bash]. How can I manually change the subtype of shell-script mode that I'm in?
5
votes
2answers
1k views

Can emacs commands be called from a shell script?

I have a directory ~/foo that contains several org files. I'd like to use htmlize to convert each org file into an html file. Ideally this would be done with a shell script. Is there a way to make a ...
5
votes
2answers
412 views

Define an emacs function to take arguments in the same way as something like M-x goto-line

I want to write an emacs function for debug purposes in c++ code. Basically I'm fed up typing the following: std::cout << "variable is: " << variable << std::endl; Instead I want ...
5
votes
2answers
222 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 ...
5
votes
3answers
698 views

How to see the name of the command every time I run it by a shortcut?

Whenever one runs a function/command for which there is already a shortcut, Emacs shows briefly a message in the echo area to recall that there is a shortcut associated with that command. For example ...
5
votes
2answers
696 views

Repeat n(th) last command in emacs?

I know that to repeat the last command, there is C-x z and then to keep using z to easily keep the last command in operation, but what can be done for the 2nd or 4th last command? Or is that ...
5
votes
1answer
2k views

Getting the full list of colors available in Emacs

When I run list-colors-display I get the following: which I think is a very small subset of colors that my Emacs supports, isn't it? For example, I know Emacs supports other colors (gray20, blue15, ...
4
votes
2answers
581 views

How does `C-x z` work?

Specifically, the keyboard event C-x, following by N z characters, will repeat the previous command N times. I do not understand how this can work. As far as I understand, after the input event C-x z,...
4
votes
2answers
860 views

How to make emacs automatically kill buffer after invoking delete-file command?

Whenever I delete a file that I no longer need in emacs using delete-file command, the buffer associated with the file is still open in emacs. Is there a way I can change this behaviour so that ...
4
votes
1answer
3k views

How to quickly create a new directory without using dired-mode?

Whenever I've to create a new directory in emacs, I enter dired mode, press "+" and enter the new directory name which creates the new directory. Is there a way I can avoid using dired-mode and ...
4
votes
2answers
116 views

Can a command determine the event sequence that invoked it?

I have a command that I would like to bind to multiple key sequences differing only in the final decimal digit (e.g. C-. 0, C-. 1, ..., C-. 9). The command needs to determine that final digit. I ...
4
votes
1answer
2k views

Open File and Directory: What's the Emacs command?

I would like to set custom keyboard shortcuts for the Open File and Open Directory commands listed in the File menu. The only problem is that I don't know the corresponding Lisp commands. I've tried ...
4
votes
2answers
738 views

What does C-Mouse-2 mean?

I'm entirely new with Emacs. I'm trying to split vertically my window, but I can't. Googling, I've discovered the commands to do it is C-Mouse-2. So I clicked Ctrl+scroll button+2 but it matched C-...
4
votes
2answers
141 views

Display keybindings typed in a buffer

On this video stream, the window on right displays the keybindings typed with its corresponding command bound. Is there any package that does that, or a way to achieve it?
4
votes
1answer
60 views

What keystrokes brings up the prompt to issue Lisp commands?

I am editing a file and I want to set the tab width (more likely the indent width) to 2 and I have come across a command (setq tab-width 2) but when I use M-x (i.e. Alt-x) on my system and I enter (...
4
votes
1answer
183 views

Binding a key sequence to a key sequence instead of a command

In my .emacs, I tried to use (global-set-key (kbd "M-r") (kbd "C-x r j") so I can use M-r to jump to a register. However, doing this and using the command gives After 0 kbd macro iterations: Args ...
4
votes
2answers
91 views

Display summary information on command when running Meta-x

Since I'm new to GNU Emacs (version 26.1 running on Debian Stable) I'd like to get some information when invoking a command using Meta-x. Currently I'm only able to see a list of possible completions ...
4
votes
1answer
217 views

How to force the user to comply with a command?

First, here is the full source code of my package. Requirement Currently I'm working on a package that provides a feature which upon the user invoking several times in a row certain command in a ...
4
votes
2answers
276 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-...
3
votes
1answer
242 views

Call function interactively and set initial content

I would like to call a function (find-file) interactively and then set the initial content of the mini buffer to my server's home folder. I got as far as using call-interactively, but after that I'm ...
3
votes
2answers
590 views

Move to the beginning of a heading smartly in Org-mode

I just started with Org-mode today and noticed whenever I press C-a on a heading, the cursor is moved all the way to the beginning of the line instead of the first character in the heading. Like so :-...
3
votes
2answers
247 views

How to disable query to turn on disabled command?

I have this in my .emacs file to disable mouse right clicks: (put 'mouse-save-then-kill 'disabled "mouse-save-then-kill disabled\n") How can I now disable the query generated by emacs to turn this ...
3
votes
1answer
378 views

How can I speed up individual commands?

When I call commands such as helm-apropos and custom Org agendas there is often a noticeable delay between the key sequence and the results presented. How can I speed up these commands to respond ...
3
votes
3answers
149 views

Reading info files without knowing their path

If I'm in a terminal, I can just type info glibc and get info about glibc. Since emacs reads info files, it's silly to use M-x term to read info files from within emacs. I know you can use C-u C-h i ...
3
votes
1answer
227 views

Bind C-e C-j and C-a C-o TAB to single key, aka insert and jump to newline

C-e C-j will insert a newline below and jump to it indented. C-a C-o TAB will insert a newline above and jump to it indented. Is there a single bind to these or where/how should I bind these commands?...
3
votes
1answer
62 views

How to specify a command that should be called by #'repeat?

I want to create a command that, when you call it for the first time, it's executed normally, but when you repeat it with C-x z, some other command is executed and the original command is never called....
3
votes
1answer
58 views

Refile and keep the original

How to refile while keeping a copy of the original object in org-mode? In other words refiling works as a cut&paste while I would like to have a copy&paste.
3
votes
2answers
449 views

Delete file (if it exists) before saving

My problem is that I can create, but not overwrite existing files. This is probably due to a bug in MegaFuse. Because of this, when I finish editing a file I must first save it under a different ...
3
votes
1answer
385 views

Prevent Spacemacs from creating double sr-speedbar

I'm trying to make Spacemacs and sr-speedbar work together smoothly. Without using Spacemacs: The command buffer is local to each buffer where it is called: Left is sr-speedbar, right is the main ...
2
votes
1answer
748 views

how to give optional arguments to commands

Looking at the documentation for shell-command (M-!) I see there are two optional arguments, OUTPUT-BUFFER, and ERROR-BUFFER. But when I type M-! it only asks me for the shell command. How do I ...
2
votes
3answers
197 views

M-x command completions to all occurrences of a substring

If I do M-x insert TAB Emacs shows a list of possible completions like below Possible completions are: insert-abbrevs insert-anniversary-diary-entry insert-block-diary-entry insert-...