unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Getting text from next non-blank line
@ 2024-04-19 20:53 Heime
  2024-04-19 21:04 ` [External] : " Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Heime @ 2024-04-19 20:53 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

This interactive function requests the user to input a string associated with 
the current line number.  I want to change it so that the function picks out
the text on the current line or the text of the next non-blank line.  But also
allow the user to write their own text for the line.

(defun tema-mark (kfrz)
  "Associate line number at cursor position with key phrase KFRZ."
  (interactive "sString: ")

  (let ( (lnum (line-number-at-pos)) )

    (setq-local tema-lugar
                 (append tema-lugar (list (cons kfrz lnum)))) ))




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

* RE: [External] : Getting text from next non-blank line
  2024-04-19 20:53 Getting text from next non-blank line Heime
@ 2024-04-19 21:04 ` Drew Adams
  2024-04-19 21:38   ` Heime
  2024-04-19 21:50   ` Heime
  0 siblings, 2 replies; 9+ messages in thread
From: Drew Adams @ 2024-04-19 21:04 UTC (permalink / raw)
  To: Heime, Heime via Users list for the GNU Emacs text editor

> This interactive function requests the user to input a string
> associated with
> the current line number.  I want to change it so that the function
> picks out
> the text on the current line or the text of the next non-blank line.
> But also
> allow the user to write their own text for the line.
...
>   (interactive "sString: ")

Don't use that, if you want to provide a 
default value for the user input.

Instead, use a function that accepts a
default value.  E.g., `read-string' or
`completing-read'.

Read how to use `interactive' with a
sexp as argument that returns the list
of args you want `interactive' to pass
to the function body.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html



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

* RE: [External] : Getting text from next non-blank line
  2024-04-19 21:04 ` [External] : " Drew Adams
@ 2024-04-19 21:38   ` Heime
  2024-04-19 21:50   ` Heime
  1 sibling, 0 replies; 9+ messages in thread
From: Heime @ 2024-04-19 21:38 UTC (permalink / raw)
  To: Drew Adams; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Saturday, April 20th, 2024 at 9:04 AM, Drew Adams <drew.adams@oracle.com> wrote:

> > This interactive function requests the user to input a string
> > associated with
> > the current line number. I want to change it so that the function
> > picks out
> > the text on the current line or the text of the next non-blank line.
> > But also
> > allow the user to write their own text for the line.
> 
> ...
> 
> > (interactive "sString: ")
> 
> 
> Don't use that, if you want to provide a
> default value for the user input.
> 
> Instead, use a function that accepts a
> default value. E.g., `read-string' or` completing-read'.
> 
> Read how to use `interactive' with a sexp as argument that returns the list of args you want` interactive' to pass
> to the function body.
> 
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html

I not quite sure of the strategy to use.  I want the user to store in a list the text 
of the current line or the text of the next non-blank line.  What would I ask the user?

Elisp does not force me to call completing-read in interactive.




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

* RE: [External] : Getting text from next non-blank line
  2024-04-19 21:04 ` [External] : " Drew Adams
  2024-04-19 21:38   ` Heime
@ 2024-04-19 21:50   ` Heime
  2024-04-19 22:37     ` Stephen Berman
  1 sibling, 1 reply; 9+ messages in thread
From: Heime @ 2024-04-19 21:50 UTC (permalink / raw)
  To: Drew Adams; +Cc: Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Saturday, April 20th, 2024 at 9:04 AM, Drew Adams <drew.adams@oracle.com> wrote:

> > This interactive function requests the user to input a string
> > associated with
> > the current line number. I want to change it so that the function
> > picks out
> > the text on the current line or the text of the next non-blank line.
> > But also
> > allow the user to write their own text for the line.
> 
> ...
> 
> > (interactive "sString: ")
> 
> 
> Don't use that, if you want to provide a
> default value for the user input.
> 
> Instead, use a function that accepts a
> default value. E.g., `read-string' or` completing-read'.
> 
> Read how to use `interactive' with a sexp as argument that returns the list of args you want` interactive' to pass
> to the function body.
> 
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html

