lispy.el function reference

Back to github This file in org-mode Parinfer function reference

G az AZ x Global bindings

G az AZ x [a-z] local bindings

G az AZ x [A-Z] local bindings

G az AZ x x[a-z] local bindings

Function reference

lispy-forward

Bound to ].

Works as replacement for the standard forward-list.

Takes a numeric prefix arg and moves forward list arg times or until error.

Unlike forward-list, no error will be reported if it's not possible to move arg times. It that case, move as many times as possible. To facilitate entering a very large arg, arg 0 is interpreted as arg 2000.

Return t if could move at least once, otherwise call lispy-right and return nil.

Unlike forward-list, parens in strings and comments are ignored.


lispy-backward

Bound to [.

Works as replacement for the standard backward-list.

Takes a numeric prefix arg and moves backward list arg times or until error.

Unlike backward-list, no error will be reported if it's not possible to move arg times. It that case, move as many times as possible. To facilitate entering a very large arg, arg 0 is interpreted as arg 2000.

Return t if could move at least once, otherwise call lispy-left return nil.

Unlike backward-list, parens in strings and comments are ignored.


lispy-right

Bound to C-3 and l.

Works as replacement for the standard up-list.

Takes a numeric prefix arg and moves up forward list arg times or until error.

Unlike up-list, no error will be reported if it's not possible to move up arg times. It that case, move as many times as possible.

Return point if could move arg times, otherwise return nil.

Unlike up-list, parens in strings and comments are ignored.


lispy-right-nostring

Bound to ).

Works the same ways as lispy-right, except self-inserts in strings and comments.

Self-inserting in strings and comments makes parens different from the other pair functions that always insert the whole pair:

key function inserts
{ lispy-braces {}
} lispy-brackets []
" lispy-quotes ""

When you want to insert a single character from the pair, use C-q. Or insert a pair and delete the other character.


lispy-left

Bound to h.

Takes a numeric prefix arg and moves up backward list arg times or until error. This is a combination of arg times lispy-right and once lispy-different.

When the region is active, the region (not the code) will move up backward arg times:

(defun lispy-right (arg)
  "Move outside list forwards ARG times.
Return nil on failure, t otherwise."
  (interactive "p")
  (if (region-active-p)
      (lispy-mark-right arg)
    (lispy--out-forward arg)))

-> h ->

(defun lispy-right (arg)
  "Move outside list forwards ARG times.
Return nil on failure, t otherwise."
  (interactive "p")
  (if (region-active-p)
      (lispy-mark-right arg)
    (lispy--out-forward arg)))

lispy-down

Bound to j.

Takes a numeric prefix arg and moves down the current list arg times.

Here, current list means the innermost list that contains the point. Moving down means so literally only if there is a newline after each element of current list, otherwise it's down or left.

j maintains a guarantee that it will not exit the current list, so you can use e.g. 99j to move to the last element of the current list.

When region is active, j will move the region by forward-sexp, i.e. move the point and the mark by forward-sexp.

This allows to easily mark any element(s) of current list. j maintains a guarantee that the region will not exit the currrent list, so if you want to mark last 3 elements of the current list, you can mark the first 3 elements of the current list and press 99j.

For example, starting with:

(a b c d e f g h i j k l m n o p q r s t u v w x y z)

after mi:

(a b c d e f g h i j k l m n o p q r s t u v w x y z)

after 2>:

(a b c d e f g h i j k l m n o p q r s t u v w x y z)

after 99j:

(a b c d e f g h i j k l m n o p q r s t u v w x y z)

lispy-up

Bound to k.

Takes a numeric prefix arg and moves up the current list arg times.

Here, current list means the innermost list that contains the point. Moving up means so literally only if there is a newline after each element of current list, otherwise it's up or right.

k maintains a guarantee that it will not exit the current list, so you can use e.g. 99k to move to the first element of current list.

When region is active, k will move the region by backward-sexp, i.e. move the point and the mark by backward-sexp.


lispy-different

Bound to d.

Switch to the different side of current sexp.

When region is active, equivalent to exchange-point-and-mark.


lispy-flow

Bound to f.

Flow in the direction of current paren, i.e.

looking at lispy-left

Find the next lispy-left not in comment or string going down the file.

looking back lispy-right

Find the next lispy-right not in comment or string going up the file.


lispy-back

Bound to b.

Move point to the previous position in lispy-back history. The following functions write to this history:

key function name
l lispy-right
h lispy-left
f lispy-flow
j lispy-down
k lispy-up
m lispy-mark-list
q lispy-ace-paren
i lispy-mark-car

lispy-knight

Bound to z.

zj and zk are bound in a hydra that allows to move through the leftmost parens on each line.

This is useful if you want to navigate disregarding syntax: since j and k can't exit the parent list they're not suitable for this.

