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

[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: Wed, 3 Oct 2018 12:11:03 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

Thanks.

On Di, Okt 02 2018, Noam Postavsky <npostavs@gmail.com> wrote:

> I think the problem is that find-file only makes sense for interactive
> functions, because it switches the displayed buffer (which takes
> effect after the current command finishes), but doesn't actually set
> the current buffer (i.e., no immediate change).
>
> So you should have
>
>     (with-current-buffer (find-file-noselect f)
>       (mark-whole-buffer)
>       ...)

The script then looks like this:

(dolist (f argv)
  (with-current-buffer (find-file-noselect f)
  (mark-whole-buffer)
  (unfill-paragraph t)
  (org-forward-paragraph)
  (save-buffer)))

It turns out that this works just on the FIRST paragraph of the file! Only this 
one is edited. The script does not move to the next paragraph.

So, what works well in a kbd macro (moving point forward to next paragraph via 
org-forward-paragraph) does not in this script.

Cf. docstring of this function: "Move forward to beginning of next paragraph or 
equivalent. The function moves point to the beginning of the next visible 
structural element, which can be a paragraph, a table, a list item, moving 
point to beginning".

> put the expression which does the work into *scratch* and evaluate.
> Something like 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)
>           (fill-region (point-min) (point-max)) ; Unfill, per `fill-column'
>           (save-buffer))))

Yes, that almost did it!

But: for some reason the "fill-region" function you use does not work on list 
constructs like:

1. text text text text text text text text text
2. text text text text text text text text text text text
3. text text text text text text text text text text

The text in these constructs doesn't get unfilled, -- whereas it is correctly 
unfilled by using the "unfill-paragraph" function (which ultimately calls 
"fill-paragraph").

I tried to rewrite your code to use "fill-paragraph" instead of "fill-region" 
but didn't succeed.

Main problem seems to be: how to iterate through ALL paragraphs of the buffer 
programmatically, applying "fill-paragraph" each time anew.

--
Sent with mu4e



reply via email to

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