27
votes
Why can't I bind my function to a key or call it with M-x?
The core point is that there is a difference between a function and a command.
In Emacs lisp, functions are not interactively callable by default. That means you can't access them via M-x or bind ...
Community wiki
15
votes
Accepted
call interactive function from elisp code without worrying about arguments
If you want to call an interactive function from within elisp, but
call it as if you invoked it interactively (e.g., via M-x some-command), you can wrap it in the call-interactively function.
The ...
Dan♦
- 32.9k
14
votes
Accepted
How to apply `call-interactively` to an interactive command that accepts the universal argument?
According to shell's interactive form, as long as current-prefix-arg is non-nil, shell will ask user a buffer to use, so you can set current-prefix-arg to non-nil (4 is used in following as an example)...
14
votes
Accepted
Insert character by its Unicode name
From the documentation of insert-char, I cannot see why
(insert-char "GREEK SMALL LETTER EPSILON")
doesn't work.
It doesn't work because insert-char understands Unicode character names only ...
8
votes
How to write a function with an interactive choice of the value of the argument?
(defun foo (choice)
"..."
(interactive
(list (completing-read "Choose: "
'(("1" . "Cow") ("2" . "Rabbit") ("3" . "Dog")) nil t)))
(message "You chose `%s'" choice)
...
8
votes
How to repeat a command immediately after calling it?
You are looking for repeat, bound by default to C-x z. The
first part of the docstring:
(repeat REPEAT-ARG)
Repeat most recently executed command.
If REPEAT-ARG is non-nil (interactively, ...
Dan♦
- 32.9k
8
votes
Accepted
Break key as a shortcut -- what am I doing wrong?
You ask several related questions, but this is the main one, I think:
How does one find out what name emacs gives to a key such as the one labeled pause/break on my keyboard?
For Emacs's description ...
8
votes
Default argument for interactive function?
(defun hello (st)
(interactive (list (read-string "Your name: " "toto")))
(message "Hello Mr %s" st))
where "toto" is the initial-input.
6
votes
Accepted
Is it possible to read user input from STDIN while tangling a source block?
Try this
Note: Made following minor changes to your code block:
Moved #!/bin/bash into code block header :shebang #!/bin/bash to automatically set executable file permissions when block is ...
6
votes
Can Emacs use tramp to run in an interactive session on a remote HPC node?
I have been struggling to do the same. I found a different route that allowed me to do basically the same thing.
You can open a shell buffer by M-x shell and from there connect to the login node, and ...
6
votes
Accepted
How to write a function with an interactive choice of the value of the argument?
The function you are looking for is read-char-choice.
I cite the corresponding documentation:
(read-char-choice PROMPT CHARS &optional INHIBIT-KEYBOARD-QUIT)
Read and return one of CHARS, ...
5
votes
Accepted
Detect interactive use of `kill-buffer` in `kill-buffer-hook`
Test the variable this-command to see whether it is kill-buffer
5
votes
How can I read a single character from the minibuffer?
The question was answered long ago, but this additional answer may provide some assistance to other searchers.
read-char-choice allows you to specify a list of choices. The fn will not return until ...
5
votes
Accepted
How to repeat a command immediately after calling it?
There is also repeat-complex-command (normally bound to C-x ESC ESC as well as several others (that's the one I use, so I remember that)). This will go back further in the history to the last command ...
5
votes
Accepted
Combine two interactive functions
[I believe you meant sort-lines, not sort - that's the only way the question makes sense, so I am going to assume it.]
Both sort-lines and delete-duplicate-lines operate on the selected region. You ...
4
votes
Accepted
how to find non-interactive function equivalents of elisp interactive functions
Most commands are absolutely fine for both interactive and non-interactive use, so a default position of "if it doesn't say otherwise, it's ok for non-interactive use" is going to be fine in the ...
4
votes
Accepted
Take path preceding cursor and run a shell command on it
One way to achieve this is by using thing-at-point and shell-command:
(defun my-open-file-at-point ()
(interactive)
(shell-command (format "open %s" (thing-at-point 'filename))))
4
votes
How to reuse last input in command with a prompt?
Commands that read input from the minibuffer use functions such as completing-read, read-string, read-regexp, etc. The most general of these is read-from-minibuffer.
All such functions take a HISTORY ...
4
votes
Accepted
Read input char without pressing RET
You apparently want to read a character and immediately dispatch behavior based on what it is.
Help > Search Documentation > Find Any Object by Name (command apropos) tells you, for read plus char ...
4
votes
Near-identical commands on multiple keys
You can bind one command to several key-sequences and access the calling key-sequence within the command with this-command-keys.
That is demonstrated with the following code. There the same command my-...
4
votes
Near-identical commands on multiple keys
Let's look at this logically: you want to have near-identical commands bound to C-f2 and C-f3. The only difference between these commands is whether they store the thing under point in the f2 memory ...
4
votes
Accepted
how to provide a parameter for interactive lamda function
The (lambda () (interactive) ...) syntax is just fine. The problem you are encountering is with your invocation of helm-swoop. The arguments for that function must be keyed (preceded by their ...
4
votes
Accepted
(interactive "r") can't be used directly after Emacs startup
The use-region-p test should be within the interactive spec.
"r" is for functions that always use the region. You probably want to use something like:
(defun try-region (&optional begin end)
(...
3
votes
Accepted
"Invalid use of '\' in replacement text" with non-interactive calls
(Credits go to Tobias)
replace-regexp (and query-replace-regexp) have their second read argument malaxed into a suitable form for the elisp call. In particular, in case the replacement string ...
3
votes
Accepted
How to reuse last input in command with a prompt?
You could use read-string and give they default value def-say-word and save in later.
(setq def-say-word "default value")
(defun say-word (word)
(interactive
(list (read-string (format "Say ...
3
votes
Accepted
Helm find-file foreground face for interactive current directory in minibuffer
M-x list-faces-display is your friend.
It shows you all faces currently defined. And you can click on a face name to open Customize for that face.
If you use library Face-Menu+ (code: facemenu+.el) ...
3
votes
Accepted
eval-last-sexp produces unnecessary void-variable error when using a macro containing eval
After looking through the GNU Emacs Lisp Reference Manual, I realized that there is a subsection of "Common Problems Using Macros" called "Evaluating Macro Arguments in Expansion" which explains this ...
3
votes
Problem with giving inputs to a function programmatically
The function sunrise-sunset is an interactive function takes a numeric prefix argument as a parameter. It does not take the latitude and longitude as parameters, which is what you're trying to pass ...
3
votes
Accepted
Use write-region in read-only buffer
The interactive code * is used to: "Signal an error if the current buffer is read-only. Special."
https://www.gnu.org/software/emacs/manual/html_node/elisp/Interactive-Codes.html
Thus, the line ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
interactive × 146commands × 22
key-bindings × 12
functions × 12
prefix-argument × 10
arguments × 10
buffers × 6
region × 6
string × 5
defun × 5
debugging × 4
regular-expressions × 4
minibuffer × 4
read × 4
call-interactively × 4
org-mode × 3
helm × 3
shell × 3
completion × 3
files × 3
advice × 3
characters × 3
completing-read × 3
thing-at-point × 3
spacemacs × 2