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
171 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
34 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
30 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
14 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 ...
3
votes
1answer
60 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
180 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
32 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
44 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
45 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
28 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
62 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
34 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
39 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
22 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
66 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 ...
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, ...
0
votes
2answers
43 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
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 (...
0
votes
1answer
54 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
97 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
73 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
86 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
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-...
0
votes
1answer
128 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
139 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
50 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
33 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
106 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
43 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
45 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
31 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
32 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
206 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
29 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
32 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
32 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 (...
5
votes
2answers
426 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,...
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/...
13
votes
1answer
2k 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
166 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
101 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
120 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
98 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 ...
12
votes
4answers
718 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 ...
2
votes
2answers
71 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
233 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) ...
3
votes
1answer
112 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) ...
7
votes
3answers
197 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 ...
7
votes
1answer
1k 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?
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 ...