From f47e86b66d41c1ce0122704f38072c4b3975f265 Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sun, 13 Apr 2014 22:54:30 -0400 Subject: [PATCH] Use mode0local bindings feature from evil-leader --- init-package/init-erlang.el | 12 +----- init-package/init-evil.el | 36 ++++++++++++++++- init-package/init-python.el | 14 +------ my-keybindings.el | 79 +++++++++++++++++++++++++++---------- 4 files changed, 94 insertions(+), 47 deletions(-) diff --git a/init-package/init-erlang.el b/init-package/init-erlang.el index dc8504075..9014f4cba 100644 --- a/init-package/init-erlang.el +++ b/init-package/init-erlang.el @@ -17,17 +17,7 @@ (require 'edts-start) ;; (setq edts-log-level 'debug) ;; (setq edts-face-inhibit-mode-line-updates t) - ;; Key Bindings - (evil-leader/set-key "Mec" 'edts-who-calls) - (evil-leader/set-key "Med" 'edts-find-doc) - (evil-leader/set-key "Mef" 'edts-find-source-under-point) - (evil-leader/set-key "Meg" 'edts-find-global-function) - (evil-leader/set-key "Meh" 'edts-find-header-source) - (evil-leader/set-key "Mel" 'edts-find-local-function) - (evil-leader/set-key "Mem" 'edts-find-macro-source) - (evil-leader/set-key "Men" 'edts-code-next-issue) - (evil-leader/set-key "Mer" 'edts-find-record-source) - (evil-leader/set-key "Mex" 'edts-refactor-extract-function))) + )) ;; not needed using EDTS ;; (require 'erlang-flymake) diff --git a/init-package/init-evil.el b/init-package/init-evil.el index b44cb4333..b2388052a 100644 --- a/init-package/init-evil.el +++ b/init-package/init-evil.el @@ -1,3 +1,32 @@ +;; relative line number for operator state +;; inspired by https://github.com/cofi/dotfiles/blob/master/emacs.d/config/cofi-evil.el +(defvar cofi/current-line 0 + "Stores the current line before linum numbers the lines.") +(defadvice linum-update (before set-current-line activate) + (setq cofi/current-line (line-number-at-pos))) +(defun cofi/relative-line (line-number) + (let ((relative (abs (- line-number cofi/current-line)))) + (propertize (format "%2d" relative) 'face (if (= relative 0) + 'linum-current-line + 'linum)))) +(defun cofi/evil-toggle-relative-lines () + (interactive) + (if (eq linum-format #'cofi/relative-line) + (progn + (linum-mode -1) + (setq linum-format #'cofi/linum-dynamic-lines)) + (progn + (linum-mode t) + (setq linum-format #'cofi/relative-line))) + (linum-update-current)) +(defun cofi/linum-dynamic-lines (line-number) + (let ((width (ceiling (log (count-lines (point-min) (point-max)) 10)))) + (propertize (format (format "%%%dd" width) line-number) + 'face (if (= cofi/current-line line-number) + 'linum-current-line + 'linum)))) +(setq linum-format #'cofi/linum-dynamic-lines) + (use-package evil :init (progn @@ -7,7 +36,9 @@ (setq evil-visual-state-cursor '("black" box)) (setq evil-insert-state-cursor '("green3" box)) (setq evil-motion-state-cursor '("purple" box)) - ;; This is an endless debate and is just a matter of convention + (add-to-hooks #'cofi/evil-toggle-relative-lines + '(evil-operator-state-entry-hook + evil-operator-state-exit-hook)) ;; I prefer to stay on the original character when leaving insert mode ;; (initiated with 'i'). (setq evil-move-cursor-back nil) @@ -42,7 +73,8 @@ (progn (setq evil-leader/in-all-states t evil-leader/leader "SPC" - evil-leader/non-normal-prefix "s-")) + evil-leader/non-normal-prefix "s-") + (global-evil-leader-mode)) :config (progn ;; Unset shortcuts which shadow evil leader diff --git a/init-package/init-python.el b/init-package/init-python.el index 06e118615..6900f0bfa 100644 --- a/init-package/init-python.el +++ b/init-package/init-python.el @@ -32,16 +32,4 @@ (evil-end-of-line) (newline-and-indent) (insert "import pdb; pdb.set_trace()") - (save-buffer)) - ;; Key Bindings - (evil-leader/set-key "Mp1" 'nosetests-one) - (evil-leader/set-key "Mp!" 'nosetests-pdb-one) - (evil-leader/set-key "Mpa" 'nosetests-all) - (evil-leader/set-key "MpA" 'nosetests-pdb-all) - (evil-leader/set-key "Mpb" 'python-add-breakpoint) - (evil-leader/set-key "Mpd" 'pylookup-lookup) - (evil-leader/set-key "Mpf" 'jedi:goto-definition) - (evil-leader/set-key "Mpm" 'nosetests-module) - (evil-leader/set-key "MpM" 'nosetests-pdb-module) - (evil-leader/set-key "Mps" 'nosetests-suite) - (evil-leader/set-key "MpS" 'nosetests-pdb-suite))) + (save-buffer)))) diff --git a/my-keybindings.el b/my-keybindings.el index 19b73ea5d..f6dfba284 100644 --- a/my-keybindings.el +++ b/my-keybindings.el @@ -151,31 +151,12 @@ "kc" 'cofi/helm-flyspell-correct "kd" 'adict-change-dictionary "kn" 'flyspell-goto-next-error) -;; Lisps ---------------------------------------------------------------------- -(evil-leader/set-key - "lB" 'sp-backward-barf-sexp - "lb" 'sp-forward-barf-sexp - "lc" 'sp-convolute-sexp - "lD" 'sp-kill - "ld" 'elisp-slime-nav-describe-elisp-thing-at-point - "lE" 'eval-defun -;; eval the current line - "le" (lambda () (interactive) (save-excursion (evil-end-of-line) - (eval-last-sexp nil))) - "lg" 'elisp-slime-nav-find-elisp-thing-at-point - "ljj" 'sp-split-sexp - "ljk" 'sp-splice-sexp-killing-forward - "ljl" 'sp-join-sexps - "lk" 'sp-splice-sexp-killing-backward - "lr" 'sp-raise-sexp - "lS" 'sp-backward-slurp-sexp - "ls" 'sp-forward-slurp-sexp) ;; Compilation ---------------------------------------------------------------- (evil-leader/set-key "cc" 'compile) ;; match it ------------------------------------------------------------------ (evil-leader/set-key - "md" 'evilmi-delete-items - "mi" 'evilmi-select-items) + "Md" 'evilmi-delete-items + "Mi" 'evilmi-select-items) ;; narrow & widen ------------------------------------------------------------- (evil-leader/set-key "nr" 'narrow-to-region @@ -282,4 +263,60 @@ ;; centered cursor ------------------------------------------------------------ (evil-leader/set-key "zz" 'global-centered-cursor-mode) +;; evil-leader modes specific ================================================= + +;; erlang --------------------------------------------------------------------- +(evil-leader/set-key-for-mode 'erlang-mode + "mc" 'edts-who-calls + "md" 'edts-find-doc + "mf" 'edts-find-source-under-point + "mg" 'edts-find-global-function + "mh" 'edts-find-header-source + "ml" 'edts-find-local-function + "mm" 'edts-find-macro-source + "mn" 'edts-code-next-issue + "mr" 'edts-find-record-source + "mx" 'edts-refactor-extract-function) +;; Lisps ---------------------------------------------------------------------- +(evil-leader/set-key-for-mode 'emacs-lisp-mode + "mB" 'sp-backward-barf-sexp + "mb" 'sp-forward-barf-sexp + "mc" 'sp-convolute-sexp + "mD" 'sp-kill + "md" 'elisp-slime-nav-describe-elisp-thing-at-point + "mE" 'eval-defun +;; Eval the current line + "me" (lambda () (interactive) (save-excursion (evil-end-of-line) + (eval-last-sexp nil))) + "mg" 'elisp-slime-nav-find-elisp-thing-at-point + "mjj" 'sp-split-sexp + "mjk" 'sp-splice-sexp-killing-forward + "mjl" 'sp-join-sexps + "mk" 'sp-splice-sexp-killing-backward + "mr" 'sp-raise-sexp + "mS" 'sp-backward-slurp-sexp + "ms" 'sp-forward-slurp-sexp) +;; magit ---------------------------------------------------------------------- +(evil-add-hjkl-bindings magit-branch-manager-mode-map 'emacs + "K" 'magit-discard-item + "L" 'magit-key-mode-popup-logging) +(evil-add-hjkl-bindings magit-status-mode-map 'emacs + "K" 'magit-discard-item + "l" 'magit-key-mode-popup-logging + "h" 'magit-toggle-diff-refine-hunk) +;; python --------------------------------------------------------------------- +(evil-leader/set-key-for-mode 'python-mode + "m1" 'nosetests-one + "m!" 'nosetests-pdb-one + "ma" 'nosetests-all + "mA" 'nosetests-pdb-all + "mb" 'python-add-breakpoint + "md" 'pylookup-lookup + "mf" 'jedi:goto-definition + "mm" 'nosetests-module + "mM" 'nosetests-pdb-module + "ms" 'nosetests-suite + "mS" 'nosetests-pdb-suite) + + (provide 'my-keybindings)