help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Splitting the input string in interactive


From: Michael Heerdegen
Subject: Re: Splitting the input string in interactive
Date: Thu, 05 Sep 2024 15:55:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Heime <heimeborgia@protonmail.com> writes:

> > How much of the docstring did you read ? - Michael.
>
> Currently one has to input a literal string from what I understood.
> Not variables or expressions.

You can also specify an expression - an expression that returns the list
of arguments.  But not an interactive ARG-DESCRIPTOR - the arguments as
a list, at runtime.


What you can do:

(1) Rewrite your interactive form to use an expression that returns the
argument list to use.  Something like

#+begin_src emacs-lisp
(interactive (list (read-string ...) (read-number ...))
#+end_src

or (2)

There is a read syntax for "escaped" line breaks in strings.  Not only
for interactive arguments descriptors - for any strings.  For example in
your case this would look like:

#+begin_src emacs-lisp
(call-interactively (lambda (s n) (interactive "\
sEnter search text: \n\
nEnter number of context lines: ")
                      (list s n)))
#+end_src

or (the explicit newline character and escaping the line break cancel out
each other) simplified

#+begin_src emacs-lisp
(call-interactively (lambda (s n) (interactive "\
sEnter search text: 
nEnter number of context lines: ")
                      (list s n)))
#+end_src

Note that it is an error to indent the string's lines here, since the
indentation would get part of the string's contents.  Emacs's
indentation commands know about this.  Looks a bit unusual first but one
gets used to it.


Michael.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]