From: charles@aurox.ch (Charles A. Roelli)
To: Eli Zaretskii <eliz@gnu.org>
Cc: 30343@debbugs.gnu.org
Subject: bug#30343: make transpose-regions interactive
Date: Wed, 07 Mar 2018 21:56:28 +0100 [thread overview]
Message-ID: <m21sgviozn.fsf@aurox.ch> (raw)
In-Reply-To: <83h8qp2jsg.fsf@gnu.org> (message from Eli Zaretskii on Sat, 10 Feb 2018 12:58:23 +0200)
> Date: Sat, 10 Feb 2018 12:58:23 +0200
> From: Eli Zaretskii <eliz@gnu.org>
>
> > @@ -183,7 +185,7 @@ Transpose
> > (@code{transpose-lines}) exchanges lines. They work like @kbd{M-t}
> > except as regards what units of text they transpose.
> >
> > - A numeric argument to a transpose command serves as a repeat count: it
> > + A numeric argument to most transpose commands serves as a repeat count: it
> > [...]
> > +@findex transpose-regions
> > + @kbd{M-x transpose-regions} transposes the text between point and
> > +mark with the text between the first two elements of the mark ring.
>
> I would say "... with the text between the last two marks pushed to
> the mark ring." I would also add a cross-reference here to where
> set-mark-command is described.
>
> > +Unlike the other transpose commands, it does not behave differently
> > +when given a prefix argument. This command is best used for
> > +transposing multiple units of text (words, sentences, paragraphs) in
> > +one go.
>
> Would it make sense to make the new command interpret the prefix
> argument the same way as the other transpose commands? E.g., why not
> use pairs of marks further back in the mark ring?
>
> > -DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, 0,
> > +DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5,
> > + "(if (< (length mark-ring) 2)\
> > + (error \"Mark ring must contain at least two elements\")\
> > + (list (point) (mark) (car mark-ring) (cadr mark-ring)))",
>
> The error message could be made more clear, e.g. by saying that the
> other region should be marked first. Talking about the size of the
> mark ring is too technical, IMO.
>
> > +Interactively, STARTR1 and ENDR1 are point and mark. STARTR2 and
> > +ENDR2 are the first and second markers in the mark ring.
> > +LEAVE-MARKERS is nil. */)
>
> "First and second" is ambiguous, since you don't tell from which end
> they are counted. Also, these 3 sentences all talk about interactive
> invocation, so they should probably be a single sentence separated
> with semi-colons instead.
Thanks for the review. Could you please look at the following second
iteration? All your points should be addressed.
diff --git a/doc/emacs/fixit.texi b/doc/emacs/fixit.texi
index 7cacac4..eb783d1 100644
--- a/doc/emacs/fixit.texi
+++ b/doc/emacs/fixit.texi
@@ -149,6 +149,8 @@ Transpose
Transpose two balanced expressions (@code{transpose-sexps}).
@item C-x C-t
Transpose two lines (@code{transpose-lines}).
+@item M-x transpose-regions
+Transpose two regions.
@end table
@kindex C-t
@@ -204,6 +206,15 @@ Transpose
transpose the character (or word or expression or line) ending after
point with the one ending after the mark.
+@findex transpose-regions
+ @kbd{M-x transpose-regions} transposes the text between point and
+mark with the text between the last two marks pushed to the mark ring
+(@pxref{Setting Mark}). With a numeric prefix argument, it transposes
+the text between point and mark with the text between two successive
+marks that many entries back in the mark ring. This command is best
+used for transposing multiple characters (or words or sentences or
+paragraphs) in one go.
+
@node Fixing Case
@section Case Conversion
diff --git a/src/editfns.c b/src/editfns.c
index 96bb271..9183bd1 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -5112,7 +5112,16 @@ transpose_markers (ptrdiff_t start1, ptrdiff_t end1,
}
}
-DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, 0,
+DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5,
+ "(if (< (length mark-ring) 2)\
+ (error \"Other region must be marked before transposing two regions\")\
+ (let* ((num (if current-prefix-arg\
+ (prefix-numeric-value current-prefix-arg)\
+ 0))\
+ (ring-length (length mark-ring))\
+ (eltnum (mod num ring-length))\
+ (eltnum2 (mod (1+ num) ring-length)))\
+ (list (point) (mark) (elt mark-ring eltnum) (elt mark-ring eltnum2))))",
doc: /* Transpose region STARTR1 to ENDR1 with STARTR2 to ENDR2.
The regions should not be overlapping, because the size of the buffer is
never changed in a transposition.
@@ -5120,7 +5129,14 @@ never changed in a transposition.
Optional fifth arg LEAVE-MARKERS, if non-nil, means don't update
any markers that happen to be located in the regions.
-Transposing beyond buffer boundaries is an error. */)
+Transposing beyond buffer boundaries is an error.
+
+Interactively, STARTR1 and ENDR1 are point and mark; STARTR2 and ENDR2
+are the last two marks pushed to the mark ring; LEAVE-MARKERS is nil.
+If a prefix argument N is given, STARTR2 and ENDR2 are the two
+successive marks N entries backwards in the mark ring. A negative
+prefix argument instead counts forwards from the oldest mark in the
+mark ring. */)
(Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers)
{
register ptrdiff_t start1, end1, start2, end2;
next prev parent reply other threads:[~2018-03-07 20:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-04 9:37 bug#30343: make transpose-regions interactive Charles A. Roelli
2018-02-04 9:45 ` Charles A. Roelli
2018-02-10 10:58 ` Eli Zaretskii
2018-03-07 20:56 ` Charles A. Roelli [this message]
2018-03-10 12:02 ` Eli Zaretskii
2018-03-10 14:22 ` Eli Zaretskii
2018-03-11 11:11 ` Charles A. Roelli
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m21sgviozn.fsf@aurox.ch \
--to=charles@aurox.ch \
--cc=30343@debbugs.gnu.org \
--cc=eliz@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.