[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [External] : Getting text from next non-blank line
From: |
Heime |
Subject: |
Re: [External] : Getting text from next non-blank line |
Date: |
Fri, 19 Apr 2024 23:00:30 +0000 |
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)))) ))