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

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

How to get all paragraphs in list?


From: Jean Louis
Subject: How to get all paragraphs in list?
Date: Mon, 05 Sep 2022 07:15:50 +0300

I would like to get all paragraphs in a list, even if paragraphs are
separated by two or more spaces, I would still like those spaces.

Purpose of doing it is joining lines of such paragraph as to paste it
into website pages or chats. Wrapped lines do not look nice when
pasted. 

Starting function to join lines is this one:

(defun join-lines ()
  "Joins lines of a paragraph of 100000 chars."
  (interactive)
  (let ((old fill-column))
    (setq fill-column 100000)
    (fill-paragraph nil)
    (setq fill-column old)))

My starting point to get all paragraphs could be in this function:

(defun sort-paragraphs (reverse beg end)
  "Sort paragraphs in region alphabetically; argument means descending order.
Called from a program, there are three arguments:
REVERSE (non-nil means reverse order), BEG and END (region to sort).
The variable `sort-fold-case' determines whether alphabetic case affects
the sort order."
  (interactive "P\nr")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (sort-subr reverse
                 (lambda ()
                   (while (and (not (eobp)) (looking-at paragraph-separate))
                     (forward-line 1)))
                 (lambda ()
                   (forward-paragraph)
                   ;; If the buffer doesn't end with a newline, add a
                   ;; newline to avoid having paragraphs being
                   ;; concatenated after sorting.
                   (when (and (eobp)
                              (not (bolp)))
                     (insert "\n")))))))

Is there any existing way to fetch all paragraphs (separated by two or
more spaces) in the list?


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]