From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Morgan Willcock Newsgroups: gmane.emacs.bugs Subject: bug#68185: [PATCH] Ensure indent-region argument order is correct Date: Sun, 31 Dec 2023 21:20:11 +0000 Message-ID: <874jfy6pdg.fsf@ice9.digital> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26987"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 68185@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 31 22:21:27 2023 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 1rK3FO-0006oN-CN for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 31 Dec 2023 22:21:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rK3F0-000183-Qf; Sun, 31 Dec 2023 16:21:02 -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 1rK3Ez-00017p-KZ for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 16:21:01 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rK3Ez-0001bU-CR for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 16:21:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rK3F0-0003TG-MW for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 16:21:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Morgan Willcock Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 Dec 2023 21:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68185 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170405764513311 (code B ref -1); Sun, 31 Dec 2023 21:21:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Dec 2023 21:20:45 +0000 Original-Received: from localhost ([127.0.0.1]:47124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rK3Ej-0003Sc-8k for submit@debbugs.gnu.org; Sun, 31 Dec 2023 16:20:45 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:43404) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rK3Eg-0003SJ-Up for submit@debbugs.gnu.org; Sun, 31 Dec 2023 16:20:43 -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 1rK3EW-00015S-JJ for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 16:20:32 -0500 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rK3EK-0001PF-4N for bug-gnu-emacs@gnu.org; Sun, 31 Dec 2023 16:20:32 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id B85F0FF805 for ; Sun, 31 Dec 2023 21:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ice9.digital; s=gm1; t=1704057613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=m5yn/nAMptIS0Y6fvyUyj0WM5nYA2vw3DytoIXjCYJU=; b=Up7J0ttMSHUxHK/6+dAFm01BANCvicYjkG6jQ6dGmgQbMXQXgLtvdd7fL6Drgiw0f0YXZ0 95iPBOmPt46woGIpA2+IOIZ+lv7cDHUH14QhrH2QONetOZ6eWA+rg8hlk1MPLlugJLW0mg aT28IVhOJ9L922jb7jvuU+KFXkgpc7I6KE1z4o2WTOyNiHGTwvCA9XvaQQDT+ef7zZz1eW BXW2W/Qei2u1vi7b3NJRDqEBW03VPqYcaWNy6jJv6EG+3z475+s6ZSKacj4NY4GjBFA4hW v033FBCQzYW9QGlkvuMq5ry4N0ULwiiBsa+9Pl0+syPCvUTwU0jJKMlJK6R0Bg== X-GND-Sasl: morgan@ice9.digital Received-SPF: pass client-ip=217.70.183.199; envelope-from=morgan@ice9.digital; helo=relay9-d.mail.gandi.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:277164 Archived-At: --=-=-= Content-Type: text/plain Tags: patch The attached patch fixes an issue with Tempo template insertion, where the region start is assumed to be a position before the region end. If the user selects a region in a backwards direction the correct indentation will not be applied: (require 'tempo) (tempo-define-template "indent-region-test" '(r>)) (with-temp-buffer (emacs-lisp-mode) (insert " one\n two\n three") (goto-char (point-min)) (set-mark-command nil) (goto-char (point-max)) (tempo-template-indent-region-test) (buffer-string)) ;; => "one\ntwo\nthree" (with-temp-buffer (emacs-lisp-mode) (insert " one\n two\n three") (goto-char (point-max)) (set-mark-command nil) (goto-char (point-min)) (tempo-template-indent-region-test) (buffer-string)) ;; => " one\n two\nthree" The start and end positions are already identified and stored using separate variables, so the patch just uses these values instead of assuming the point and mark order. I've also removed passing nil as the third argument since the argument is optional. In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw3d scroll bars) of 2023-07-31 built on inspiron Windowing system distributor 'The X.Org Foundation', version 11.0.12101007 System Description: Debian GNU/Linux 12 (bookworm) Configured using: 'configure --with-native-compilation --with-cairo --with-json --with-xml2 --with-x-toolkit=lucid' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Ensure-indent-region-argument-order-is-correct.patch >From 4d7fdafeee5f6540d5e39549fa0a9927176171bb Mon Sep 17 00:00:00 2001 From: Morgan Willcock Date: Sun, 31 Dec 2023 20:47:17 +0000 Subject: [PATCH] Ensure indent-region argument order is correct * lisp/tempo.el (tempo-insert): Call indent-region with the stored region markers to ensure that the start and end arguments are used in the correct order. --- lisp/tempo.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/tempo.el b/lisp/tempo.el index 45dc24dcc97..1b6cc4476e1 100644 --- a/lisp/tempo.el +++ b/lisp/tempo.el @@ -333,7 +333,8 @@ tempo-insert (`(r> . ,rest) (if on-region (progn (goto-char tempo-region-stop) - (indent-region (mark) (point) nil)) + (indent-region tempo-region-start + tempo-region-stop)) (tempo-insert-prompt-compat rest))) (`(s ,name) (tempo-insert-named name)) (`(l . ,rest) (dolist (elt rest) (tempo-insert elt on-region))) @@ -344,7 +345,7 @@ tempo-insert ('r> (if on-region (progn (goto-char tempo-region-stop) - (indent-region (mark) (point) nil)) + (indent-region tempo-region-start tempo-region-stop)) (tempo-insert-mark (point-marker)))) ('> (indent-according-to-mode)) ('& (if (not (or (= (current-column) 0) -- 2.39.2 --=-=-=--