From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: charles@aurox.ch (Charles A. Roelli) Newsgroups: gmane.emacs.bugs Subject: bug#30343: make transpose-regions interactive Date: Wed, 07 Mar 2018 21:56:28 +0100 Message-ID: References: <83h8qp2jsg.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1520455463 15124 195.159.176.226 (7 Mar 2018 20:44:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 7 Mar 2018 20:44:23 +0000 (UTC) Cc: 30343@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 07 21:44:19 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etfv4-0002kC-85 for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Mar 2018 21:44:14 +0100 Original-Received: from localhost ([::1]:35551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etfx7-0002sv-3b for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Mar 2018 15:46:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etfws-0002ov-Ew for bug-gnu-emacs@gnu.org; Wed, 07 Mar 2018 15:46:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etfwo-00040v-Gx for bug-gnu-emacs@gnu.org; Wed, 07 Mar 2018 15:46:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41969) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1etfwo-00040h-CJ for bug-gnu-emacs@gnu.org; Wed, 07 Mar 2018 15:46:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1etfwn-0000lE-Sy for bug-gnu-emacs@gnu.org; Wed, 07 Mar 2018 15:46:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: charles@aurox.ch (Charles A. Roelli) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Mar 2018 20:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30343 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 30343-submit@debbugs.gnu.org id=B30343.15204555322882 (code B ref 30343); Wed, 07 Mar 2018 20:46:01 +0000 Original-Received: (at 30343) by debbugs.gnu.org; 7 Mar 2018 20:45:32 +0000 Original-Received: from localhost ([127.0.0.1]:49866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etfwK-0000kP-16 for submit@debbugs.gnu.org; Wed, 07 Mar 2018 15:45:32 -0500 Original-Received: from sinyavsky.aurox.ch ([37.35.109.145]:54429) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etfwH-0000k5-B2 for 30343@debbugs.gnu.org; Wed, 07 Mar 2018 15:45:30 -0500 Original-Received: from sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) by sinyavsky.aurox.ch (Postfix) with ESMTP id DA839226BA for <30343@debbugs.gnu.org>; Wed, 7 Mar 2018 20:45:59 +0000 (UTC) Authentication-Results: sinyavsky.aurox.ch (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=aurox.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aurox.ch; h= references:subject:subject:in-reply-to:to:from:from:message-id :date:date; s=dkim; t=1520455557; x=1521319558; bh=C3TXayagvxzDv CgqCt4WzfkiGMdFaoJVyycihcgjfXk=; b=VI8XAp27hoD4MLO+UNL+Tm5hTHnoy ElDQVHyE+V24F3Flig33uwR22tJPGKwliyOVdD7jiQ3c7DFcF5hF8iKSiwwtBoJx IXZkfdVK6md72G27k5zswgZj9GFbmr4gkNsuH4k9L7WAgtxdaKjS84m7I5ZL3Ipw Rj8aKOMS3pLOLs= X-Virus-Scanned: Debian amavisd-new at test.virtualizor.com Original-Received: from sinyavsky.aurox.ch ([127.0.0.1]) by sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id qR-UbHeoO48L for <30343@debbugs.gnu.org>; Wed, 7 Mar 2018 20:45:57 +0000 (UTC) Original-Received: from gray (125.85.192.178.dynamic.wline.res.cust.swisscom.ch [178.192.85.125]) by sinyavsky.aurox.ch (Postfix) with ESMTPSA id 1BF4E22688; Wed, 7 Mar 2018 20:45:57 +0000 (UTC) In-reply-to: <83h8qp2jsg.fsf@gnu.org> (message from Eli Zaretskii on Sat, 10 Feb 2018 12:58:23 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:143992 Archived-At: > Date: Sat, 10 Feb 2018 12:58:23 +0200 > From: Eli Zaretskii > > > @@ -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;