zj and zk move like the knight figure in chess, in a combination of horizontal and vertical movement.


lispy-mark-car

Bound to i while the region is active.

Mark the first element (car) of the currently selected thing (list or region).

when at list boundary

(defun lispy-right (arg)
  "Move outside list forwards ARG times\.
Return nil on failure, t otherwise\."
  (interactive "p")
  (if (region-active-p)
      (lispy-mark-right arg)
    (lispy--out-forward arg)))</span>

-> i ->

(defun lispy-right (arg)
  "Move outside list forwards ARG times.
Return nil on failure, t otherwise."
  (interactive "p")
  (if (region-active-p)
      (lispy-mark-right arg)
    (lispy--out-forward arg)))

when at string boundary

Mark its inner contents.

(list "spam spam spam")

-> i ->

(list "spam spam spam")

when at region boundary

(list "spam spam spam")

-> i ->

(list "spam spam spam")

when a quoted symbol is marked

Select the unquoted part, it's useful for a subsequent e (lispy-eval).

(add-to-list 'auto-mode-alist 
             '("\\.\\(h\\)\\'" . c++-mode))

-> i ->

(add-to-list 'auto-mode-alist 
             '("\\.\\(h\\)\\'" . c++-mode))

lispy-move-end-of-line

Bound to C-e.

Works as replacement for the standard move-end-of-line.

Regular move-end-of-line does nothing the second time when called twice in a row.

When called twice in a row and

inside string

Move to the end of the string.

otherwise

Return to the starting position.


lispy-ace-paren

Bound to q.

Starting with this:

(defun lispy-define-key (keymap key def &optional from-start)
  "Forward to (`define-key' KEYMAP KEY (`lispy-defun' DEF FROM-START))."
  (let ((func (defalias (intern (concat "special-" (symbol-name def)))
                  (lispy--insert-or-call def from-start))))
    (unless (member func ac-trigger-commands)
      (push func ac-trigger-commands))
    (unless (member func company-begin-commands)
      (push func company-begin-commands))
    (eldoc-add-command func)
    (define-key keymap (kbd key) func)))

by pressing q you get this:

temp
adefun lispy-define-key bkeymap key def &optional from-start)
  "Forward to c`define-key' KEYMAP KEY d`lispy-defun' DEF FROM-START))."
  elet fgfunc hdefalias iintern jconcat "special-" ksymbol-name def)))
                  llispy--insert-or-call def from-start))))
    munless nmember func ac-trigger-commands)
      opush func ac-trigger-commands))
    punless qmember func company-begin-commands)
      rpush func company-begin-commands))
    seldoc-add-command func)
    tdefine-key keymap ukbd key) func)))

Now you can change the point position by pressing a letter or cancel with C-g.


lispy-ace-symbol

Bound to a.

Starting with this:

(defun lispy-define-key (keymap key def &optional from-start)
  "Forward to (`define-key' KEYMAP KEY (`lispy-defun' DEF FROM-START))."
  (let ((func (defalias (intern (concat "special-" (symbol-name def)))
                  (lispy--insert-or-call def from-start))))
    (unless (member func ac-trigger-commands)
      (push func ac-trigger-commands))
    (unless (member func company-begin-commands)
      (push func company-begin-commands))
    (eldoc-add-command func)
    (define-key keymap (kbd key) func)))

by pressing a you get this:

*Org Src oblog-min.org[ elisp ]*
(defun lispy-define-key (keymap key def &optional from-start)
  "Forward to (`define-key' KEYMAP KEY (`lispy-defun' DEF FROM-START))."
  (let ((func (defalias (intern (concat "special-" (symbol-name def)))
                  (lispy--insert-or-call def from-start))))
    aunlessb(membercfuncdac-trigger-commands)
     e(pushffuncgac-trigger-commands))
    (unless (member func company-begin-commands)
      (push func company-begin-commands))
    (eldoc-add-command func)
    (define-key keymap (kbd key) func)))

Now you can mark a symbol by pressing a letter, or cancel with C-g.

Here's the end result of ad:

(defun lispy-define-key (keymap key def &optional from-start)
  "Forward to (`define-key' KEYMAP KEY (`lispy-defun' DEF FROM-START))."
  (let ((func (defalias (intern (concat "special-" (symbol-name def)))
                  (lispy--insert-or-call def from-start))))
    (unless (member func ac-trigger-commands)
      (push func ac-trigger-commands))
    (unless (member func company-begin-commands)
      (push func company-begin-commands))
    (eldoc-add-command func)
    (define-key keymap (kbd key) func)))

lispy-ace-symbol's jump scope is the current list by default. Calling it with digit-argument will extend this to the current list's parents.

Now you can follow up with

key function name
F lispy-follow
C-1 lispy-describe-inline
e lispy-eval
E lispy-eval-and-insert
P lispy-paste
r lispy-raise

