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
1answer
33 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) ...
0
votes
0answers
12 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
58 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
175 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, ...
0
votes
1answer
42 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 ...
1
vote
1answer
31 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
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
27 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 ...
1
vote
1answer
33 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 ("...
1
vote
1answer
29 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
1answer
34 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
21 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 ...
0
votes
1answer
57 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
2answers
64 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 ...
0
votes
2answers
42 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?
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
89 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
0answers
85 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-...
0
votes
1answer
118 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
71 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
136 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
31 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
105 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
44 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
30 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
31 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
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 ...
1
vote
1answer
153 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
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 (...
13
votes
1answer
1k 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
160 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
95 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
118 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
95 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
70 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
227 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
108 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
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?
7
votes
3answers
195 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
33 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
135 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
141 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
863 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
202 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
775 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
394 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 :...