Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [interactive]

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

1
vote
2answers
19 views

Enter a string interactively on specific keyboard shortcut

I'm new to this kind of Q&A site. Now I'm writing some article using Sphinx (reStructured text). Writing an equation (like E = mc^{2}) in Sphinx is a little bit demanding, because you have to ...
0
votes
1answer
28 views

Is there any way to ask for a interactive input after a condition is met?

Something like the example below, which I want to test whether you are eligible to enter a number before you actually enter this number (defun foo (x) (cond (condition (progn (interactive "nEnter ...
0
votes
0answers
20 views

Interactive 'TAGS/PROP/TODO' query limited to particular level of tree?

I want to do a search where I interactively specify a tag (ideally with counsel-org-tag-style tag completion) and get an agenda buffer listing matching items at a particular level of the hierarchy (...
12
votes
1answer
586 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
88 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
votes
1answer
35 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 ...
3
votes
1answer
49 views

how to provide a parameter for interactive lamda function

I want to be able to perform helm-swoop on an input error: on a compiler output buffer using C-x C-r, here is how I tried to achieve it. (global-set-key (kbd "C-x C-r") (lambda () (interactive) (...
0
votes
2answers
23 views

bind an insertion to a mouse click [duplicate]

I need to change a space to a | here and there and i guessed that the best possibility were to bind a mouse click and the insertion of the pipe (global-set-key [s-mouse-1] '(insert "|")) But when I ...
2
votes
2answers
37 views

Arbitrary length lists as argument for interactive function

Say I have a defun with a dolist inside that I want to be able to pass a string that is then converted to a list with a length equal to the number of words in said string via the minibuffer, so ...
0
votes
1answer
63 views

Adding advice to interactive functions

I want to add advice to `describe-function'. However, when I try to do so, I get an error due to wrong number of arguments. Function: (defun describe-function-advice (function) ...
2
votes
1answer
50 views

How can I set the default value for reading a directory name?

I have a folder hardcoded in variable: (defvar folder-start-mine "/path/to/start/folder/") Then I want to interactively define new non-existing subfolder name: (defun my-new-defun (sel-subdir) ...
4
votes
1answer
436 views

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. Is there a non-interactive way to insert a character given its Unicode name?
7
votes
3answers
121 views

Near-identical commands on multiple keys

Visual Studio has this nice feature where you can put the point on something, press C-f3 and it'll both find the next instance of the thing under the point and it'll remember it. You can then press ...
1
vote
0answers
37 views

What methods are available for complex user input?

I am experimenting with writing a plugin which requires quite a bit of user input, its a front end to an api. A typical request will have 4 required inputs and many optional inputs, obviously I can ...
0
votes
1answer
22 views

How to mapping from the value of one alist entry to the value of another entry of the same alist

I have a data structure like: ((fid . FID) (name . NAME) (count . COUNT) (data . ORIGINAL_DATA)) I have following Elisp code try to interactively select FID through display the NAME instead of FID. (...
0
votes
1answer
56 views

setting font-height interactively

I thought it would be handy to be able to change the font height of a buffer on the fly by invoking a key press and giving the font height you would want, e.g. C-t 130 would set the local buffer font ...
1
vote
1answer
89 views

Interactive: region beginning/end as markers

When I need a function to operate on a region I do, for example: (defun myfunction (B E) (interactive "r") (let ((b (make-marker)) (e (make-marker))) (set-marker b B) (set-marker e E) ...
2
votes
0answers
364 views

Run interactive shell script in new buffer using elisp

I am looking for a way to display and interact with long running shell scripts in a separate buffer. While using eshell works, I'd like to automate most shell tasks using elisp. The best way I came ...
3
votes
1answer
103 views

Can an emacs command tell if it was called via key binding or via M-x command-name?

Is there a way to program some Emacs command in elisp that could tell whether it is called interactively through some key binding or by typing its full name after M-x? I thought this could be done ...
3
votes
3answers
248 views

Display path and filename in a minibuffer

Eval this code: (defun xx-display-filename (filename) "" (interactive "Ffilename: ") (message (concat "Filename is: " filename))) Let's assume that I am editing a ~/.emacs.d/personal/custom.el ...
2
votes
0answers
166 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 :...
1
vote
2answers
44 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
65 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
33 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 ...
2
votes
1answer
464 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 ...
2
votes
2answers
428 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
256 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 [...
0
votes
1answer
50 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/...
1
vote
1answer
299 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
33 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
57 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
62 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 `(...
3
votes
2answers
151 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
517 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 ...
6
votes
2answers
166 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
210 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 ...
3
votes
1answer
206 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
26 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 ...
4
votes
1answer
938 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 ...
1
vote
1answer
151 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-...
3
votes
2answers
40 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 ...
9
votes
1answer
825 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
183 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
246 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" ...
4
votes
2answers
186 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
391 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
99 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
27 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) ...
3
votes
2answers
199 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 ...
1
vote
1answer
345 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 "...