]> git.eshelyaron.com Git - emacs.git/commitdiff
If the region is active, join all the lines it spans
authorŁukasz Stelmach <stlman@poczta.fm>
Fri, 15 Mar 2019 21:06:16 +0000 (22:06 +0100)
committerEli Zaretskii <eliz@gnu.org>
Fri, 22 Mar 2019 08:47:36 +0000 (11:47 +0300)
* lisp/simple.el (delete-indentation): Join lines in the active region.
(Bug#34796)

* doc/misc/org.texi: Describe the arguments of delete-indentation.

* etc/NEWS: Mention region support in delete-indentation.

doc/emacs/indent.texi
etc/NEWS
lisp/simple.el

index a6aa75bbb4252aa3c6388228ba6935ab1e6a1c1d..61cf7332b5c56cdd4fd9d3a9a74925bf374aaa3f 100644 (file)
@@ -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
index 3380be75f9ca6760b808bde822e950e104d91a09..7ebc9f291835fa176b4a652d4d78e979fd536108 100644 (file)
--- 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
+
++++
 \f
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
index d4ae5ebb1f9de3d02153e2ac906150a6df42be1d..7878272ec9002462ace92961e2f10cf2553632a0 100644 (file)
@@ -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