[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-exchange 72bf29c9fa 01/46: initial commit
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-exchange 72bf29c9fa 01/46: initial commit |
Date: |
Thu, 6 Jan 2022 03:59:50 -0500 (EST) |
branch: elpa/evil-exchange
commit 72bf29c9fa3aa6b621183542977e46fbd49f3457
Author: Dewdrops <v_v_4474@126.com>
Commit: Dewdrops <v_v_4474@126.com>
initial commit
---
.gitignore | 1 +
README.md | 40 +++++++++++++++++++
evil-exchange.el | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 157 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..c531d9867f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.elc
diff --git a/README.md b/README.md
new file mode 100644
index 0000000000..55b68f741e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,40 @@
+evil-exchange
+============
+
+English is not my first language, so feel free to correct me of any mistake.
+
+Easy text exchange operator for Evil. This is the port of
[vim-exchange](https://github.com/tommcdo/vim-exchange) by Tom McDonald.
+
+Default bindings
+--------
+
+`gx`
+
+On the first use, define the first {motion} to exchange. On the second use,
+define the second {motion} and perform the exchange.
+
+`gX`
+
+Clear any {motion} pending for exchange.
+
+### Notes
+
+* `gx` (and `gX`) can also be used from visual mode, which is sometimes easier
than coming
+ up with the right {motion}
+* If you're using the same motion again (e.g. exchanging two words using
+ `gxiw`), you can use `.` (evil-repeat) the second time.
+
+Installation
+------------
+
+```lisp
+(require 'evil-exchange)
+;; if you want to change default key bindings
+;; (setq evil-exchange-key (kbd "zx"))
+(evil-exchange-install)
+```
+
+Customization
+-------
+
+You can change the default bindings by customizing `evil-exchange-key` and/or
`evil-exchange-cancel-key` BEFORE `evil-exchange-install` is called.
diff --git a/evil-exchange.el b/evil-exchange.el
new file mode 100644
index 0000000000..1cbdfe550d
--- /dev/null
+++ b/evil-exchange.el
@@ -0,0 +1,116 @@
+;;; evil-exchange.el --- Exchange text more easily within Evil
+
+;; Copyright (C) 2013 by Dewdrops
+
+;; Author: Dewdrops <v_v_4474@126.com>
+;; URL: http://github.com/Dewdrops/evil-exchange
+;; Version: 0.1
+;; Keywords: evil, plugin
+
+;; This file is NOT part of GNU Emacs.
+
+;;; License:
+;;
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Port of vim-exchange by Tom McDonald
(https://github.com/tommcdo/vim-exchange)
+
+;; Installation:
+
+;; put evil-exchange.el into somewhere in your load-path and add these
+;; lines to your .emacs:
+;; (require 'evil-exchange)
+;; ;; if you want to change default key bindings, bind it to as you like HERE
+;; ;; (setq evil-exchange-key (kbd "zx"))
+;; (evil-exchange-install)
+
+;;; Code:
+
+(require 'evil)
+
+(defgroup evil-exchange nil
+ "Easy text exchange operator for Evil."
+ :prefix "evil-exchange"
+ :group 'evil)
+
+(defcustom evil-exchange-key (kbd "gx")
+ "Default binding for evil-exchange."
+ :type `,(if (get 'key-sequence 'widget-type)
+ 'key-sequence
+ 'sexp)
+ :group 'evil-exchange)
+
+(defcustom evil-exchange-cancel-key (kbd "gX")
+ "Default binding for evil-exchange-cancel."
+ :type `,(if (get 'key-sequence 'widget-type)
+ 'key-sequence
+ 'sexp)
+ :group 'evil-exchange)
+
+(defvar evil-exchange-position nil "Text position which will be exchanged")
+
+;;;###autoload
+(evil-define-operator evil-exchange (beg end type)
+ "Exchange two regions with evil motion."
+ :move-point nil
+ (interactive "<R>")
+ (let ((beg-marker (copy-marker beg t))
+ (end-marker (copy-marker end t)))
+ (if (null evil-exchange-position)
+ ;; call without evil-exchange-position set: store region
+ (setq evil-exchange-position (list beg-marker end-marker type))
+ ;; secondary call: do exchange
+ (cl-destructuring-bind
+ (orig-beg orig-end orig-type) evil-exchange-position
+ (cond
+ ;; exchange block region
+ ((and (eq orig-type 'block) (eq type 'block))
+ (let ((orig-rect (delete-extract-rectangle orig-beg orig-end))
+ (curr-rect (delete-extract-rectangle beg-marker end-marker)))
+ (save-excursion
+ (goto-char orig-beg)
+ (insert-rectangle curr-rect)
+ (goto-char beg-marker)
+ (insert-rectangle orig-rect)))
+ (setq evil-exchange-position nil))
+ ;; signal error if regions incompatible
+ ((or (eq orig-type 'block) (eq type 'block))
+ (error "Can't exchange block region with non-block region."))
+ ;; exchange normal region
+ (t
+ (transpose-regions orig-beg orig-end beg end)
+ (setq evil-exchange-position nil))))))
+ ;; place cursor on beginning of line
+ (when (and (evil-called-interactively-p) (eq type 'line))
+ (evil-first-non-blank)))
+
+;;;###autoload
+(defun evil-exchange-cancel ()
+ "Cancel current pending exchange."
+ (interactive)
+ (setq evil-exchange-position nil)
+ (message "Exchange cancelled"))
+
+;;;###autoload
+(defun evil-exchange-install ()
+ "Setting evil-exchange key bindings."
+ (define-key evil-normal-state-map evil-exchange-key 'evil-exchange)
+ (define-key evil-visual-state-map evil-exchange-key 'evil-exchange)
+ (define-key evil-normal-state-map evil-exchange-cancel-key
'evil-exchange-cancel)
+ (define-key evil-visual-state-map evil-exchange-cancel-key
'evil-exchange-cancel))
+
+(provide 'evil-exchange)
+;;; evil-exchange.el ends here
- [nongnu] elpa/evil-exchange 35dd0f0662 43/46: Merge pull request #13 from nnoodle/patch-1, (continued)
- [nongnu] elpa/evil-exchange 35dd0f0662 43/46: Merge pull request #13 from nnoodle/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 3030e21ee1 45/46: Merge pull request #15 from tmurph/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 6411ce3e5f 03/46: require fix, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 31dad20db1 05/46: header fix, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 271c4b3b0a 09/46: Add require for cl-lib, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 25b3eda13b 12/46: doc fix, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange d862e1c321 32/46: Add support for lispyville, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange cbd31e6a73 34/46: remove [Experimental] label for cx bindings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 0739b4ca7c 42/46: Don't do exchange when buffer is dead., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange ac50f21b29 46/46: fix README english mistake. (#7), ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 72bf29c9fa 01/46: initial commit,
ELPA Syncer <=
- [nongnu] elpa/evil-exchange ee17ab47fe 02/46: improve doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange ba64a66e26 11/46: correct autoloads, try to fix #2, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 3efefb1bd7 07/46: Add a Bitdeli badge to README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-exchange 37fd36065d 10/46: Merge https://github.com/Dewdrops/evil-exchange, ELPA Syncer, 2022/01/06
- [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