We changed our privacy policy. Read more.

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
2
votes
3answers
204 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-...
2
votes
3answers
52 views

How to get the argument from previous use of `command-execute`?

I want to automatically rename the buffer name of compilation mode. The default name is *compilation*. Let's call my new compilation command my-compile. So supposing we run my command like this: M-x ...
2
votes
2answers
724 views

How can I pass the NO-LINE-BREAK argument to base64-encode-region in M-x?

I'm editing YAML files where I have to frequently encode and decode base64 values in a buffer. base64-encode-region and base64-decode-region are perfect for this, but very long strings get encoded as ...
2
votes
2answers
119 views

How to limit when yasnippet fires?

I found that yasnippet suggests using this code to limit it to only expand when the trigger text has just been typed: (setq yas-expand-only-for-last-commands 'self-insert-command) Unfortunately when ...
2
votes
1answer
487 views

Repeat regexp from isearc-forward-regexp on a subsequent replace-regexp?

I use C-M-s to search for a regexp. Then I use M-x replace-regexp to replace the same regexp with some string. Can I save typing the regexp for the second time? Generally, when typing an argument ...
2
votes
1answer
267 views

Is it possible to alias an internal command?

Since I discovered multi-term, I use it exclusively over term or eshell. But, I'm lazy and would prefer to be able to simply type term to activate multi-term. Is this possible?
2
votes
1answer
316 views

How to scroll back through the command line history in the Emacs interactive subshell?

Let us say in the interactive subshell I run these commands: command_a command-b command_c ... command_z I type M-p to go back to command_z. But how can I scroll back the history of commands until ...
2
votes
1answer
338 views

How to use unread-command-events variable?

I want to generate some input from my command programmatically. I have tried using unread-command-events variable for that, see: (defun unread_test () "Repeat input after toggling input method" (...
2
votes
1answer
46 views

How to create a command that runs all of those functions on the current buffer?

I'm a total noob so be patient with me. I wrote a piece of elisp code that reads a .csv file (FILE.CSV) on which every line has the format Key, Value It composes a mail using the keys and values in ...
2
votes
2answers
531 views

C-g has stopped breaking out of commands like `C-x C-f` and `M-x` in graphical emacs-25

I have always used C-g (ie keyboard-quit) to break out of commands like M-x and C-x C-f. At some point not too long ago this stopped working. All that happens is that Quit flashes in the minibuffer ...
2
votes
1answer
331 views

Run command on custom key binding [duplicate]

I am trying to customize emacs/spacemacs to run a command after a key stroke, like running eslint --fix command on the buffer to fix errors. I already tried (defun fix-errors-with-eslint () (shell-...
2
votes
1answer
79 views

Finding Like Variables or Functions

Is there a command that will jump cursor to other iteration of the variable or function name under the cursor? I suppose it wouldn't matter if the text is specifically a variable or function, but ...
2
votes
1answer
339 views

Can helm-apropos display the key bindings for commands the way helm-M-x does?

I'm a recent convert to helm. helm-M-x displays commands and includes key-bindings in parens after the command name. helm-apropos displays commands and other things. I'd like it to display the key ...
2
votes
1answer
58 views

Emacs execute keymap entry

Emacs defines a fair variety of objects that can be bound to keys, with e.g. global-set-key. (The canonical list can be found here). I would like to simulate the invocation of a keymap entry. For ...
2
votes
1answer
1k views

command works with M-x but gives "Wrong type argument: commandp" when calling through key binding [closed]

I wrote this command and key binding to use with cider for Clojure development: (defun reload-and-eval-in-repl () "Set the ns of the repl to the one in the current buffer, then eval the region of ...
2
votes
1answer
206 views

How to quickly jump to a directory in emacs?

Say I have a project directory called "project". In the directory there are two directories "mini1" and "mini2". Suppose my active buffer is deep within a subdirectory in "mini1". Is there a way to ...
2
votes
1answer
322 views

Remapping global keybindings to a prefix command

The following works: (define-prefix-command 'my-map) (global-set-key (kbd "C-@") 'my-map) ;; MacOS (global-set-key (kbd "C-SPC") 'my-map) ;; Windows 10 The following does not: (global-set-key [...
2
votes
1answer
195 views

How to disable C-<number>

I don't know the name of the command C-<number> <entry> to repeat the <entry>, <number> times. For me it is more annoying than useful, several times I have accidentally ...
2
votes
1answer
56 views

repeat string-inflection command

I would like to repeat M-x string-inflection-camelcase on several words. For example in: foo_bar baz qux-quux quuz CORGE_GRAULT GARPLY I place my cursor on foo_bar and then enter M-x string-...
2
votes
1answer
127 views

Create a command or key binding for closing code blocks

In AUXtex there is the key binding macro C-c ] which closes the lowest current TeX environment. For example \begin{equation} ... would be closed (by putting an \end{equation} on a new line after ...
2
votes
0answers
542 views

Interactive lambda functions [closed]

How do I create interactive lambda functions? (use-package general :ensure t :config (general-evil-setup t) ;;(setq general-default-keymaps 'evil-normal-state-map) (general-define-key :...
2
votes
0answers
247 views

Trace Evil-mode commands

At the moment, I only know one way to determine which Emacs functions are called by any given Evil command (e.g. a sequence of key bindings in the Normal state): read the Evil source code. Is there a ...
1
vote
3answers
814 views

Is there Sublime Text - style command palette in Emacs?

There is such feature as Command Palette in Sublime text: It provides searchable list of command with human-readable descriptions. Is there anything similar to this in Emacs?
1
vote
2answers
792 views

How can I set a key binding to run two other key bindings?

Specifically, I want the binding 'C-x C-a' to do 'C-x C-s' then 'C-c C-a'. (Context: I'd like to save my TeX document, then have AUCTeX render it.) How can I do this? I don't want to map 'C-x C-a' to ...
1
vote
2answers
73 views

Are commands not equivalent to functions in Emacs? [duplicate]

The documentation for M-x says: M-x runs the command execute-extended-command (found in global-map), which is an interactive compiled Lisp function in ‘simple.el’. It is bound to <execute>, <...
1
vote
3answers
112 views

Finding Numbers in Brackets and Summing Them

QUESTION: How can I make an emacs command M-x sum-the-brackets that scans highlighted text for all occurrences of [ <number> u ] and [ <number>u ], and sums them? EXAMPLE: Selecting ...
1
vote
2answers
2k views

Is there an equivalent of `M-x check-parens` for finding unmatches braces or ['s in any buffer (not a particular mode)

M-x check-parens finds unmatched parentheses in a buffer. I am wondering if there is a similar command which finds unmatched { or [.
1
vote
1answer
266 views

What function does C-x invoke?

I learned that M-x invokes command execute-extended-command. Extended commands - GNU Emacs FAQ What command does C-x invoke? I looked through the reference but failed to find the answer.
1
vote
2answers
933 views

How to reuse last input in command with a prompt?

Some existing functions have ability to remember last input, which you can use in the next command call - for example, replace-string will suggest the last replacement by default, while isearch will ...
1
vote
2answers
124 views

Count the number of paragraphs

There are plenty of ways to count lines, words, and characters in Emacs. For instance, invoking M-= (AKA count-words-region) does that very thing on a given region. However, I am having trouble ...
1
vote
2answers
116 views

How to push this command in to history?

I have this function in config (defun launch-separate-emacs-under-x () (interactive) (call-process "sh" nil nil nil "-c" "emacs &")) (defun restart-emacs () (interactive) (add-hook 'kill-...
1
vote
3answers
276 views

Emacs equivalent of the following vim operation

In the answer to a question on Quora, Gilles Castel wrote an answer highlighting the power of vim. The Question was: How would you write a C program to print 1 to 100 without loop, recursion, or ...
1
vote
1answer
48 views

How to check if point moved or is on a different line in a buffer since the last user command?

I would like to make a snippet of code that only executes if the point is on a different line in a particular buffer since the last user command. The only way I could think to do it was using the post-...
1
vote
2answers
79 views

Efficiently calling multiple variants of the grep command

The context I commonly execute the following variants of the grep command grep --color -RHIn '' (search in the current working directory) grep --color -RHIn --include='*.org' '' ~/repos/dotfiles/...
1
vote
1answer
294 views

Insert space but don't move point

Search didn't yield any success. Perhaps I'm using the wrong search terms... I'd like to insert a single space (just like when you hit SPC) but without changing point. I come up with an example (let |...
1
vote
1answer
51 views

How to write a command which uses the prefix argument AND some strings

I want to write a command which uses a prefix argument and reads some strings. I know both parts individually: (defun xtest(arg) (interactive "P") ... reads the prefix arg. (defun xtest(t1 ...
1
vote
1answer
42 views

how to use this-command and last-command in tests?

I have a usecase for this-command and last-command, because I'd like a double invocation of a command to behave differently (it's an indenter, FWIW). Some manual interactive experiments suggest that ...
1
vote
1answer
173 views

Command abbreviation

After running M-x magit-status Emacs provided me this suggestion in the mini-buffer: You can run the command ‘magit-status’ with M-x m-stat RET Is this a built-in feature of emacs? If not, does ...
1
vote
2answers
131 views

how does optional argument `ALLOW-EXTEND` in `mark-word` work?

I am switching from VIM to Emacs for just a couple weeks and trying to write some Elisp. Having difficulties to adapt, I am exploring different options to do marking and reached this function. (defun ...
1
vote
1answer
82 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 `(...
1
vote
1answer
2k views

How to change keyboard shortcuts for copy, cut and paste and set keyboard shortcut for debugger (GDB)?

I would like to set the following keyboard shortcuts: Copy (selected text): C-c Cut (selected text): C-x Paste from clipboard: C-v Debugger (GDB): M-g Now I realize that to do this I merely need the ...
1
vote
1answer
312 views

Adding eldoc support to js2-mode

Since js2-mode does not have eldoc-mode support, I was wondering if I could get some similar functionality to js2-mode with the help of tern-mode. tern-mode has a command tern-get-type which will ...
1
vote
1answer
97 views

How to retain selection after command run (indent-code-rigidly)?

I found a neat code snippet for ~/.emacs configuration: (global-set-key (kbd "C->") (lambda (b e &optional n) (interactive "r") (...
1
vote
2answers
128 views

(load-theme) at the bottom of .emacs, or manually renders a different screen

Adding this line at the very end of the .emacs file, that loads a default theme coming with the Emacs package, (load-theme 'tsdh-dark) the (main) screen looks like Note the black-on-dark text, the ...
1
vote
1answer
49 views

Command that does different things based on whether something is selected

I am trying to make emacs function somewhat like sublime text, where C-x cuts text that is selected and cuts the whole line when nothing is selected. I got the full-line cut to work using (global-set-...
1
vote
2answers
511 views

how to define an evil-operator to move forward/backward a text-object?

I am trying to define a function that moves to the begin/end of current text-object. First - I define an operator: (evil-define-operator evil-forward-text-object (beg end type) "move to end of ...
1
vote
1answer
136 views

Execute shell command and then some text into document

I have a python script ss.py that gets a screenshot from a connected device and puts into particular dir. From terminal I run it with the target path as an arg: $ python ss.py {document-name}/{image-...
1
vote
1answer
172 views

deactivate active region after `eval-region`

I do the following to activate the region and evaluate it M-x spc to begin mark C-n C-n C-n M-x eval-region The region is still active (highlighted) after the eval-region is performed. I would ...
1
vote
1answer
83 views

eshell backtrace when trying to use character command

I have written a custom interactive command that takes a character as an argument. When I happen to use the key binding for that command while in a eshell buffer where a long-running command is ...
1
vote
0answers
12 views

How to write an interactive function which repeats when the last key in the keybinding is repeatedly pressed? [duplicate]

I want to repeat a function when the last key in the key binding is repeatedly pressed. For example, say the keybinding is C-n for next-line, what I want to happen is that next-line is repeated when I ...