We’re rewarding the question askers & reputations are being recalculated! Read more.

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
0
votes
1answer
19 views

how to bind custom commands to keys in existing mode map?

I wrote some extra commands for Python mode: python-insert-quote and python-insert-double-quote. I want to have these commands be available in the minibuffer when python-mode is active. How can I add ...
0
votes
1answer
47 views

Assign buffer-name to variable

I'd like to write Elisp code that compares text character by character between two buffers. To do that, I need to first assign buffer names to the variables source-buffer and target-buffer ...
1
vote
1answer
98 views

Use write-region in read-only buffer

I am writing a custom function which is supposed to write selected text to some arbitrary file on the system. It does something like (defun write-region-to-file (&optional arg) (interactive "*...
0
votes
0answers
41 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
22 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-...
1
vote
2answers
93 views

Problem with giving inputs to a function programmatically

Some programs take user inputs, for example by calling the interactive function `sunrise-sunset', two arguments are taken from the user. Assume that the inputs are 0.0098 and 51.4934 (these are ...
0
votes
1answer
29 views

Prompt for command to reset variable to 1 or any other number

I have a command that semi-automates the insertion of numbered chapter headings in an org-mode file. (defun reset-counter () (interactive) (setq n 1)) (defun insert-numbered-chapter-headings () ...
1
vote
1answer
26 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 ...
0
votes
1answer
25 views

How do I revert to the English keyboard after switching to Devanagari?

I do this to switch to a Hindi keyboard:- C-x RET C-\ [TAB] and then I choose : devanagari-inscript My query is : How do I switch back to an English keyboard? I can see options for english-dvorak ...
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 ...
1
vote
2answers
27 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
30 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
1answer
77 views

(interactive “r”) can't be used directly after Emacs startup

The proper way to deal with region is using (interactive "r"). But in my case, (interactive "r") always complaints 'The mark is not set now, so there is no region' after fresh Emacs startup. This ...
0
votes
0answers
30 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
977 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
92 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
54 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
85 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
40 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
47 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
128 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
64 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) ...
6
votes
1answer
763 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
151 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
24 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
84 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
122 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) ...
4
votes
0answers
566 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 ...
4
votes
2answers
163 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 ...
4
votes
3answers
402 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
263 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
65 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
85 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
34 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 ...
3
votes
1answer
715 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
696 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
314 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
56 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
382 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
36 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
66 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
68 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
175 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
632 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
178 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
252 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
233 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
27 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 ...
8
votes
1answer
1k 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 ...