branch: externals/shift-number
commit 67d94463b8da7c15bdb421c4976d6651eea3d69e
Author: Campbell Barton <[email protected]>
Commit: Campbell Barton <[email protected]>
Support "motion" when there is a region
Move the point to the numbers end if the point overlaps a number.
---
shift-number.el | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)
diff --git a/shift-number.el b/shift-number.el
index 23724e9d43..191b6d7383 100644
--- a/shift-number.el
+++ b/shift-number.el
@@ -267,18 +267,32 @@ Otherwise search forward limited by LIMIT-END."
(defun shift-number--on-region-impl (n region-beg region-end)
"Shift the numbers N in the region defined.
REGION-BEG & REGION-END define the region."
- (save-excursion
- (let ((bounds-pair nil))
- (goto-char region-beg)
- (while (and (setq bounds-pair (shift-number--impl n region-beg
region-beg region-end)))
- (let* ((old-bounds (car bounds-pair))
- (new-bounds (cdr bounds-pair))
- (old-end (cdr old-bounds))
- (new-end (cdr new-bounds)))
-
- ;; Keep contracting the region forward & updating it's end-points.
- (setq region-beg new-end)
- (setq region-end (+ region-end (- new-end old-end)))))))
+ (let ((pos-old (point))
+ (pos-new nil))
+ (save-excursion
+ (let ((bounds-pair nil))
+ (goto-char region-beg)
+ (while (and (setq bounds-pair (shift-number--impl n region-beg
region-beg region-end)))
+ (let* ((old-bounds (car bounds-pair))
+ (new-bounds (cdr bounds-pair))
+ (old-beg (car old-bounds))
+ (old-end (cdr old-bounds))
+ (new-end (cdr new-bounds))
+ (delta (- new-end old-end)))
+
+ (when shift-number-motion
+ (cond
+ ((<= pos-old old-beg)) ; NOP.
+ ((> pos-old old-end)
+ (setq pos-old (+ pos-old delta)))
+ (t
+ (setq pos-new new-end))))
+
+ ;; Keep contracting the region forward & updating it's end-points.
+ (setq region-beg new-end)
+ (setq region-end (+ region-end delta))))))
+ (when pos-new
+ (goto-char pos-new)))
region-end)
(defun shift-number--on-region (n)