Questions tagged [interactive]

`interactive` spec of an Emacs-Lisp command (function invocable using `M-x` or a key binding)

Filter by
Sorted by
Tagged with
1
vote
2answers
86 views

Always use default as input to describe-symbol function

I want to map describe-symbol to shortcut, but I constantly have to press additional enter for show describe on found default suggestion. Is there a way to force emacs to newer ask for confirmation ...
1
vote
1answer
136 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 ...
2
votes
0answers
36 views

Record Emacs interactive function invocations

I want to optimize my keybindings, in a way that the more a command invoked interactively, the more accessible will be a key-binding for it. Is there a way to record all interactive function ...
7
votes
1answer
1k views

call interactive function from elisp code without worrying about arguments

So, I want to do (ispell-change-dictionary) inside a function I'm writing, but doing a test throws this error: (wrong-number-of-arguments #[(dict &optional arg) I was told that M-x calls the ...
3
votes
2answers
1k views

How to write a function with an interactive choice of the value of the argument?

How to write a function in Emacs Lisp that interactively would give the opportunity to choose one of the options? Choose your animal: Cow Rabbit Dog You have to press 1 to select Cow, 2 to select ...
1
vote
1answer
367 views

Read input char without pressing RET

I want to perform the same task as in the function below, but without having to press ENTER every time I select an option. (defun my-fun () (interactive) (setq something (read-string "Options:\n [...
1
vote
1answer
68 views

How to prompt user for register name?

I'd like to prompt the user for a register name. Is there an easy way to do this? Apparently, this functionality isn't built into interactive (https://www.gnu.org/software/emacs/manual/html_node/elisp/...
2
votes
1answer
551 views

“Invalid use of '\' in replacement text” with non-interactive calls

It seems that replace-regexp has a different behavior if called interactively and not, but I do not understand why, and how to get the wanted behavior. What I want is the non-interactive equivalent ...
1
vote
3answers
41 views

How to know if user input a string or a number using interactive

I want to check if a user input a word or a number. And I write the function look like this: (defun check-input (arg) "description" (interactive "senter arg: ") (setq isnum (string-match "\\'[0-...
1
vote
1answer
87 views

Detect interactive use of `kill-buffer` in `kill-buffer-hook`

As per title, I want to define a kill buffer hook with the variable kill-buffer-hook and the function should be able to detect when (kill-buffer ) has been called interactively. Is this possible? ...
1
vote
1answer
77 views

Reuse other command's “interactive” form

Example, I want to define a package-open-homepage command, which reuses C-h P (describe-package)'s "interactive" form. I don't want to copy-and-paste because it is too long. The following (eval `(...
4
votes
2answers
234 views

Custom C-arrow cursor movement

I was not satisfied with the behavior of standard C-arrow and C-S-arrow, so I wrote this functions to replace standard ones. (setq separators-regexp "[\-'\"();:,.\\/?!@#%&*+=]") (defun forward-...
1
vote
2answers
809 views

How to reuse last input in command with a prompt?

Some existing functions have ability to remember last input, which you can use in the next command call - for example, replace-string will suggest the last replacement by default, while isearch will ...
5
votes
2answers
201 views

How to repeat a command immediately after calling it?

I've just called an interactive function (i.e., a command). I want to call it again, with the same arguments. I know that I can call a keyboard macro again by using e right after running it the ...
2
votes
1answer
347 views

Helm find-file foreground face for interactive current directory in minibuffer

I'm using Spacemacs with $ emacs --version > GNU Emacs 24.5.1 On OSX 10.10.5 Using C-x C-f to find files shows a minibuffer like: I have been able to get rid of the ugly green foreground ...
2
votes
1answer
314 views

how to find non-interactive function equivalents of elisp interactive functions

In the description of the function goto-line in the built-in emacs documentation, I found the following at the end: This function is usually the wrong thing to use in a Lisp program. What you ...
0
votes
1answer
32 views

eval-last-sexp produces unnecessary void-variable error when using a macro containing eval

Suppose I have defined the following macro: (defmacro mymacro (a) "" (eval a)) If I then use eval-last-sexp (i.e. C-x C-e) to evaluate the following, (defun somefcn (b) "" (mymacro b)) I get the ...
9
votes
1answer
2k views

How to apply `call-interactively` to an interactive command that accepts the universal argument?

I've read the documentation on how to make interactive calls from within Elisp, but I still can't figure out how to pass the universal argument when using call-interactively on a command that ...
2
votes
2answers
358 views

Compile from parent directory in Emacs

I'm trying to map F5 to compile from a parent directory of the current buffer. Emacs compile-command find makefile in superior directory provides an excellent answer to achieve this: (defun compile-...
2
votes
2answers
41 views

Take path preceding cursor and run a shell command on it

Consider a buffer holding the following contents: foo ... some text /foo/bar/hello.csv𝙸 ... bar where 𝙸 represents the location of cursor. I would like to have an interactive function that ...
11
votes
1answer
1k views

Is it possible to read user input from STDIN while tangling a source block?

Is it possible to read user input from STDIN while tangling a source block with org-babel-tangle? I am aware of this: Org Mode Babel - Interactive code block evaluation. That doesn't help solve this ...
2
votes
1answer
286 views

how to parameterize prompt for interactive/command?

background I had elisp code (in this very small git repo) like (defun bulk-replace-file (filepath) (interactive "FPath to file to bulk-replace: ") (bulk-replace-file-non-interactive filepath) ) ...
0
votes
4answers
364 views

elisp pattern for handling region || buffer || file

summary Elisp newbie has been given interactive code (aka commands, called with M-x whatever) that "does stuff" on the currently-selected region in the current buffer. What is an/the "elispish way" ...
3
votes
2answers
203 views

Elisp code execution order?

I cannot understand the behavior of this simple code: (defun foo (str bool) (interactive (list (read-string "Some text: ") (y-or-n-p "Yes or no? "))) (message "%s is first" str) (...
5
votes
1answer
433 views

Why does multiple cursors use the same char for all cursors with zap-to-char but not with zap-up-to-char?

This a follow up to my earlier question Why does multiple-cursors use the same char for all cursors with iy-go-to-char, but not with zap-up-to-char?. As I describe in that question, for some commands ...
4
votes
1answer
171 views

How can I make an interactive function be local to directories?

I want to make it so that I have interactive functions that can only be called from buffers in a certain directory, like variables in .dir-locals.el. Is there a way to do this? For example, say I'm ...
1
vote
1answer
32 views

Defining a function that takes as an input the current buffer's path

I am hoping to define an interactive function that I can invoke with M-x <function-name> and that will: Automatically grab the path to the file Run the following code on it: (require 'tramp) ...
4
votes
2answers
322 views

How to initiate a prompt for user input based on the prefix argument?

The below dummy foo describes how I need the prefix variable setting to work. I'd like the read-number prompt to show up only if the user entered C-u as prefix. In all other cases, the prefix will be ...
2
votes
1answer
461 views

How to programmatically invoke interactive function? [duplicate]

I have written an interactive function to connect to multiple mysql databases (defun mysql-connect (name) "Connect to a predefined MySQL connection." (interactive (list (completing-read "...
5
votes
2answers
427 views

Default base directory in rgrep

Whenever I'm using M-x rgrep to search inside my project arborescence, the interactive prompts suggest the following default arguments for the function: Search for (default: <current word>) (OK,...
4
votes
3answers
196 views

What are the situations where defining a function as non-interactive is better than interactive?

Assume that we have a function which can be defined either interactive or non-interactive. When we define it as interactive, we can use it as a command by invoking M-x so we have more freedom. I am ...
9
votes
3answers
2k views

What is a raw prefix argument? (capital P in interactive)

And what can they be used for? (interactive "p") takes a numerical argument from the universal argument right? And the universal argument is just an int either way, so what does capital (interactive "...
3
votes
1answer
179 views

Can I make a function non-interactive after it's been defined?

I'm defining a minor-mode not meant to be interactively activated. I'd like to use define-minor-mode because it's very convenient, but the downside is that it always sets the mode function as ...
1
vote
2answers
260 views

What does the (interactive …) form mean?

I want to write a function that will write the output of wc -l <file-name> next to each file in dired mode. I got to this point: (defun my-dired-insert-add-wc (beg end) (save-excursion (...
5
votes
1answer
449 views

log keystrokes with timestamp and other metadata?

If I evaluate this form: (open-dribble-file "/home/joe/keys.log") then type something, Emacs saves what I type to the keys.log file: <return>hellow<backspace> keyloggi<down-mouse-5&...
12
votes
2answers
918 views

Can Emacs use tramp to run in an interactive session on a remote HPC node?

I have been using Emacs with ESS and tramp to load remote files and run remote R processes on HPC computers. With ssh keys, tramp makes this easy with C-x C-f to find file at /ssh:myserver:/path/to/...
22
votes
1answer
2k views

Elisp for applying command to only the selected region

Say, I have some code like this: (defun some-function () (interactive) ;; do something ) Now I want some-function to operate only on the selected region in the buffer ? How can I do that ? ...
4
votes
1answer
205 views

Partial input to interactive command

Let's say I want to provide partial input to an interactive function such as insert-char. For example, I might want to have a command that automatically starts typing GREEK SMALL LETTER or BOX ...
2
votes
1answer
188 views

buffer-file-name is a function, so why doesn't M-x buffer-file-name work? [duplicate]

When trying to run it I get M-x buffer-file-name [No match] But it has a function help entry via C-h f and I can evaluate it with M-: buffer-file-name. So why isn't it accessible via M-x?
0
votes
1answer
86 views

Interactive input, strings and quoted items

(defun ecli-metadata-single (ecli meta) "meta needs to be quotes \n example: (case-metadata ECLI:NL:HR:2013:BY6108 'identifier)" (interactive "sEnter ecli: \nxEnter identifier: ") (insert (car (...
3
votes
1answer
132 views

Mongo console doesn't behave properly in ansi-term

In ansi-term when using mongo console (or 'repl') control codes do not seem to behave properly. When I move cursor it doesn't get redrawn at a expected location. Instead all entered text get appended ...
3
votes
4answers
864 views

How can I determine which function was called interactively in the stack?

Say I have two functions (defun tmp:a () (interactive) (tmp:b)) (defun tmp:b () (message "called from %S" "?")) If I call M-x tmp:a, how can I determine this from tmp:b?
0
votes
1answer
106 views

How to interactivelly pass a `listp arg` to `yank`

Is it possible to interactively pass an argument that matches listp to the function yank so that current-kill receives an argument of 0? If so, how please can that be achieved? Background: I am ...
3
votes
1answer
269 views

How can I use an interactive function in a script?

I'm using virtualenvwrapper.el to load Python virtualenvs during emacs sessions. I would like emacs to start with a default one, so I don't have to load it manually every time. To load it manually, I ...
3
votes
1answer
174 views

Can I accept a prefix argument based on another argument within an `(interactive …)` form?

(defun tmp:interactive (&optional scope pos-style) "POS-STYLE has no effect when SCOPE is `directory'." (interactive (list (cdr (assoc (read-char-choice "Copy (f)ull ...
12
votes
4answers
719 views

How can I read a single character from the minibuffer?

When part of a defun, (interactive "c(C)hoose (A)n (O)ption") will prompt the user for a single character; RET is not required. How can I replicate this reading behavior without the need for ...
8
votes
1answer
425 views

ielm, bound to a certain buffer

Is there a way to run ielm, but with variables bound to a certain buffer? I know about M-:, but having a shell like ielm to inspect things would be much easier.
4
votes
1answer
249 views

How do I maintain a history of ido-read-filenames?

I've written a helper function for mu4e to run checkpatch against a message. However I want to be easily able to switch between previous calls to checkpatch and this seems difficult with ido-read-file-...
5
votes
1answer
314 views

Helm and custom commands

If I write a command that calls (interactive "f"), Emacs will prompt the user to select a file when the command is run interactively. With Helm enabled, this selection is done through Helm with no ...
6
votes
3answers
1k views

How to search for lines not containing some text?

In a large file, I want to find which lines which do not contain a given string, grep -v basically. M-x grep helps, but it forces to protect special characters, is not interactive nor incremental, ...