GNU bug report logs - #34796
[PATCH] * lisp/simple.el (delete-indentation): Join lines in a region

Previous Next

Package: emacs;

Reported by: Łukasz Stelmach <stlman <at> poczta.fm>

Date: Sat, 9 Mar 2019 18:00:02 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 34796 in the body.
You can then email your comments to 34796 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#34796; Package emacs. (Sat, 09 Mar 2019 18:00:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Łukasz Stelmach <stlman <at> poczta.fm>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 09 Mar 2019 18:00:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Łukasz Stelmach <stlman <at> poczta.fm>
To: bug-gnu-emacs <at> gnu.org
Cc: Łukasz Stelmach <stlman <at> poczta.fm>
Subject: [PATCH] * lisp/simple.el (delete-indentation): Join lines in a region
Date: Sat,  9 Mar 2019 18:56:34 +0100
If a region is active, join all the lines it spans.
---
 lisp/simple.el | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index d4ae5eb..1b3d1bf 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -593,25 +593,33 @@ When called from Lisp code, ARG may be a prefix string to copy."
     (indent-to col 0)
     (goto-char pos)))
 
-(defun delete-indentation (&optional arg)
+(defun delete-indentation (&optional arg beg end)
   "Join this line to previous and fix up whitespace at join.
-If there is a fill prefix, delete it from the beginning of this line.
-With argument, join this line to following line."
-  (interactive "*P")
+If there is a fill prefix, delete it from the beginning of this
+line.  With argument, join this line to following line. With a
+region active, join lines in the region. If both argument and
+region are set, the region is ignored."
+  (interactive "*P\nr")
+  (if arg (forward-line 1)
+    (if (use-region-p)
+	(goto-char end)))
   (beginning-of-line)
-  (if arg (forward-line 1))
-  (if (eq (preceding-char) ?\n)
-      (progn
-	(delete-region (point) (1- (point)))
-	;; 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))))
-	(fixup-whitespace))))
+  (while (eq (preceding-char) ?\n)
+    (progn
+      (delete-region (point) (1- (point)))
+      ;; 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))))
+      (fixup-whitespace)
+      (if (and beg
+               (not arg)
+	       (< beg (point-at-bol)))
+	  (beginning-of-line)))))
 
 (defalias 'join-line #'delete-indentation) ; easier to find
 
-- 
2.20.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34796; Package emacs. (Sun, 10 Mar 2019 08:19:02 GMT) Full text and rfc822 format available.

Message #8 received at 34796 <at> debbugs.gnu.org (full text, mbox):

From: Łukasz Stelmach <stlman <at> poczta.fm>
To: 34796 <at> debbugs.gnu.org
Subject: Re: [PATCH] * lisp/simple.el (delete-indentation): Join lines in a
 region
Date: Sun, 10 Mar 2019 08:14:03 +0100
Control: tags -1 + patch




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34796; Package emacs. (Fri, 15 Mar 2019 08:15:01 GMT) Full text and rfc822 format available.

Message #11 received at 34796 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Łukasz Stelmach <stlman <at> poczta.fm>
Cc: 34796 <at> debbugs.gnu.org
Subject: Re: bug#34796: [PATCH] * lisp/simple.el (delete-indentation): Join
 lines in a region
Date: Fri, 15 Mar 2019 10:13:59 +0200
> From: Łukasz Stelmach <stlman <at> poczta.fm>
> Date: Sat,  9 Mar 2019 18:56:34 +0100
> Cc: Łukasz Stelmach <stlman <at> poczta.fm>
> 
> If a region is active, join all the lines it spans.

Thanks.

Please provide a ChangeLog-style commit log message for your proposed
changes, and also accompany them with suitable changes to NEWS and the
user manual.

