[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to do a massive unfill paragraph operation over several hundred
From: |
Gerald Wildgruber |
Subject: |
Re: How to do a massive unfill paragraph operation over several hundred files? |
Date: |
Mon, 8 Oct 2018 07:42:52 +0200 |
User-agent: |
mu4e 1.1.0; emacs 27.0.50 |
On Do, Okt 04 2018, Noam Postavsky <npostavs@gmail.com> wrote:
>> Main problem seems to be: how to iterate through ALL paragraphs of the
>> buffer programmatically, applying "fill-paragraph" each time anew.
>
> Perhaps this?
>
> (let ((fill-column most-positive-fixnum))
> (dolist (f (directory-files-recursively
> "dir/with/my/files/" (rx (or ".tex" ".org") eos)))
> (with-current-buffer (find-file-noselect f)
> (while (not (eobp))
> (fill-paragraph)
> (org-forward-paragraph))
> (save-buffer))))
Thanks Noam, this almost did it! but I couldn't see through a last problem, it
sometimes worked, sometimes didn't. Here's the solution someone from the emacs
Org mode mailing list pointed me to:
http://lists.gnu.org/archive/html/emacs-orgmode/2018-10/msg00070.html
I had to UNFOLD the entries before working on them, even programmatically, via
"(org-show-all)".
I do this now from a lisp buffer and both functions work exactly as expected:
single file:
============
(let ((fill-column most-positive-fixnum))
(dolist (f (list "~/lorem.org"))
(with-current-buffer (find-file-noselect f)
(org-show-all)
(while (not (eobp))
(fill-paragraph)
(org-forward-paragraph))
(save-buffer))))
recursively through dir tree:
=============================
(let ((fill-column most-positive-fixnum))
(dolist (f (directory-files-recursively
"/dirs/with/org/files/" (rx (or ".org" ".outl") eos)))
(with-current-buffer (find-file-noselect f)
(org-show-all)
(while (not (eobp))
(fill-paragraph)
(org-forward-paragraph))
(save-buffer))))
That's great; I'm glad it works now from within emacs itself (and not via sed,
awk or tr as I tried before), harnessing all the knowledge the editor has of
its own constructs, especially with some of the more complicated list and
enumeration structures, -- all of them are correctly unfilled. This is solved
now.
Thanks again to everyone who contributed!
Gerald.
--
Sent with mu4e
- Re: How to do a massive unfill paragraph operation over several hundred files?, Gerald Wildgruber, 2018/10/01
- Re: How to do a massive unfill paragraph operation over several hundred files?, Emanuel Berg, 2018/10/01
- Re: How to do a massive unfill paragraph operation over several hundred files?, Gerald Wildgruber, 2018/10/01
- Re: How to do a massive unfill paragraph operation over several hundred files?, Robert Pluim, 2018/10/01
- Re: How to do a massive unfill paragraph operation over several hundred files?, Gerald Wildgruber, 2018/10/02
- Re: How to do a massive unfill paragraph operation over several hundred files?, Noam Postavsky, 2018/10/02
- Re: How to do a massive unfill paragraph operation over several hundred files?, Gerald Wildgruber, 2018/10/03
- Re: How to do a massive unfill paragraph operation over several hundred files?, Noam Postavsky, 2018/10/03
- Re: How to do a massive unfill paragraph operation over several hundred files?,
Gerald Wildgruber <=
- Message not available
- Re: How to do a massive unfill paragraph operation over several hundred files?, Emanuel Berg, 2018/10/03
- Message not available
- Re: How to do a massive unfill paragraph operation over several hundred files?, Emanuel Berg, 2018/10/02
Message not available