From 7d3b71b4269e2742f7f997c3e588d593a07ec8a0 Mon Sep 17 00:00:00 2001 From: Matteo Ricci Date: Wed, 3 Apr 2019 13:43:45 +0200 Subject: [PATCH 1/4] add feature: new sexp (bound to M-N) start a new balanced sexp --- command-functions.lisp | 10 ++++++++++ command-keys.lisp | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/command-functions.lisp b/command-functions.lisp index 8449b10..99540ed 100644 --- a/command-functions.lisp +++ b/command-functions.lisp @@ -80,6 +80,16 @@ (declare (ignore chord editor)) (throw 'linedit-done t)) +(defun new-sexp (chord editor) + (declare (ignore chord editor)) + (with-editor-point-and-string ((point string) editor) + (move-to-eol chord editor) + (add-char #\( editor) + (incf (get-point editor)) + (move-to-eol chord editor) + (add-char #\) editor) + (decf (get-point editor)))) + ;;; CASE CHANGES (flet ((frob-case (frob editor) diff --git a/command-keys.lisp b/command-keys.lisp index d53dc1c..7e59b40 100644 --- a/command-keys.lisp +++ b/command-keys.lisp @@ -65,7 +65,7 @@ (defcommand "M-K") (defcommand "M-L" 'downcase-word) (defcommand "M-M") -(defcommand "M-N") +(defcommand "M-N" 'new-sexp) (defcommand "M-O") (defcommand "M-P") (defcommand "M-Q") From e4b37ca34666b77c9916bda7f5861178575f7daf Mon Sep 17 00:00:00 2001 From: Matteo Ricci Date: Wed, 3 Apr 2019 14:15:21 +0200 Subject: [PATCH 2/4] add feature: clear screen (bound to C-L) --- command-functions.lisp | 4 ++++ command-keys.lisp | 2 +- smart-terminal.lisp | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/command-functions.lisp b/command-functions.lisp index 99540ed..9a01873 100644 --- a/command-functions.lisp +++ b/command-functions.lisp @@ -90,6 +90,10 @@ (add-char #\) editor) (decf (get-point editor)))) +(defun clear-screen (chord editor) + (declare (ignore chord)) + (terminal-clear-screen)) + ;;; CASE CHANGES (flet ((frob-case (frob editor) diff --git a/command-keys.lisp b/command-keys.lisp index 7e59b40..d3dcb80 100644 --- a/command-keys.lisp +++ b/command-keys.lisp @@ -36,7 +36,7 @@ (defcommand "C-G") (defcommand "C-J") (defcommand "C-K" 'kill-to-eol) -(defcommand "C-L") +(defcommand "C-L" 'clear-screen) (defcommand "C-N" 'history-next) (defcommand "C-O" 'close-all-sexp) (defcommand "C-P" 'history-previous) diff --git a/smart-terminal.lisp b/smart-terminal.lisp index f30d937..ddd4e19 100644 --- a/smart-terminal.lisp +++ b/smart-terminal.lisp @@ -41,6 +41,9 @@ (or ti:column-address (and ti:cursor-left ti:cursor-right)) (or ti:auto-right-margin ti:enter-am-mode))) +(defun terminal-clear-screen () + (ti:tputs ti:clear-screen)) + (defmethod backend-init ((backend smart-terminal)) (call-next-method) (when ti:enter-am-mode From 11bd00f3a2bfa581eacf8b951d846581529f79d9 Mon Sep 17 00:00:00 2001 From: Matteo Ricci Date: Wed, 3 Apr 2019 14:31:49 +0200 Subject: [PATCH 3/4] prevent freezing of repl when pressing C-. Bind C-right/left to forward/back sexp --- command-keys.lisp | 3 +++ terminal-translations.lisp | 3 +++ terminal.lisp | 20 +++++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/command-keys.lisp b/command-keys.lisp index d3dcb80..0825e33 100644 --- a/command-keys.lisp +++ b/command-keys.lisp @@ -113,3 +113,6 @@ (defcommand "Page-down") (defcommand "Home" 'move-to-bol) (defcommand "End" 'move-to-eol) + +(defcommand "C-Right-arrow" 'forward-sexp) +(defcommand "C-Left-arrow" 'backward-sexp) diff --git a/terminal-translations.lisp b/terminal-translations.lisp index 7357a85..c8ebbab 100644 --- a/terminal-translations.lisp +++ b/terminal-translations.lisp @@ -112,3 +112,6 @@ (deftrans "Page-down" (#\Esc #\[ #\6 #\~)) (deftrans "Home" (#\Esc #\[ #\7 #\~) (#\Esc #\[ #\1 #\~) (#\Esc #\[ #\H)) (deftrans "End" (#\Esc #\[ #\8 #\~) (#\Esc #\[ #\4 #\~) (#\Esc #\[ #\F)) + +(deftrans "C-Right-arrow" (#\Esc #\[ #\1 #\; #\5 #\C)) +(deftrans "C-Left-arrow" (#\Esc #\[ #\1 #\; #\5 #\D)) diff --git a/terminal.lisp b/terminal.lisp index 8169aac..dc8bce0 100644 --- a/terminal.lisp +++ b/terminal.lisp @@ -51,8 +51,21 @@ (flet ((read-open-chord () (do ((chars nil) (c #1=(read-char) #1#)) - ((member c '(#\- #\~ #\$)) (nconc (nreverse chars) (list c))) - (push c chars)))) + ((or (member c '(#\- #\~ #\$)) + (if (char-equal c #\;) + (let ((c1 (read-char)) + (c2 (read-char))) + (push #\; chars) + (push c1 chars) + (push c2 chars) + ;; (format t "add (~A,~A,~A): chars:~A~%" + ;; c c1 c2 chars) + t))) + (nconc (nreverse chars) + (if (char-not-equal c #\;) + (list c)))) + (when (char-not-equal c #\;) + (push c chars))))) (let ((chord (acase (read-char) (#\Esc @@ -63,7 +76,8 @@ (if (digit-char-p char) (cons char (read-open-chord)) - (list char))))) + (when (char-not-equal char #\;) + (list char)))))) (t (list it))))) (t (if (graphic-char-p it) it From 24e2e207094db02569fa812bbd98db2b16c10300 Mon Sep 17 00:00:00 2001 From: Matteo Ricci Date: Wed, 3 Apr 2019 14:45:46 +0200 Subject: [PATCH 4/4] fix clear-screen (bound to C-L) --- smart-terminal.lisp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smart-terminal.lisp b/smart-terminal.lisp index ddd4e19..3778d02 100644 --- a/smart-terminal.lisp +++ b/smart-terminal.lisp @@ -42,7 +42,8 @@ (or ti:auto-right-margin ti:enter-am-mode))) (defun terminal-clear-screen () - (ti:tputs ti:clear-screen)) + (when ti:clear-screen + (format t "~A~A" ti:clear-screen (editor-prompt *editor*)))) (defmethod backend-init ((backend smart-terminal)) (call-next-method)