lispy-ace-subword

Bound to -.

Similar to lispy-ace-symbol, but selects a subword instead.


lispy-splice

Bound to /.

Splice the current list into the parent list. Move the point to the next list to splice in appropriate direction. If there are none within the parent list, move to the parent list in appropriate direction.

((a) (b) (c))

-> / ->

(a (b) (c))

lispy-occur

Bound to y.

Do an occur for the current top-level sexp. Go back-to-paren afterwards.

This is useful e.g. to see where a particular variable is used within the current defun.


lispy-follow

Bound to F.

When region is active jump to the definition of marked symbol. Otherwise jump to the definition of the first symbol in current sexp.

Use D or M-, to go back.

Elisp, Clojure and Common Lisp are supported.


lispy-goto-symbol

Bound to M-..

Goto definition of symbol at point. You can go back with M-, (pop-tag-mark).


pop-tag-mark

Bound to D and M-,.

This is a standard Emacs function that reverses:

It's bound to M-* in the default Emacs. I like to bind it to M-, everywhere.


lispy-describe-inline

Bound to C-1.

Show the documentation for current function or currently marked symbol (see lispy-ace-symbol).

temp
(defun lispy-define-key (keymap key def &optional from-start)
  "Forward to (`define-key' KEYMAP KEY (`lispy-defun' DEF FROM-START))."
  (let ((func (defalias (intern (concat "special-" (symbol-name def)))
                  (lispy--insert-or-call def from-start))))
            Return non-nil if ELT is an element of LIST.  Comparison done with `equal'.
            The value is actually the tail of LIST whose car is ELT.

            (fn ELT LIST)
    (unless (member func ac-trigger-commands)
      (push func ac-trigger-commands))
    (unless (member func company-begin-commands)
      (push func company-begin-commands))
    (eldoc-add-command func)
    (define-key keymap (kbd key) func)))

lispy-arglist-inline

Bound to C-2.

Show the argument list for current function.

lispy-arglist-inline
(defun lispy-define-key (keymap key def &optional from-start)
  "Forward to (`define-key' KEYMAP KEY (`lispy-defun' DEF FROM-START))."
  (let ((func (defalias (intern (concat "special-" (symbol-name def)))
                  (lispy--insert-or-call def from-start))))
            (member elt list)
    (unless (member func ac-trigger-commands)
      (push func ac-trigger-commands))
    (unless (member func company-begin-commands)
      (push func company-begin-commands))
    (eldoc-add-command func)
    (define-key keymap (kbd key) func)))

lispy-eval

Bound to e.

Eval current region or sexp. The result will be displayed in the minibuffer.

Elisp, Clojure, Scheme and Common Lisp are supported.

Elisp extensions:

lispy-lax-eval

When lispy-lax-eval isn't nil, "Symbol's value as variable is void…" error will be caught and the variable in question will be set to nil.

eval of defvar

Will do a setq in addition to defvar (i.e. the behavior of C-M-x).

eval of defcustom

Same as for defvar.


lispy-eval-and-insert

Bound to E.

Eval current region or sexp. The result will be inserted in the current buffer after the evaluated expression.

  • Starting with |( the point will not be moved, allowing to press E again.
  • Starting with )| the point will end up after the inserted expression.
  • Starting with an active region, the region will be deactivated and result will be inserted at point.

lispy-bind-variable

Bound to xb.

Transform the current list expression into a let-bound variable; iedit-mode is used to name the new variable. Use M-m to finish naming the variable.

(defun my-forward-line (arg)
  (message "%S lines"
           (forward-line arg)))

-> xbln M-m ChO->

(defun my-forward-line (arg)
  (let ((ln (forward-line arg)))
    (message "%S lines" ln)))

lispy-unbind-variable

Bound to xu.

Unbind a let-bound variable.

(defun foobar ()
  (let ((x 10)
        (y 20)
        (z 30))
    (foo1 x y z)
    (foo2 x z y)
    (foo3 y x z)
    (foo4 y z x)
    (foo5 z x y)
    (foo6 z y x)))

-> xu ->

(defun foobar ()
  (let ((y 20)
        (z 30))
    (foo1 10 y z)
    (foo2 10 z y)
    (foo3 y 10 z)
    (foo4 y z 10)
    (foo5 z 10 y)
    (foo6 z y 10)))

lispy-eval-and-replace

Bound to xr.

Eval current expression and replace it at point.

(foo (+ 2 2))

-> xr ->

(foo 4)

lispy-store-region-and-buffer

Bound to xB.

Store current buffer and region for further usage. When region isn't active, store the bounds of current expression instead.

Currently, these functions make use of stored info:

key function name
B lispy-ediff-regions

lispy-ediff-regions

Bound to B.

