unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: Drew Adams <drew.adams@oracle.com>,
	Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: [External] : Getting text from next non-blank line
Date: Fri, 19 Apr 2024 23:31:39 +0000	[thread overview]
Message-ID: <aiXqsRC0pc9YrOq6rnmo7Qp0xTWf-8PA63arhaoatFfxWaTkHT4HM2VA8o8-pzTXOwR9j6TizDTZ924pQggTFmnS5OByRbJgqhJU_hUUEss=@protonmail.com> (raw)
In-Reply-To: <87h6fxkkuq.fsf@gmx.net>






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



      parent reply	other threads:[~2024-04-19 23:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='aiXqsRC0pc9YrOq6rnmo7Qp0xTWf-8PA63arhaoatFfxWaTkHT4HM2VA8o8-pzTXOwR9j6TizDTZ924pQggTFmnS5OByRbJgqhJU_hUUEss=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=stephen.berman@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).