Emacs - bindings of evil with org mode and lispy mode
authorPeng Li <seudut@gmail.com>
Fri, 22 Sep 2017 02:50:40 +0000 (10:50 +0800)
committerPeng Li <seudut@gmail.com>
Tue, 26 Sep 2017 18:29:07 +0000 (02:29 +0800)
emacs.d/config.org
emacs.d/elisp/shell-command-output-mode.el
emacs.d/emacs-evil.org

index 73dfe4b..72c368f 100644 (file)
@@ -1760,6 +1760,7 @@ as a http download client tool
       (dired-up-directory)
       (kill-buffer old)))
 #+END_SRC
+
 ** Dired bindings
 =C-o= is defined as a global key for window operation, here unset it in dired mode
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
index 451e121..25ed64b 100644 (file)
 
 ;;; Code:
 
-;; (defun haha/delet-window ()
-;;   (interactive)
-;;   (quit-window t))
-
 (defvar shell-command-output-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "q") (lambda () (interactive) (quit-window t)))
@@ -46,8 +42,7 @@
   ;; enable evil motion state for this mode
   (if (and (boundp evil-mode) (fboundp 'evil-motion-state))
       (progn (add-to-list 'evil-motion-state-modes 'shell-command-output-mode)
-            (evil-motion-state)))
-  )
+            (evil-motion-state))))
 
 (provide 'shell-command-output-mode)
 ;;; shell-command-output-mode.el ends here
index c66dc9e..fb5dbdb 100644 (file)
@@ -22,7 +22,7 @@ https://www.emacswiki.org/emacs/Evil.
     (setq evil-replace-state-cursor '("red" bar))
     (setq evil-operator-state-cursor '("red" hollow))
     ;; others, don't move back cursor when exit insert mode
-    ;; (setq evil-move-cursor-back nil)
+    (setq evil-move-cursor-back nil)
     :config
     (use-package evil-leader
       :ensure t
@@ -37,6 +37,16 @@ https://www.emacswiki.org/emacs/Evil.
                                 (modify-syntax-entry ?_ "w")
                                 ;; (modify-syntax-entry ?- "w")
                                 ))
+
+  (with-eval-after-load "evil"
+    ;; remap x to X as `evil-move-cursor-back' is set nil
+    ;; (define-key evil-normal-state-map [remap evil-delete-char] 'evil-delete-backward-char)
+    (define-key evil-normal-state-map (kbd "x") (lambda () (interactive)
+                                                  (let ((org evil-move-cursor-back))
+                                                    (setq evil-move-cursor-back t)
+                                                    (call-interactively 'evil-delete-char)
+                                                    ;; (evil-delete-char)
+                                                    (setq evil-move-cursor-back org)))))
 #+END_SRC
 
 ** Initial mode and state config
@@ -142,6 +152,7 @@ https://www.emacswiki.org/emacs/Evil.
     (global-evil-surround-mode 1))
 #+END_SRC
 * Key bindings
+** Basic state bindings
 There are three kinds key bindings
 - prefix key is the leader key, defined by evil-leader. *;*
 - prefix key is the =Ctrl=,
@@ -187,7 +198,7 @@ Let the search highlight persistent, https://stackoverflow.com/questions/2576803
     (define-key evil-normal-state-map "\\\\" #'evil-ex-nohighlight))
 #+END_SRC
 
-- Dired mode
+** Dired mode
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (with-eval-after-load "evil"
     ;; file and directory explore
@@ -228,7 +239,7 @@ Let the search highlight persistent, https://stackoverflow.com/questions/2576803
 
 #+END_SRC
 
-- expand region
+** expand region
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (with-eval-after-load "evil"
     (with-eval-after-load "expand-region"
@@ -238,6 +249,29 @@ Let the search highlight persistent, https://stackoverflow.com/questions/2576803
       (define-key evil-normal-state-map (kbd "S-SPC") 'er/contract-region)))
 #+END_SRC
 
+** Org Mode (worf mode) and Lispy mode
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (with-eval-after-load "evil"
+    (with-eval-after-load "lispy-mode"
+      (evil-define-key 'normal lispy-mode-map (kbd "[") (lambda ()
+                                                          (interactive)
+                                                          (call-interactively #'lispy-backward)
+                                                          (evil-emacs-state)))
+      (evil-define-key 'normal lispy-mode-map (kbd "]") (lambda ()
+                                                          (interactive)
+                                                          (call-interactively #'lispy-forward)
+                                                          (evil-emacs-state))))
+    (with-eval-after-load "worf-mode"
+      (evil-define-key 'normal worf-mode-map (kbd "[") (lambda ()
+                                                         (interactive)
+                                                         (call-interactively #'worf-backward)
+                                                         (evil-emacs-state)))
+      (evil-define-key 'normal worf-mode-map (kbd "]") (lambda ()
+                                                         (interactive)
+                                                         (call-interactively #'worf-forward)
+                                                         (evil-emacs-state)))))
+#+END_SRC
+
 * Others
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (dolist (mode '(c-mode-hook lua-mode-hook))