-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert-mode.lisp
More file actions
41 lines (36 loc) · 1.6 KB
/
insert-mode.lisp
File metadata and controls
41 lines (36 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
;;;; Hold the control during the input.
;;; Author: chiku (Takehiko Nawata, samugari.is.s.u-tokyo.ac.jp)
;;; Dec. 01st 2012, chiku
;;; In order to keep normal mode after the execution of a command
;;; that comes with input, we have to avoid going back to the raw
;;; mode during the input.
(in-package :chiku.screen-keybind)
(defun octal-desc (code)
(format nil "\\~o" code))
(defun ctrl-code-p (code)
(< code #b100000))
(defun use-charname-p (code)
(or (ctrl-code-p code) (= #o40 code)))
(defun stuffmsg-string (code)
(concat-str "stuff "
(if (use-charname-p code)
(char-name (code-char code))
(string (code-char code)))))
(defun define-insert-mode (imode &optional
(finish-keys '(#\Return #\Newline))
(cancel-keys '(#\Bel)))
(macrolet ((aux (cur goal print-mode msg)
`(keybind-common t (octal-desc code)
,cur ,goal
((stuff (octal-desc code)))
(default-message ,print-mode ,msg))))
(with-slots (mode primary-mode insert-mode next-mode) imode
(dolist (code (iota #x80))
(cond ((member (code-char code) finish-keys)
(aux insert-mode next-mode next-mode ""))
((member (code-char code) cancel-keys)
(aux insert-mode primary-mode primary-mode ""))
(t (aux insert-mode (if (eq mode 'transient)
next-mode insert-mode)
"insert"
(stuffmsg-string code))))))))