Update lispy
This commit is contained in:
parent
7b53a19bc9
commit
0d44776af2
|
@ -1,6 +1,6 @@
|
|||
;;; evil-collection-lispy.el --- Evil Bindings for Lispy -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||
|
||||
;; Copyright (C) 2018 James Nguyen
|
||||
;; Copyright (C) 2019 James Nguyen
|
||||
|
||||
;; Author: James Nguyen <james@jojojames.com>
|
||||
;; Maintainer: James Nguyen <james@jojojames.com>
|
||||
|
@ -25,19 +25,13 @@
|
|||
|
||||
;;; Commentary:
|
||||
;; Evil bindings for `lispy-mode'.
|
||||
;; This is not included in the default init list for `evil-collection'.
|
||||
;; Add `lispy' to `evil-collection-mode-list' to use this package.
|
||||
;; e.g. (push 'lispy evil-collection-mode-list)
|
||||
;; This file is meant to be an experimental ground for `lispy' keybindings
|
||||
;; and the changes here are intended to be created as a PR to the main `lispy'
|
||||
;; repository.
|
||||
;; PRs, tweaks or comments are very welcome!
|
||||
|
||||
;;; Code:
|
||||
(require 'lispy nil t)
|
||||
(require 'evil-collection)
|
||||
|
||||
(defconst evil-collection-lispy-maps '(lispy-mode-map))
|
||||
(defconst evil-collection-lispy-maps '(lispy-mode-map
|
||||
evil-collection-lispy-mode-map))
|
||||
|
||||
(defvar lispy-mode-map-base)
|
||||
(defvar lispy-mode-map-special)
|
||||
|
@ -51,6 +45,7 @@
|
|||
(declare-function lispy-define-key "lispy")
|
||||
(declare-function lispy-set-key-theme "lispy")
|
||||
|
||||
;; FIXME: Decouple this from `lispyville'.
|
||||
(declare-function lispyville-insert-at-beginning-of-list "lispyville")
|
||||
(declare-function lispyville-insert-at-end-of-list "lispyville")
|
||||
|
||||
|
@ -64,11 +59,38 @@
|
|||
(interactive)
|
||||
(lispyville-insert-at-beginning-of-list 1))
|
||||
|
||||
(defhydra g-knight (:color blue :hint nil :idle .3)
|
||||
(defun evil-collection-lispy-action-then-next-sexp (lispy-action)
|
||||
"Return function that triggers LISPY-ACTION and then moves to next sexp."
|
||||
(defalias (intern (format "%S-then-next-sexp" lispy-action))
|
||||
(lambda ()
|
||||
(interactive)
|
||||
(call-interactively lispy-action)
|
||||
(unless (or (lispy-left-p)
|
||||
(lispy-right-p)
|
||||
(and (lispy-bolp)
|
||||
(or (looking-at lispy-outline-header)
|
||||
(looking-at lispy-outline))))
|
||||
(call-interactively #'sp-next-sexp)))))
|
||||
|
||||
(defun evil-collection-lispy-delete (arg)
|
||||
"Copy and delete current sexp.
|
||||
Passes ARG to `lispy-delete' or `lispy-delete-back'.
|
||||
|
||||
Copy of `noc:lispy-delete'."
|
||||
(interactive "p")
|
||||
(cond ((or (lispy-left-p)
|
||||
(region-active-p))
|
||||
(lispy-new-copy)
|
||||
(lispy-delete arg))
|
||||
((lispy-right-p)
|
||||
(lispy-new-copy)
|
||||
(lispy-delete-backward arg))))
|
||||
|
||||
(defhydra g-knight (:color blue :hint nil :idle .3 :columns 3)
|
||||
"g knight"
|
||||
("j" lispy-knight-down "Knight Down")
|
||||
("k" lispy-knight-up "Knight Up")
|
||||
("g" lispy-beginning-of-defun "Beginning of Defun")
|
||||
("j" lispy-knight-down "Down")
|
||||
("k" lispy-knight-up "Up")
|
||||
("g" lispy-beginning-of-defun "Beginning")
|
||||
("d" lispy-goto "Goto")
|
||||
("l" lispy-goto-local "Goto Local"))
|
||||
|
||||
|
@ -77,7 +99,7 @@
|
|||
("i" lispy-tab "Tab")
|
||||
("s" lispy-shifttab "Shifttab"))
|
||||
|
||||
(defvar evil-collection-lispy-mode-map-special-evil
|
||||
(defvar evil-collection-lispy-mode-map-special
|
||||
(let ((map (make-sparse-keymap)))
|
||||
;; navigation
|
||||
(lispy-define-key map "l" 'lispy-right)
|
||||
|
@ -87,16 +109,16 @@
|
|||
(View-quit)))) ;; `lispy-flow' -> w
|
||||
(lispy-define-key map "j" 'lispy-down)
|
||||
(lispy-define-key map "k" 'lispy-up)
|
||||
(lispy-define-key map "d" 'lispy-delete) ;; `lispy-different' -> o
|
||||
|
||||
(lispy-define-key lispy-mode-map-special
|
||||
"d" (evil-collection-lispy-action-then-next-sexp
|
||||
'evil-collection-lispy-delete)) ;; `lispy-different' -> o
|
||||
|
||||
(lispy-define-key map "o" 'lispy-different) ;; `lispy-other-mode' -> Q
|
||||
(lispy-define-key map "p" 'lispy-paste) ;; `lispy-eval-other-window' -> P
|
||||
(lispy-define-key map "P" 'lispy-eval-other-window) ;; `lispy-paste' -> p
|
||||
(lispy-define-key map "y" 'lispy-new-copy) ;; `lispy-occur' -> /
|
||||
|
||||
(lispy-define-key map "g" 'g-knight/body) ;; `lispy-goto' -> gd
|
||||
|
||||
;; FIXME: Looks like one of the evil keymaps is taking precedence.
|
||||
(lispy-define-key map "C-t" 'pop-tag-mark)
|
||||
(lispy-define-key map "y" 'lispy-new-copy) ;; `lispy-occur' -> /
|
||||
(lispy-define-key map "z" 'lispy-view) ;; `lispy-mark-list' -> v
|
||||
|
||||
;; outline
|
||||
(lispy-define-key map "J" 'lispy-join) ;; `lispy-outline-next'
|
||||
|
@ -105,11 +127,9 @@
|
|||
|
||||
;; Paredit transformations
|
||||
(lispy-define-key map ">" 'lispy-slurp-or-barf-right) ;; `lispy-slurp'
|
||||
(lispy-define-key map "<" 'lispy-slurp-or-barf-left) ;; `lispy-barf'
|
||||
(lispy-define-key map "<" 'lispy-slurp-or-barf-left) ;; `lispy-barf'
|
||||
|
||||
;; FIXME: This doesn't work for me for some reason.
|
||||
;; `lispy-occur' doesn't show up in evil-collection-lispy-mode-map-special-evil.
|
||||
;; Evaluating lispy-define-key again in *scratch* works...
|
||||
;; FIXME: This doesn't work for me for some reason...
|
||||
(lispy-define-key map "/" 'lispy-occur) ;; `lispy-x' -> q
|
||||
|
||||
(lispy-define-key map "r" 'lispy-raise)
|
||||
|
@ -131,7 +151,6 @@
|
|||
:override '(cond ((looking-at lispy-outline)
|
||||
(lispy-meta-return))))
|
||||
(lispy-define-key map "H" 'lispy-ace-symbol-replace)
|
||||
(lispy-define-key map "m" 'lispy-view) ;; `lispy-mark-list' -> v
|
||||
|
||||
;; dialect-specific
|
||||
(lispy-define-key map "e" 'lispy-eval)
|
||||
|
@ -141,6 +160,7 @@
|
|||
;; `end-of-defun' doesn't work quite right yet. It exits the list
|
||||
;; which would exit lispy state.
|
||||
(lispy-define-key map "G" 'end-of-defun) ;; `lispy-goto-local' -> gl
|
||||
(lispy-define-key map "g" 'g-knight/body) ;; `lispy-goto' -> gd
|
||||
|
||||
(lispy-define-key map "A" 'evil-collection-lispy-insert-at-end-of-list) ;; `lispy-beginning-of-defun' -> gg
|
||||
(lispy-define-key map "I" 'evil-collection-lispy-insert-at-beginning-of-list) ;; `lispy-shifttab' -> zs
|
||||
|
@ -148,20 +168,21 @@
|
|||
(lispy-define-key map "F" 'lispy-follow t)
|
||||
(lispy-define-key map "D" 'pop-tag-mark)
|
||||
(lispy-define-key map "_" 'lispy-underscore)
|
||||
|
||||
;; miscellanea
|
||||
(define-key map (kbd "SPC") 'lispy-space)
|
||||
(lispy-define-key map "z" 'lispy-tab-hydra/body) ;; `lh-knight/body' -> g
|
||||
(lispy-define-key map "TAB" 'lispy-tab-hydra/body) ;; `lh-knight/body' -> g
|
||||
|
||||
(lispy-define-key map "N" 'lispy-narrow)
|
||||
(lispy-define-key map "W" 'lispy-widen)
|
||||
(lispy-define-key map "c" 'lispy-clone)
|
||||
(lispy-define-key map "u" 'lispy-undo)
|
||||
|
||||
(lispy-define-key map "q" 'lispy-x) ;; `lispy-ace-paren' -> f
|
||||
(lispy-define-key map "q" 'lispy-x) ;; `lispy-ace-paren' -> f
|
||||
(lispy-define-key map "Q" 'lispy-other-mode) ;; `lispy-ace-char' -> t
|
||||
(lispy-define-key map "v" 'lispy-mark-list) ;; `lispy-view' -> m
|
||||
(lispy-define-key map "t" 'lispy-ace-char) ;; `lispy-teleport' -> T
|
||||
(lispy-define-key map "n" 'lispy-flow) ;; `lispy-new-copy' -> y
|
||||
(lispy-define-key map "v" 'lispy-mark-list) ;; `lispy-view' -> z
|
||||
(lispy-define-key map "t" 'lispy-ace-char) ;; `lispy-teleport' -> T
|
||||
(lispy-define-key map "n" 'lispy-flow) ;; `lispy-new-copy' -> y
|
||||
(lispy-define-key map "b" 'lispy-back)
|
||||
|
||||
(lispy-define-key map "B" 'lispy-ediff-regions)
|
||||
|
@ -180,46 +201,21 @@
|
|||
(lispy-define-key map "T" 'lispy-teleport
|
||||
:override '(cond ((looking-at lispy-outline)
|
||||
(end-of-line))))
|
||||
(lispy-define-key map "C-J" 'lispy-outline-next) ;; Hmnn...
|
||||
(lispy-define-key map "C-K" 'lispy-outline-prev) ;; Hmnn...
|
||||
(lispy-define-key map "]" 'lispy-forward)
|
||||
(lispy-define-key map "[" 'lispy-backward)
|
||||
(lispy-define-key map "{" 'lispy-brackets)
|
||||
|
||||
;; Experimental
|
||||
(lispy-define-key map "C-J" 'lispy-outline-next)
|
||||
(lispy-define-key map "C-K" 'lispy-outline-prev)
|
||||
(lispy-define-key map "^" 'lispy-splice-sexp-killing-backward)
|
||||
(lispy-define-key map "$" 'lispy-splice-sexp-killing-forward)
|
||||
(lispy-define-key map "M-j" 'lispy-move-down) ;; `lispy-split'
|
||||
(lispy-define-key map "M-k" 'lispy-move-up) ;; `lispy-kill-sentence'
|
||||
map)
|
||||
"`evil' flavored `lispy' bindings when in special state.")
|
||||
|
||||
(defvar evil-collection-lispy-mode-map-evil
|
||||
(let ((map (copy-keymap lispy-mode-map-base)))
|
||||
(define-key map (kbd "M-)") 'lispy-wrap-round)
|
||||
(define-key map (kbd "M-s") 'lispy-splice)
|
||||
(define-key map (kbd "M-<up>") 'lispy-splice-sexp-killing-backward)
|
||||
(define-key map (kbd "M-<down>") 'lispy-splice-sexp-killing-forward)
|
||||
|
||||
(define-key map (kbd "M-r") 'lispy-raise-sexp)
|
||||
(define-key map (kbd "M-R") 'lispy-raise-some)
|
||||
(define-key map (kbd "M-C") 'lispy-convolute-sexp)
|
||||
(define-key map (kbd "M-S") 'lispy-split)
|
||||
(define-key map (kbd "M-J") 'lispy-join)
|
||||
(define-key map (kbd "]") 'lispy-forward)
|
||||
(define-key map (kbd "[") 'lispy-backward)
|
||||
(define-key map (kbd "M-(") 'lispy-wrap-round)
|
||||
(define-key map (kbd "M-{") 'lispy-wrap-braces)
|
||||
(define-key map (kbd "M-}") 'lispy-wrap-braces)
|
||||
(define-key map (kbd "<") 'lispy-slurp-or-barf-left)
|
||||
(define-key map (kbd ">") 'lispy-slurp-or-barf-right)
|
||||
(define-key map (kbd "M-y") 'lispy-new-copy)
|
||||
(define-key map (kbd "<C-return>") 'lispy-open-line)
|
||||
(define-key map (kbd "<M-return>") 'lispy-meta-return)
|
||||
(define-key map (kbd "M-k") 'lispy-move-up)
|
||||
(define-key map (kbd "M-j") 'lispy-move-down)
|
||||
(define-key map (kbd "M-o") 'lispy-string-oneline)
|
||||
(define-key map (kbd "M-p") 'lispy-clone)
|
||||
(define-key map (kbd "M-d") 'lispy-delete)
|
||||
map)
|
||||
(defvar evil-collection-lispy-mode-map (make-sparse-keymap)
|
||||
"`evil' flavored `lispy-mode' bindings.")
|
||||
|
||||
(defun evil-collection-lispy-set-key-theme (theme)
|
||||
|
@ -233,8 +229,8 @@ This is an exact copy of `lispy-set-key-theme' except with the additions of
|
|||
(make-composed-keymap
|
||||
(delq nil
|
||||
(list
|
||||
(when (memq 'special-evil theme) evil-collection-lispy-mode-map-special-evil)
|
||||
(when (memq 'evil theme) evil-collection-lispy-mode-map-evil)
|
||||
(when (memq 'special-evil theme) evil-collection-lispy-mode-map-special)
|
||||
(when (memq 'evil theme) evil-collection-lispy-mode-map)
|
||||
(when (memq 'special theme) lispy-mode-map-special)
|
||||
(when (memq 'lispy theme) lispy-mode-map-lispy)
|
||||
(when (memq 'paredit theme) lispy-mode-map-paredit)
|
||||
|
@ -250,7 +246,54 @@ This is an exact copy of `lispy-set-key-theme' except with the additions of
|
|||
(defun evil-collection-lispy-setup ()
|
||||
"Set up `evil' bindings for `lispy'."
|
||||
(advice-add 'lispy-set-key-theme :override 'evil-collection-lispy-set-key-theme)
|
||||
(lispy-set-key-theme '(special-evil evil)))
|
||||
(lispy-set-key-theme '(special-evil evil))
|
||||
(evil-collection-define-key 'normal 'evil-collection-lispy-mode-map
|
||||
;; Instead of inheriting, explicitly define keys from `lispy-mode-map-base'.
|
||||
;; navigation.
|
||||
;; Commented out define-keys are from the original map that we're not using.
|
||||
;; -- Begin Inheritance
|
||||
;; (define-key map (kbd "C-a") 'lispy-move-beginning-of-line)
|
||||
;; (define-key map (kbd "C-e") 'lispy-move-end-of-line)
|
||||
(kbd "M-n") 'lispy-left
|
||||
;; killing
|
||||
;; (define-key map (kbd "C-k") 'lispy-kill)
|
||||
(kbd "M-d") 'lispy-kill-word
|
||||
(kbd "M-DEL") 'lispy-backward-kill-word
|
||||
;; misc
|
||||
"(" 'lispy-parens
|
||||
";" 'lispy-comment
|
||||
;; (kbd "M-q") 'lispy-fill
|
||||
;; (define-key map (kbd "C-j") 'lispy-newline-and-indent)
|
||||
;; (define-key map (kbd "RET") 'lispy-newline-and-indent-plain)
|
||||
;; tags
|
||||
"gd" 'lispy-goto-symbol
|
||||
(kbd "C-t") 'pop-tag-mark
|
||||
;; -- End Inheritance.
|
||||
|
||||
(kbd "M-)") 'lispy-wrap-round
|
||||
(kbd "M-s") 'lispy-splice
|
||||
(kbd "M-<up>") 'lispy-splice-sexp-killing-backward
|
||||
(kbd "M-<down>") 'lispy-splice-sexp-killing-forward
|
||||
(kbd "M-r") 'lispy-raise-sexp
|
||||
(kbd "M-R") 'lispy-raise-some
|
||||
(kbd "M-C") 'lispy-convolute-sexp
|
||||
(kbd "M-S") 'lispy-split
|
||||
(kbd "M-J") 'lispy-join
|
||||
"]" 'lispy-forward
|
||||
"[" 'lispy-backward
|
||||
(kbd "M-(") 'lispy-wrap-round
|
||||
(kbd "M-{") 'lispy-wrap-braces
|
||||
(kbd "M-}") 'lispy-wrap-braces
|
||||
"<" 'lispy-slurp-or-barf-left
|
||||
">" 'lispy-slurp-or-barf-right
|
||||
(kbd "M-y") 'lispy-new-copy
|
||||
(kbd "<C-return>") 'lispy-open-line
|
||||
(kbd "<M-return>") 'lispy-meta-return
|
||||
(kbd "M-k") 'lispy-move-up
|
||||
(kbd "M-j") 'lispy-move-down
|
||||
(kbd "M-o") 'lispy-string-oneline
|
||||
(kbd "M-p") 'lispy-clone
|
||||
(kbd "M-d") 'evil-collection-lispy-delete))
|
||||
|
||||
(provide 'evil-collection-lispy)
|
||||
;;; evil-collection-lispy.el ends here
|
||||
|
|
Loading…
Reference in New Issue