diff options
| author | Karl Fogel | 2018-03-18 16:43:18 -0500 |
|---|---|---|
| committer | Karl Fogel | 2018-03-18 16:43:18 -0500 |
| commit | 3a3aa0e056a3f4e8023bc8e8142ffbc73daac4ea (patch) | |
| tree | df8de3f2c87890813a936307453417214fe1df57 | |
| parent | 9667ba25b4af54179c28a719163c4b74f02d0ff8 (diff) | |
| download | emacs-3a3aa0e056a3f4e8023bc8e8142ffbc73daac4ea.tar.gz emacs-3a3aa0e056a3f4e8023bc8e8142ffbc73daac4ea.zip | |
Move interactive `transpose-regions' to Lisp
Define `transpose-regions' in Lisp, because its complex interactive
spec was ungainly in C, and change the C version to non-interactive
`transpose-regions-internal'. The Lisp function is just a wrapper
around the C function, which still does all the work.
* lisp/simple.el (transpose-regions): New wrapper function, with
interactive spec taken from old C `transpose-regions'.
* src/editfns.c (Ftranspose_regions): Rename to...
(Ftranspose_regions_internal): ...here, and remove interactive spec.
Discussion on Emacs Devel:
From: Karl Fogel
To: Emacs Development
Cc: Richard Copley, Charles A. Roelli
Subject: Re: [Emacs-diffs] master b88e7c8: \
Make transpose-regions interactive (Bug#30343)
Date: Fri, 16 Mar 2018 10:23:31 -0500
Message-ID: <87po44jb7w.fsf@red-bean.com>
https://lists.gnu.org/archive/html/emacs-devel/2018-03/msg00555.html
| -rw-r--r-- | lisp/simple.el | 28 | ||||
| -rw-r--r-- | src/editfns.c | 22 |
2 files changed, 31 insertions, 19 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index fa93cf87c7a..543fa08233c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -7014,6 +7014,34 @@ With argument 0, interchanges line point is in with line mark is in." | |||
| 7014 | (forward-line arg)))) | 7014 | (forward-line arg)))) |
| 7015 | arg)) | 7015 | arg)) |
| 7016 | 7016 | ||
| 7017 | (defun transpose-regions (startr1 endr1 startr2 endr2 &optional leave-markers) | ||
| 7018 | "Transpose region STARTR1 to ENDR1 with STARTR2 to ENDR2. | ||
| 7019 | The regions should not be overlapping, because the size of the buffer is | ||
| 7020 | never changed in a transposition. | ||
| 7021 | |||
| 7022 | Optional fifth arg LEAVE-MARKERS, if non-nil, means don't update | ||
| 7023 | any markers that happen to be located in the regions. | ||
| 7024 | |||
| 7025 | Transposing beyond buffer boundaries is an error. | ||
| 7026 | |||
| 7027 | Interactively, STARTR1 and ENDR1 are point and mark; STARTR2 and ENDR2 | ||
| 7028 | are the last two marks pushed to the mark ring; LEAVE-MARKERS is nil. | ||
| 7029 | If a prefix argument N is given, STARTR2 and ENDR2 are the two | ||
| 7030 | successive marks N entries back in the mark ring. A negative prefix | ||
| 7031 | argument instead counts forward from the oldest mark in the mark | ||
| 7032 | ring." | ||
| 7033 | (interactive | ||
| 7034 | (if (< (length mark-ring) 2) | ||
| 7035 | (error "Other region must be marked before transposing two regions") | ||
| 7036 | (let* ((num (if current-prefix-arg | ||
| 7037 | (prefix-numeric-value current-prefix-arg) | ||
| 7038 | 0)) | ||
| 7039 | (ring-length (length mark-ring)) | ||
| 7040 | (eltnum (mod num ring-length)) | ||
| 7041 | (eltnum2 (mod (1+ num) ring-length))) | ||
| 7042 | (list (point) (mark) (elt mark-ring eltnum) (elt mark-ring eltnum2))))) | ||
| 7043 | (transpose-regions-internal startr1 endr1 startr2 endr2 leave-markers)) | ||
| 7044 | |||
| 7017 | ;; FIXME seems to leave point BEFORE the current object when ARG = 0, | 7045 | ;; FIXME seems to leave point BEFORE the current object when ARG = 0, |
| 7018 | ;; which seems inconsistent with the ARG /= 0 case. | 7046 | ;; which seems inconsistent with the ARG /= 0 case. |
| 7019 | ;; FIXME document SPECIAL. | 7047 | ;; FIXME document SPECIAL. |
diff --git a/src/editfns.c b/src/editfns.c index d26319441b3..e24867298e1 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -5112,16 +5112,7 @@ transpose_markers (ptrdiff_t start1, ptrdiff_t end1, | |||
| 5112 | } | 5112 | } |
| 5113 | } | 5113 | } |
| 5114 | 5114 | ||
| 5115 | DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, | 5115 | DEFUN ("transpose-regions-internal", Ftranspose_regions_internal, Stranspose_regions_internal, 4, 5, 0, |
| 5116 | "(if (< (length mark-ring) 2)\ | ||
| 5117 | (error \"Other region must be marked before transposing two regions\")\ | ||
| 5118 | (let* ((num (if current-prefix-arg\ | ||
| 5119 | (prefix-numeric-value current-prefix-arg)\ | ||
| 5120 | 0))\ | ||
| 5121 | (ring-length (length mark-ring))\ | ||
| 5122 | (eltnum (mod num ring-length))\ | ||
| 5123 | (eltnum2 (mod (1+ num) ring-length)))\ | ||
| 5124 | (list (point) (mark) (elt mark-ring eltnum) (elt mark-ring eltnum2))))", | ||
| 5125 | doc: /* Transpose region STARTR1 to ENDR1 with STARTR2 to ENDR2. | 5116 | doc: /* Transpose region STARTR1 to ENDR1 with STARTR2 to ENDR2. |
| 5126 | The regions should not be overlapping, because the size of the buffer is | 5117 | The regions should not be overlapping, because the size of the buffer is |
| 5127 | never changed in a transposition. | 5118 | never changed in a transposition. |
| @@ -5129,14 +5120,7 @@ never changed in a transposition. | |||
| 5129 | Optional fifth arg LEAVE-MARKERS, if non-nil, means don't update | 5120 | Optional fifth arg LEAVE-MARKERS, if non-nil, means don't update |
| 5130 | any markers that happen to be located in the regions. | 5121 | any markers that happen to be located in the regions. |
| 5131 | 5122 | ||
| 5132 | Transposing beyond buffer boundaries is an error. | 5123 | Transposing beyond buffer boundaries is an error. */) |
| 5133 | |||
| 5134 | Interactively, STARTR1 and ENDR1 are point and mark; STARTR2 and ENDR2 | ||
| 5135 | are the last two marks pushed to the mark ring; LEAVE-MARKERS is nil. | ||
| 5136 | If a prefix argument N is given, STARTR2 and ENDR2 are the two | ||
| 5137 | successive marks N entries back in the mark ring. A negative prefix | ||
| 5138 | argument instead counts forward from the oldest mark in the mark | ||
| 5139 | ring. */) | ||
| 5140 | (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers) | 5124 | (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers) |
| 5141 | { | 5125 | { |
| 5142 | register ptrdiff_t start1, end1, start2, end2; | 5126 | register ptrdiff_t start1, end1, start2, end2; |
| @@ -5581,5 +5565,5 @@ functions if all the text being accessed has this property. */); | |||
| 5581 | defsubr (&Swiden); | 5565 | defsubr (&Swiden); |
| 5582 | defsubr (&Snarrow_to_region); | 5566 | defsubr (&Snarrow_to_region); |
| 5583 | defsubr (&Ssave_restriction); | 5567 | defsubr (&Ssave_restriction); |
| 5584 | defsubr (&Stranspose_regions); | 5568 | defsubr (&Stranspose_regions_internal); |
| 5585 | } | 5569 | } |