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: Sun, 30 Sep 2018 21:47:32 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

Hi,

thanks for the hint!

What I do now is the following: in every file I want to normalize (= unwrap) I 
use a kbd macro consisting of two consecutive functions:

1. an unfill function (originally posted by Stefan Monnier if I remember 
correctly):

(defun unfill-paragraph (&optional region)
  "Takes a multi-line paragraph and makes it into a single line of text."
  (interactive (progn (barf-if-buffer-read-only) '(t)))
  (let ((fill-column (point-max)))
    (fill-paragraph nil region)))

2. org-forward-paragraph

I then repeat the macro with an infinite argument.

This works quite well and the result requires very little manual correction; 
all Org mode constructs like lists, blocks etc are preserved.

But these are of course interactive functions; how would I script them to 
non-interactive code in the way you proposed for emacs batch processing, i.e. 
not expecting any input except a number files to operate on? Can I load 
org-mode on the fly in order for emacs to understand the second function 
(org-forward-paragraph)?

Thanks

Gerald.



On Sa, Sep 29 2018, Emanuel Berg <moasen@zoho.com> wrote:

> Gerald Wildgruber wrote:
>
>> MY QUESTION: What would be a good way to
>> AUTOMATE such an unfill operation, removing all
>> line breaks from all paragraphs over a large
>> number of files?
>
> Script to insert a string into files
> 1, 2, and 3:
>
>     #! /bin/zsh
>
>     local script=do-this.el
>
>     emacs -Q --batch --script $script 1 2 3
>
> Elisp to do it:
>
>     ;; do-this.el
>
>     (dolist (f argv)
>       (find-file f)
>       (insert "Sail Ho!") ; do your thing here
>       (save-buffer) )

---------------------
Sent with mu4e



reply via email to

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