From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#35021: M-^ (delete-indentation) doesn't work without a mark present Date: Wed, 27 Mar 2019 16:09:14 +0000 Message-ID: <874l7o47v9.fsf@tcd.ie> References: <20190327141917.GA7614@odo.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="66932"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 35021@debbugs.gnu.org, Stephen Leake , =?UTF-8?Q?=C5=81ukasz?= Stelmach To: Jon Irving Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 27 17:10:19 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9B84-000HEP-1m for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Mar 2019 17:10:16 +0100 Original-Received: from localhost ([127.0.0.1]:50266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9B82-00038x-7n for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Mar 2019 12:10:14 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9B7s-00037S-Vy for bug-gnu-emacs@gnu.org; Wed, 27 Mar 2019 12:10:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9B7r-0002vQ-4U for bug-gnu-emacs@gnu.org; Wed, 27 Mar 2019 12:10:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48199) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h9B7q-0002v9-N4 for bug-gnu-emacs@gnu.org; Wed, 27 Mar 2019 12:10:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h9B7q-0007Qe-DY for bug-gnu-emacs@gnu.org; Wed, 27 Mar 2019 12:10:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 27 Mar 2019 16:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35021 X-GNU-PR-Package: emacs Original-Received: via spool by 35021-submit@debbugs.gnu.org id=B35021.155370296528506 (code B ref 35021); Wed, 27 Mar 2019 16:10:02 +0000 Original-Received: (at 35021) by debbugs.gnu.org; 27 Mar 2019 16:09:25 +0000 Original-Received: from localhost ([127.0.0.1]:33510 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h9B7F-0007Pi-Ak for submit@debbugs.gnu.org; Wed, 27 Mar 2019 12:09:25 -0400 Original-Received: from mail-ed1-f49.google.com ([209.85.208.49]:37007) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h9B7C-0007PS-On for 35021@debbugs.gnu.org; Wed, 27 Mar 2019 12:09:24 -0400 Original-Received: by mail-ed1-f49.google.com with SMTP id v21so14527636edq.4 for <35021@debbugs.gnu.org>; Wed, 27 Mar 2019 09:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=osyhRWtbXZRs3ON1O3WGGGF1x1+56i6MRsVO9ZPbpAo=; b=WZtVuRQpdAC5R2MzCjdu+Z9ld9jefnlU6ov9A4nRLwwcgOaaFNLcrJ1wrx8NPWqhB3 LGAUltKpVU6NgQMDTVWjXM/x8a7rd+YIpADJ+i8nJtTvJsR0Ppc9cIWqIiYo+1XTX3Nk vGa725sMFVE1MS3JQD5ZY5aB+RdPnguabf2AYSWr3fuowatX/+MzlvVPXPkbop1mqqhx Wk0MEvkZTt7y440pUD5K3EDurIdAsohs0T76+vBX3tQqaAVHiCQ5TBpkIKp8Ia2xz3Wp kCOexay7cxWUmzWeGBB/6VeIcTfLl7//QGu1FgQU0l4G/Sf17sGRlutQq9/nff1VQ75p Z9OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=osyhRWtbXZRs3ON1O3WGGGF1x1+56i6MRsVO9ZPbpAo=; b=N5x9hdiv9oeAfmFrRJF7LBdSXSQK6GI4lqwV6omdhaes0ghjEHcvHgNbeRNbDGJ97n ioc/078SxbUnjB9MsCBfXM4cS9O1vMQxT8XiP0Vpmus55fRX4zdH+JbCl/orvSHQlRe9 Ojna3Xsv2qlCf8Oton1Z4g6dX8jW10OKsJ+MOu4F1OczR/w44P+ZmuelsbvHY2vuJPtC oOb53ZENgazyxxlcuoApBUbmTPnZhqJQ7UESQJr2BHksWzdr+P3CZApYxzk/aXHCOTSy Sj2i3aLALVcKeIweSM54ciLxsvj699ou6Q2HXofa4+qMPaDQsMmOPzfiiL42KwyOSgfK EuKQ== X-Gm-Message-State: APjAAAXizueq/0AqZ+e5OYlvG/w+sVno4SapJweEZ1HjCMVG6Napsq1K 4o+6mVz1SgOsX3PFZxq9CFjDHw== X-Google-Smtp-Source: APXvYqwVLlRfN11p5txu2qybjuCCtDQTWDDc4+BKOcta6yIOhaeBWKbkbxIDORHVa9OwmXLgL2LsPQ== X-Received: by 2002:a17:906:18a1:: with SMTP id c1mr15582718ejf.116.1553702956980; Wed, 27 Mar 2019 09:09:16 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:f786:805d:f4ab:1006]) by smtp.gmail.com with ESMTPSA id h10sm4754783ejl.51.2019.03.27.09.09.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 27 Mar 2019 09:09:15 -0700 (PDT) In-Reply-To: <20190327141917.GA7614@odo.localdomain> (Jon Irving's message of "Wed, 27 Mar 2019 10:19:17 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:156859 Archived-At: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-delete-indentation-when-region-is-inactive.patch >From 80cde7b9e392e81d70dc338a4dfa4bfc12f54103 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Wed, 27 Mar 2019 15:13:25 +0000 Subject: [PATCH] Fix delete-indentation when region is inactive * lisp/simple.el (delete-indentation): Do not barf if called interactively when region is inactive. (bug#35021) * test/lisp/simple-tests.el (simple-delete-indentation-no-region): (simple-delete-indentation-inactive-region): Update commentary. Call delete-indentation interactively when testing for behavior with inactive region and region is not explicitly defined. * doc/lispref/text.texi (User-Level Deletion): Document new optional arguments of delete-indentation. --- doc/lispref/text.texi | 10 ++++++-- lisp/simple.el | 36 ++++++++++++++-------------- test/lisp/simple-tests.el | 50 +++++++++++++++++---------------------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 21c5a73f88..b430adf597 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -723,12 +723,18 @@ User-Level Deletion @end example @end deffn -@deffn Command delete-indentation &optional join-following-p +@deffn Command delete-indentation &optional join-following-p beg end This function joins the line point is on to the previous line, deleting any whitespace at the join and in some cases replacing it with one space. If @var{join-following-p} is non-@code{nil}, @code{delete-indentation} joins this line to the following line -instead. The function returns @code{nil}. +instead. Otherwise, if @var{beg} and @var{end} are non-@code{nil}, +this function joins all lines in the region they define. + +In an interactive call, @var{join-following-p} is the prefix argument, +and @var{beg} and @var{end} are, respectively, the start and end of +the region if it is active, else @code{nil}. The function returns +@code{nil}. If there is a fill prefix, and the second of the lines being joined starts with the prefix, then @code{delete-indentation} deletes the diff --git a/lisp/simple.el b/lisp/simple.el index f76f31ad14..6738df3cb9 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -598,29 +598,29 @@ delete-indentation If there is a fill prefix, delete it from the beginning of this line. With prefix ARG, join the current line to the following line. -If the region is active, join all the lines in the region. (The -region is ignored if prefix argument is given.)" - (interactive "*P\nr") - (if arg (forward-line 1) - (if (use-region-p) - (goto-char end))) +When BEG and END are non-nil, join all lines in the region they +define. Interactively, BEG and END are, respectively, the start +and end of the region if it is active, else nil. (The region is +ignored if prefix ARG is given.)" + (interactive + (progn (barf-if-buffer-read-only) + (cons current-prefix-arg + (and (use-region-p) + (list (region-beginning) (region-end)))))) + (cond (arg (forward-line 1)) + (end (goto-char end))) (beginning-of-line) - (while (eq (preceding-char) ?\n) - (progn - (delete-region (point) (1- (point))) + (let ((prefix (and fill-prefix (regexp-quote fill-prefix)))) + (while (= (preceding-char) ?\n) + (delete-char -1) ;; If the second line started with the fill prefix, ;; delete the prefix. - (if (and fill-prefix - (<= (+ (point) (length fill-prefix)) (point-max)) - (string= fill-prefix - (buffer-substring (point) - (+ (point) (length fill-prefix))))) - (delete-region (point) (+ (point) (length fill-prefix)))) + (if (and prefix (looking-at prefix)) + (replace-match "" t t)) (fixup-whitespace) - (if (and (use-region-p) - beg + (if (and beg (not arg) - (< beg (point-at-bol))) + (< beg (line-beginning-position))) (beginning-of-line))))) (defalias 'join-line #'delete-indentation) ; easier to find diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el index d9f059c8fc..f80578c673 100644 --- a/test/lisp/simple-tests.el +++ b/test/lisp/simple-tests.el @@ -216,36 +216,30 @@ simple-test--transpositions ;;; `delete-indentation' (ert-deftest simple-delete-indentation-no-region () - "delete-indentation works when no mark is set." - ;; interactive \r returns nil for BEG END args - (unwind-protect - (with-temp-buffer - (insert (concat "zero line \n" - "first line \n" - "second line")) - (delete-indentation) - (should (string-equal - (buffer-string) - (concat "zero line \n" - "first line second line"))) - ))) + "`delete-indentation' works when no mark is set." + (with-temp-buffer + (insert "first line \n" + "second line \n" + "third line") + (call-interactively #'delete-indentation) + (should (string-equal + (buffer-string) + (concat "first line \n" + "second line third line"))))) (ert-deftest simple-delete-indentation-inactive-region () - "delete-indentation ignores inactive region." - ;; interactive \r returns non-nil for BEG END args - (unwind-protect - (with-temp-buffer - (insert (concat "zero line \n" - "first line \n" - "second line")) - (push-mark (point-min) t t) - (deactivate-mark) - (delete-indentation) - (should (string-equal - (buffer-string) - (concat "zero line \n" - "first line second line"))) - ))) + "`delete-indentation' ignores inactive region." + (with-temp-buffer + (insert "first line \n" + "second line \n" + "third line") + (push-mark (point-min) t t) + (deactivate-mark) + (call-interactively #'delete-indentation) + (should (string-equal + (buffer-string) + (concat "first line \n" + "second line third line"))))) ;;; `delete-trailing-whitespace' -- 2.20.1 --=-=-= Content-Type: text/plain Jon Irving writes: > I believe this is related to the following commits: > > b515edb985 Fix bug in delete-indentation when region is inactive > 09c220a5cf Minor fixes for the last change > 8fa94a1ecc If the region is active, join all the lines it spans > > From a clean `emacs -Q` start: > > 1. Move point up to the bottom line of the *scratch* buffer comments > 2. Type M-^ (or M-x delete-indentation) > 3. Observe the following message in the minibuffer: > The mark is not set now, so there is no region This is because delete-indentation is currently using the 'r' interactive code, which barfs if the region is inactive. I attach a patch which fixes this and also updates the entry for delete-indentation in the Elisp manual. Is it acceptable? Stephen, what is the difference between the two tests simple-delete-indentation-no-region and simple-delete-indentation-inactive-region? Can they be merged? Thanks, -- Basil --=-=-=--