From: "Łukasz Stelmach" <stlman@poczta.fm>
To: 34796@debbugs.gnu.org
Cc: "Łukasz Stelmach" <stlman@poczta.fm>
Subject: bug#34796: [PATCH] If the region is active, join all the lines it spans
Date: Fri, 15 Mar 2019 22:06:16 +0100 [thread overview]
Message-ID: <20190315210616.1217-1-stlman@poczta.fm> (raw)
In-Reply-To: <837ed01rnc.fsf@gnu.org>
* 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
+
++++
\f
* 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
next prev parent reply other threads:[~2019-03-15 21:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-09 17:56 bug#34796: [PATCH] * lisp/simple.el (delete-indentation): Join lines in a region Łukasz Stelmach
[not found] ` <handler.34796.B.155215436111455.ack@debbugs.gnu.org>
2019-03-10 7:14 ` Łukasz Stelmach
2019-03-15 8:13 ` Eli Zaretskii
2019-03-15 21:06 ` Łukasz Stelmach [this message]
2019-03-22 9:08 ` bug#34796: [PATCH] If the region is active, join all the lines it spans Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190315210616.1217-1-stlman@poczta.fm \
--to=stlman@poczta.fm \
--cc=34796@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).