Comparable to ediff-regions-linewise, except the region and buffer selection is done differently:

  • first buffer and region are defined by lispy-store-region-and-buffer.
  • second buffer and region are the current buffer and region (or current sexp bounds if the region isn't active)

The buffers can of course be the same.

A useful scenario for this function is C-x v ~ (vc-revision-other-window) RET and then follow up by selecting one function that was changed with b in one buffer and with B in other buffer. This results in ediff just for that one single function. This is helpful if ediff-buffers isn't what you want.

Another scenario is to compare two different functions that have similar code, for instance lispy-move-down and lispy-move-up.


lispy-to-lambda

Use xl (local) or C-4 l (global) to turn the current function definition into a lambda.

One use case is when I want to edebug a lambda but not the function that's using it. So I extract the lambda with lispy-to-defun, edebug it and turn it back into a lambda with this function.

Other use case is that I simply want to get the lambda since the function isn't used anywhere else.

Starting with this:

(defun helm-owiki-action (x)
  (find-file (expand-file-name
              (format "%s.org" x) 
              helm-owiki-directory)))

by pressing xl you will get this:

(lambda (x)
  (find-file (expand-file-name
              (format "%s.org" x)
              helm-owiki-directory)))

lispy-to-defun

Use xd (local) or C-4 d (global) to turn the current lambda into a defun.

You'll be prompted for a name, the lambda will be replaced with that name and the new definition will be in the kill ring.

Starting with this:

(mapcar (lambda (x) (* x x))
        (number-sequence 1 10))

by pressing xd and entering square and then pressing d C-m C-y you'll get this:

(mapcar #'square
        (number-sequence 1 10))
(defun square (x) (* x x)) 

It's also possible to transform a toplevel function call into a defun with xd:

Starting with this

(foo-delete-region beg end) 

by pressing xd you'll get this:

(defun foo-delete-region (beg end)
  )

lispy-parens

Bound to (.

Call lispy-pair specialized with ().


lispy-braces

Bound to {.

Call lispy-pair specialized with {}.


lispy-brackets

Bound to }.

Call lispy-pair specialized with [].


lispy-quotes

Bound to ".

Insert a pair of quotes around the point.

Takes a prefix arg.

The result depends on the following conditions, each tried one by one until one that holds true is found:

region is active, contained in string

Wrap the region with quoted quotes:

(message "We are the Knights who say Ni")

-> " ->

(message "We are the Knights who say \"Ni\"")

region active

Wrap the region with quotes.

(list 'foo bar)

-> " ->

(list 'foo "bar")

in string and arg isn't nil

Unquote current string.

(list 'foo "bar")

-> C-u " ->

(list 'foo bar)

in string and arg is nil

Insert a pair of quoted quotes around point.

Starting with

"We are the Knights who say "

pressing " will give:

"We are the Knights who say \"\""

arg isn't nil

Forward to lispy-stringify.

otherwise

Insert quotes, with a single space on either side where appropriate, and position the point between the quotes.

Starting with

(message)

pressing " will give:

(message "")

lispy-parens-down

Bound to C-8.

Exit current list and insert a newline and a pair of parens.

(foo)

-> C-8 ->

(foo)
()

lispy-space

Bound to SPC.

Insert a space.

Behave differently in this situation:

((foo))

-> SPC ->

( (foo))

lispy-pair

This function, taking arguments left and right, is used to generate lispy-parens, lispy-braces and lispy-brackets, which in turn take prefix arg. The arguments align with those of lispy-slurp.

The result depends on the following conditions, each tried one by one until one that holds true is found:

region active

Wrap the region with left and right.

inside a string before "\\"

Starting with

"a regex \\"

pressing ( will give:

"a regex \\(\\)"

and pressing { will give:

"a regex \\{\\}"

and pressing } will give:

"a regex \\[\\]"

inside string or comment

Insert left, right and put the point between them.

Starting with:

"a string  "
key result
( "a string ("
) "a string )"
{ "a string {}"
} "a string []"

elisp character expression

Starting with

?\ 

pressing ( will self-insert it to give:

?\( 

This also works for ), {, }.

This doesn't work for [ and ], they should be inserted with C-q [ and C-q ].

no arg is explicitly specified

  1. Re-indent and insert space according to lispy--space-unless.
  2. Insert left, right and put the point between them.
  3. Insert a space after right if it's appropriate.

arg is positive

Wrap that number of sexps with left and right.

Starting with:

(do-some-thing)
(do-other-thing)

pressing 1( will give:

( (do-some-thing))
(do-other-thing)

1 here is responsible to setting arg to 1. C-u will also cause a single sexp to be wrapped.

arg is 0

Wrap as many sexps as possible.

Starting with:

(foo
 bar baz
 quux)

pressing M-0( will give:

(foo
 ( bar baz
       quux))

arg is -1

Wrap to the end of the line where the current sexp ends or as far as possible before that position.

Starting with:

(foo
 bar baz
 quux)

pressing M--( will give:

(foo
 ( bar baz)
 quux)

lispy-x

Bound to x (locally) or C-4 (globally).

Just a prefix to calling other commands, see.


lispy-kill

Bound to C-k.

A replacement for kill-line that keeps parens consistent.

The result depends on the following conditions, each tried one by one until one that holds true is found:

inside comment

Call kill-line.

inside string and string extends past this line

Call kill-line.

inside string that ends on this line

Delete up to the end of the string.

on a line of whitespace

Delete whole line, moving to the next one, and re-indent.

inside empty list

Delete the empty list.

parens between point and eol are balanced

Call kill-line.

possible to up-list

Delete from point to end of list.

otherwise

Delete current sexp.


lispy-new-copy

Bound to n.

Copy current sexp or region to kill ring.


lispy-yank

Bound to C-y.

Replaces yank. The only difference is that yanking into an empty string will add escape sequences.

Starting with:

(message "test")

pressing C-k " C-y will give:

"(message \"test\")"

whereas a regular yank would give:

"(message "test")"

lispy-delete

Bound to C-d.

Replaces delete-char, keeping parens consistent.

The result depends on the following conditions, each tried one by one until one that holds true is found:

region active

Delete region.

inside a string before \"

Delete \".

"say \"hi\""

-> C-d ->

"say hi\""

at last char of the string

Move to the beginning of string. This allows to delete the whole string with the next C-d.

(message "more gold is required")

-> C-d ->

(message "more gold is required")

in string near \\( or \\)

Remove \\( and \\).

(looking-at "\\([a-z]+\\)")

-> C-d ->

(looking-at "[a-z]+")
(looking-at "\\([a-z]+\\)")

-> C-d ->

(looking-at "[a-z]+")

the next char isn't end of string

Call delete-char.

inside comment

Call delete-char.

before lispy-left

Delete arg sexps.

(foo (bar) (baz))

-> 2 C-d ->

(foo)

before "

Delete string.

before lispy-right

Delete containing sexp.

(foo (bar) (baz))

-> C-d ->

(foo (bar))

otherwise

Call delete-char.


lispy-delete-backward

Bound to DEL.

Replaces backward-delete-char, keeping parens consistent.

The result depends on the following conditions, each tried one by one until one that holds true is found:

region active

Delete region.

at first char of the string

Move to the end of the string. This allows to delete the whole string with the next DEL.

(message "more gold is required")

-> DEL ->

(message "more gold is required")

in string near \\( or \\)

Remove \\( and \\).

(looking-at "\\([a-z]+\\)")

-> DEL ->

(looking-at "[a-z]+")
(looking-at "\\([a-z]+\\)")

-> DEL ->

(looking-at "[a-z]+")

in string or comment

Call backward-delete-char.

after lispy-right

Delete arg sexps.

(foo (bar) (baz))

-> 2 DEL ->

(foo) 

before lispy-left

Delete containing sexp.

(foo (bar) (baz))

-> DEL ->

(foo (bar))

after a string

Delete string.

(message "more gold is required")

-> DEL ->

(message) 

otherwise

Call backward-delete-char.


lispy-mark

Bound to C-M-,.

Mark the smallest comment or string or list that includes point.

This command will expand region when repeated.


lispy-kill-at-point

Bound to C-,.

Kill the smallest comment or string or list that includes point.


lispy-mark-symbol

Bound to M-m.

The result depends on the following conditions, each tried one by one until one that holds true is found:

lispy-bind-variable in progress

Exit iedit-mode and mark the newly bound variable with a region. This allows to use lispy-convolute to place the new let binding into an appropriate place.

in comment

Mark comment.

looking at space or parens

Skip space and parens and mark the next thing between them.

looking back lispy-right

Mark last symbol in previous list.

region is active

Call forward-sexp.

otherwise

Forward to lispy-mark.


lispy-string-oneline

Bound to M-o.

Convert current string to one line.

Starting with

(message "foo 
bar
baz")

pressing M-o will give:

(message "foo\nbar\nbaz")

This can be useful when debugging a macro-generated function (i.e. it doesn't have a body). First produce the body with symbol-function, then prettify the body with M and M-o, then edebug with x e. For instance, (symbol-function 'lispy-parens) E M a p M-o.


lispy-outline-next

Bound to J.

Takes a numeric prefix arg and calls outline-next-visible-heading arg times or until past the last outline-regexp.

See lispy-shifttab for more info.


lispy-outline-prev

Bound to K.

Takes a numeric prefix arg and calls outline-previous-visible-heading arg times or until past the first outline-regexp.

See lispy-shifttab for more info.


lispy-shifttab

Bound to I.

Toggles on/off an org-mode-like outline.

To make this work, lispy-mode will modify outline-regexp and outline-level-function for the current buffer while it's on.

To give an example of the recommended outline syntax:

;;* Level 1
;;** Level 2
;;*** Level 3

You can create new outlines with M-RET (lispy-meta-return).

You can promote the current outline with:

  • M-right (lispy-meta-right),
  • l (lispy-right).

You can demote the current outline with:

  • M-left (lispy-meta-left),
  • h (lispy-left).

Useful together with:

key function name
J lispy-outline-next
K lispy-outline-prev
i lispy-tab

lispy-tab

Bound to i.

The result depends on the following conditions, each tried one by one until one that holds true is found:

in outline

Hide/show outline.

region is active

Forward to lispy-mark-car.

otherwise

Indent and prettify code. Prettify means to remove hanging closing parens, extra spaces, and to add space where it's needed, e.g. (lambda (x)) instead of (lambda(x)):

(defun test-function ()
  (message  "testing: %s"
            (mapconcat
             (lambda(x) (prin1-to-string
                    (* x x)
                    ))
             (list 0 1 2 3 4 5)
             ",")
            )
  )

-> i ->

(defun test-function ()
  (message "testing: %s"
           (mapconcat
            (lambda (x) (prin1-to-string
                         (* x x)))
            (list 0 1 2 3 4 5)
            ",")))

lispy-edebug-stop

Bound to Z.

Does the same as q in edebug, except current function's arguments will be saved to their current values.

This allows to continue debugging with lispy-eval (e) from edebug's current context.

The advantage is that you can edit the code as you debug, as edebug puts your code in read-only mode.


lispy-flatten

Bound to xf.

Inline current function or macro call, i.e. replace it with function body. The function should be interned and its body find-able.

(setq-local foo 10)

-> xf ->

(set (make-local-variable 'foo) 10)

lispy-to-ifs

Bound to xi.

Transform current cond expression to equivalent nested if expressions. The whitespace, such as comments and newlines, is preserved as much as possible.

The reverse is lispy-to-cond.

(cond ((region-active-p)
       (dotimes-protect arg
         (if (= (point) (region-beginning))
             (progn
               (forward-sexp 1)
               (skip-chars-forward " \n"))
           (forward-sexp 1))))

      ((looking-at lispy-left)
       (lispy-forward arg)
       (let ((pt (point)))
         (if (lispy-forward 1)
             (lispy-backward 1)
           (goto-char pt))))

      ((looking-back lispy-right)
       (let ((pt (point)))
         (unless (lispy-forward arg)
           (goto-char pt)
           (lispy-backward 1))))

      (t
       (lispy-forward 1)
       (lispy-backward 1)))

-> xi ->

(if (region-active-p)
    (dotimes-protect arg
      (if (= (point) (region-beginning))
          (progn
            (forward-sexp 1)
            (skip-chars-forward " \n"))
        (forward-sexp 1)))

  (if (looking-at lispy-left)
      (progn
        (lispy-forward arg)
        (let ((pt (point)))
          (if (lispy-forward 1)
              (lispy-backward 1)
            (goto-char pt))))

    (if (looking-back lispy-right)
        (let ((pt (point)))
          (unless (lispy-forward arg)
            (goto-char pt)
            (lispy-backward 1)))

      (lispy-forward 1)
      (lispy-backward 1))))

lispy-to-cond

Bound to xc.

Transform current nested if expressions to an equivalent cond expression. The whitespace, such as comments and newlines, is preserved as much as possible.

The reverse is lispy-to-ifs.

(if (region-active-p)
    (dotimes-protect arg
      (if (= (point) (region-beginning))
          (progn
            (forward-sexp 1)
            (skip-chars-forward " \n"))
        (forward-sexp 1)))

  (if (looking-at lispy-left)
      (progn
        (lispy-forward arg)
        (let ((pt (point)))
          (if (lispy-forward 1)
              (lispy-backward 1)
            (goto-char pt))))

    (if (looking-back lispy-right)
        (let ((pt (point)))
          (unless (lispy-forward arg)
            (goto-char pt)
            (lispy-backward 1)))

      (lispy-forward 1)
      (lispy-backward 1))))

-> xc ->

(cond ((region-active-p)
       (dotimes-protect arg
         (if (= (point) (region-beginning))
             (progn
               (forward-sexp 1)
               (skip-chars-forward " \n"))
           (forward-sexp 1))))

      ((looking-at lispy-left)
       (lispy-forward arg)
       (let ((pt (point)))
         (if (lispy-forward 1)
             (lispy-backward 1)
           (goto-char pt))))

      ((looking-back lispy-right)
       (let ((pt (point)))
         (unless (lispy-forward arg)
           (goto-char pt)
           (lispy-backward 1))))

      (t
       (lispy-forward 1)
       (lispy-backward 1)))

lispy-visit

Bound to V.

Visit another file within this project using projectile or find-file-in-project (customize lispy-visit-method to choose).

Use V to call projectile-find-file. Use 2V to call projectile-find-file-other-window.


lispy-narrow

Bound to N.

Narrow to current sexp or region.


lispy-widen

Bound to W.

Forward to widen.


lispy-oneline

Bound to O.

Turn current sexp into one line.

(progn
  (foo)
  (bar))

-> O ->

(progn (foo) (bar))

lispy-multiline

Bound to M.

Extend current sexp into multiple lines. Especially useful on results of macroexpand.

Turn current sexp into one line.

(progn (foo) (bar) (baz))

-> M ->

(progn (foo)
       (bar)
       (baz))

lispy-view

Bound to v.

Recenter current sexp to be on the first line of the window. When called twice in a row, recenter back to the original position.

It's just a slightly modified shorthand for the standard C-l (recenter-top-bottom).


lispy-slurp

Bound to >.

Grow either current sexp or region (if it's active) in appropriate direction. Opposite of lispy-barf. With an arg of 0, grow as far as possible. With an arg of -1, grow until the end of the line where the current sexp ends or as far as possible before that position.

Example 1:

(progn) (foo) (bar)

-> > ->

(progn (foo)) (bar)

Example 2:

"foo" (bar)

-> > ->

("foo" bar)

Example 3:

(foo bar baz)

-> > ->

(foo bar baz)

Example 4:

((foo) bar baz
 quux)

-> 0> ->

((foo bar baz
      quux))

Example 5:

((foo) bar baz
 quux)

-> M--> ->

((foo bar baz) 
 quux)

lispy-barf

Bound to <.

Shrink either current sexp or region (if it's active) in appropriate direction. Opposite of lispy-slurp.

Example 1:

(progn (foo)) (bar)

-> < ->

(progn) (foo) (bar)

Example 2:

("foo" bar)

-> > ->

"foo" (bar)

Example 3:

(foo bar bar)

-> < ->

(foo bar bar)

lispy-other-mode

Bound to o.

This is a minor mode that changes the behavior of several key bindings, most notably the hjkl arrow keys. This mode can is turned off automatically after one of its key bindings is used. You can toggle it off with o if you change your mind about calling the modified hjkl.

key function name
h lispy-move-left
j lispy-down-slurp
k lispy-up-slurp
l lispy-move-right
SPC  
g  

lispy-move-left

Bound to oh.

Move current expression to the left, outside the current list.

(require 'ob-python)
(let ((color "Blue"))
  (message "What... is your favorite color?")
  (message "%s. No yel..." color))

-> oh ->

(require 'ob-python)
(message "What... is your favorite color?")
(let ((color "Blue"))
  (message "%s. No yel..." color))

lispy-down-slurp

Bound to oj.

Move current expression to become the first element of the first list below.

(first!)
'(foo bar)

-> oj ->

'((first!)
  foo bar)

lispy-up-slurp

Bound to ok.

Move current expression to become the last element of the first list above.

(list 'my-sword
      'my-bow)
(my-axe)

-> ok ->

(list 'my-sword
      'my-bow
      (my-axe))

lispy-move-right

Bound to ol.

Move current expression to the right, outside the current list.

(require 'ob-python)
(message "What... is your favorite color?")
(let ((color "Blue"))
  (message color)
  (message "Go on. Off you go."))

-> ol ->

(require 'ob-python)
(message "What... is your favorite color?")
(let ((color "Blue"))
  (message color))
(message "Go on. Off you go.")

lispy-comment

Bound to ;.

Comment current expression or region. With a prefix arg, comment many expressions. With a prefix arg and already inside comment, uncomment instead.

(require 'ob-python)
(defun cheeseshop (kind)
  (message "Do you have any %s?" kind))

-> ; ->

(require 'ob-python)
;; (defun cheeseshop (kind)
;;   (message "Do you have any %s?" kind))

lispy-clone

Bound to c.

Copy current list or region and paste it below, without changing point or mark.

With a prefix arg, copy that many times.

(message "A witch!")

-> 3c ->

(message "A witch!")
(message "A witch!")
(message "A witch!")
(message "A witch!")

lispy-goto

Bound to g.

Collect the tags (e.g. functions, variables …) in current directory and offer a helm completion list to jump to a selected tag.


lispy-goto-local

Bound to G.

Similar to lispy-goto, but only current file's tags are used instead of whole directory's tags.


lispy-goto-recursive

Bound to ogr.

Similar to lispy-goto, but all sub-directories' tags are used in addition to directory's tags.


lispy-goto-projectile

Bound to 0g and ogp.

Similar to lispy-goto-recursive, but projectile-project-root is used as the base directory.


lispy-mark-list

Bound to m.

Mark the current sexp. When the mark is already active, deactivate it instead.


lispy-raise

Bound to r.

Use current sexp or region as replacement for its parent.

(let ((foo 1))
  (+ bar baz))

-> r ->

(+ bar baz)

lispy-move-down

Bound to s.

Move current sexp or region down arg times. Don't exit the parent list.

(progn
  (foo)
  (bar)
  (baz))

-> s ->

(progn
  (bar)
  (foo)
  (baz))

lispy-move-up

Bound to w.

Move current sexp or region up arg times. Don't exit the parent list.

It's the reciprocal of lispy-move-down.


lispy-teleport

Bound to t.

Move the current sexp or region to a location specified by lispy-ace-paren.


lispy-undo

Bound to u.

Forward to undo. If the mark is active, deactivate it first.


lispy-ace-symbol-replace

Bound to H.

Calls lispy-ace-symbol and deletes the selected symbol.


lispy-eval-other-window

Bound to p.

Eval the current sexp in the context of the other window. This is useful for debugging interactive Elisp functions:

  • in one window keep the code of the function being debugged
  • in the other window, keep the buffer on which the debugged function is supposed to work

Special behavior in let (what gets evaled is on the right):

(let ((foo 10))
  (bar))

-> p ->

(setq foo 10)

Special behavior in cond (what gets evaled is on the right):

(cond ((foo-1)
       (bar-1))
      ((foo-2)
       (bar-2)))

-> p ->

(if (foo-1)
    (progn
      (bar-1))
  (message "cond: nil"))

lispy-describe

Bound to xh.

A shorthand for describe-function or describe-variable.

If you want to call describe-variable, you should mark the symbol first. You can do this quickly with:

From special:

  • 2m, 3m, etc. if you want the second or third element of the list accordingly
  • a to select the symbol with lispy-ace-symbol

Globally:


lispy-beginning-of-defun

Bound to A.

Forward to beginning-of-defun. When called twice in a row, restore the previous point and mark positions.

A useful combo while debugging is Aa to select symbol, and eA to look at its value and go back. Repeat when needed.


lispy-convolute

Bound to C.

Exchange the order of application of two closest outer forms, relative to current expression or region.

(if (= (weight person) standard-duck-weight)
    (unless (sinks-in-water person)
      (message "Burn her!")))

-> C ->

(unless (sinks-in-water person)
  (if (= (weight person) standard-duck-weight)
      (message "Burn her!")))

This operation reverses itself. See gif.


lispy-ace-char

Bound to Q.

Call ace-jump-mode, while narrowed to current list.


lispy-raise-some

Bound to R.

Use current sexp and the following (if called from the left), or the preceeding (if called from the right) sexps, or the active region as replacement for their parent.

Example 1:

(progn
  (message "one")
  (message "two")
  (message "three"))

-> R ->

(message "two")
(message "three")

Example 2:

(progn
  (message "one")
  (message "two") 
  (message "three"))

-> R ->

progn
(message "one")
(message "two")

lispy-ert

Bound to T.

Forward to ert.


lispy-stringify

Bound to S.

Transform current sexp into a string. Quote newlines if arg isn't 1.

(progn
  (message "one")
  (message "two")
  (message "three"))

-> S ->

(progn
  (message "one")
  "(message \"two\")"
  (message "three"))

lispy-paste

Bound to P.

When region is active, replace it with current kill. Forward to yank otherwise.


lispy-edebug

Bound to xe.

edebug current defun. Or cider-debug-defun-at-point for Clojure.

2xe will eval current defun instead.


lispy-debug-step-in

Bound to xj.

  1. Evaluate the arguments at the current function's call
  2. Jump to the function's definition
  3. Set the result of evaluation to the function's arguments

For example, starting with:

(do-stuff 1 (+ 1 1) (+ 2 2))

after pressing xj you will jump to the definition of do-stuff:

(defun do-stuff (x y z &optional a &rest b)
  (foo)
  (bar))

At this point the following global variables will be set to their corresponding values:

var val
x 1
y 2
z 4
a nil
b nil

lispy-kill-word

Bound to M-d.

Kill arg words, keeping parens and quotes consistent


lispy-backward-kill-word

Bound to M-DEL.

Kill arg words backward, keeping parens and quotes consistent.


lispy-kill-sentence

Bound to M-k.

Kill until the end of the current list or string.

If located exactly at the beginning of the list or string, kill only that list or string instead.

(message "Then shalt thou count to three,
no more, no less.
Three shall be the number thou shalt count,
and the number of the counting shall be three.")

-> M-k ->

(message "Then shalt thou count to three")

digit-argument

Bound to 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

This is the standard Emacs function. Except instead of calling it globally with e.g. M-2, you can call it locally with just e.g. 2.

Many lispy commands take a prefix arg, e.g. 3j is equivalent to jjj.