[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-lisp-state c6131e28e0 056/125: New navigation model l
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-lisp-state c6131e28e0 056/125: New navigation model leading to version 2.0 |
Date: |
Thu, 6 Jan 2022 04:58:41 -0500 (EST) |
branch: elpa/evil-lisp-state
commit c6131e28e0781d67953e0f8b040fbb9590adf81f
Author: syl20bnr <sylvain.benner@gmail.com>
Commit: syl20bnr <sylvain.benner@gmail.com>
New navigation model leading to version 2.0
---
README.md | 77 +++++++++++++++++++++++++---------------
evil-lisp-state.el | 102 ++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 119 insertions(+), 60 deletions(-)
diff --git a/README.md b/README.md
index 4046f04b3f..46883ec9df 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@ basis.**
- [Manually](#manually)
- [Configuration](#configuration)
- [Backward prefix](#backward-prefix)
+ - [Simple to grasp navigation model](#simple-to-grasp-navigation-model)
- [Text selection](#text-selection)
- [Key bindings map](#key-bindings-map)
- [Thanks](#thanks)
@@ -47,7 +48,7 @@ both `evil` and `smartparens` to be installed.
## Configuration
-Example of a configuration overriding the `L` key bindings of `normal state`
+Example of a configuration overriding the `L` key bindings of `<tab>ormal
state`
in order to trigger the `lisp state`.
```elisp
@@ -65,10 +66,30 @@ M-x customize-group evil-lisp-state
Corresponding backward version of a command is performed by a common prefix
whose value is determined by the custom variable
-`evil-lisp-state-backward-prefix`. Default value is `n`.
+`evil-lisp-state-backward-prefix`. Default value is `<tab>`.
For instance, `slurping forward` is performed with `s` and the backward
-version `slurping backward` with `ns`.
+version `slurping backward` with `<tab>s`.
+
+## Simple to grasp navigation model
+
+A lot of experimentation led to the following navigation model which should
+hopefully be a lot more intuitive than other models.
+
+**Next sexp on the same level**
+`l`: next sexp
+`h`: previous sexp
+
+**Change level (depth)**
+`j`: go to next sexp one level down
+`k`: go to previous one level up
+
+**Enter inside an sexp**
+`L`: next symbol
+`H`: previous symbol
+
+And that's it! All these commands always put the point _at the beginning_ of
+the sexp. Use the regular `e` binding to go at the end of a word.
## Text selection
@@ -78,7 +99,7 @@ It is also possible to select the whole line with `V`.
## Key bindings map
While in `lisp state` (assume that `evil-lisp-state-backward-prefix` is set
-to default `n`):
+to default `<tab>`):
Key Binding | Function
--------------|------------------------------------------------------------
@@ -87,54 +108,54 @@ Key Binding | Function
`0` | sp-beginning-of-sexp
`a` | sp-absorb-sexp
`b` | sp-forward-barf-sexp
-`nb` | sp-backward-barf-sexp
+`<tab>b` | sp-backward-barf-sexp
`c` | sp-convolute-sexp
`C` | sp-comment
`dd` | sp-kill-hybrid-sexp
`dx` | sp-kill-sexp
-`ndx` | sp-backward-kill-sexp
+`<tab>dx` | sp-backward-kill-sexp
`ds` | sp-kill-symbol
-`nds` | sp-backward-kill-symbol
+`<tab>ds` | sp-backward-kill-symbol
`dw` | sp-kill-word
-`ndw` | sp-backward-kill-word
+`<tab>dw` | sp-backward-kill-word
`D` | evil-delete-line
-`e$` | evil-lisp-state-eval-sexp-end-of-line
-`ef` | eval-defun
-`el` | eval-last-sexp
-`es` | eval-sexp
`gs` | go to source of symbol under point
-`h` | sp-backward-symbol
-`H` | sp-backward-sexp
+`h` | previous sexp at the same level
+`H` | previous symbol
`i` | evil-insert-state
-`j` | sp-down-sexp
-`J` | sp-backward-down-sexp
-`k` | sp-up-sexp
-`K` | sp-backward-up-sexp
-`l` | sp-forward-symbol
-`L` | go to the beginning of next sexp at the same level
+`j` | next sexp one level down
+`J` | next visual line
+`k` | previous sexp one level up
+`K` | previous visual line
+`l` | next sexp of the same level
+`L` | next symbol
`m` | sp-join-sexp (think about `merge-sexp`)
-`o` | sp-newline and switch to `insert state`
-`O` | evil-open-above
+`o` | insert sexp after the current one and switch to `insert state`
+`O` | insert sexp before the current one and switch to `insert state`
`p` | evil-past-after
`P` | evil-past-before
`r` | sp-raise-sexp
`R` | sp-rewrap-sexp
`C-r` | undo-tree-redo
`s` | sp-forward-slurp-sexp
-`ns` | sp-backward-slurp-sexp
+`<tab>s` | sp-backward-slurp-sexp
`S` | sp-splice-sexp-killing-forward
-`nS` | sp-splice-sexp-killing-backward
+`<tab>S` | sp-splice-sexp-killing-backward
`t` | sp-transpose-sexp
`T` | sp-transpose-hybrid-sexp
`u` | undo-tree-undo
`U` | sp-unwrap-sexp
-`nU` | sp-backward-unwrap-sexp
+`<tab>U` | sp-backward-unwrap-sexp
`v` | er/expand-region
`V` | select whole line and switch to `visual state`
-`x` | sp-delete-char
-`X` | sp-backward-delete-char
+`x$` | evil-lisp-state-eval-sexp-end-of-line
+`xf` | eval-defun
+`xl` | eval-last-sexp
+`xs` | eval-sexp
`y` | sp-copy-sexp
-`ny` | sp-backward-copy-sexp
+`<tab>y` | sp-backward-copy-sexp
+`backspace` | sp-backward-delete-char
+`S-backspace` | sp-delete-char
`RET` | sp-newline (stay in `lisp state` see `o` to switch to `insert
state`)
`ESC` | evil-normal-state
diff --git a/evil-lisp-state.el b/evil-lisp-state.el
index 0f56da96e1..940f79250b 100644
--- a/evil-lisp-state.el
+++ b/evil-lisp-state.el
@@ -1,11 +1,11 @@
;;; evil-lisp-state.el --- An evil state to navigate Lisp code and modify it
with smartparens
;; Copyright (C) 2014 syl20bnr
-
-;; Author: Sylvain Benner <sylvain.benner@gmail.com>
+;;
+;;;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; Keywords: convenience editing evil smartparens lisp mnemonic
;; Created: 9 Oct 2014
-;; Version: 1.6
+;; Version: 2.0
;; Package-Requires: ((evil "1.0.9") (smartparens "1.6.1") (expand-region
"0.10.0"))
;; URL: https://github.com/syl20bnr/evil-lisp-state
@@ -29,8 +29,22 @@
;; Adds a new Evil state called --LISP-- (<L>) with mnemonics key bindings
;; to navigate Lisp code and edit the sexp tree.
-;; Example of a configuration overriding the `L` key bindings of
-;; evil `motion state`:
+;; Simple to grasp navigation model:
+
+;; **Next sexp on the same level**
+;; `l`: next sexp
+;; `h`: previous sexp
+
+;; **Change level (depth)**
+;; `j`: go to next sexp one level down
+;; `k`: go to previous one level up
+
+;; **Enter inside an sexp**
+;; `L`: next symbol
+;; `H`: previous symbol
+
+;; Example Configuration:
+;; override the `L` key bindings of evil `motion state`:
;; (require 'evil-lisp-state)
;; (define-key evil-normal-state-map "L" 'evil-lisp-state)
@@ -60,7 +74,7 @@
:group 'emulations
:prefix 'evil-lisp-state-)
-(defcustom evil-lisp-state-backward-prefix "n"
+(defcustom evil-lisp-state-backward-prefix "<tab>"
"Prefix to execute the backward version of a command"
:type 'string
:group 'evil-lisp-state)
@@ -80,7 +94,7 @@ of COMMAND.
(concat "backward-" cmdstr)))
(bcmdsym (intern (format "sp-%s" bcmdstr)))
(bkey ,(concat evil-lisp-state-backward-prefix key)))
- (define-key evil-lisp-state-map bkey bcmdsym)))))
+ (define-key evil-lisp-state-map (kbd bkey) bcmdsym)))))
;; key bindings
(define-key evil-lisp-state-map "(" 'evil-lisp-state-insert-left-paren)
@@ -104,22 +118,18 @@ of COMMAND.
(evil-lisp-state-define-key "ds" kill-symbol t)
(evil-lisp-state-define-key "dw" kill-word t)
(define-key evil-lisp-state-map "D" 'evil-delete-line)
-(define-key evil-lisp-state-map "e$" 'evil-lisp-state-eval-sexp-end-of-line)
-(define-key evil-lisp-state-map "ef" 'eval-defun)
-(define-key evil-lisp-state-map "el" 'eval-last-sexp)
-(define-key evil-lisp-state-map "es" 'eval-sexp)
(define-key evil-lisp-state-map "gs"
'elisp-slime-nav-find-elisp-thing-at-point)
-(define-key evil-lisp-state-map "h" 'sp-backward-symbol)
-(define-key evil-lisp-state-map "H" 'sp-backward-sexp)
-(define-key evil-lisp-state-map "j" 'sp-down-sexp)
-(define-key evil-lisp-state-map "J" 'sp-backward-down-sexp)
-(define-key evil-lisp-state-map "k" 'sp-up-sexp)
-(define-key evil-lisp-state-map "K" 'sp-backward-up-sexp)
-(define-key evil-lisp-state-map "l" 'sp-forward-symbol)
-(define-key evil-lisp-state-map "L" 'evil-lisp-state-next-sexp)
+(define-key evil-lisp-state-map "h" 'evil-lisp-state-previous-sexp)
+(define-key evil-lisp-state-map "H" 'sp-backward-symbol)
+(define-key evil-lisp-state-map "j" 'evil-lisp-state-next-sexp-down)
+(define-key evil-lisp-state-map "J" 'evil-next-visual-line)
+(define-key evil-lisp-state-map "k" 'sp-backward-up-sexp)
+(define-key evil-lisp-state-map "K" 'evil-previous-visual-line)
+(define-key evil-lisp-state-map "l" 'sp-next-sexp)
+(define-key evil-lisp-state-map "L" 'evil-lisp-state-forward-symbol)
(define-key evil-lisp-state-map "m" 'sp-join-sexp)
-(define-key evil-lisp-state-map "o" 'evil-lisp-state-insert-below)
-(define-key evil-lisp-state-map "O" 'evil-open-above)
+(define-key evil-lisp-state-map "o" 'evil-lisp-state-insert-sexp-after)
+(define-key evil-lisp-state-map "O" 'evil-lisp-state-insert-sexp-before)
(define-key evil-lisp-state-map "p" 'evil-paste-after)
(define-key evil-lisp-state-map "P" 'evil-paste-before)
(define-key evil-lisp-state-map "r" 'sp-raise-sexp)
@@ -132,10 +142,14 @@ of COMMAND.
(define-key evil-lisp-state-map "u" 'undo-tree-undo)
(evil-lisp-state-define-key "U" unwrap-sexp t)
(define-key evil-lisp-state-map "v" 'er/expand-region)
-(define-key evil-lisp-state-map "x" 'sp-delete-char)
-(define-key evil-lisp-state-map "X" 'sp-backward-delete-char)
+(define-key evil-lisp-state-map "x$" 'evil-lisp-state-eval-sexp-end-of-line)
+(define-key evil-lisp-state-map "xf" 'eval-defun)
+(define-key evil-lisp-state-map "xl" 'eval-last-sexp)
+(define-key evil-lisp-state-map "xs" 'eval-sexp)
(evil-lisp-state-define-key "y" copy-sexp t)
-(define-key evil-lisp-state-map (kbd "DEL") 'evil-backward-char)
+(define-key evil-lisp-state-map (kbd "<S-tab>") 'evil-lisp-state-previous-sexp)
+(define-key evil-lisp-state-map (kbd "<backspace>") 'sp-backward-delete-char)
+(define-key evil-lisp-state-map (kbd "<S-backspace>") 'sp-delete-char)
(define-key evil-lisp-state-map (kbd "RET") 'sp-newline)
(define-key evil-lisp-state-map "i" 'evil-insert-state)
(define-key evil-lisp-state-map [escape] 'evil-normal-state)
@@ -147,22 +161,46 @@ of COMMAND.
(evil-end-of-line)
(eval-last-sexp nil)))
-(defun evil-lisp-state-next-sexp ()
- "Go to the beginning of the next sexp of the same level."
+(defun evil-lisp-state-insert-left-paren ()
+ "Switch to insert state and insert `('"
+ (interactive)
+ (evil-insert-state)
+ (sp-insert-pair "("))
+
+(defun evil-lisp-state-previous-sexp ()
+ "Go to the beginning of the previous sexp."
(interactive)
- (sp-forward-sexp) (sp-forward-sexp)
+ (sp-previous-sexp)
(sp-backward-sexp))
-(defun evil-lisp-state-insert-left-paren ()
- "Switch to insert state and insert `('"
+(defun evil-lisp-state-next-sexp-down ()
+ "Go to the beginning of the next sexp one level down."
(interactive)
+ (sp-down-sexp 2)
+ (sp-backward-up-sexp))
+
+(defun evil-lisp-state-forward-symbol ()
+ "Go to the beginning of the next symbol."
+ (interactive)
+ (let ((n (if (char-equal (char-after) ?\() 1 2)))
+ (sp-forward-symbol n)
+ (sp-backward-symbol)))
+
+(defun evil-lisp-state-insert-sexp-after ()
+ "Insert sexp after the current one."
+ (interactive)
+ (sp-up-sexp)
(evil-insert-state)
+ (insert " ")
(sp-insert-pair "("))
-(defun evil-lisp-state-insert-below ()
- "Mimic `o' command for lisp state."
+(defun evil-lisp-state-insert-sexp-before ()
+ "Insert sexp before the current one."
(interactive)
+ (sp-backward-up-sexp)
(evil-insert-state)
- (sp-newline))
+ (insert " ")
+ (backward-char 1)
+ (sp-insert-pair "("))
(provide 'evil-lisp-state)
- [nongnu] elpa/evil-lisp-state 4167ee0b21 015/125: Add `RET` key binding for sp-newline, (continued)
- [nongnu] elpa/evil-lisp-state 4167ee0b21 015/125: Add `RET` key binding for sp-newline, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 797f09bfbb 013/125: Update readme with last key bindings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state cbe505d26d 014/125: Add sp-comment key binding `C`, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 3a0230162e 019/125: Add key binding for sp-absorb-sexp `a`, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state b4a1371a01 020/125: Add key bindings for transpose functions, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state af7ce842d1 024/125: Add fine grain forward and backward motion with evil standard, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state eefaabc310 027/125: Add installation instruction for MELPA and Cask in readme, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 563654c8cd 040/125: Swap back `k` and `K`, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state d2fe2754c7 044/125: Add disclaimer about experimentation in readme, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 5569669299 049/125: Add `gs` key binding for elisp-slime-nav-find-elisp-thing-at-point, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state c6131e28e0 056/125: New navigation model leading to version 2.0,
ELPA Syncer <=
- [nongnu] elpa/evil-lisp-state 90c8a95714 061/125: Add `%` key binding documentation in readme, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 46fbe7ade7 069/125: Keep `a` for evil-append, absorb-sexp is now on `A`, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 176ebd50e8 062/125: Change key binding `xs` to `xx` for consistency, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 3a72893879 031/125: New common backward prefix, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 37533c6d13 032/125: Type in readme, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 769d43ab36 036/125: Add forward/backward symbol binding to `L` and `H` respectively, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 7b1d98bf75 041/125: Version 1.3, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 0f6eefcb3e 045/125: Add `o` command to insert a new sexp at point on a new line below, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state 77b8cc7bd8 050/125: Add key binding `(` which switches to insert state and insert `(`, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-lisp-state dbc6ae05b5 051/125: Add evil-open-above with binding `O`, ELPA Syncer, 2022/01/06