[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-exchange e7e3d679b9 27/46: implement exchange across
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-exchange e7e3d679b9 27/46: implement exchange across buffers |
Date: |
Thu, 6 Jan 2022 03:59:52 -0500 (EST) |
branch: elpa/evil-exchange
commit e7e3d679b9c55d32d76982e3c118586a1385dba7
Author: Dewdrops <v_v_4474@126.com>
Commit: Dewdrops <v_v_4474@126.com>
implement exchange across buffers
---
evil-exchange.el | 50 ++++++++++++++++++++++++++++++++------------------
1 file changed, 32 insertions(+), 18 deletions(-)
diff --git a/evil-exchange.el b/evil-exchange.el
index 42fc8963b1..1fcb76d056 100644
--- a/evil-exchange.el
+++ b/evil-exchange.el
@@ -76,7 +76,8 @@
(overlay-put o 'face evil-exchange-highlight-face)
(add-to-list 'evil-exchange--overlays o)))
-(defun evil-exchange--remove-overlays ()
+(defun evil-exchange--clean ()
+ (setq evil-exchange--position nil)
(mapc 'delete-overlay evil-exchange--overlays)
(setq evil-exchange--overlays nil))
@@ -93,18 +94,19 @@
(if (null evil-exchange--position)
;; call without evil-exchange--position set: store region
(progn
- (setq evil-exchange--position (list beg-marker end-marker type))
+ (setq evil-exchange--position (list (current-buffer) beg-marker
end-marker type))
;; highlight area marked to exchange
(if (eq type 'block)
(evil-apply-on-block #'evil-exchange--highlight beg end nil)
(evil-exchange--highlight beg end)))
;; secondary call: do exchange
(cl-destructuring-bind
- (orig-beg orig-end orig-type) evil-exchange--position
+ (orig-buffer orig-beg orig-end orig-type) evil-exchange--position
(cond
;; exchange block region
((and (eq orig-type 'block) (eq type 'block))
- (evil-exchange--do-swap beg-marker end-marker
+ (evil-exchange--do-swap (current-buffer) orig-buffer
+ beg-marker end-marker
orig-beg orig-end
#'delete-extract-rectangle #'insert-rectangle
nil))
@@ -113,7 +115,8 @@
(user-error "Can't exchange block region with non-block region"))
;; exchange normal region
(t
- (evil-exchange--do-swap beg-marker end-marker
+ (evil-exchange--do-swap (current-buffer) orig-buffer
+ beg-marker end-marker
orig-beg orig-end
#'delete-and-extract-region #'insert
t))))))
@@ -121,7 +124,8 @@
(when (and (evil-called-interactively-p) (eq type 'line))
(evil-first-non-blank)))
-(defun evil-exchange--do-swap (curr-beg curr-end orig-beg orig-end extract-fn
insert-fn not-block)
+(defun evil-exchange--do-swap (curr-buffer orig-buffer curr-beg curr-end
orig-beg
+ orig-end extract-fn insert-fn
not-block)
;; This function does the real exchange work. Here's the detailed steps:
;; 1. call extract-fn with orig-beg and orig-end to extract orig-text.
;; 2. call extract-fn with curr-beg and curr-end to extract curr-text.
@@ -135,19 +139,30 @@
;; thus resulting incorrect behaviour.
;; To fix this edge case, we swap two extracted texts before step 3 to
;; effectively reverse the (problematic) order of two `evil-exchange' calls.
- (let ((adjacent (and not-block (equal (marker-position orig-beg)
(marker-position curr-end))))
- (orig-text (funcall extract-fn orig-beg orig-end))
- (curr-text (funcall extract-fn curr-beg curr-end)))
- ;; swaps two texts if adjacent is set
- (let ((orig-text (if adjacent curr-text orig-text))
- (curr-text (if adjacent orig-text curr-text)))
+ (if (eq curr-buffer orig-buffer)
+ ;; in buffer exchange
+ (let ((adjacent (and not-block (equal (marker-position orig-beg)
(marker-position curr-end))))
+ (orig-text (funcall extract-fn orig-beg orig-end))
+ (curr-text (funcall extract-fn curr-beg curr-end)))
+ ;; swaps two texts if adjacent is set
+ (let ((orig-text (if adjacent curr-text orig-text))
+ (curr-text (if adjacent orig-text curr-text)))
+ (save-excursion
+ (goto-char orig-beg)
+ (funcall insert-fn curr-text)
+ (goto-char curr-beg)
+ (funcall insert-fn orig-text))))
+ ;; exchange across buffers
+ (let ((orig-text (with-current-buffer orig-buffer
+ (funcall extract-fn orig-beg orig-beg)))
+ (curr-text (funcall extract-fn curr-beg curr-end)))
(save-excursion
- (goto-char orig-beg)
- (funcall insert-fn curr-text)
+ (with-current-buffer orig-buffer
+ (goto-char orig-beg)
+ (funcall insert-fn curr-text))
(goto-char curr-beg)
(funcall insert-fn orig-text))))
- (setq evil-exchange--position nil)
- (evil-exchange--remove-overlays))
+ (evil-exchange--clean))
;;;###autoload
(defun evil-exchange-cancel ()
@@ -155,8 +170,7 @@
(interactive)
(if (null evil-exchange--position)
(message "No pending exchange")
- (setq evil-exchange--position nil)
- (evil-exchange--remove-overlays)
+ (evil-exchange--clean)
(message "Exchange cancelled")))
;;;###autoload
- [nongnu] elpa/evil-exchange 1e3ba07be4 18/46: Merge pull request #5 from fbergroth/remove-transpose-regions, (continued)
- [nongnu] elpa/evil-exchange 1e3ba07be4 18/46: Merge pull request #5 from fbergroth/remove-transpose-regions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 7cd34aea03 13/46: use non-advancable marker to mark the end of the region to exchange, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 7f1436b781 14/46: highlight the area marked to exchange, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange d35ebe9a7d 16/46: doc improvement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 5b0c4ab07c 20/46: add vim-compatible key bindings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 2ae6e0a203 24/46: ignore tags, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 22d9b6ce1b 19/46: bump version and rename internal function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 51c830b65d 21/46: better error message, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 328370e898 23/46: vim compatible bindings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 47c017cc9a 22/46: Fix weird behaviour for adjacent areas, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange e7e3d679b9 27/46: implement exchange across buffers,
ELPA Syncer <=
- [nongnu] elpa/evil-exchange 19b4b6277e 29/46: Merge pull request #8 from Dewdrops/cross-buffer, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 9d59144066 30/46: improve doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 492c6f7ff0 33/46: Merge pull request #9 from sooheon/support-lispyville, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 6e80e2509b 35/46: mention compatibility issues in doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 8902966aec 36/46: add melpa badge, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange a17eca6d0d 38/46: Merge pull request #11 from Dewdrops/add-test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 548393cb16 44/46: Always inhibit operator code when canceling an exchange., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 4769153781 41/46: update version and copyright, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 86500b91f6 37/46: add test, ELPA Syncer, 2022/01/06