all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Splitting the input string in interactive
@ 2024-09-05 12:04 Heime
  2024-09-05 12:21 ` tomas
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-09-05 12:04 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

Why do I encounter problems when splitting the input string
in interactive ?  How can I split each input entry on a different
line without harm ?

  (interactive (concat "sEnter search text: \n"
                       "nEnter number of context lines: "))






^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 12:04 Splitting the input string in interactive Heime
@ 2024-09-05 12:21 ` tomas
  2024-09-05 12:31   ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: tomas @ 2024-09-05 12:21 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

[-- Attachment #1: Type: text/plain, Size: 199 bytes --]

On Thu, Sep 05, 2024 at 12:04:18PM +0000, Heime wrote:
> Why do I encounter problems when splitting the input string
> in interactive ?

Have you read interactive's docstring?

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 12:21 ` tomas
@ 2024-09-05 12:31   ` Heime
  2024-09-05 12:36     ` tomas
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-09-05 12:31 UTC (permalink / raw)
  To: tomas; +Cc: Heime via Users list for the GNU Emacs text editor


On Friday, September 6th, 2024 at 12:21 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:

> On Thu, Sep 05, 2024 at 12:04:18PM +0000, Heime wrote:
> 
> > Why do I encounter problems when splitting the input string
> > in interactive ?
> 
> Have you read interactive's docstring?

I did.  The argument of ‘interactive’ is a string containing a code
letter followed optionally by a prompt. To pass several arguments to
the command, concatenate the individual strings, separating them by 
newline characters.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 12:31   ` Heime
@ 2024-09-05 12:36     ` tomas
  2024-09-05 12:54       ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: tomas @ 2024-09-05 12:36 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

[-- Attachment #1: Type: text/plain, Size: 897 bytes --]

On Thu, Sep 05, 2024 at 12:31:21PM +0000, Heime wrote:
> 
> On Friday, September 6th, 2024 at 12:21 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:
> 
> > On Thu, Sep 05, 2024 at 12:04:18PM +0000, Heime wrote:
> > 
> > > Why do I encounter problems when splitting the input string
> > > in interactive ?
> > 
> > Have you read interactive's docstring?
> 
> I did.  The argument of ‘interactive’ is a string containing a code
> letter followed optionally by a prompt.

Exactly. And (concat ... ...) is not a string. It's an expression, that,
when evaluated, yields a string.

What is the fourth word in interactive's doc string?

> To pass several arguments to
> the command, concatenate the individual strings, separating them by 
> newline characters.

You have to concatenate them: you might solve that riddle if/when you
answer the question above.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 12:36     ` tomas
@ 2024-09-05 12:54       ` Heime
  2024-09-05 13:04         ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-09-05 13:19         ` tomas
  0 siblings, 2 replies; 12+ messages in thread
From: Heime @ 2024-09-05 12:54 UTC (permalink / raw)
  To: tomas; +Cc: Heime via Users list for the GNU Emacs text editor

On Friday, September 6th, 2024 at 12:36 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:

> On Thu, Sep 05, 2024 at 12:31:21PM +0000, Heime wrote:
> 
> > On Friday, September 6th, 2024 at 12:21 AM, tomas@tuxteam.de tomas@tuxteam.de wrote:
> > 
> > > On Thu, Sep 05, 2024 at 12:04:18PM +0000, Heime wrote:
> > > 
> > > > Why do I encounter problems when splitting the input string
> > > > in interactive ?
> > > 
> > > Have you read interactive's docstring?
> > 
> > I did. The argument of ‘interactive’ is a string containing a code
> > letter followed optionally by a prompt.
> 
> 
> Exactly. And (concat ... ...) is not a string. It's an expression, that,
> when evaluated, yields a string.
> 
> What is the fourth word in interactive's doc string?
> 
> > To pass several arguments to
> > the command, concatenate the individual strings, separating them by
> > newline characters.
> 
> 
> You have to concatenate them: you might solve that riddle if/when you
> answer the question above.

So it must be a hardwired string.  Not very convenient for multiple
user values.  It would be a good change if the string could be constructed
with concat or with a variable.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 12:54       ` Heime
@ 2024-09-05 13:04         ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-09-05 13:11           ` Heime
  2024-09-05 13:19         ` tomas
  1 sibling, 1 reply; 12+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-09-05 13:04 UTC (permalink / raw)
  To: help-gnu-emacs

Heime <heimeborgia@protonmail.com> writes:

> > You have to concatenate them: you might solve that riddle if/when you
> > answer the question above.
>
> So it must be a hardwired string.  Not very convenient for multiple
> user values.  It would be a good change if the string could be constructed
> with concat or with a variable.

How much of the docstring did you read?

Michael.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 13:04         ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-09-05 13:11           ` Heime
  2024-09-05 13:55             ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-09-05 13:11 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

On Friday, September 6th, 2024 at 1:04 AM, Michael Heerdegen via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> Heime heimeborgia@protonmail.com writes:
> 
> > > You have to concatenate them: you might solve that riddle if/when you
> > > answer the question above.
> > 
> > So it must be a hardwired string. Not very convenient for multiple
> > user values. It would be a good change if the string could be constructed
> > with concat or with a variable.
> 
> 
> 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.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 12:54       ` Heime
  2024-09-05 13:04         ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-09-05 13:19         ` tomas
  1 sibling, 0 replies; 12+ messages in thread
From: tomas @ 2024-09-05 13:19 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

[-- Attachment #1: Type: text/plain, Size: 508 bytes --]

On Thu, Sep 05, 2024 at 12:54:23PM +0000, Heime wrote:
> On Friday, September 6th, 2024 at 12:36 AM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:

[...]

> > You have to concatenate them: you might solve that riddle if/when you
> > answer the question above.
> 
> So it must be a hardwired string.  Not very convenient for multiple
> user values.  It would be a good change if the string could be constructed
> with concat or with a variable.

Theree might be a reason for that.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 13:11           ` Heime
@ 2024-09-05 13:55             ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-09-05 14:15               ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-09-05 13:55 UTC (permalink / raw)
  To: help-gnu-emacs

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.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 13:55             ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-09-05 14:15               ` Heime
  2024-09-05 14:30                 ` Heime
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-09-05 14:15 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs


On Friday, September 6th, 2024 at 1:55 AM, Michael Heerdegen via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> 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.

Correct.  I do not see much code using it, interactive usage frequently 
uses the list approach.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 14:15               ` Heime
@ 2024-09-05 14:30                 ` Heime
  2024-09-05 15:23                   ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2024-09-05 14:30 UTC (permalink / raw)
  To: Heime; +Cc: Michael Heerdegen, help-gnu-emacs






Sent with Proton Mail secure email.

On Friday, September 6th, 2024 at 2:15 AM, Heime <heimeborgia@protonmail.com> wrote:

> On Friday, September 6th, 2024 at 1:55 AM, Michael Heerdegen via Users list for the GNU Emacs text editor help-gnu-emacs@gnu.org wrote:
> 
> > 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.

I have noticed that in the latter there is not a space after ""sEnter search text".
Is the correct way to have "sEnter search text: \n\" ?

Using the string approach has a number of caveats.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Splitting the input string in interactive
  2024-09-05 14:30                 ` Heime
@ 2024-09-05 15:23                   ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 12+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-09-05 15:23 UTC (permalink / raw)
  To: help-gnu-emacs

Heime <heimeborgia@protonmail.com> writes:

> Is the correct way to have "sEnter search text: \n\" ?

Sure.


Michael.




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-09-05 15:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-05 12:04 Splitting the input string in interactive Heime
2024-09-05 12:21 ` tomas
2024-09-05 12:31   ` Heime
2024-09-05 12:36     ` tomas
2024-09-05 12:54       ` Heime
2024-09-05 13:04         ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-09-05 13:11           ` Heime
2024-09-05 13:55             ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-09-05 14:15               ` Heime
2024-09-05 14:30                 ` Heime
2024-09-05 15:23                   ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-09-05 13:19         ` tomas

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.