Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lispy-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -3032,6 +3032,9 @@ Insert KEY if there's no command."
"(foo (| bar) baz)"))
(lispy-set-key-theme '(special lispy c-digits oleh)))

(ert-deftest lispy-cycle-parens ()
(should (string= (lispy-with "(|foo)" (lispy-cycle-parens)) "[|foo]")))

(ert-deftest lispy-paredit-splice-sexp ()
(lispy-set-key-theme '(special paredit))
(should (string= (lispy-with "(foo (bar| baz) quux)"
Expand Down
27 changes: 27 additions & 0 deletions lispy.el
Original file line number Diff line number Diff line change
Expand Up @@ -9167,6 +9167,7 @@ FUNC is obtained from (`lispy--insert-or-call' DEF PLIST)."
(lispy-define-key map "O" 'lispy-oneline)
(lispy-define-key map "M" 'lispy-alt-multiline)
(lispy-define-key map "S" 'lispy-stringify)
(lispy-define-key map "M-c" 'lispy-cycle-parens)
;; marking
(lispy-define-key map "a" 'lispy-ace-symbol
:override '(cond ((looking-at lispy-outline)
Expand Down Expand Up @@ -9525,6 +9526,32 @@ When ARG is non-nil, unquote the current string."
(interactive "P")
(lispy-braces (or arg 1)))

(defun lispy-cycle-parens ()
"Cycle parenthesis types for the list at `point'.
\(\) -> [] -> {} (`clojure-mode')."
(interactive)
(let* ((bounds (or (lispy--bounds-list)
(user-error "No list at `point'")))
(open (char-after (car bounds)))
(new-pair (cond
((= open ?\() '(?\[ . ?\]))
((= open ?\[) (if (derived-mode-p 'clojure-mode)
'(?{ . ?}) '(?\( . ?\))))
((and (derived-mode-p 'clojure-mode) (= open ?\{)) '(?\( . ?\)))
(t (error "Unknow list type"))))
(old-point (point)))
(goto-char (car bounds))
(delete-char 1)
(insert (car new-pair))

(goto-char (cdr bounds))
(delete-char -1)
(insert (cdr new-pair))

;; `save-excursion' doesn't work if point is immediately after the paren
;; (point is before afterwards), so save `point' less "intelligently".
(goto-char old-point)))

(defun lispy-splice-sexp-killing-backward ()
"Forward to `lispy-raise'."
(interactive)
Expand Down