From: Jean Louis <bugs@gnu.support>
To: Drew Adams <drew.adams@oracle.com>
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: [External] : How to get all paragraphs in list?
Date: Wed, 7 Sep 2022 09:03:28 +0300 [thread overview]
Message-ID: <Yxg0MKUfISeRyIzA@protected.localdomain> (raw)
In-Reply-To: <SJ0PR10MB5488E51C7B1B732BD9A2AF49F37F9@SJ0PR10MB5488.namprd10.prod.outlook.com>
* Drew Adams <drew.adams@oracle.com> [2022-09-05 21:07]:
> > However, there is some problem as it blocks, never ends, when I
> > interrupt it with Ctrl-G then I see that lines have been joined in all
> > of the buffer, but `while' loop was I guess still running.
> >
> > Do you maybe know why?
>
> You're repeatedly refilling/joining the same paragraphs.
>
> `M-x debug-on-entry' shows you exactly what any of
> your functions is doing, step by step.
You have made this function:
(defun paragraphs-in-region (&optional start end msgp)
"Return list of paragraphs in region.
By Drew Adams, Date: Mon, 5 Sep 2022 16:02:32 +0000, GNU Emacs Help."
(interactive
(if (use-region-p)
(list (region-beginning) (region-end) t)
(list (point-min) (point-max) t)))
(let ((paras ()))
(save-excursion
(goto-char start)
(while (< (point) end)
(push (buffer-substring-no-properties
(point)
(progn (forward-paragraph) (point)))
paras))
(setq paras (nreverse paras))
(when msgp (message "Paras: %S" paras))
paras)))
Then I wanted to make general function to iterate over paragraphs this
way:
(defun rcd-paragraphs-iterate (function)
"Iterate FUNCTION over paragraphs.
FUNCTION must accept string as single argument."
(let ((start (if (use-region-p) (region-beginning) (point-min)))
(end (if (use-region-p) (region-end) (point-max))))
(save-excursion
(goto-char start)
(while (< (point) end)
(funcall function)
(forward-paragraph)))))
Then I use following functions to apply on the paragraph.
(defun join-lines ()
"Joins lines of a paragraph."
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(defun join-lines-buffer-or-region ()
"Join lines on all buffer."
(interactive)
(rcd-paragraphs-iterate 'join-lines))
That means `join-lines-buffer-or-region' applies on paragraphs in
buffer or region.
Problem is in:
(while (< (point) end)
(funcall function)
(forward-paragraph)))))
I still cannot understand WHEN is that happening, I just assume that
it happens when there are some empty lines on the end. Sometimes it
works, sometimes not.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2022-09-07 6:03 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-05 4:15 How to get all paragraphs in list? Jean Louis
2022-09-05 4:40 ` Teemu Likonen
2022-09-05 5:12 ` Emanuel Berg
2022-09-05 9:13 ` Alessandro Bertulli
2022-09-05 16:40 ` Jean Louis
2022-09-06 1:31 ` Emanuel Berg
2022-09-16 14:18 ` Jean Louis
2022-09-16 14:21 ` Jean Louis
2022-09-05 16:02 ` [External] : " Drew Adams
2022-09-05 17:04 ` Jean Louis
2022-09-05 18:05 ` Drew Adams
2022-09-06 11:17 ` Jean Louis
2022-09-07 6:03 ` Jean Louis [this message]
2022-09-07 6:13 ` Emanuel Berg
2022-09-07 13:05 ` Yuri Khan
2022-09-07 15:04 ` Drew Adams
2022-09-07 23:51 ` Emanuel Berg
2022-09-16 16:17 ` Yuri Khan
2022-09-16 19:04 ` Jean Louis
2022-09-16 18:55 ` Jean Louis
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=Yxg0MKUfISeRyIzA@protected.localdomain \
--to=bugs@gnu.support \
--cc=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
/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).