> -(defun delete-indentation (&optional arg)
> +(defun delete-indentation (&optional arg beg end)
>    "Join this line to previous and fix up whitespace at join.
> -If there is a fill prefix, delete it from the beginning of this line.
> -With argument, join this line to following line."
> -  (interactive "*P")
> +If there is a fill prefix, delete it from the beginning of this
> +line.  With argument, join this line to following line. With a
> +region active, join lines in the region. If both argument and
> +region are set, the region is ignored."

Please leave 2 spaces between sentences in the doc string.

With those issues taken care of, I think this feature can be
installed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34796; Package emacs. (Fri, 15 Mar 2019 21:08:02 GMT) Full text and rfc822 format available.

Message #14 received at 34796 <at> debbugs.gnu.org (full text, mbox):

From: Łukasz Stelmach <stlman <at> poczta.fm>
To: 34796 <at> debbugs.gnu.org
Cc: Łukasz Stelmach <stlman <at> poczta.fm>
Subject: [PATCH] If the region is active, join all the lines it spans
Date: Fri, 15 Mar 2019 22:06:16 +0100
* lisp/simple.el (delete-indentation): Join lines in the active region.
* doc/misc/org.texi: Describe the arguments of delete-indentation.
* etc/NEWS: Mention region support in delete-indentation.
---
 doc/emacs/indent.texi |  4 ++++
 etc/NEWS              |  4 ++++
 lisp/simple.el        | 42 +++++++++++++++++++++++++-----------------
 3 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/doc/emacs/indent.texi b/doc/emacs/indent.texi
index a6aa75bbb4..61cf7332b5 100644
--- a/doc/emacs/indent.texi
+++ b/doc/emacs/indent.texi
@@ -110,6 +110,10 @@ parentheses, or if the junction follows another newline.
 If there is a fill prefix, @kbd{M-^} deletes the fill prefix if it
 appears after the newline that is deleted.  @xref{Fill Prefix}.
 
+With the universal prefix argument, join the current line line to the
+following line.  With the region active, join lines in the region.  If
+both the argument is set and the region is active, the region is ignored.
+
 @item C-M-\
 @kindex C-M-\
 @findex indent-region
diff --git a/etc/NEWS b/etc/NEWS
index 000d211c1a..129d882735 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -370,6 +370,10 @@ region using a given replacement-function in a non-destructive manner
 arguments mitigating performance issues when operating on huge
 buffers.
 
+** The command `delete-indentation` now can operate on the active
+region
+
++++
 
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
diff --git a/lisp/simple.el b/lisp/simple.el
index d4ae5ebb1f..7878272ec9 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -593,25 +593,33 @@ When called from Lisp code, ARG may be a prefix string to copy."
     (indent-to col 0)
     (goto-char pos)))
 
-(defun delete-indentation (&optional arg)
+(defun delete-indentation (&optional arg beg end)
   "Join this line to previous and fix up whitespace at join.
-If there is a fill prefix, delete it from the beginning of this line.
-With argument, join this line to following line."
-  (interactive "*P")
+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.
+With the region active, join lines in the region. If both the
+argument is set and the region is active, the region is ignored."
+  (interactive "*P\nr")
+  (if arg (forward-line 1)
+    (if (use-region-p)
+	(goto-char end)))
   (beginning-of-line)
-  (if arg (forward-line 1))
-  (if (eq (preceding-char) ?\n)
-      (progn
-	(delete-region (point) (1- (point)))
-	;; 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))))
-	(fixup-whitespace))))
+  (while (eq (preceding-char) ?\n)
+    (progn
+      (delete-region (point) (1- (point)))
+      ;; 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))))
+      (fixup-whitespace)
+      (if (and beg
+               (not arg)
+	       (< beg (point-at-bol)))
+	  (beginning-of-line)))))
 
 (defalias 'join-line #'delete-indentation) ; easier to find
 
-- 
2.20.1





Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Fri, 22 Mar 2019 09:09:02 GMT) Full text and rfc822 format available.

Notification sent to Łukasz Stelmach <stlman <at> poczta.fm>:
bug acknowledged by developer. (Fri, 22 Mar 2019 09:09:03 GMT) Full text and rfc822 format available.

Message #19 received at 34796-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Łukasz Stelmach <stlman <at> poczta.fm>
Cc: 34796-done <at> debbugs.gnu.org
Subject: Re: bug#34796: [PATCH] If the region is active,
 join all the lines it spans
Date: Fri, 22 Mar 2019 12:08:55 +0300
> From: Łukasz Stelmach <stlman <at> poczta.fm>
> Date: Fri, 15 Mar 2019 22:06:16 +0100
> Cc: Łukasz Stelmach <stlman <at> poczta.fm>
> 
> * lisp/simple.el (delete-indentation): Join lines in the active region.
> * doc/misc/org.texi: Describe the arguments of delete-indentation.
> * etc/NEWS: Mention region support in delete-indentation.

Thanks, I pushed this to the master branch (with some changes).

P.S. Your patch was formatted almost, but exactly, like the command
"git format-patch", so it needed some manual work.  In the future,
using "got format-patch" will be most appreciated.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 19 Apr 2019 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 5 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.