-
Notifications
You must be signed in to change notification settings - Fork 75
/
extended_mode.go
170 lines (163 loc) · 3.84 KB
/
extended_mode.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package main
import (
"github.com/nsf/termbox-go"
"github.com/nsf/tulib"
"strconv"
)
//----------------------------------------------------------------------------
// extended mode
//----------------------------------------------------------------------------
type extended_mode struct {
stub_overlay_mode
godit *godit
}
func init_extended_mode(godit *godit) extended_mode {
e := extended_mode{godit: godit}
e.godit.set_status("C-x")
return e
}
func (e extended_mode) on_key(ev *termbox.Event) {
g := e.godit
v := g.active.leaf
b := v.buf
switch ev.Key {
case termbox.KeyCtrlC:
if g.has_unsaved_buffers() {
g.set_overlay_mode(init_key_press_mode(
g,
map[rune]func(){
'y': func() {
g.quitflag = true
},
'n': func() {},
},
0,
"Modified buffers exist; exit anyway? (y or n)",
))
return
} else {
g.quitflag = true
}
case termbox.KeyCtrlX:
v.on_vcommand(vcommand_swap_cursor_and_mark, 0)
case termbox.KeyCtrlW:
g.set_overlay_mode(init_view_op_mode(g))
return
case termbox.KeyCtrlA:
v.on_vcommand(vcommand_autocompl_init, 0)
case termbox.KeyCtrlU:
v.on_vcommand(vcommand_region_to_upper, 0)
case termbox.KeyCtrlL:
v.on_vcommand(vcommand_region_to_lower, 0)
case termbox.KeyCtrlF:
g.set_overlay_mode(init_line_edit_mode(g, g.open_buffer_lemp()))
return
case termbox.KeyCtrlS:
g.save_active_buffer(false)
return
case termbox.KeyCtrlSlash:
g.active.leaf.on_vcommand(vcommand_redo, 0)
g.set_overlay_mode(init_redo_mode(g))
return
case termbox.KeyCtrlR:
if !v.buf.is_mark_set() {
v.ctx.set_status("The mark is not set now, so there is no region")
break
}
g.set_overlay_mode(init_line_edit_mode(g, g.search_and_replace_lemp1()))
return
default:
switch ev.Ch {
case '0':
g.kill_active_view()
case '1':
g.kill_all_views_but_active()
case '2':
g.split_vertically()
case '3':
g.split_horizontally()
case 'o':
sibling := g.active.sibling()
if sibling != nil && sibling.leaf != nil {
g.active.leaf.deactivate()
g.active = sibling
g.active.leaf.activate()
}
case 'b':
g.set_overlay_mode(init_line_edit_mode(g, g.switch_buffer_lemp()))
return
case '(':
g.set_status("Defining keyboard macro...")
g.recording = true
g.keymacros = g.keymacros[:0]
case ')':
g.stop_recording()
case 'e':
g.stop_recording()
if len(g.keymacros) > 0 {
g.set_overlay_mode(init_macro_repeat_mode(g))
return
}
case '>':
g.set_overlay_mode(init_region_indent_mode(g, 1))
return
case '<':
g.set_overlay_mode(init_region_indent_mode(g, -1))
return
case 'k':
if !b.synced_with_disk() {
g.set_overlay_mode(init_key_press_mode(
g,
map[rune]func(){
'y': func() {
g.kill_buffer(b)
},
'n': func() {},
},
0,
"Buffer "+b.name+" modified; kill anyway? (y or n)",
))
return
} else {
g.kill_buffer(b)
}
case 'S':
if ev.Mod&termbox.ModAlt != 0 {
g.set_overlay_mode(init_line_edit_mode(g,
g.save_as_buffer_lemp(true)))
return
}
g.save_active_buffer(true)
return
case 's':
if ev.Mod&termbox.ModAlt != 0 {
g.set_overlay_mode(init_line_edit_mode(g,
g.save_as_buffer_lemp(false)))
return
}
case '=':
var r rune
if v.cursor.eol() {
r = '\n'
} else {
r, _ = v.cursor.rune_under()
}
cursor_ex := make_cursor_location_ex(v.cursor)
g.set_status("Char: %s (dec: %d, oct: %s, hex: %s), Cursor offset: %d bytes",
strconv.QuoteRune(r), r,
strconv.FormatInt(int64(r), 8),
strconv.FormatInt(int64(r), 16),
cursor_ex.abs_boffset)
case '!':
g.set_overlay_mode(init_line_edit_mode(g, g.filter_region_lemp()))
return
default:
goto undefined
}
}
g.set_overlay_mode(nil)
return
undefined:
g.set_status("C-x %s is undefined", tulib.KeyToString(ev.Key, ev.Ch, ev.Mod))
g.set_overlay_mode(nil)
}