From 8461b0a421181ef3299f7f098e15e50a8cd504bd Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sat, 6 Dec 2014 23:40:18 -0500 Subject: [PATCH] Add `A`, `I`, `$`, `0` bindings to iedit state --- contrib/iedit/README.md | 21 +++---- .../evil-iedit-state/evil-iedit-state.el | 59 ++++++++++++++++--- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/contrib/iedit/README.md b/contrib/iedit/README.md index 86f1a880d..635240f97 100644 --- a/contrib/iedit/README.md +++ b/contrib/iedit/README.md @@ -7,10 +7,9 @@ - [Install](#install) - [Key bindings](#key-bindings) - [State transitions](#state-transitions) - - [In `iedit state`](#in-iedit-state) - - [In `iedit-insert state`](#in-iedit-insert-state) + - [In iedit state](#in-iedit-state) + - [In iedit-insert state](#in-iedit-insert-state) - [Examples](#examples) - - [Tips](#tips) @@ -58,7 +57,7 @@ or fd to return to `normal state`. **Note:** evil commands which switch to `insert state` will switch in `iedit-insert state`. -### In `iedit state` +### In iedit state `iedit state` inherits from `normal state`, the following key bindings are specific to `iedit state`. @@ -66,12 +65,15 @@ specific to `iedit state`. Key Binding | Description ------------------|------------------------------------------------------------ ESC | go back to `normal state` +0 | go to then beginning of the current occurrence +$ | go to then end of the current occurrence # | prefix all occurrences with an increasing number (SPC u to choose the starting number). +A | go to the beginning of the current occurrence and switch to `iedit-insert state` D | delete the occurrences F | restrict the scope to the function gg | go to first occurrence G | go to last occurrence -I | toggle case-sensitivity +I | go to the end of the current occurrence and switch to `iedit-insert state` J | increase the edition scope by one line below K | increase the edition scope by one line above L | restrict the scope to the current line @@ -83,7 +85,7 @@ specific to `iedit state`. U | Up-case the occurrences C-U | down-case the occurrences -### In `iedit-insert state` +### In iedit-insert state Key Binding | Description ---------------------------|------------------------------------------------------------ @@ -97,13 +99,6 @@ specific to `iedit state`. - substitute symbol _with expand-region_: SPC v v e S "toto" ESC ESC - replace symbol with yanked (copied) text _with expand region_: SPC v e p ESC ESC -## Todo - -- Make `A` append to the end of the edited region. -- Make `I` insert to the beginning of the edited region. -- Make `0` go to the beginning of the edited region. -- Make `$` go to the end of the edited region. - [auto-highlight-symbol]: https://github.com/gennad/auto-highlight-symbol [iedit]: https://github.com/tsdh/iedit [expand-region]: https://github.com/magnars/expand-region.el diff --git a/contrib/iedit/extensions/evil-iedit-state/evil-iedit-state.el b/contrib/iedit/extensions/evil-iedit-state/evil-iedit-state.el index 44d1d6d91..cc16d639f 100644 --- a/contrib/iedit/extensions/evil-iedit-state/evil-iedit-state.el +++ b/contrib/iedit/extensions/evil-iedit-state/evil-iedit-state.el @@ -30,13 +30,49 @@ (iedit-done) (evil-normal-state)) -(defmacro evil-iedit-state|wrap-evil-command (command) - "Call evil command and switch to iedit-insert state." +(defmacro evil-iedit-state||swith-to-insert-state-after-command (command &optional interactive) + "Call COMMAND and switch to iedit-insert state. +If INTERACTIVE is non-nil then COMMAND is called interactively." `(progn - (call-interactively ',command) - (evil-iedit-state) ; required to correctly update the cursors + (if ,interactive + (call-interactively ',command) + (funcall ',command)) + ;; required to correctly update the cursors + (evil-iedit-state) (evil-iedit-insert-state))) +(defun evil-iedit-state//goto-overlay-start () + "Return the position of the start of the current overlay." + (goto-char (overlay-start (iedit-find-current-occurrence-overlay)))) + +(defun evil-iedit-state//goto-overlay-end () + "Return the position of the end of the current overlay." + (goto-char (overlay-end (iedit-find-current-occurrence-overlay)))) + +(defun evil-iedit-state/evil-beginning-of-line (count) + "Go to the beginning of the current overlay." + (interactive "p") + (evil-iedit-state//goto-overlay-start)) + +(defun evil-iedit-state/evil-end-of-line () + "Go to the beginning of the current overlay." + (interactive) + (evil-iedit-state//goto-overlay-end)) + +(defun evil-iedit-state/evil-append-line () + "Put the point at then end of current overlay and switch to +`iedit-insert state'." + (interactive) + (evil-iedit-state||swith-to-insert-state-after-command + evil-iedit-state//goto-overlay-end)) + +(defun evil-iedit-state/evil-insert-line () + "Put the point at then end of current overlay and switch to +`iedit-insert state'." + (interactive) + (evil-iedit-state||swith-to-insert-state-after-command + evil-iedit-state//goto-overlay-start)) + (defun evil-iedit-state/substitute () "Wipe all the occurrences and switch in `iedit-insert state'" (interactive) @@ -46,7 +82,7 @@ (defun evil-iedit-state/evil-change () "Wipe all the occurrences and switch in `iedit-insert state'" (interactive) - (evil-iedit-state|wrap-evil-command evil-change)) + (evil-iedit-state||swith-to-insert-state-after-command evil-change t)) (defun evil-iedit-state/paste-replace (count) "Replace the selection with the yanked text." @@ -57,12 +93,12 @@ (defun evil-iedit-state/evil-append () "Append and switch to `iedit-insert state'" (interactive) - (evil-iedit-state|wrap-evil-command evil-append)) + (evil-iedit-state||swith-to-insert-state-after-command evil-append t)) (defun evil-iedit-state/evil-substitute () "Append and switch to `iedit-insert state'" (interactive) - (evil-iedit-state|wrap-evil-command evil-substitute)) + (evil-iedit-state||swith-to-insert-state-after-command evil-substitute t)) ;; expand-region integration, add an "e" command (eval-after-load 'expand-region @@ -112,14 +148,17 @@ the initial string globally." (run-hooks 'iedit-mode-end-hook)) (define-key evil-iedit-state-map "#" 'iedit-number-occurrences) +(define-key evil-iedit-state-map "$" 'evil-iedit-state/evil-end-of-line) +(evil-redirect-digit-argument evil-iedit-state-map "0" 'evil-iedit-state/evil-beginning-of-line) (define-key evil-iedit-state-map "a" 'evil-iedit-state/evil-append) +(define-key evil-iedit-state-map "A" 'evil-iedit-state/evil-append-line) (define-key evil-iedit-state-map "c" 'evil-iedit-state/evil-change) (define-key evil-iedit-state-map "D" 'iedit-delete-occurrences) (define-key evil-iedit-state-map "F" 'iedit-restrict-function) (define-key evil-iedit-state-map "gg" 'iedit-goto-first-occurrence) (define-key evil-iedit-state-map "G" 'iedit-goto-last-occurrence) (define-key evil-iedit-state-map "i" 'evil-iedit-insert-state) -(define-key evil-iedit-state-map "I" 'iedit-toggle-case-sensitive) +(define-key evil-iedit-state-map "I" 'evil-iedit-state/evil-insert-line) (define-key evil-iedit-state-map "J" 'iedit-expand-down-a-line) (define-key evil-iedit-state-map "K" 'iedit-expand-up-a-line) (define-key evil-iedit-state-map "L" 'iedit-restrict-current-line) @@ -138,4 +177,8 @@ the initial string globally." (define-key evil-iedit-insert-state-map "\C-g" 'evil-iedit-state/quit-iedit-mode) (define-key evil-iedit-insert-state-map [escape] 'evil-iedit-state) +;; unbound iedit commands: +;; toggle buffering +;; toggle case sensitive + (provide 'evil-iedit-state)