Have started with this to get the non-blank text.  But still no way for
use to use his own text.

(defun tema-mark (text)
  "Associate line number at cursor position with text."

  (interactive
    (list (if (string-blank-p (thing-at-point 'line t))
                (progn (forward-line)
                       (thing-at-point 'line t))
            (thing-at-point 'line t))))

  (let ( (line-number (line-number-at-pos)) )
    (setq-local tema-lugar
                 (append tema-lugar
                          (list (cons text line-number))))
    ))



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

* Re: [External] : Getting text from next non-blank line
  2024-04-19 21:50   ` Heime
@ 2024-04-19 22:37     ` Stephen Berman
  2024-04-19 23:00       ` Heime
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen Berman @ 2024-04-19 22:37 UTC (permalink / raw)
  To: Heime; +Cc: Drew Adams, Heime via Users list for the GNU Emacs text editor

On Fri, 19 Apr 2024 21:50:12 +0000 Heime <heimeborgia@protonmail.com> wrote:

> Sent with Proton Mail secure email.
>
> On Saturday, April 20th, 2024 at 9:04 AM, Drew Adams <drew.adams@oracle.com> wrote:
>
>> > This interactive function requests the user to input a string
>> > associated with the current line number. I want to change it so
>> > that the function picks out the text on the current line or the
>> > text of the next non-blank line.  But also allow the user to write
>> > their own text for the line.
>>
>> ...
>>
>> > (interactive "sString: ")
>>
>>
>> Don't use that, if you want to provide a
>> default value for the user input.
>>
>> Instead, use a function that accepts a
>> default value. E.g., `read-string' or` completing-read'.
>>
>> Read how to use `interactive' with a sexp as argument that returns the list
>> of args you want` interactive' to pass
>> to the function body.
>>
>> https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html
>
> Have started with this to get the non-blank text.  But still no way for
> use to use his own text.

Follow Drew's advice, e.g. use read-string with your if-sexp as the
default value.  (But what if the next line after a blank line is also
blank?  And the string (thing-at-point 'line t) returns includes the
newline at the end of the line; do you want that?)

Steve Berman

> (defun tema-mark (text)
>   "Associate line number at cursor position with text."
>
>   (interactive
>     (list (if (string-blank-p (thing-at-point 'line t))
>                 (progn (forward-line)
>                        (thing-at-point 'line t))
>             (thing-at-point 'line t))))
>
>   (let ( (line-number (line-number-at-pos)) )
>     (setq-local tema-lugar
>                  (append tema-lugar
>                           (list (cons text line-number))))
>     ))




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

* Re: [External] : Getting text from next non-blank line
  2024-04-19 22:37     ` Stephen Berman
@ 2024-04-19 23:00       ` Heime
  2024-04-19 23:12         ` Stephen Berman
  0 siblings, 1 reply; 9+ messages in thread
From: Heime @ 2024-04-19 23:00 UTC (permalink / raw)
  To: Stephen Berman
  Cc: Drew Adams, Heime via Users list for the GNU Emacs text editor

On Saturday, April 20th, 2024 at 10:37 AM, Stephen Berman <stephen.berman@gmx.net> wrote:

> On Fri, 19 Apr 2024 21:50:12 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > Sent with Proton Mail secure email.
> > 
> > On Saturday, April 20th, 2024 at 9:04 AM, Drew Adams drew.adams@oracle.com wrote:
> > 
> > > > This interactive function requests the user to input a string
> > > > associated with the current line number. I want to change it so
> > > > that the function picks out the text on the current line or the
> > > > text of the next non-blank line. But also allow the user to write
> > > > their own text for the line.
> > > 
> > > ...
> > > 
> > > > (interactive "sString: ")
> > > 
> > > Don't use that, if you want to provide a
> > > default value for the user input.
> > > 
> > > Instead, use a function that accepts a
> > > default value. E.g., `read-string' or` completing-read'.
> > > 
> > > Read how to use `interactive' with a sexp as argument that returns the list of args you want` interactive' to pass
> > > to the function body.
> > > 
> > > https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html
> > 
> > Have started with this to get the non-blank text. But still no way for
> > use to use his own text.
> 
> Follow Drew's advice, e.g. use read-string with your if-sexp as the
> default value. (But what if the next line after a blank line is also
> blank? And the string (thing-at-point 'line t) returns includes the
> newline at the end of the line; do you want that?)
> 
> Steve Berman

If the next line after a blank line is also blank, I continue until
I get to the first non-blank line.

I have noticed the newline at the end of the line - I do not want that.
Want to remove leading and trailing blanks as well.
 
My latest version follows. 


 (defun tema-mark ()
  "Store a string with the line number in `my-alist`.
If the current line is blank, move to the next non-blank line."
  (interactive)

  (let* ((initial-line (thing-at-point 'line t))
         (initial-line-number (line-number-at-pos))
         (line (if (string-blank-p initial-line)
                   (progn
                     (forward-line)
                     (while (string-blank-p (thing-at-point 'line t))
                       (forward-line))
                     (thing-at-point 'line t))
                 initial-line))
         (lnum (line-number-at-pos))
         (text (read-string "Enter text to store: " line)))

    (setq-local tema-lugar
                 (append tema-lugar
                          (list (cons text lnum)))) ))



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

* Re: [External] : Getting text from next non-blank line
  2024-04-19 23:00       ` Heime
@ 2024-04-19 23:12         ` Stephen Berman
  2024-04-19 23:18           ` Heime
  2024-04-19 23:31           ` Heime
  0 siblings, 2 replies; 9+ messages in thread
From: Stephen Berman @ 2024-04-19 23:12 UTC (permalink / raw)
  To: Heime; +Cc: Drew Adams, Heime via Users list for the GNU Emacs text editor

On Fri, 19 Apr 2024 23:00:30 +0000 Heime <heimeborgia@protonmail.com> wrote:

> On Saturday, April 20th, 2024 at 10:37 AM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>> On Fri, 19 Apr 2024 21:50:12 +0000 Heime heimeborgia@protonmail.com wrote:
>>
>> > Sent with Proton Mail secure email.
>> >
>> > On Saturday, April 20th, 2024 at 9:04 AM, Drew Adams drew.adams@oracle.com wrote:
>> >
>> > > > This interactive function requests the user to input a string
>> > > > associated with the current line number. I want to change it so
>> > > > that the function picks out the text on the current line or the
>> > > > text of the next non-blank line. But also allow the user to write
>> > > > their own text for the line.
>> > >
>> > > ...
>> > >
>> > > > (interactive "sString: ")
>> > >
>> > > Don't use that, if you want to provide a
>> > > default value for the user input.
>> > >
>> > > Instead, use a function that accepts a
>> > > default value. E.g., `read-string' or` completing-read'.
>> > >
>> > > Read how to use `interactive' with a sexp as argument that returns the
>> > > list of args you want` interactive' to pass
>> > > to the function body.
>> > >
>> > > https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html
>> >
>> > Have started with this to get the non-blank text. But still no way for
>> > use to use his own text.
>>
>> Follow Drew's advice, e.g. use read-string with your if-sexp as the
>> default value. (But what if the next line after a blank line is also
>> blank? And the string (thing-at-point 'line t) returns includes the
>> newline at the end of the line; do you want that?)
>>
>> Steve Berman
>
> If the next line after a blank line is also blank, I continue until
> I get to the first non-blank line.

What happens if the buffer ends in one or more blank lines?

> I have noticed the newline at the end of the line - I do not want that.
> Want to remove leading and trailing blanks as well.

string-trim

Steve Berman

> My latest version follows.
>
>
>  (defun tema-mark ()
>   "Store a string with the line number in `my-alist`.
> If the current line is blank, move to the next non-blank line."
>   (interactive)
>
>   (let* ((initial-line (thing-at-point 'line t))
>          (initial-line-number (line-number-at-pos))
>          (line (if (string-blank-p initial-line)
>                    (progn
>                      (forward-line)
>                      (while (string-blank-p (thing-at-point 'line t))
>                        (forward-line))
>                      (thing-at-point 'line t))
>                  initial-line))
>          (lnum (line-number-at-pos))
>          (text (read-string "Enter text to store: " line)))
>
>     (setq-local tema-lugar
>                  (append tema-lugar
>                           (list (cons text lnum)))) ))



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

* Re: [External] : Getting text from next non-blank line
  2024-04-19 23:12         ` Stephen Berman
@ 2024-04-19 23:18           ` Heime
  2024-04-19 23:31           ` Heime
  1 sibling, 0 replies; 9+ messages in thread
From: Heime @ 2024-04-19 23:18 UTC (permalink / raw)
  To: Stephen Berman
  Cc: Drew Adams, Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Saturday, April 20th, 2024 at 11:12 AM, Stephen Berman <stephen.berman@gmx.net> wrote:

> On Fri, 19 Apr 2024 23:00:30 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > On Saturday, April 20th, 2024 at 10:37 AM, Stephen Berman
> > stephen.berman@gmx.net wrote:
> > 
> > > On Fri, 19 Apr 2024 21:50:12 +0000 Heime heimeborgia@protonmail.com wrote:
> > > 
> > > > Sent with Proton Mail secure email.
> > > > 
> > > > On Saturday, April 20th, 2024 at 9:04 AM, Drew Adams drew.adams@oracle.com wrote:
> > > > 
> > > > > > This interactive function requests the user to input a string
> > > > > > associated with the current line number. I want to change it so
> > > > > > that the function picks out the text on the current line or the
> > > > > > text of the next non-blank line. But also allow the user to write
> > > > > > their own text for the line.
> > > > > 
> > > > > ...
> > > > > 
> > > > > > (interactive "sString: ")
> > > > > 
> > > > > Don't use that, if you want to provide a
> > > > > default value for the user input.
> > > > > 
> > > > > Instead, use a function that accepts a
> > > > > default value. E.g., `read-string' or` completing-read'.
> > > > > 
> > > > > Read how to use `interactive' with a sexp as argument that returns the list of args you want` interactive' to pass
> > > > > to the function body.
> > > > > 
> > > > > https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html
> > > > 
> > > > Have started with this to get the non-blank text. But still no way for
> > > > use to use his own text.
> > > 
> > > Follow Drew's advice, e.g. use read-string with your if-sexp as the
> > > default value. (But what if the next line after a blank line is also
> > > blank? And the string (thing-at-point 'line t) returns includes the
> > > newline at the end of the line; do you want that?)
> > > 
> > > Steve Berman
> > 
> > If the next line after a blank line is also blank, I continue until
> > I get to the first non-blank line.
> 
> 
> What happens if the buffer ends in one or more blank lines?

In such case I give an empty string to read-string default value LINE,
and the user can insert his own text.
 
> > I have noticed the newline at the end of the line - I do not want that.
> > Want to remove leading and trailing blanks as well.
> 
> string-trim
> 
> Steve Berman
 
There will certainly be a lot of elisp in the interactive part.

> > My latest version follows.
> > 
> > (defun tema-mark ()
> > "Store a string with the line number in `my-alist`.
> > If the current line is blank, move to the next non-blank line."
> > (interactive)
> > 
> > (let* ((initial-line (thing-at-point 'line t))
> > (initial-line-number (line-number-at-pos))
> > (line (if (string-blank-p initial-line)
> > (progn
> > (forward-line)
> > (while (string-blank-p (thing-at-point 'line t))
> > (forward-line))
> > (thing-at-point 'line t))
> > initial-line))
> > (lnum (line-number-at-pos))
> > (text (read-string "Enter text to store: " line)))
> > 
> > (setq-local tema-lugar
> > (append tema-lugar
> > (list (cons text lnum)))) ))



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

* Re: [External] : Getting text from next non-blank line
  2024-04-19 23:12         ` Stephen Berman
  2024-04-19 23:18           ` Heime
@ 2024-04-19 23:31           ` Heime
  1 sibling, 0 replies; 9+ messages in thread
From: Heime @ 2024-04-19 23:31 UTC (permalink / raw)
  To: Stephen Berman
  Cc: Drew Adams, Heime via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Saturday, April 20th, 2024 at 11:12 AM, Stephen Berman <stephen.berman@gmx.net> wrote:

> On Fri, 19 Apr 2024 23:00:30 +0000 Heime heimeborgia@protonmail.com wrote:
> 
> > On Saturday, April 20th, 2024 at 10:37 AM, Stephen Berman
> > stephen.berman@gmx.net wrote:
> > 
> > > On Fri, 19 Apr 2024 21:50:12 +0000 Heime heimeborgia@protonmail.com wrote:
> > > 
> > > > Sent with Proton Mail secure email.
> > > > 
> > > > On Saturday, April 20th, 2024 at 9:04 AM, Drew Adams drew.adams@oracle.com wrote:
> > > > 
> > > > > > This interactive function requests the user to input a string
> > > > > > associated with the current line number. I want to change it so
> > > > > > that the function picks out the text on the current line or the
> > > > > > text of the next non-blank line. But also allow the user to write
> > > > > > their own text for the line.
> > > > > 
> > > > > ...
> > > > > 
> > > > > > (interactive "sString: ")
> > > > > 
> > > > > Don't use that, if you want to provide a
> > > > > default value for the user input.
> > > > > 
> > > > > Instead, use a function that accepts a
> > > > > default value. E.g., `read-string' or` completing-read'.
> > > > > 
> > > > > Read how to use `interactive' with a sexp as argument that returns the list of args you want` interactive' to pass
> > > > > to the function body.
> > > > > 
> > > > > https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Interactive.html
> > > > 
> > > > Have started with this to get the non-blank text. But still no way for
> > > > use to use his own text.
> > > 
> > > Follow Drew's advice, e.g. use read-string with your if-sexp as the
> > > default value. (But what if the next line after a blank line is also
> > > blank? And the string (thing-at-point 'line t) returns includes the
> > > newline at the end of the line; do you want that?)
> > > 
> > > Steve Berman
> > 
> > If the next line after a blank line is also blank, I continue until
> > I get to the first non-blank line.
> 
> 
> What happens if the buffer ends in one or more blank lines?
> 
> > I have noticed the newline at the end of the line - I do not want that.
> > Want to remove leading and trailing blanks as well.
> 
> 
> string-trim

string-trim should also handle the removal of the ending newline.
 
> Steve Berman
> 
> > My latest version follows.
> > 
> > (defun tema-mark ()
> > "Store a string with the line number in `my-alist`.
> > If the current line is blank, move to the next non-blank line."
> > (interactive)
> > 
> > (let* ((initial-line (thing-at-point 'line t))
> > (initial-line-number (line-number-at-pos))
> > (line (if (string-blank-p initial-line)
> > (progn
> > (forward-line)
> > (while (string-blank-p (thing-at-point 'line t))
> > (forward-line))
> > (thing-at-point 'line t))
> > initial-line))
> > (lnum (line-number-at-pos))
> > (text (read-string "Enter text to store: " line)))
> > 
> > (setq-local tema-lugar
> > (append tema-lugar
> > (list (cons text lnum)))) ))



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

end of thread, other threads:[~2024-04-19 23:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19 20:53 Getting text from next non-blank line Heime
2024-04-19 21:04 ` [External] : " Drew Adams
2024-04-19 21:38   ` Heime
2024-04-19 21:50   ` Heime
2024-04-19 22:37     ` Stephen Berman
2024-04-19 23:00       ` Heime
2024-04-19 23:12         ` Stephen Berman
2024-04-19 23:18           ` Heime
2024-04-19 23:31           ` Heime

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).