From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Gerald Wildgruber Newsgroups: gmane.emacs.help Subject: Re: How to do a massive unfill paragraph operation over several hundred files? Date: Mon, 8 Oct 2018 07:42:52 +0200 Message-ID: <8736thouxv.fsf@tu-berlin.de> References: <8636ts4jz3.fsf@zoho.com> <86zhvyzq4c.fsf@zoho.com> <86muryype2.fsf@zoho.com> <87in2lvikf.fsf@tu-berlin.de> <875zyl1yls.fsf@gmail.com> <87efd8v99e.fsf@tu-berlin.de> <877eizwdag.fsf@tu-berlin.de> Reply-To: wildgruber@tu-berlin.de NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1538977286 20766 195.159.176.226 (8 Oct 2018 05:41:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 8 Oct 2018 05:41:26 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 27.0.50 Cc: Robert Pluim , moasen@zoho.com, Help Gnu Emacs mailing list To: Noam Postavsky Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 08 07:41:22 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g9OID-0005IY-Sf for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Oct 2018 07:41:22 +0200 Original-Received: from localhost ([::1]:44585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9OKK-0000yW-Aj for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Oct 2018 01:43:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9OJn-0000yE-4N for help-gnu-emacs@gnu.org; Mon, 08 Oct 2018 01:43:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9OJj-0003MK-Oz for help-gnu-emacs@gnu.org; Mon, 08 Oct 2018 01:42:58 -0400 Original-Received: from exchange.tu-berlin.de ([130.149.7.70]:15073) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9OJj-0003Lm-DI for help-gnu-emacs@gnu.org; Mon, 08 Oct 2018 01:42:55 -0400 Original-Received: from SPMA-02.tubit.win.tu-berlin.de (localhost.localdomain [127.0.0.1]) by localhost (Email Security Appliance) with SMTP id 4216735F14_BBAEE5EB; Mon, 8 Oct 2018 05:42:54 +0000 (GMT) Original-Received: from exchange.tu-berlin.de (exchange.tu-berlin.de [130.149.7.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "exchange.tu-berlin.de", Issuer "DFN-Verein Global Issuing CA" (not verified)) by SPMA-02.tubit.win.tu-berlin.de (Sophos Email Appliance) with ESMTPS id DEE1132F5E_BBAEE5DF; Mon, 8 Oct 2018 05:42:53 +0000 (GMT) Original-Received: from corax (178.198.8.89) by ex-mbx-10.tubit.win.tu-berlin.de (130.149.6.164) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Oct 2018 07:42:53 +0200 In-Reply-To: X-ClientProxiedBy: EX-MBX06.tubit.win.tu-berlin.de (130.149.6.150) To ex-mbx-10.tubit.win.tu-berlin.de (130.149.6.164) X-PMWin-Version: 4.0.1, Antivirus-Engine: 3.73.0, Antivirus-Data: 5.55 X-PureMessage: [Scanned] X-SASI-RCODE: 200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tu-berlin.de; h=references:from:to:cc:subject:reply-to:in-reply-to:date:message-id:mime-version:content-type; s=dkim-tub; bh=5295L7qp8PBIrYIHDXSmeX743oxrl5B8QRZzmgeqgBw=; b=cuWG28maM2IIah0e5JbSELUOGZ6AYlIvDGBN5M8bJz+tuduDQMLXaIaE7PiaU9wRRTn5tXsjlbSlj+dWlU69R2UCMYh/BjC0nFZEd2V9t6bOxsii43gVLcuZ4dWobkDt02C+8cWqT91LZRtIvOJ/1H6rU7XixpZyIJCUl/jXTas= X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 130.149.7.70 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118198 Archived-At: On Do, Okt 04 2018, Noam Postavsky 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