help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : How to get all paragraphs in list?


From: Jean Louis
Subject: Re: [External] : How to get all paragraphs in list?
Date: Mon, 5 Sep 2022 20:04:51 +0300
User-agent: Mutt/+ () (2022-06-11)

* Drew Adams <drew.adams@oracle.com> [2022-09-05 19:03]:
> Without looking at the details of all you ask,
> maybe something like this helps?
> 
> (defun paragraphs-in-region (&optional start end msgp)
>   (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)))

Thank you, that gave me idea for these functions:

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

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

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?

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]