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
3
votes
1answer
24 views

command print no results with (interactive "r")

Consider this test function (tested in emacs -q): (defun foo (start end) "for testing purposes" (interactive "r") (when (region-active-p) (cons start end))) ...
1
vote
1answer
42 views

How to pass a string argument to a function from global-set-key definition inside .emacs

Inside my .emacs file I have these two functions: (defun bh/switch-to-vs () (interactive) (universal-argument) (shell "*vs*")) (defun bh/switch-to-android () (interactive) (...
0
votes
2answers
19 views

Pass arguments captured from minibuffer to shell command in a function

I'm struggling with passing arguments read from the minibuffer to a shell command in a elisp function. I've written the following so far: (defun perlclean (review clean) "Script PERL blablabla&...
1
vote
1answer
66 views

Call an interactive function and pass argument to it in elisp without user input

I am new to elisp and am trying to write an Elisp function that calls org-pandoc-export-to-html5-pdf-and-open. org-pandoc-export-to-html5-pdf-and-open is an interactive function that will write to a ...
0
votes
0answers
59 views

Read multiples arguments for interactive function without sequential read functions

I have an interactive function taking 2 arguments. I can read them with (defun example-fct (arg1 arg2) "This function take two arguments" (interactive (let ((arg1 (read-string "...
0
votes
2answers
316 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) ...
13
votes
3answers
1k 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/...
0
votes
1answer
29 views

How to prompt for function use be used within a function?

Consider the following example function (defun simple-function () (dotimes (counter 10) (input-function))) This requires input-function to be hard coded within the definition of simple-...
1
vote
1answer
16 views

Is there an easy way to use thing-at-point to initialize interactive read string (interactive "sfoo:")

Is there an easy way to use thing-at-point to initialize the contents of an interactive string reading? I have a function the looks something like this: (defun foo (string) (interactive "...
5
votes
1answer
75 views

Default argument for interactive function?

Using (interactive "sPROMPT: ") one can set a prompt for, e.g., a string function. Question: Is it possible to also supplement a default argument to the function? Say (interactive "...
0
votes
2answers
88 views

copy string at point func

I'm trying to build a simple proc that copies the text on which the point is set and returns the point to where it was, but can't make it work properly. Before you say "thing-at-point" - I ...
0
votes
1answer
46 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) ...
0
votes
1answer
50 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
0answers
12 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 ...
1
vote
1answer
54 views

How do I make C-x b (switch-to-buffer) ignore some buffers?

I want C-x b (i.e. switch-to-buffer) to ignore some buffers. For example, I want to ignore *Ibuffer*. In other words, when I press C-x b, I should not see Switch to buffer (default *Ibuffer*): . *...
1
vote
0answers
53 views

How to override a value inside a function temporarily?

There is this function in tide: ;; Defined in ~/.emacs.d/.local/straight/repos/tide/tide.el (defun tide-rename-file () "Rename current file and all it's references in other files." (...
3
votes
1answer
266 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 ...
1
vote
1answer
40 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) ...
1
vote
1answer
33 views

unread-command-events and batch mode

I'm writing tests for an interactive function. I've been using the unread-command-events variable in conjunction with call-interactively to verify that it does the right thing. However, I just ...
0
votes
0answers
15 views

GAP mode (interactive mode for working with GAP) swallows first lines of output

On Windows 10, I have emacs under cygwin which works well. In particular, I am running GAP in emacs using gap-mode and everything is OK. Now to use some other apps, I was forced to install another ...
4
votes
1answer
84 views

Combine two interactive functions

For example, I want to sort a file, then remove the duplicate lines. I run M-x sort followed by M-x delete-duplicate-lines. I wanted to combine them into a single interactive function. Here is an ...
0
votes
1answer
235 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, ...
1
vote
1answer
45 views

How to disable "/" 's default behavior on the F interactive mode?

I use interactive mode with Ivy and Dired for interactively creating new files, like so: (evil-local-set-key 'normal (kbd "t") (lambda (file) (...
0
votes
1answer
88 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
1answer
190 views

How to call an interactive function and pass arguments to it from within Elisp?

I'm trying to compose a link to the describe-package help buffer to the xref package like this: [[(elisp:(describe-package "xref"))][xref]] But it can't execute. So I wonder how to pass ...
0
votes
1answer
44 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 ...
0
votes
1answer
194 views

How to call xref-find-definitions without being prompted?

Is it possible to call xref-find-definitions to find the definition at the current point without being prompted to select the default? I'd like to bind this to a key, so it immediately jumps to a ...
1
vote
1answer
83 views

How to access variables/lists by the strings of their names, prompted interactively

I have a question about how to use interactive to allow the user to identify a desired list element to output. Let's say I have a variable x assigned to a list structured like this: (setq x '((y ("...
0
votes
1answer
42 views

Trying to use `pdfgrep` program from within my command

I want to be asked what string %s I want [0] pdfgrep to search for? While M-x pdfgrep mysearchString works, I'm somehow missing something on wrapping it up as sole function? (require 'pdfgrep) (...
1
vote
1answer
29 views

rgrep: string-match("<C>", nil) error

I found a weird behaviour with rgrep. The following is tested under emacs 26.3 with emacs -Q. Evaluate (rgrep "test" "*.org" "~/Org/wiki") gives me a string-match("<C>" nil) error: Debugger ...
1
vote
2answers
79 views

Prompt for user input flexibly with interactive

I have a function that uses smartparens to replace specified pairs of parentheses. (defun replace-paren-at-point (paren) (interactive "sReplace with: ") (if (looking-at "[「『《〈(〔【]") (progn ...
7
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, ...
0
votes
2answers
59 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?
1
vote
2answers
295 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 (...
0
votes
1answer
58 views

Accessing regular expression groups outside a buffer

The code from here accesses groups of a regular expression match in a buffer in interactive mode: (let ((re (concat "\\([ \t]*" org-clock-string " *\\)" "\\([[<][^]>]+[]&...
2
votes
1answer
160 views

Can "advice-add ... :filter-args" detect if the advised function was called interactively?

Using advice-add from nadvice.el, I am trying to add a :filter-args advice to an interactive function. Is it somehow possible for it to detect, whether the advised function has been called ...
0
votes
1answer
84 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 ...
0
votes
0answers
109 views

Defining function that takes funciton as argument results in "Wrong type argument: commandp, (bm-my bm-next)"

When using the below and invoking the function via <leader>Bn I get an error of command-execute: Wrong type argument: commandp, (bm-my bm-next) (defun bm-my (a) (interactive) (a) (bm-show-...
2
votes
2answers
464 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-...
0
votes
1answer
301 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 ...
1
vote
1answer
155 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
57 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
49 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
110 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
52 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
51 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 ...
1
vote
1answer
42 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 ...
4
votes
2answers
248 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 ...
1
vote
2answers
31 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
33 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 ...