Questions tagged [commands]
Commands are functions that can be invoked interactively either through `M-x` or by a key binding.
115
questions
0
votes
1answer
25 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
48 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
43 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
23 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
39 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
279 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
30 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
27 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
40 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
47 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
24 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
55 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
35 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
63 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
262 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
77 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.
3
votes
1answer
74 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
98 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
71 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
87 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 ...
12
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
95 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 ...
0
votes
2answers
221 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
56 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
29 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
77 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
126 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
443 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
37 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
36 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: +...
1
vote
2answers
414 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
178 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 ...
4
votes
1answer
508 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
37 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
197 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 ...
6
votes
3answers
809 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 ...
2
votes
0answers
271 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
:...
3
votes
1answer
58 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....
0
votes
1answer
344 views
Wrong type argument: commandp cscope
My question is how to let the command SPC-m-c-Cget the function name automatically?
I am using 0.200.10@25.3.1 (spacemacs), on Ubuntu 16.04 64 bit
I am using cscope layer, it is great but with one ...
1
vote
1answer
192 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
41 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 ...
-1
votes
1answer
77 views
Emacs Lisp Error when called as command but works well when called as function
https://github.com/Cheatinikle/Spacemacs-settings/blob/master/emacs-package/preetest-mode.el
This is my full source code, and 'just-utils package is also included in the repository.
The problem is, ...
0
votes
0answers
133 views
How to change the command for comment toggling
spacemacs with Evil uses gcc to toggle whether a line is commented or not.
I'd like to change it to ,cc. How should I go about this in my .spacemacs file?
1
vote
1answer
122 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-...
0
votes
1answer
72 views
how to fixup line breaks?
I'm looking for a command that behaves similiar to fixup-whitespace, but I want it to also remove line breaks between objects around point.
1
vote
1answer
129 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 ...
8
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 ...
1
vote
1answer
88 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
2answers
80 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 ...
0
votes
1answer
239 views
Equivalent to the ViM :smile command
In ViM, there is a :smile command that displays lighthearted ASCII graphics of a figure that smiles.
Is there an equivalent command available in Emacs?