From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#59201: `fill-paragraph' works differently depending on whether Emacs is run in batch mode or not Date: Sat, 12 Nov 2022 13:17:05 +0200 Message-ID: <83cz9so21a.fsf@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9864"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59201@debbugs.gnu.org To: Paul Pogonyshev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 12 12:18:34 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1otoWw-0002LN-Nu for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Nov 2022 12:18:34 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otoWc-0005Vs-OK; Sat, 12 Nov 2022 06:18:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otoWQ-0005UG-Au for bug-gnu-emacs@gnu.org; Sat, 12 Nov 2022 06:18:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otoWQ-0002k5-09 for bug-gnu-emacs@gnu.org; Sat, 12 Nov 2022 06:18:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otoWP-0008N9-NS for bug-gnu-emacs@gnu.org; Sat, 12 Nov 2022 06:18:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Nov 2022 11:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59201 X-GNU-PR-Package: emacs Original-Received: via spool by 59201-submit@debbugs.gnu.org id=B59201.166825183232119 (code B ref 59201); Sat, 12 Nov 2022 11:18:01 +0000 Original-Received: (at 59201) by debbugs.gnu.org; 12 Nov 2022 11:17:12 +0000 Original-Received: from localhost ([127.0.0.1]:47399 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otoVc-0008Ly-0d for submit@debbugs.gnu.org; Sat, 12 Nov 2022 06:17:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60196) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otoVW-0008LK-DE; Sat, 12 Nov 2022 06:17:10 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otoVQ-0002YX-HL; Sat, 12 Nov 2022 06:17:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=rF9K21WzflKuhHTEMQ1zH+lwdm42AsD+dK/XgmZY0bs=; b=MyZcNfVhBKVWci4S07a2 Kg3sBWwRxUHGYc6gql4zSE+9zFXv7EJi+32a9gDF72SLMya06pMnU9l/IlL+Pk+FsR3FeKuVwt5l4 k36TTVBwW4W4DxN2IijUMzPmzt8yKCheQ4gfGU7au2CDQL336AbOFHjdIVcJIjpybp+qLCpJ5Xcgg z4pNF7cuIodcSYDlG/NkPtjLTADd5dlrWKjKyC/F9+6HONH8FPsNmTZLUWoKewgMaO82zo+NO/28o fes16+qNJee5XzSbNrTnlJTO2pGDNQ0moe8/xBmDWTeR9JuR1mj7qyGiG6A1BH+/ldcU+h+jhe5rc IJMzOlgfyG1+DQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otoVP-00057T-NF; Sat, 12 Nov 2022 06:17:00 -0500 In-Reply-To: (message from Paul Pogonyshev on Fri, 11 Nov 2022 20:40:25 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:247647 Archived-At: tags 59201 notabug thanks > From: Paul Pogonyshev > Date: Fri, 11 Nov 2022 20:40:25 +0100 > > $ emacs --batch --eval "(princ (with-temp-buffer (insert \"Lorem ipsum dolor sit amet, consectetur > adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...\n\") (set-mark 1) > (fill-paragraph nil t) (buffer-string)) 'external-debugging-output)" > > Prints the text in one line, i.e. `fill-paragraph' appears to have done nothing. > > If you replace `--batch' in the command line with `-Q' without changing anything else: > > $ emacs -Q --eval "(princ (with-temp-buffer (insert \"Lorem ipsum dolor sit amet, consectetur adipiscing > elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...\n\") (set-mark 1) (fill-paragraph nil > t) (buffer-string)) 'external-debugging-output)" > > the output in the console becomes formatted in two lines, i.e. `fill-paragraph' does its work. > > In both cases the code is exactly the same and the function is called non-interactively. The only difference, > as far as I see, is the batch mode. Your program has a bug: it doesn't make sure transient-mark-mode is turned ON, and it doesn't move point after inserting the text into the inserted text. Thus, point is left at EOB, where there's no paragraph that fill-paragraph can work on. The doc string of fill-paragraph says: Fill paragraph at or after point. [...] The REGION argument is non-nil if called interactively; in that case, if Transient Mark mode is enabled and the mark is active, call ‘fill-region’ to fill each of the paragraphs in the active region, instead of just filling the current paragraph. If you modify the program as follows: $ emacs --batch --eval "(princ (with-temp-buffer (insert \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...\n\") (goto-char (point-min)) (set-mark 1) (fill-paragraph nil t) (buffer-string)) 'external-debugging-output)" then the text will be filled in --batch mode as well. Transient Mark mode is turned on by default only in interactive sessions, and if you meant fill-region to work on the active region, then the solution is to modify the program like this: $ emacs --batch --eval "(princ (with-temp-buffer (insert \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...\n\") (transient-mark-mode 1) (set-mark 1) (fill-paragraph nil t) (buffer-string)) 'external-debugging-output)"