From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.help Subject: Re: How to do a massive unfill paragraph operation over several hundred files? Date: Tue, 2 Oct 2018 11:37:50 -0400 Message-ID: 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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1538494697 29085 195.159.176.226 (2 Oct 2018 15:38:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 2 Oct 2018 15:38:17 +0000 (UTC) Cc: Robert Pluim , moasen@zoho.com, Help Gnu Emacs mailing list To: wildgruber@tu-berlin.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 02 17:38:12 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 1g7MkV-0007RV-KU for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Oct 2018 17:38:11 +0200 Original-Received: from localhost ([::1]:44336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7Mmc-0000qV-5X for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Oct 2018 11:40:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7MkX-0007mr-0b for help-gnu-emacs@gnu.org; Tue, 02 Oct 2018 11:38:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7MkO-0006vO-UU for help-gnu-emacs@gnu.org; Tue, 02 Oct 2018 11:38:07 -0400 Original-Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]:42873) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g7MkN-0006u8-N5 for help-gnu-emacs@gnu.org; Tue, 02 Oct 2018 11:38:04 -0400 Original-Received: by mail-ot1-x329.google.com with SMTP id h26-v6so2311855otl.9 for ; Tue, 02 Oct 2018 08:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wLuZs0cJOCfnG9+eFxYcKHs6KPiqhcMfZjlF4X/2EaE=; b=c9FuRpPM8c433uG8AARK7A6rmGTTtVcsKZQxPCj3KNbXscOw5tQvNmxQnoYqi+wnog EutWAqnuiUn65G1ymIschRA+KSriRQzA1N7BXljqfKsuvWVU7nKealUse2XnFdk/jsdl VvfjXItOpQL1kMa+VwFGGt/NcVFaoYVsv7OiNKUVl1u3lA3DU9xgI7zLnAdujyzLOo7M clUB2p+vL/1DrF11E4F/0M4BzirC2w1gwXgyl7NAcETElqMUFwTpmTXpa9Lu9EDt5sKt q4z0bCCVJq7cXiK6TNZWNt43QHaLEt0+t9FL7Z3p92XpXla4P4eyif5VCPUOVlqH0k2X EJfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wLuZs0cJOCfnG9+eFxYcKHs6KPiqhcMfZjlF4X/2EaE=; b=GgekfT4GqfiLMgVESHknplQ1tCziuQ/bN7V4PU8sYA7DZC2QQTJuejCH8OX2NHL0K3 JukF8GPqxzMVx45Ri4qAU8SHKkbzXGDrnuvCJ3QBxC7BtdMayRYPt49tP3+9bRrFE+fB dxHeKWuQvfFjr7KOPa8E7ZYPjrlJFklWC+3kCOUjM/GqwQB4XMzCs9tICIODtcJJ9az9 ZCq9OW2ly+7eUqynx8UtNqA5PEiY5QnQnS6hElXtI0YMx6dr7x6dOvy+76GCnU6/lxEv 4L/uYVN6HQwj/8QZ6Fb58aDcS7f17U3/p6zz6aqbUHWXs4SB8C3ebgWU8ysbDFZR8W7k S/nw== X-Gm-Message-State: ABuFfoi4ckOJJW9HGKrUSuupCnKsh8j6LNaOUni5i4E48tIHqLVX3+sL 0Asd2w/pRjs7hJG0W2wH1bLuMCqJdTiD1bVLRis= X-Google-Smtp-Source: ACcGV61NbWQ6jp9S2XHiqp71B1aDvW2QNLfEVKr+23vUIn2K1OeFsl0ZG3Q1vdWphVbXmiZZltInzkKESVtPRxrrPwo= X-Received: by 2002:a9d:5ab:: with SMTP id 40-v6mr9169441otd.264.1538494682393; Tue, 02 Oct 2018 08:38:02 -0700 (PDT) In-Reply-To: <87efd8v99e.fsf@tu-berlin.de> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::329 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:118093 Archived-At: On Tue, 2 Oct 2018 at 08:11, Gerald Wildgruber wrote: > (dolist (f argv) > (find-file f) > (mark-whole-buffer) > (unfill-paragraph t) > (org-forward-paragraph) > (save-buffer)) > > ------------------------------------------------------------ > > I call this from a terminal like so: > > emacs -Q --batch --script unfill.el FILE.org > > Unfortunately, nothing happens; I get two "Mark set" messages in the terminal, but the file itself remains untouched. It isn't edited at all, same timestamp etc. 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) ...) By the way, I don't see the benefit of invoking Emacs in batch mode here, especially since this sounds like a one-off transformation. Just 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)))) (of course replace the (directory-files-recursively...) thing with (list "test-file.org") first to make sure it works right.)