Skip to content

Commit

Permalink
Move terminal troublesome keybindings to separate alist
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
tomdl89 committed May 29, 2024
1 parent d757b17 commit 6637717
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 88 deletions.
171 changes: 87 additions & 84 deletions evil-cleverparens-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -853,24 +853,25 @@ alpha (bravo (charlie delta) echo) foxtrot")))
"(alpha bravo)\n\necho[]\n\n(charlie delta)")))

(ert-deftest evil-cp-open-above-form-test ()
(ert-info ("Can open above a form")
(evil-cp-test-buffer
"(alpha (bravo [c]harlie) delta)"
(evil-cp-set-additional-bindings)
("\M-O")
"(alpha []\n(bravo charlie) delta)"))
(ert-info ("Can open below a top-level form")
(evil-cp-test-buffer
"(alpha bravo)\n\n(charlie [d]elta)"
(evil-cp-set-additional-bindings)
("\M-O" "echo")
"(alpha bravo)\n\necho[]\n\n(charlie delta)"))
(ert-info ("Can open between top-level forms")
(evil-cp-test-buffer
"(alpha bravo)\n[]\n(charlie delta)"
(evil-cp-set-additional-bindings)
("\M-O" "echo")
"(alpha bravo)\necho[]\n\n(charlie delta)")))
(let ((window-system t))
(ert-info ("Can open above a form")
(evil-cp-test-buffer
"(alpha (bravo [c]harlie) delta)"
(evil-cp-set-additional-bindings)
("\M-O")
"(alpha []\n(bravo charlie) delta)"))
(ert-info ("Can open below a top-level form")
(evil-cp-test-buffer
"(alpha bravo)\n\n(charlie [d]elta)"
(evil-cp-set-additional-bindings)
("\M-O" "echo")
"(alpha bravo)\n\necho[]\n\n(charlie delta)"))
(ert-info ("Can open between top-level forms")
(evil-cp-test-buffer
"(alpha bravo)\n[]\n(charlie delta)"
(evil-cp-set-additional-bindings)
("\M-O" "echo")
"(alpha bravo)\necho[]\n\n(charlie delta)"))))

(ert-deftest evil-cp-yank-sexp-test ()
(ert-info ("Can yank a sexp")
Expand Down Expand Up @@ -1049,74 +1050,76 @@ india[]
"alpha ((bravo charlie delta)[)] echo"))) ;; TODO inconsistent cursor with wrap-next-round

(ert-deftest evil-cp-wrap-next-square-test ()
(ert-info ("Can wrap next sexp with square brackets")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha« »bravo charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-[")
"alpha[« »bravo] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha «b»ravo charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-[")
"alpha [«b»ravo] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha brav«o» charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-[")
"alpha [brav«o»] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha [bravo «c»harlie delta] echo"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\C-u\M-[")
"alpha [«[»bravo charlie delta]] echo")))
(let ((window-system t))
(ert-info ("Can wrap next sexp with square brackets")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha« »bravo charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-[")
"alpha[« »bravo] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha «b»ravo charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-[")
"alpha [«b»ravo] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha brav«o» charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-[")
"alpha [brav«o»] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha [bravo «c»harlie delta] echo"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\C-u\M-[")
"alpha [«[»bravo charlie delta]] echo"))))

(ert-deftest evil-cp-wrap-previous-square-test ()
(ert-info ("Can wrap next sexp with square brackets")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha bravo« »charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-]")
"alpha [bravo«]» charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha brav«o» charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-]")
"alpha [brav«o»] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha «b»ravo charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-]")
"[alpha «]»bravo charlie") ;; TODO surely not desired?
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha [bravo «c»harlie delta] echo"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\C-u\M-]")
"alpha [[bravo charlie delta]«]» echo"))) ;; TODO inconsistent cursor with wrap-next-square
(let ((window-system t))
(ert-info ("Can wrap next sexp with square brackets")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha bravo« »charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-]")
"alpha [bravo«]» charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha brav«o» charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-]")
"alpha [brav«o»] charlie")
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha «b»ravo charlie"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\M-]")
"[alpha «]»bravo charlie") ;; TODO surely not desired?
(evil-test-buffer
:point-start "«"
:point-end "»"
"alpha [bravo «c»harlie delta] echo"
(evil-cleverparens-mode t)
(evil-cp-set-additional-bindings)
("\C-u\M-]")
"alpha [[bravo charlie delta]«]» echo")))) ;; TODO inconsistent cursor with wrap-next-square

(ert-deftest evil-cp-wrap-next-curly-test ()
(ert-info ("Can wrap next sexp with curly braces")
Expand Down
17 changes: 13 additions & 4 deletions evil-cleverparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -2092,18 +2092,22 @@ and/or beginning."
("M-C" . evil-cp-change-enclosing)
("M-q" . sp-indent-defun)
("M-o" . evil-cp-open-below-form)
("M-O" . evil-cp-open-above-form)
("M-v" . sp-convolute-sexp)
("M-(" . evil-cp-wrap-next-round)
("M-)" . evil-cp-wrap-previous-round)
("M-[" . evil-cp-wrap-next-square)
("M-]" . evil-cp-wrap-previous-square)
("M-{" . evil-cp-wrap-next-curly)
("M-}" . evil-cp-wrap-previous-curly))
"Alist containing additional functionality for
evil-cleverparens via a modifier key (using the meta-key by
default). Only enabled in evil's normal mode.")

(defvar evil-cp-additional-bindings-graphical
'(("M-[" . evil-cp-wrap-next-square)
("M-]" . evil-cp-wrap-previous-square)
("M-O" . evil-cp-open-above-form))
"As with evil-cp-additional-bindings but these bindings are not safe in some
terminals.")

(defvar evil-cp-insert-key "i"
"Key to use to switch to insert mode")

Expand Down Expand Up @@ -2181,7 +2185,12 @@ true."
(evil-cp--populate-mode-bindings-for-state
evil-cp-additional-bindings
'normal
evil-cleverparens-use-additional-bindings))
evil-cleverparens-use-additional-bindings)
(when window-system
(evil-cp--populate-mode-bindings-for-state
evil-cp-additional-bindings-graphical
'normal
evil-cleverparens-use-additional-bindings)))

(defun evil-cp--enable-C-w-delete ()
(when evil-want-C-w-delete
Expand Down

0 comments on commit 6637717

Please sign in to comment.