Questions tagged [commands]
Commands are functions that can be invoked interactively either through `M-x` or by a key binding.
152
questions
0
votes
1
answer
29
views
To remove characters in the beginnings of lines
To add // in the beginnings of multiple lines I can use either string-insert-rectangle or string-rectangle (C-x r t).
But how is it possible to remove these characters instead?
This question is not ...
0
votes
0
answers
26
views
How can I temporarily disable all (other) key bindings?
How can I write a command, and bind it to a key, so that when invoked it disables all key bindings other than the current key, until that same key binding is pressed again?
The goal is to facilitate ...
1
vote
1
answer
34
views
What makes an elisp function available with M-x [duplicate]
Why some functions in simple.el are invokable with M-x and some others aren't?
For example I can do M-x what-line but I can't do M-x line-number-at-pos.
2
votes
1
answer
31
views
Why is ivy-switch-buffer not found in counsel-M-x, but works when called by C-x b (or from the scratch buffer)
According to helpful-key, C-x b is bound to ivy switch buffer:
According to the code, that is an interactive function. However, when I look for it in the Counsel-M-x menu, it's not found:
I figured ...
1
vote
1
answer
35
views
Hide a command from user
Is there a way to hide a command from user?
Or, in other words, is there a way to undo an interactive spec?
Background:
I have a derived mode, which is used in a special buffer as the buffer's mode. ...
1
vote
1
answer
44
views
How to write a Lisp representation of a keyboard macro and bind it to a command name?
I'm using spacemacs with vim-bindings, but I only mention it so you
don't scratch your head too long at the keystrokes of the macro. A
regular emacs solution will work just the same.
I've read through ...
1
vote
1
answer
40
views
Why does `C-h b` show `??` as the command name for my key binding?
I've just added a nice custom key binding:
;; Open files in dired mode using 'open'
(eval-after-load "dired"
'(progn
(define-key dired-mode-map (kbd "z")
(lambda () (...
0
votes
1
answer
37
views
How to define a command to switch to the current candidate buffer in Ido?
I'm trying to write a command that I would call while using ido-switch-buffer or ido-kill-buffer to open the current candidate in another window. Ideally it would be able to open virtual buffers as ...
1
vote
1
answer
49
views
How can I apply ansi-color to complete buffer?
I am using following code to apply colorize text in emacs, such as for ^[ characters to apply color. In order to use this code I have to select text to apply it
reference: https://unix.stackexchange....
0
votes
1
answer
66
views
Error /bin/bash: line 1: nil: command not found
I have the following code to auto format python code using autopep8:
(defcustom python-autopep8-path (executable-find "autopep8")
"autopep8 executable path."
:group 'python
:...
2
votes
1
answer
70
views
How to move from one source block to another, in Org-mode?
Is there a key-binding, command, or even evil extension for Emacs, so that I can move from one source block to another?
For example,org-forward-heading-same-level, which is bound in my system to C-j, ...
3
votes
1
answer
132
views
Keymap that is dependent on the buffer
I want to create a "toggle shell" shortcut with F1 such that it will run shell when I'm in any other buffer, but will call mode-line-other-buffer when I'm in the shell buffer. What is an ...
0
votes
1
answer
65
views
How to know (in Elisp) what buffer was current when a command is invoked?
I want to give an arbitrary command some buffer-local
behavior without advising it. (I can do it by advising, but I want to also be able to do it without
advising.)
E.g., just looking at some ...
0
votes
0
answers
13
views
How to create commands to search specific kinds of files using `helm-projectile`?
I want to be able to search python, typescript, and markdown files separely with helm-projectile. Is there a way to create distinct keybindings to search the contents of files with each extension.
...
1
vote
1
answer
66
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-...
0
votes
1
answer
44
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
1
answer
61
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
2
answers
354
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
0
answers
13
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
0
answers
21
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
1
answer
102
views
Why ivy-immediate-done is not shown in counsel-M-x
I realize that ivy-immediate-done is not shown in counsel-M-x. Since it's an interactive command, I'm assuming counsel-M-x somehow filters it from its result. But a quick search of the function name ...
1
vote
2
answers
78
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
1
answer
54
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
0
answers
232
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
2
answers
146
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
1
answer
322
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
2
answers
105
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
1
answer
286
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, ...
6
votes
1
answer
485
views
How to change the default transient level temporarily? ("Show hidden magit commands")
Many commands that are rarely used in magit are hidden by default. Magit uses the transient.el library for popups and the visibility of infix and suffix commands are controlled by transient-default-...
0
votes
1
answer
161
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
1
answer
67
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
2
answers
216
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
2
answers
105
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
1
answer
324
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
2
answers
653
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
2
answers
162
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
1
answer
81
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
1
answer
45
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
1
answer
420
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
0
answers
59
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
1
answer
64
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
1
answer
460
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
3
answers
360
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
0
answers
41
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
1
answer
54
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
3
answers
61
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
1
answer
134
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
1
answer
62
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
1
answer
268
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
0
answers
64
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 ...