Questions tagged [commands]
Commands are functions that can be invoked interactively either through `M-x` or by a key binding.
135
questions
0
votes
1answer
37 views
How to append some behavior to a command?
How do I string together functions and actions in a key binding.
Say I want to make a binding that does comment-dwim and then appends "TODO: " to achieve /* TODO: */ in C.
(global-set-key (...
0
votes
1answer
42 views
How to modify interactive function `occur` to a non-interactive function
occur is an interactive compiled Lisp function in ‘replace.el’.
The definition is as follows:
(defun occur (regexp &optional nlines region)
(interactive
(nconc (occur-read-primary-args)
...
1
vote
2answers
104 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
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 ...
0
votes
0answers
19 views
how to insert leaders with periods around dot?
(This is not about org-mode.)
Assume point is between "left" and "right" below
left right
Is there a command that will change that to, for example,
left . . . right
...
1
vote
2answers
69 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
1answer
37 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
61 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 ...
4
votes
2answers
78 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
67 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
67 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
209 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
64 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
34 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
118 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
41 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
171 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
2answers
239 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
52 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
63 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
37 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
225 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
54 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
35 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
198 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
326 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
37 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
48 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
49 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
105 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
37 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
161 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
54 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
309 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
567 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
217 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
164 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
170 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
113 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
120 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 ...
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,...
1
vote
0answers
221 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
453 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
132 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
53 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
123 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
359 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
1k 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
51 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: +...