From 6637717af0bdac55f97eef98433d53a10395cf77 Mon Sep 17 00:00:00 2001 From: Tom Dalziel Date: Wed, 29 May 2024 10:54:23 +0200 Subject: [PATCH] Move terminal troublesome keybindings to separate alist Fixes #58 --- evil-cleverparens-tests.el | 171 +++++++++++++++++++------------------ evil-cleverparens.el | 17 +++- 2 files changed, 100 insertions(+), 88 deletions(-) diff --git a/evil-cleverparens-tests.el b/evil-cleverparens-tests.el index 49ebfce..ca16574 100644 --- a/evil-cleverparens-tests.el +++ b/evil-cleverparens-tests.el @@ -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") @@ -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") diff --git a/evil-cleverparens.el b/evil-cleverparens.el index 8d9e332..f8bfcf5 100644 --- a/evil-cleverparens.el +++ b/evil-cleverparens.el @@ -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") @@ -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