line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Padre::Plugin::Vi; |
2
|
1
|
|
|
1
|
|
23504
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
22
|
use 5.008005; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
29
|
use base 'Padre::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1043
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
8
|
use Scalar::Util qw(refaddr); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
142
|
|
9
|
1
|
|
|
1
|
|
3030
|
use Padre::Util ('_T'); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Padre::Constant (); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.23'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Padre::Plugin::Vi - vi keyboard for Padre |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Once installed and enabled the user is in full vi-emulation mode, |
21
|
|
|
|
|
|
|
which was partially implemented. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
The 3 basic modes of vi are in development: |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
When you turn on vi-mode, or load Padre with vi-mode already enabled |
26
|
|
|
|
|
|
|
you reach the normal navigation mode of vi. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
We don't plan to implement many of the configuration options of vi. |
29
|
|
|
|
|
|
|
Even parts that are going to be implemented will not use the same method |
30
|
|
|
|
|
|
|
of configuration. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
That said, we are planning to add looking for vi configuration options in |
33
|
|
|
|
|
|
|
the source file so the editor can set its own configuration based on the |
34
|
|
|
|
|
|
|
vi configuration options. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The following are implemented: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 Navigation mode |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item * |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
in navigation mode catch ':' and open the command line |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item * |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
l,h,k,j - (right, left, up, down) navigation |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
4 arrows also work |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Number prefix are allowed in both the 4 letter and the 4 arrows |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item * |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
PageUp, PageDown |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item * |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Home - goto first character on line |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item * |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
End - goto last character on line |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item * |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
^ - (shift-6) jump to beginning of line |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item * |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$ - (shift-4) jump to end of line |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item * |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
v - visual mode, to start marking section |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
d - delete the selection |
80
|
|
|
|
|
|
|
x - delete the selection |
81
|
|
|
|
|
|
|
y - yank the selection |
82
|
|
|
|
|
|
|
v - stop the visual mode, remove selection |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
p - paste below |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
P - paste above |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Ctrl-6 - jump to last window edited. (This is inherited from Padre) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
a - switch to insert mode after the current character |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
i - switch to insert mode before the current character |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
TODO this is currently step one character back as the caret is not |
104
|
|
|
|
|
|
|
ON a caracter but between two. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
o - add an empty line below current line and switch to insert mode |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
O - add an empty line above current line and switch to insert mode |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
x - delete current character |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Nx - delete N characters |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
dd - delete current line |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Ndd - (N any number) delete N lines |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
d$ - delete till end of line |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Ndw - delete N word |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
yy - yank (copy) current line to buffer |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Nyy - yank (copy) N lines to buffer |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
y$ - yank till end of line |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Nyw - yank N words |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
u - undo last editing |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
J - (shift-j) join lines, join the next line after the current one |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
ZZ - save file and close editor |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
42G - jump to line 42 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
G - jump to last line |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
w, Nw - next word, forward N words |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
b, Nb - back one word, back N words |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 Insert mode |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=over 4 |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
ESC moves to navigation mode |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Ctrl-p - autocompletion (inherited from Padre) |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
For now at least, everything else should work as in standard Padre. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=back |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 Command mode |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=over 4 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
:w - write current buffer |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
:e filename - open file for editing |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
TAB completition of directory and filenames |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
:42 - goto line 42 |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
(we have it in generalized form, you can type any number there :) |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
:q - exit |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
:wq - write and exit |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
:bN to switch buffer N |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
TODO: it is not working the same way as in vi, |
215
|
|
|
|
|
|
|
first of all numbers are from and if a file is closed |
216
|
|
|
|
|
|
|
the buffers are renumbered. If we really want to |
217
|
|
|
|
|
|
|
support this option we might need to have our own |
218
|
|
|
|
|
|
|
separate mapping of numbers to buffers and files. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=back |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 TODO |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Better indication that Padre is in vi-mode. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Change the cursor for navigation mode and back to insert mode. |
227
|
|
|
|
|
|
|
(fix i) |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Integrate command line pop-up |
230
|
|
|
|
|
|
|
move it to the bottom of the window |
231
|
|
|
|
|
|
|
make it come up faster (show/hide instead of create/destroy?) |
232
|
|
|
|
|
|
|
(maybe actually we should have it integrated it into the main GUI |
233
|
|
|
|
|
|
|
and add it as another window under or above the output window?) |
234
|
|
|
|
|
|
|
Most importantly, make it faster to come up |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
/ and search connect it to the new (and yet experimental search) |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
r for replacing current character |
242
|
|
|
|
|
|
|
:q! - discard changes and exit |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
:e! |
245
|
|
|
|
|
|
|
:ls and |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub padre_interfaces { |
251
|
|
|
|
|
|
|
'Padre::Plugin' => 0.43; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub plugin_enable { |
255
|
|
|
|
|
|
|
my ($self) = @_; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
require Padre::Plugin::Vi::Editor; |
258
|
|
|
|
|
|
|
require Padre::Plugin::Vi::CommandLine; |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# foreach my $editor ( Padre->ide->wx->main->pages ) { |
261
|
|
|
|
|
|
|
# $self->editor_enable($editor); |
262
|
|
|
|
|
|
|
# } |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub plugin_disable { |
266
|
|
|
|
|
|
|
my ($self) = @_; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
foreach my $editor ( Padre->ide->wx->main->pages ) { |
269
|
|
|
|
|
|
|
$self->editor_stop($editor); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
delete $INC{"Padre/Plugin/Vi/Editor.pm"}; |
272
|
|
|
|
|
|
|
delete $INC{"Padre/Plugin/Vi/CommandLine.pm"}; |
273
|
|
|
|
|
|
|
return; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub editor_enable { |
277
|
|
|
|
|
|
|
my ( $self, $editor, $doc ) = @_; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
$self->{editor}{ refaddr $editor} = Padre::Plugin::Vi::Editor->new($editor); |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Wx::Event::EVT_KEY_DOWN( $editor, sub { $self->evt_key_down(@_) } ); |
282
|
|
|
|
|
|
|
Wx::Event::EVT_CHAR( $editor, sub { $self->evt_char(@_) } ); |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
return 1; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub editor_stop { |
288
|
|
|
|
|
|
|
my ( $self, $editor, $doc ) = @_; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
delete $self->{editor}{ refaddr $editor}; |
291
|
|
|
|
|
|
|
Wx::Event::EVT_KEY_DOWN( $editor, undef ); |
292
|
|
|
|
|
|
|
Wx::Event::EVT_CHAR( $editor, undef ); |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
return 1; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub menu_plugins_simple { |
298
|
|
|
|
|
|
|
return ( "Vi mode" => [ _T('About') => \&about ] ); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub about { |
302
|
|
|
|
|
|
|
my ($main) = @_; |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
my $about = Wx::AboutDialogInfo->new; |
305
|
|
|
|
|
|
|
$about->SetName("Padre::Plugin::Vi"); |
306
|
|
|
|
|
|
|
$about->SetDescription("Try to emulate the vi modes of operation\n"); |
307
|
|
|
|
|
|
|
$about->SetVersion($Padre::Plugin::Vi::VERSION); |
308
|
|
|
|
|
|
|
$about->SetCopyright( _T("Copyright 2008 Gabor Szabo") ); |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
# Only Unix/GTK native about box supports websites |
311
|
|
|
|
|
|
|
if (Padre::Constant::WXGTK) { |
312
|
|
|
|
|
|
|
$about->SetWebSite("http://padre.perlide.org/"); |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
$about->AddDeveloper("Gabor Szabo"); |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
Wx::AboutBox($about); |
318
|
|
|
|
|
|
|
return; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
sub evt_key_down { |
322
|
|
|
|
|
|
|
my ( $self, $editor, $event ) = @_; |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
my $mod = $event->GetModifiers || 0; |
325
|
|
|
|
|
|
|
my $code = $event->GetKeyCode; |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
#print("key: '$mod', '$code'\n"); |
328
|
|
|
|
|
|
|
if ( 32 <= $code and $code <= 127 ) { |
329
|
|
|
|
|
|
|
$event->Skip; |
330
|
|
|
|
|
|
|
return; |
331
|
|
|
|
|
|
|
} |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
my $skip = $self->{editor}{ refaddr $editor}->key_down( $mod, $code ); |
334
|
|
|
|
|
|
|
$event->Skip($skip); |
335
|
|
|
|
|
|
|
return; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
sub evt_char { |
339
|
|
|
|
|
|
|
my ( $self, $editor, $event ) = @_; |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
my $mod = $event->GetModifiers || 0; |
342
|
|
|
|
|
|
|
my $code = $event->GetKeyCode; |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
#printf("char: '$mod', '$code' '%s'\n", chr($code)); |
345
|
|
|
|
|
|
|
if ( 32 <= $code and $code <= 127 ) { |
346
|
|
|
|
|
|
|
my $skip = $self->{editor}{ refaddr $editor}->get_char( $mod, $code, chr($code) ); |
347
|
|
|
|
|
|
|
$event->Skip($skip); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
return; |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
1; |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
# Copyright 2008-2010 Gabor Szabo. |
355
|
|
|
|
|
|
|
# LICENSE |
356
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
357
|
|
|
|
|
|
|
# modify it under the same terms as Perl 5 itself. |