-
Notifications
You must be signed in to change notification settings - Fork 349
/
emacs.go
120 lines (108 loc) · 2.61 KB
/
emacs.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package prompt
import "github.com/c-bata/go-prompt/internal/debug"
/*
========
PROGRESS
========
Moving the cursor
-----------------
* [x] Ctrl + a Go to the beginning of the line (Home)
* [x] Ctrl + e Go to the End of the line (End)
* [x] Ctrl + p Previous command (Up arrow)
* [x] Ctrl + n Next command (Down arrow)
* [x] Ctrl + f Forward one character
* [x] Ctrl + b Backward one character
* [x] Ctrl + xx Toggle between the start of line and current cursor position
Editing
-------
* [x] Ctrl + L Clear the Screen, similar to the clear command
* [x] Ctrl + d Delete character under the cursor
* [x] Ctrl + h Delete character before the cursor (Backspace)
* [x] Ctrl + w Cut the Word before the cursor to the clipboard.
* [x] Ctrl + k Cut the Line after the cursor to the clipboard.
* [x] Ctrl + u Cut/delete the Line before the cursor to the clipboard.
* [ ] Ctrl + t Swap the last two characters before the cursor (typo).
* [ ] Esc + t Swap the last two words before the cursor.
* [ ] ctrl + y Paste the last thing to be cut (yank)
* [ ] ctrl + _ Undo
*/
var emacsKeyBindings = []KeyBind{
// Go to the End of the line
{
Key: ControlE,
Fn: func(buf *Buffer) {
x := []rune(buf.Document().TextAfterCursor())
buf.CursorRight(len(x))
},
},
// Go to the beginning of the line
{
Key: ControlA,
Fn: func(buf *Buffer) {
x := []rune(buf.Document().TextBeforeCursor())
buf.CursorLeft(len(x))
},
},
// Cut the Line after the cursor
{
Key: ControlK,
Fn: func(buf *Buffer) {
x := []rune(buf.Document().TextAfterCursor())
buf.Delete(len(x))
},
},
// Cut/delete the Line before the cursor
{
Key: ControlU,
Fn: func(buf *Buffer) {
x := []rune(buf.Document().TextBeforeCursor())
buf.DeleteBeforeCursor(len(x))
},
},
// Delete character under the cursor
{
Key: ControlD,
Fn: func(buf *Buffer) {
if buf.Text() != "" {
buf.Delete(1)
}
},
},
// Backspace
{
Key: ControlH,
Fn: func(buf *Buffer) {
buf.DeleteBeforeCursor(1)
},
},
// Right allow: Forward one character
{
Key: ControlF,
Fn: func(buf *Buffer) {
buf.CursorRight(1)
},
},
// Left allow: Backward one character
{
Key: ControlB,
Fn: func(buf *Buffer) {
buf.CursorLeft(1)
},
},
// Cut the Word before the cursor.
{
Key: ControlW,
Fn: func(buf *Buffer) {
buf.DeleteBeforeCursor(len([]rune(buf.Document().GetWordBeforeCursorWithSpace())))
},
},
// Clear the Screen, similar to the clear command
{
Key: ControlL,
Fn: func(buf *Buffer) {
consoleWriter.EraseScreen()
consoleWriter.CursorGoTo(0, 0)
debug.AssertNoError(consoleWriter.Flush())
},
},
}