For example, I have the code like this:
(defn greetings [name]
(str "hello"
name))
I want:
(defn greetings [name]
(print (vec (str "hello"
name))))
- Move the cursor to the point before
(str
. - Switch to Paren Mode.
- Type
(print_(vec_
(underscore stands for white space). - Press
C-M-f
(builtin command, forward sexp), this will lead my cursor to point aftername)
. - Type
))
to close parens, code will be auto indent after this. - Switch back to Ident Mode (or using
(setq parinfer-auto-switch-indent-mode t)
to skip this step).
To simplify these steps, I’m trying to combine Indent Mode & Paren Mode into One Mode.
IMO, the strategy will be:
- Rule 1
- When inserting before an open parens, insert close parens and call Paren Mode.
- Rule 2
- When cursor is between two open parens (
(<cursor>(
) and backspace is pressed, delete the corresponding close parens and call Paren Mode. - Rule 3
- When modifying indentation, call Indent Mode.
- Rule 4
- When Insert/Delete parens(except Rule 1 & 2), call Ident Mode.
- Rule 5
- Otherwise, call Paren Mode.
This is a demo, this feature is WIP, very experimental.
You can try by add one
to parinfer-extensions
.