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
1 answer
14 views

Getting prefix as argument

With this function, I get the error test: Wrong type argument: stringp, 2 Is it good to pass prefix this way? Thought that the argument prefix would be filled up with the prefix value. (defun test (...
user avatar
  • 135
1 vote
1 answer
72 views

Function arguments and interactive

I am having difficulty seeing how to properly use function arguments with the interactive command. Suppose I have a function with three arguments myfunc (arg1 &optional arg2 arg3), the last two ...
user avatar
  • 135
-1 votes
0 answers
29 views

Interactive selection of major mode

With the following function I can make a new buffer. I also want the user to be able to set the major-mode for it. I could use completing-read in this way (cseq '("sh-mode" "emacs-lisp-...
user avatar
  • 135
0 votes
1 answer
26 views

Using function both as interactive command and in elisp code

I am trying to understand the use of the interactive and the intern commands so I can use a function both within an interactive context and an elisp context. Require some explanation of how intern is ...
user avatar
  • 135
3 votes
1 answer
62 views

interactive function: Meaning of Does not do I/O

I'm going through the documentation for the interactive function and there are some code letters which are documented like this: d -- Value of point as number. Does not do I/O. P -- Prefix arg in raw ...
user avatar
  • 3,403
2 votes
2 answers
186 views

Can there be two prefix arguments?

I am very confused by the definitions of define-skeleton and skeleton-proxy-new in skeleton.el in the emacs source (version 28.1). The command generated by the define-skeleton macro has the ...
user avatar
1 vote
1 answer
27 views

How to preselect initial text in the minibuffer with Elisp?

I'm using read-string to read a string from the minibuffer, with an initial input. How can I highlight the initial input, so that I can start replacing it with one key stroke? IOW, given (read-string &...
user avatar
  • 1,414
1 vote
1 answer
30 views

project.el: override project-find-regexp with use-package to show live results like project-find-file (preferably with consult)?

When switching projects, there's a few commands available off the bat that can be selected from the mini-buffer after selecting a project. [f] Find file [g] Find regexp [d] Find directory ... Both ...
user avatar
  • 185
0 votes
1 answer
29 views

Pass default value to org-set-property

The documentation says: (org-set-property PROPERTY VALUE) When called interactively, this will prompt for a property name, offering completion on existing and default properties. And then it will ...
user avatar
  • 224
1 vote
1 answer
35 views

What makes an elisp function available with M-x [duplicate]

Why some functions in simple.el are invokable with M-x and some others aren't? For example I can do M-x what-line but I can't do M-x line-number-at-pos.
user avatar
  • 27
1 vote
1 answer
58 views

Interactive option for function with optional arguments

Am unsure whether making brcmk-end optional is possible for interactive use. If one can have optional arguments, what would be the changed necessary? Would the interactive expression change? (...
user avatar
  • 159
1 vote
1 answer
28 views

Displaying character input with interactive declaration

I have the following code for reading two characters, using the interactive declaration. When I run the interactive function the input character is not being shown after the description string. (...
user avatar
  • 159
0 votes
1 answer
33 views

Command that accepts a string and a selected region

Would like to have a function that selects a string (from a list or from a user-defined string, using the mini-buffer) and a selected region. User would input (), [], {} specifying the opening and ...
user avatar
  • 159
1 vote
1 answer
28 views

How to use `projectile-multi-occur` to find a symbol at point?

I am trying to make projectile-multi-occur to work with the symbol at point. I have done that for occur already, this works: (defun occur-symbol-at-point () (interactive) (let ((sym (thing-at-...
user avatar
  • 387
1 vote
2 answers
77 views

Using defadvice to add an interactive argument to a non-interactive function?

Is there a way to wrap a non-interactive function within defadvice so that the new function can accept an interactive argument which can alter the way that the wrapped function gets called? In other ...
user avatar
  • 522
2 votes
2 answers
50 views

How to avoid the prompt in `revert-buffer` [duplicate]

I'm trying to get rid of the annoying prompt at the end of revert-buffer. This prompt would make sense in a lesser text editor where reverting the buffer is an irreversible action (pardon the pun). ...
user avatar
3 votes
1 answer
31 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))) ...
user avatar
  • 1,710
1 vote
1 answer
83 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) (...
user avatar
  • 113
0 votes
2 answers
35 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&...
user avatar
  • 179
1 vote
1 answer
432 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 ...
user avatar
0 votes
0 answers
94 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 "...
user avatar
0 votes
1 answer
33 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-...
user avatar
  • 288
1 vote
1 answer
28 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 "...
user avatar
6 votes
1 answer
166 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 "...
user avatar
  • 807
0 votes
2 answers
231 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 ...
user avatar
0 votes
1 answer
62 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) ...
user avatar
  • 121
1 vote
0 answers
13 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 ...
user avatar
  • 509
1 vote
1 answer
107 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*): . *...
user avatar
  • 553
1 vote
0 answers
80 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." (...
user avatar
  • 141
1 vote
1 answer
54 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) ...
user avatar
4 votes
1 answer
125 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 ...
user avatar
  • 227
0 votes
1 answer
287 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, ...
user avatar
0 votes
1 answer
161 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 ...
user avatar
1 vote
1 answer
56 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) (...
user avatar
0 votes
1 answer
349 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 ...
user avatar
0 votes
1 answer
67 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 ...
user avatar
1 vote
1 answer
176 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 ("...
user avatar
1 vote
1 answer
47 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 ...
user avatar
  • 5,775
0 votes
1 answer
46 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) (...
user avatar
  • 617
1 vote
1 answer
32 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 ...
user avatar
1 vote
1 answer
330 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 ...
user avatar
  • 7,199
1 vote
2 answers
85 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 ...
user avatar
  • 645
0 votes
2 answers
163 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?
user avatar
0 votes
1 answer
61 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 " *\\)" "\\([[<][^]>]+[]&...
user avatar
  • 1,499
2 votes
1 answer
233 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 ...
user avatar
  • 1,481
0 votes
0 answers
131 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-...
user avatar
0 votes
1 answer
410 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 ...
user avatar
  • 163
0 votes
1 answer
120 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 ...
user avatar
  • 645
1 vote
1 answer
162 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 "*...
user avatar
  • 124
0 votes
0 answers
59 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]+>\)" ...
user avatar