From cf9c4f0e6b9674ffbeec5355b31beac567a7ad4b Mon Sep 17 00:00:00 2001 From: Nikita Bloshchanevich Date: Sun, 4 Apr 2021 22:56:40 +0200 Subject: [PATCH 1/2] Add a command to cycle parentheses () -> [] -> {} Currently, there is no keybinding. --- lispy-test.el | 3 +++ lispy.el | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lispy-test.el b/lispy-test.el index eeabe2de..ec3cb27b 100644 --- a/lispy-test.el +++ b/lispy-test.el @@ -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)" diff --git a/lispy.el b/lispy.el index 70134b7f..9bd4d34f 100644 --- a/lispy.el +++ b/lispy.el @@ -9525,6 +9525,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) From ee7cf40fdec6910dfe133f3647d96094271195fa Mon Sep 17 00:00:00 2001 From: Nikita Bloshchanevich Date: Mon, 5 Apr 2021 11:14:21 +0200 Subject: [PATCH 2/2] Add a keybinding: M-c --- lispy.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lispy.el b/lispy.el index 9bd4d34f..1a1807ab 100644 --- a/lispy.el +++ b/lispy.el @@ -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)