aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorƁukasz Stelmach2019-03-15 22:06:16 +0100
committerEli Zaretskii2019-03-22 11:47:36 +0300
commit8fa94a1ecc18a41ca2738f438b3fbc817c9fdc82 (patch)
tree8b95453244ce2e7a65e252aa8140786bb8bce140
parent09d746dad36e4780d379f975a84b1b076da78c50 (diff)
downloademacs-8fa94a1ecc18a41ca2738f438b3fbc817c9fdc82.tar.gz
emacs-8fa94a1ecc18a41ca2738f438b3fbc817c9fdc82.zip
If the region is active, join all the lines it spans
* 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.
-rw-r--r--doc/emacs/indent.texi4
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/simple.el42
3 files changed, 33 insertions, 17 deletions
diff --git a/doc/emacs/indent.texi b/doc/emacs/indent.texi
index a6aa75bbb42..61cf7332b5c 100644
--- a/doc/emacs/indent.texi
+++ b/doc/emacs/indent.texi
@@ -110,6 +110,10 @@ parentheses, or if the junction follows another newline.
110If there is a fill prefix, @kbd{M-^} deletes the fill prefix if it 110If there is a fill prefix, @kbd{M-^} deletes the fill prefix if it
111appears after the newline that is deleted. @xref{Fill Prefix}. 111appears after the newline that is deleted. @xref{Fill Prefix}.
112 112
113With the universal prefix argument, join the current line line to the
114following line. With the region active, join lines in the region. If
115both the argument is set and the region is active, the region is ignored.
116
113@item C-M-\ 117@item C-M-\
114@kindex C-M-\ 118@kindex C-M-\
115@findex indent-region 119@findex indent-region
diff --git a/etc/NEWS b/etc/NEWS
index 3380be75f9c..7ebc9f29183 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -370,6 +370,10 @@ region using a given replacement-function in a non-destructive manner
370arguments mitigating performance issues when operating on huge 370arguments mitigating performance issues when operating on huge
371buffers. 371buffers.
372 372
373** The command `delete-indentation` now can operate on the active
374region
375
376+++
373 377
374* Changes in Specialized Modes and Packages in Emacs 27.1 378* Changes in Specialized Modes and Packages in Emacs 27.1
375 379
diff --git a/lisp/simple.el b/lisp/simple.el
index d4ae5ebb1f9..7878272ec90 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."
593 (indent-to col 0) 593 (indent-to col 0)
594 (goto-char pos))) 594 (goto-char pos)))
595 595
596(defun delete-indentation (&optional arg) 596(defun delete-indentation (&optional arg beg end)
597 "Join this line to previous and fix up whitespace at join. 597 "Join this line to previous and fix up whitespace at join.
598If there is a fill prefix, delete it from the beginning of this line. 598If there is a fill prefix, delete it from the beginning of this
599With argument, join this line to following line." 599line. With prefix ARG, join the current line to the following line.
600 (interactive "*P") 600With the region active, join lines in the region. If both the
601argument is set and the region is active, the region is ignored."
602 (interactive "*P\nr")
603 (if arg (forward-line 1)
604 (if (use-region-p)
605 (goto-char end)))
601 (beginning-of-line) 606 (beginning-of-line)
602 (if arg (forward-line 1)) 607 (while (eq (preceding-char) ?\n)
603 (if (eq (preceding-char) ?\n) 608 (progn
604 (progn 609 (delete-region (point) (1- (point)))
605 (delete-region (point) (1- (point))) 610 ;; If the second line started with the fill prefix,
606 ;; If the second line started with the fill prefix, 611 ;; delete the prefix.
607 ;; delete the prefix. 612 (if (and fill-prefix
608 (if (and fill-prefix 613 (<= (+ (point) (length fill-prefix)) (point-max))
609 (<= (+ (point) (length fill-prefix)) (point-max)) 614 (string= fill-prefix
610 (string= fill-prefix 615 (buffer-substring (point)
611 (buffer-substring (point) 616 (+ (point) (length fill-prefix)))))
612 (+ (point) (length fill-prefix))))) 617 (delete-region (point) (+ (point) (length fill-prefix))))
613 (delete-region (point) (+ (point) (length fill-prefix)))) 618 (fixup-whitespace)
614 (fixup-whitespace)))) 619 (if (and beg
620 (not arg)
621 (< beg (point-at-bol)))
622 (beginning-of-line)))))
615 623
616(defalias 'join-line #'delete-indentation) ; easier to find 624(defalias 'join-line #'delete-indentation) ; easier to find
617 625