From a5dceee45565268053e96ec4e6ebbae10da49e36 Mon Sep 17 00:00:00 2001 From: Peng Li Date: Fri, 22 Sep 2017 10:50:40 +0800 Subject: [PATCH 1/1] Emacs - bindings of evil with org mode and lispy mode --- emacs.d/config.org | 1 + emacs.d/elisp/shell-command-output-mode.el | 7 +----- emacs.d/emacs-evil.org | 40 +++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/emacs.d/config.org b/emacs.d/config.org index 73dfe4b..72c368f 100644 --- a/emacs.d/config.org +++ b/emacs.d/config.org @@ -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 diff --git a/emacs.d/elisp/shell-command-output-mode.el b/emacs.d/elisp/shell-command-output-mode.el index 451e121..25ed64b 100644 --- a/emacs.d/elisp/shell-command-output-mode.el +++ b/emacs.d/elisp/shell-command-output-mode.el @@ -24,10 +24,6 @@ ;;; 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 diff --git a/emacs.d/emacs-evil.org b/emacs.d/emacs-evil.org index c66dc9e..fb5dbdb 100644 --- a/emacs.d/emacs-evil.org +++ b/emacs.d/emacs-evil.org @@ -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)) -- 2.11.0