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
1
vote
1answer
31 views

How to script a bookmark-jump call

I am trying to write a function which will perform a bookmark-jump but then reset the the bookmark line to the top of the screen. So far I have: (defun foo () (interactive) (bookmark-jump) ...
0
votes
0answers
18 views

A command to get buffer content centered in the window

I'm looking for the built-in command, probably a minor mode, that got my text unstuck from the left border of the window and showed more or less horizontally centered. The command doesn't modify the ...
2
votes
2answers
40 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 ...
0
votes
1answer
34 views

View a history of commands

While in web-mode, when I type {{ emacs will add }} to the end, and when I press SPC it will then add another }} to the end with a space either side and one extra space to the right, so it looks like ...
1
vote
2answers
59 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/...
0
votes
1answer
173 views

Break key as a shortcut — what am I doing wrong?

I would like to define a keyboard shortcut in my .emacs file so that the Break (a.k.a. Pause) key does a C-x C-s C-x C-c. As a warmup, I thought I would try something simpler, so as a test I did this, ...
0
votes
1answer
42 views

Switch to *scratch* buffer (global-set-key)

I am reading the Intro to Lisp Programing and got to the chapter where switch-to-buffer is introduced. I tried to bind (switch-to-buffer "*scratch*") via global-set-key But this does not ...
0
votes
1answer
26 views

Asterisk in interactive specification

Just when is it appropriate to put the asterisk * into the interactive spec of a command function? The elisp manual says the effect is to cause an error if the command is attempted in a read only ...
4
votes
2answers
85 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?
0
votes
2answers
27 views

Interactive function to convert Windows path to POSIX path

Here at 'dayjob I'm often sent paths from developers using Windows in Windows format: D:\Some\Path These paths can uniformly be converted to paths valid on at least some Linux machines at 'dayjob ...
2
votes
1answer
118 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 ...
0
votes
0answers
15 views

How to remove all console.logs() from the buffer and also how to comment all console.logs from the buffer?

When I do a regex-replace and replace with the empty string, the console.logs() are removed but the empty lines still remain. How would I remove these empty lines? Furthermore, how would I replace all ...
0
votes
2answers
125 views

How to save and execute a python file?

I do not prefer python-mode. I would like a generic way so that I can understand emacs. I wish the file be saved and python file command then be run as if in a shell.
0
votes
2answers
42 views

How do I define a function to execute as a command with M-x? [duplicate]

I wish to M-x my-func and let my code run. This seems basic but where can I get more documentation about this, if possible inside emacs itself?
0
votes
1answer
46 views

Retrieve past command from Emacs history using first letter of command

In Vim I could retrieve past commands by typing :<first-letter-of-command>↑ . If my Vim command history is:- colorscheme + source % shell set spell colorscheme? bp term Typing :s↑ directly ...
0
votes
1answer
36 views

What is the command to transpose line from point till end of line?

Is there a emacs command to tranpose the line from the point till end of the line. For example: quick brown fox jumps over **<point>** the lazy dog meaning After transpose it should be the ...
1
vote
1answer
146 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 |...
0
votes
0answers
50 views

defun to replace regex pattern with original pattern plus new line

I have written the following lisp code to search for a regex pattern and append new line to it: (defun readmode () (interactive) (goto-char 1) (while (search-forward-regex "\(</[a-z]+>\)" ...
1
vote
1answer
31 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-...
2
votes
1answer
114 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 [...
6
votes
3answers
307 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 ...
1
vote
0answers
35 views

Memory Profiler reporting error upon profiler-report

After calling profiler-report after doing profiler-start and selecting mem I get the following error: maphash: Wrong type argument: number-or-marker-p, unbound Any Idea why?
1
vote
1answer
44 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 ...
2
votes
3answers
43 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 ...
0
votes
1answer
80 views

`vc-root-dir` is not a valid command name

Trying to use the vc-root-dir function on Emacs gives the error message vc-root-dir is not a valid command name On inspecting vc.elc as found by locate-library the function appears to exist as a ...
1
vote
1answer
31 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 ...
0
votes
1answer
114 views

Custom command like execute-extended-command

I want to implement a custom M-x (execute-extended-command). This time real skeleton-coding (crying) (defun gbq-extended-command (inst) (interactive "sgbq-X ") (cond ((equal inst "eob") (end-of-...
0
votes
0answers
49 views

Call an interactive function without asking for user input [duplicate]

I would like to call an interactive function that requires user input (projectile-test-project, for instance) by using a predefined argument and therefore executes without asking the user anything. I ...
0
votes
1answer
225 views

Emacs custom command help

I am pretty new to Emacs. Could someone please help me to write a custom command which I can add to my init file? It would do the following: Split the screen vertically to get two windows. Check if ...
4
votes
2answers
543 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,...
1
vote
1answer
167 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.
4
votes
1answer
125 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 ...
1
vote
1answer
145 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 ...
1
vote
2answers
100 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 ...
2
votes
1answer
112 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 ...
13
votes
1answer
1k 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,...
1
vote
0answers
159 views

How do I define a function in my init.el and make it available with M-x? [duplicate]

I have the following function, which does what it says on the tin -- swaps the values of the ns-alternate-modifier and ns-right-alternate-modifier variables. (defun swap-left-and-right-alt () "Swap ...
1
vote
2answers
381 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
votes
1answer
94 views

how to get region start and region end from the whole buffer as variables to call another func

(defun buffer-to-shell() (let (buffer mark-whole-buffer))) (shell-command-on-region start end "sed s/foo/bar/") ;; start, end not defined ) As you might see there are undefined variables start ...
2
votes
1answer
44 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-...
0
votes
1answer
102 views

How to `transpose-chars' backwards

I'm trying to make a trivial function that simply transposes chars backwards. This is what I got so far: (defun jd:backward-transpose-chars () (interactive) (transpose-chars -1)) (define-key ...
0
votes
1answer
232 views

insert a single character

My goal Write code in my init.el file so that from now on, M-v will just print the BELL character (character number 27 in hexadecimal) instead of scrolling down as it does by default. My failed ...
0
votes
3answers
850 views

How show minibuffer's history of commands

windows 10, Emacs 25.1, Helm I open buffer scratch and execute 3 commands sequence: M-x I-search helm-occur replace-string here sreenshots: Nice. It's work fine. But now I want to show in list ...
2
votes
1answer
47 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 ...
0
votes
0answers
38 views

dig.el broken when invoking with type? How to fix?

Running emacs 26.1 on window using bind tools x64 9.13. When I M-x dig heise.de MX it seems the question gets mangled: ; <<>> DiG 9.13.0 <<>> heise.de MX ;; global options: +...
2
votes
2answers
543 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
1answer
252 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 ...
6
votes
1answer
815 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 ...
0
votes
1answer
39 views

How to find all active bindings which act on a region?

As explained https://emacs.stackexchange.com/a/733/ C-h b lists all bindings available in a buffer. Is there a way to list all bindings which act on a region? For example C-w (kill-region) is one of ...
3
votes
1answer
227 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 ...