Subject: bug#34796: closed (Re: bug#34796: [PATCH] If the region is active, join all the lines it spans)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 22 Mar 2019 09:09:03 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
34796: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=34796
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#34796: [PATCH] If the region is active, join all the lines it spans
From: Eli Zaretskii <[email-masked]>
To: Łukasz Stelmach <[email-masked]>
Cc: [email-masked]
Date: Fri, 22 Mar 2019 12:08:55 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Łukasz Stelmach <[email-masked]>
> Date: Fri, 15 Mar 2019 22:06:16 +0100
> Cc: Łukasz Stelmach <[email-masked]>
> 
> * 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.

Subject: [PATCH] * lisp/simple.el (delete-indentation): Join lines in a region
From: Łukasz Stelmach <[email-masked]>
To: [email-masked]
Cc: Łukasz Stelmach <[email-masked]>
Date: Sat, 9 Mar 2019 18:56:34 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

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