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: Wed, 3 Oct 2018 12:11:03 +0200 Message-ID: <877eizwdag.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> 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 1538561388 6246 195.159.176.226 (3 Oct 2018 10:09:48 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 3 Oct 2018 10:09:48 +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 Wed Oct 03 12:09:44 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 1g7e6B-0001XY-Gg for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Oct 2018 12:09:43 +0200 Original-Received: from localhost ([::1]:47791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7e8H-0000Pj-NL for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Oct 2018 06:11:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7e7e-0000O4-W0 for help-gnu-emacs@gnu.org; Wed, 03 Oct 2018 06:11:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7e7a-0000Lf-L5 for help-gnu-emacs@gnu.org; Wed, 03 Oct 2018 06:11:14 -0400 Original-Received: from exchange.tu-berlin.de ([130.149.7.70]:55141) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7e7Z-0000Ix-NP for help-gnu-emacs@gnu.org; Wed, 03 Oct 2018 06:11:10 -0400 Original-Received: from SPMA-01.tubit.win.tu-berlin.de (localhost.localdomain [127.0.0.1]) by localhost (Email Security Appliance) with SMTP id 3B0D87DE285_BB495B9B; Wed, 3 Oct 2018 10:11:05 +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-01.tubit.win.tu-berlin.de (Sophos Email Appliance) with ESMTPS id C83507DE270_BB495B8F; Wed, 3 Oct 2018 10:11:04 +0000 (GMT) Original-Received: from corax (178.198.8.89) by ex-mbx-10.tubit.win.tu-berlin.de (172.26.35.180) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 3 Oct 2018 12:11:04 +0200 In-Reply-To: X-ClientProxiedBy: EX-MBX06.tubit.win.tu-berlin.de (172.26.35.176) To ex-mbx-10.tubit.win.tu-berlin.de (172.26.35.180) 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=ElUF1Wyakh1i3pLe2fdADLS2So4Qqqp9tlTwWqedEFI=; b=cf4FsyvRdK/h14BjYmPj8QiE6ckvM7QmsBJf7g0VXY93eChfdOYzEV7l4yt4CpahOKPrqNEZW7BVnf8OrT2W5wjjGguvdtDB/PpsyPGOHd7Z7/xLdZcfBj/lSQ7A4yLROMEmZoPMohlxrV/7BbnaSajfZ8JcOJY4263qmXpRa6E= 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:118098 Archived-At: Thanks. On Di, Okt 02 2018, Noam Postavsky 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