diakonos 0.8.11 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +439 -0
- data/LICENCE.md +675 -0
- data/bin/diakonos +6 -0
- data/diakonos-256-colour.conf +220 -0
- data/diakonos.conf +1802 -0
- data/help/about-help.dhf +31 -0
- data/help/clipboard.dhf +45 -0
- data/help/close-file.dhf +6 -0
- data/help/code-block-navigation.dhf +16 -0
- data/help/column-markers.dhf +15 -0
- data/help/config.dhf +69 -0
- data/help/cursor-stack.dhf +19 -0
- data/help/delete.dhf +41 -0
- data/help/extensions.dhf +125 -0
- data/help/file-type.dhf +24 -0
- data/help/key-mapping.dhf +127 -0
- data/help/line-numbers.dhf +22 -0
- data/help/macros.dhf +27 -0
- data/help/new-file.dhf +6 -0
- data/help/open-file.dhf +21 -0
- data/help/quit.dhf +7 -0
- data/help/resizing.dhf +19 -0
- data/help/ruby.dhf +17 -0
- data/help/save-file.dhf +10 -0
- data/help/scripting.dhf +92 -0
- data/help/search.dhf +103 -0
- data/help/shell.dhf +60 -0
- data/help/speed.dhf +23 -0
- data/help/support.dhf +15 -0
- data/help/switch-buffers.dhf +15 -0
- data/help/tabs.dhf +36 -0
- data/help/undo.dhf +9 -0
- data/help/uninstall.dhf +18 -0
- data/help/welcome.dhf +32 -0
- data/help/word-wrap.dhf +17 -0
- data/lib/diakonos/about.rb +70 -0
- data/lib/diakonos/bookmark.rb +46 -0
- data/lib/diakonos/buffer/bookmarking.rb +47 -0
- data/lib/diakonos/buffer/cursor.rb +335 -0
- data/lib/diakonos/buffer/delete.rb +170 -0
- data/lib/diakonos/buffer/display.rb +362 -0
- data/lib/diakonos/buffer/file.rb +157 -0
- data/lib/diakonos/buffer/indentation.rb +175 -0
- data/lib/diakonos/buffer/searching.rb +552 -0
- data/lib/diakonos/buffer/selection.rb +360 -0
- data/lib/diakonos/buffer/undo.rb +73 -0
- data/lib/diakonos/buffer-hash.rb +60 -0
- data/lib/diakonos/buffer-management.rb +59 -0
- data/lib/diakonos/buffer.rb +698 -0
- data/lib/diakonos/clipboard-klipper-dbus.rb +62 -0
- data/lib/diakonos/clipboard-klipper.rb +62 -0
- data/lib/diakonos/clipboard-osx.rb +59 -0
- data/lib/diakonos/clipboard-xclip.rb +60 -0
- data/lib/diakonos/clipboard.rb +47 -0
- data/lib/diakonos/config-file.rb +67 -0
- data/lib/diakonos/config.rb +382 -0
- data/lib/diakonos/core-ext/enumerable.rb +15 -0
- data/lib/diakonos/core-ext/hash.rb +60 -0
- data/lib/diakonos/core-ext/object.rb +6 -0
- data/lib/diakonos/core-ext/regexp.rb +6 -0
- data/lib/diakonos/core-ext/string.rb +122 -0
- data/lib/diakonos/ctag.rb +28 -0
- data/lib/diakonos/cursor.rb +27 -0
- data/lib/diakonos/display/format.rb +75 -0
- data/lib/diakonos/display.rb +336 -0
- data/lib/diakonos/extension-set.rb +49 -0
- data/lib/diakonos/extension.rb +34 -0
- data/lib/diakonos/finding.rb +40 -0
- data/lib/diakonos/functions/basics.rb +34 -0
- data/lib/diakonos/functions/bookmarking.rb +61 -0
- data/lib/diakonos/functions/buffers.rb +491 -0
- data/lib/diakonos/functions/clipboard.rb +70 -0
- data/lib/diakonos/functions/cursor.rb +264 -0
- data/lib/diakonos/functions/grepping.rb +83 -0
- data/lib/diakonos/functions/indentation.rb +71 -0
- data/lib/diakonos/functions/readline.rb +93 -0
- data/lib/diakonos/functions/search.rb +179 -0
- data/lib/diakonos/functions/selection.rb +98 -0
- data/lib/diakonos/functions/sessions.rb +78 -0
- data/lib/diakonos/functions/shell.rb +250 -0
- data/lib/diakonos/functions/tags.rb +65 -0
- data/lib/diakonos/functions/text-manipulation.rb +196 -0
- data/lib/diakonos/functions-deprecated.rb +77 -0
- data/lib/diakonos/functions.rb +292 -0
- data/lib/diakonos/grep.rb +98 -0
- data/lib/diakonos/help.rb +47 -0
- data/lib/diakonos/hooks.rb +13 -0
- data/lib/diakonos/installation.rb +19 -0
- data/lib/diakonos/interaction-handler.rb +216 -0
- data/lib/diakonos/interaction.rb +52 -0
- data/lib/diakonos/key-map.rb +62 -0
- data/lib/diakonos/keying.rb +442 -0
- data/lib/diakonos/line-mover.rb +42 -0
- data/lib/diakonos/list.rb +59 -0
- data/lib/diakonos/logging.rb +27 -0
- data/lib/diakonos/mode.rb +17 -0
- data/lib/diakonos/mouse.rb +18 -0
- data/lib/diakonos/number-fitter.rb +11 -0
- data/lib/diakonos/range.rb +31 -0
- data/lib/diakonos/readline/functions.rb +82 -0
- data/lib/diakonos/readline.rb +223 -0
- data/lib/diakonos/search.rb +58 -0
- data/lib/diakonos/sessions.rb +257 -0
- data/lib/diakonos/sized-array.rb +48 -0
- data/lib/diakonos/text-mark.rb +19 -0
- data/lib/diakonos/vendor/fuzzy_file_finder.rb +386 -0
- data/lib/diakonos/version.rb +25 -0
- data/lib/diakonos/window.rb +43 -0
- data/lib/diakonos.rb +592 -0
- metadata +160 -68
@@ -0,0 +1,360 @@
|
|
1
|
+
module Diakonos
|
2
|
+
|
3
|
+
class Buffer
|
4
|
+
|
5
|
+
# @mark_start[ "col" ] is inclusive,
|
6
|
+
# @mark_end[ "col" ] is exclusive.
|
7
|
+
def record_mark_start_and_end
|
8
|
+
if @mark_anchor.nil?
|
9
|
+
@text_marks[ :selection ] = nil
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
crow = @last_row
|
14
|
+
ccol = @last_col
|
15
|
+
arow = @mark_anchor[ 'row' ]
|
16
|
+
acol = @mark_anchor[ 'col' ]
|
17
|
+
|
18
|
+
case @selection_mode
|
19
|
+
when :normal
|
20
|
+
anchor_first = true
|
21
|
+
|
22
|
+
if crow < arow
|
23
|
+
anchor_first = false
|
24
|
+
elsif crow > arow
|
25
|
+
anchor_first = true
|
26
|
+
else
|
27
|
+
if ccol < acol
|
28
|
+
anchor_first = false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if anchor_first
|
33
|
+
@text_marks[ :selection ] = TextMark.new( ::Diakonos::Range.new(arow, acol, crow, ccol), @selection_formatting )
|
34
|
+
else
|
35
|
+
@text_marks[ :selection ] = TextMark.new( ::Diakonos::Range.new(crow, ccol, arow, acol), @selection_formatting )
|
36
|
+
end
|
37
|
+
when :block
|
38
|
+
if crow < arow
|
39
|
+
if ccol < acol # Northwest
|
40
|
+
@text_marks[ :selection ] = TextMark.new( ::Diakonos::Range.new(crow, ccol, arow, acol), @selection_formatting )
|
41
|
+
else # Northeast
|
42
|
+
@text_marks[ :selection ] = TextMark.new( ::Diakonos::Range.new(crow, acol, arow, ccol), @selection_formatting )
|
43
|
+
end
|
44
|
+
else
|
45
|
+
if ccol < acol # Southwest
|
46
|
+
@text_marks[ :selection ] = TextMark.new( ::Diakonos::Range.new(arow, ccol, crow, acol), @selection_formatting )
|
47
|
+
else # Southeast
|
48
|
+
@text_marks[ :selection ] = TextMark.new( ::Diakonos::Range.new(arow, acol, crow, ccol), @selection_formatting )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def selection_mark
|
55
|
+
@text_marks[:selection]
|
56
|
+
end
|
57
|
+
|
58
|
+
def selecting?
|
59
|
+
!! selection_mark
|
60
|
+
end
|
61
|
+
|
62
|
+
def select_current_line
|
63
|
+
selection_mode_normal
|
64
|
+
anchor_selection( @last_row, 0, DONT_DISPLAY )
|
65
|
+
if @last_row == @lines.size - 1
|
66
|
+
row = @last_row
|
67
|
+
col = @lines[ @last_row ].size
|
68
|
+
else
|
69
|
+
row = @last_row + 1
|
70
|
+
col = 0
|
71
|
+
end
|
72
|
+
cursor_to( row, col, DO_DISPLAY )
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_selection_current_line
|
76
|
+
@text_marks[ :selection ] = TextMark.new(
|
77
|
+
::Diakonos::Range.new(@last_row, 0, @last_row, @lines[ @last_row ].size),
|
78
|
+
@selection_formatting
|
79
|
+
)
|
80
|
+
@lines[ @last_row ]
|
81
|
+
end
|
82
|
+
|
83
|
+
def select_all
|
84
|
+
selection_mode_normal
|
85
|
+
anchor_selection( 0, 0, DONT_DISPLAY )
|
86
|
+
cursor_to( @lines.length - 1, @lines[ -1 ].length, DO_DISPLAY )
|
87
|
+
end
|
88
|
+
|
89
|
+
def select_wrapping_block
|
90
|
+
block_level = indentation_level( @last_row )
|
91
|
+
if selecting?
|
92
|
+
block_level -= 1
|
93
|
+
end
|
94
|
+
if block_level <= 0
|
95
|
+
return select_all
|
96
|
+
end
|
97
|
+
|
98
|
+
end_row = start_row = @last_row
|
99
|
+
|
100
|
+
# Find block end
|
101
|
+
( @last_row...@lines.size ).each do |row|
|
102
|
+
next if @lines[ row ].strip.empty?
|
103
|
+
if indentation_level( row ) < block_level
|
104
|
+
end_row = row
|
105
|
+
break
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Go to block beginning
|
110
|
+
( 0...@last_row ).reverse_each do |row|
|
111
|
+
next if @lines[ row ].strip.empty?
|
112
|
+
if indentation_level( row ) < block_level
|
113
|
+
start_row = row + 1
|
114
|
+
break
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
anchor_selection( end_row, 0 )
|
119
|
+
cursor_to( start_row, 0, DO_DISPLAY )
|
120
|
+
end
|
121
|
+
|
122
|
+
def select_word
|
123
|
+
coords = word_under_cursor_pos( or_after: true )
|
124
|
+
if coords.nil?
|
125
|
+
remove_selection
|
126
|
+
else
|
127
|
+
cursor_to *coords[0]
|
128
|
+
anchor_selection
|
129
|
+
cursor_to *coords[1]
|
130
|
+
display
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def select_word_another
|
135
|
+
m = selection_mark
|
136
|
+
if m.nil?
|
137
|
+
select_word
|
138
|
+
else
|
139
|
+
row, col, _ = pos_of_next( /\w\b/, @last_row, @last_col )
|
140
|
+
if row && col
|
141
|
+
cursor_to row, col+1, DO_DISPLAY
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def select( from_regexp, to_regexp, include_ending = true )
|
147
|
+
start_row = nil
|
148
|
+
|
149
|
+
@lines[ 0..@last_row ].reverse.each_with_index do |line,index|
|
150
|
+
if line =~ from_regexp
|
151
|
+
start_row = @last_row - index
|
152
|
+
break
|
153
|
+
end
|
154
|
+
end
|
155
|
+
if start_row
|
156
|
+
end_row = nil
|
157
|
+
@lines[ start_row..-1 ].each_with_index do |line,index|
|
158
|
+
if line =~ to_regexp
|
159
|
+
end_row = start_row + index
|
160
|
+
break
|
161
|
+
end
|
162
|
+
end
|
163
|
+
if end_row
|
164
|
+
if include_ending
|
165
|
+
end_row += 1
|
166
|
+
end
|
167
|
+
anchor_selection( start_row, 0, DONT_DISPLAY )
|
168
|
+
cursor_to( end_row, 0 )
|
169
|
+
display
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def set_selection( start_row, start_col, end_row, end_col )
|
175
|
+
@text_marks[ :selection ] = TextMark.new( ::Diakonos::Range.new(start_row, start_col, end_row, end_col), @selection_formatting )
|
176
|
+
@changing_selection = false
|
177
|
+
end
|
178
|
+
|
179
|
+
def anchor_selection( row = @last_row, col = @last_col, do_display = DO_DISPLAY )
|
180
|
+
@mark_anchor = ( @mark_anchor || Hash.new )
|
181
|
+
@mark_anchor[ "row" ] = row
|
182
|
+
@mark_anchor[ "col" ] = col
|
183
|
+
record_mark_start_and_end
|
184
|
+
@changing_selection = true
|
185
|
+
@auto_anchored = false
|
186
|
+
display if do_display
|
187
|
+
end
|
188
|
+
|
189
|
+
def anchor_unanchored_selection(*args)
|
190
|
+
if @mark_anchor.nil?
|
191
|
+
anchor_selection *args
|
192
|
+
@changing_selection = false
|
193
|
+
end
|
194
|
+
@auto_anchored = true
|
195
|
+
end
|
196
|
+
|
197
|
+
def remove_selection( do_display = DO_DISPLAY )
|
198
|
+
return if selection_mark.nil?
|
199
|
+
@mark_anchor = nil
|
200
|
+
record_mark_start_and_end
|
201
|
+
@changing_selection = false
|
202
|
+
@last_finding = nil
|
203
|
+
display if do_display
|
204
|
+
end
|
205
|
+
|
206
|
+
def toggle_selection
|
207
|
+
if @changing_selection
|
208
|
+
remove_selection
|
209
|
+
else
|
210
|
+
anchor_selection
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def copy_selection
|
215
|
+
selected_text
|
216
|
+
end
|
217
|
+
|
218
|
+
# @return [Array<String>, nil]
|
219
|
+
def selected_text
|
220
|
+
selection = selection_mark
|
221
|
+
if selection.nil?
|
222
|
+
nil
|
223
|
+
elsif selection.start_row == selection.end_row
|
224
|
+
[ @lines[ selection.start_row ][ selection.start_col...selection.end_col ] ]
|
225
|
+
else
|
226
|
+
if @selection_mode == :block
|
227
|
+
@lines[ selection.start_row .. selection.end_row ].collect { |line|
|
228
|
+
line[ selection.start_col ... selection.end_col ]
|
229
|
+
}
|
230
|
+
else
|
231
|
+
[ @lines[ selection.start_row ][ selection.start_col..-1 ] ] +
|
232
|
+
( @lines[ (selection.start_row + 1) .. (selection.end_row - 1) ] || [] ) +
|
233
|
+
[ @lines[ selection.end_row ][ 0...selection.end_col ] ]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def selected_string
|
239
|
+
lines = selected_text
|
240
|
+
if lines
|
241
|
+
lines.join( "\n" )
|
242
|
+
else
|
243
|
+
nil
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def selected_lines
|
248
|
+
selection = selection_mark
|
249
|
+
if selection
|
250
|
+
if selection.end_col == 0
|
251
|
+
end_row = selection.end_row - 1
|
252
|
+
else
|
253
|
+
end_row = selection.end_row
|
254
|
+
end
|
255
|
+
@lines[ selection.start_row..end_row ]
|
256
|
+
else
|
257
|
+
[ @lines[ @last_row ] ]
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def selection_mode_block
|
262
|
+
@selection_mode = :block
|
263
|
+
end
|
264
|
+
def selection_mode_normal
|
265
|
+
@selection_mode = :normal
|
266
|
+
end
|
267
|
+
|
268
|
+
def delete_selection( do_display = DO_DISPLAY )
|
269
|
+
return if @text_marks[ :selection ].nil?
|
270
|
+
|
271
|
+
take_snapshot
|
272
|
+
|
273
|
+
selection = @text_marks[ :selection ]
|
274
|
+
start_row = selection.start_row
|
275
|
+
start_col = selection.start_col
|
276
|
+
end_row = selection.end_row
|
277
|
+
end_col = selection.end_col
|
278
|
+
start_line = @lines[ start_row ]
|
279
|
+
|
280
|
+
if end_row == selection.start_row
|
281
|
+
@lines[ start_row ] = start_line[ 0...start_col ] + start_line[ end_col..-1 ]
|
282
|
+
else
|
283
|
+
case @selection_mode
|
284
|
+
when :normal
|
285
|
+
end_line = @lines[ end_row ]
|
286
|
+
@lines[ start_row ] = start_line[ 0...start_col ] + end_line[ end_col..-1 ]
|
287
|
+
@lines = @lines[ 0..start_row ] + @lines[ (end_row + 1)..-1 ]
|
288
|
+
when :block
|
289
|
+
@lines[ start_row..end_row ] = @lines[ start_row..end_row ].collect { |line|
|
290
|
+
line[ 0...start_col ] + ( line[ end_col..-1 ] || '' )
|
291
|
+
}
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
cursor_to start_row, start_col
|
296
|
+
remove_selection DONT_DISPLAY
|
297
|
+
set_modified do_display
|
298
|
+
end
|
299
|
+
|
300
|
+
# text is an array of Strings, or a String with zero or more newlines ("\n")
|
301
|
+
def paste( text, typing = ! TYPING, do_parsed_indent = false )
|
302
|
+
return if text.nil?
|
303
|
+
|
304
|
+
if ! text.kind_of?(Array)
|
305
|
+
s = text.to_s
|
306
|
+
if s.include?( "\n" )
|
307
|
+
text = s.split( "\n", -1 )
|
308
|
+
else
|
309
|
+
text = [ s ]
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
take_snapshot typing
|
314
|
+
|
315
|
+
delete_selection DONT_DISPLAY
|
316
|
+
|
317
|
+
row = @last_row
|
318
|
+
col = @last_col
|
319
|
+
new_col = nil
|
320
|
+
line = @lines[ row ]
|
321
|
+
if text.length == 1
|
322
|
+
@lines[ row ] = line[ 0...col ] + text[ 0 ] + line[ col..-1 ]
|
323
|
+
if do_parsed_indent
|
324
|
+
parsed_indent row: row, do_display: false
|
325
|
+
end
|
326
|
+
cursor_to( @last_row, @last_col + text[ 0 ].length, DONT_DISPLAY, ! typing )
|
327
|
+
elsif text.length > 1
|
328
|
+
|
329
|
+
case @selection_mode
|
330
|
+
when :normal
|
331
|
+
@lines[ row ] = line[ 0...col ] + text[ 0 ]
|
332
|
+
@lines[ row + 1, 0 ] = text[ -1 ] + line[ col..-1 ]
|
333
|
+
@lines[ row + 1, 0 ] = text[ 1..-2 ]
|
334
|
+
new_col = column_of( text[ -1 ].length )
|
335
|
+
when :block
|
336
|
+
@lines += [ '' ] * [ 0, ( row + text.length - @lines.length ) ].max
|
337
|
+
@lines[ row...( row + text.length ) ] = @lines[ row...( row + text.length ) ].collect.with_index { |line,index|
|
338
|
+
pre = line[ 0...col ].ljust( col )
|
339
|
+
post = line[ col..-1 ]
|
340
|
+
"#{pre}#{text[ index ]}#{post}"
|
341
|
+
}
|
342
|
+
new_col = col + text[ -1 ].length
|
343
|
+
end
|
344
|
+
|
345
|
+
new_row = @last_row + text.length - 1
|
346
|
+
if do_parsed_indent
|
347
|
+
( row..new_row ).each do |r|
|
348
|
+
parsed_indent row: r, do_display: false
|
349
|
+
end
|
350
|
+
end
|
351
|
+
cursor_to( new_row, new_col )
|
352
|
+
|
353
|
+
end
|
354
|
+
|
355
|
+
set_modified
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Diakonos
|
2
|
+
|
3
|
+
class Buffer
|
4
|
+
|
5
|
+
DO_USE_MD5 = true
|
6
|
+
DONT_USE_MD5 = false
|
7
|
+
|
8
|
+
def take_snapshot( typing = false )
|
9
|
+
do_it = false
|
10
|
+
|
11
|
+
if ! @modified && file_modified? && file_different?
|
12
|
+
return if $diakonos.revert( "File has been altered externally. Load on-disk version?" )
|
13
|
+
end
|
14
|
+
|
15
|
+
if @typing != typing
|
16
|
+
@typing = typing
|
17
|
+
# If we just started typing, take a snapshot, but don't continue
|
18
|
+
# taking snapshots for every keystroke
|
19
|
+
if typing
|
20
|
+
do_it = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
if ! @typing
|
24
|
+
do_it = true
|
25
|
+
end
|
26
|
+
|
27
|
+
if do_it
|
28
|
+
undo_size = 0
|
29
|
+
@buffer_states[ 1..-1 ].each do |state|
|
30
|
+
undo_size += state.length
|
31
|
+
end
|
32
|
+
while ( ( undo_size + @lines.length ) >= @settings[ "max_undo_lines" ] ) && @buffer_states.length > 1
|
33
|
+
@cursor_states.pop
|
34
|
+
popped_state = @buffer_states.pop
|
35
|
+
undo_size = undo_size - popped_state.length
|
36
|
+
end
|
37
|
+
|
38
|
+
if @current_buffer_state > 0
|
39
|
+
@buffer_states.unshift @lines.deep_clone
|
40
|
+
@cursor_states.unshift [ @last_row, @last_col ]
|
41
|
+
end
|
42
|
+
|
43
|
+
@buffer_states.unshift @lines.deep_clone
|
44
|
+
@cursor_states.unshift [ @last_row, @last_col ]
|
45
|
+
@current_buffer_state = 0
|
46
|
+
@lines = @buffer_states[ @current_buffer_state ]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def undo
|
51
|
+
return if @current_buffer_state >= @buffer_states.length - 1
|
52
|
+
|
53
|
+
@current_buffer_state += 1
|
54
|
+
@lines = @buffer_states[ @current_buffer_state ]
|
55
|
+
cursor_to( @cursor_states[ @current_buffer_state - 1 ][ 0 ], @cursor_states[ @current_buffer_state - 1 ][ 1 ] )
|
56
|
+
$diakonos.set_iline "Undo level: #{@current_buffer_state} of #{@buffer_states.length - 1}"
|
57
|
+
set_modified DO_DISPLAY, DO_USE_MD5
|
58
|
+
end
|
59
|
+
|
60
|
+
# Since redo is a Ruby keyword...
|
61
|
+
def unundo
|
62
|
+
return if @current_buffer_state <= 0
|
63
|
+
|
64
|
+
@current_buffer_state += -1
|
65
|
+
@lines = @buffer_states[ @current_buffer_state ]
|
66
|
+
cursor_to( @cursor_states[ @current_buffer_state ][ 0 ], @cursor_states[ @current_buffer_state ][ 1 ] )
|
67
|
+
$diakonos.set_iline "Undo level: #{@current_buffer_state} of #{@buffer_states.length - 1}"
|
68
|
+
set_modified DO_DISPLAY, DO_USE_MD5
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# A Hash which is iterated in insertion order.
|
2
|
+
# Keys are assumed to be paths; these paths are expanded on read and write.
|
3
|
+
class BufferHash < Hash
|
4
|
+
def initialize
|
5
|
+
@keys_ = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def [] ( key )
|
9
|
+
super File.expand_path( key.to_s )
|
10
|
+
end
|
11
|
+
|
12
|
+
def []= ( key, value )
|
13
|
+
key = File.expand_path( key.to_s )
|
14
|
+
if ! @keys_.include?( key )
|
15
|
+
@keys_ << key
|
16
|
+
end
|
17
|
+
super key, value
|
18
|
+
end
|
19
|
+
|
20
|
+
def each
|
21
|
+
@keys_.each do |key|
|
22
|
+
yield key, self[ key ]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_key
|
27
|
+
@keys_.each do |key|
|
28
|
+
yield key
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def each_value
|
33
|
+
@keys_.each do |key|
|
34
|
+
yield self[ key ]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear
|
39
|
+
@keys_ = []
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete( key )
|
44
|
+
@keys_.delete key
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
def keys
|
49
|
+
@keys_.dup
|
50
|
+
end
|
51
|
+
|
52
|
+
def values
|
53
|
+
@keys_.map { |key| self[ key ] }
|
54
|
+
end
|
55
|
+
|
56
|
+
def length
|
57
|
+
@keys_.length
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Diakonos
|
2
|
+
class Diakonos
|
3
|
+
attr_reader :buffer_current
|
4
|
+
|
5
|
+
# @param [Buffer] the Buffer to switch to
|
6
|
+
# @option opts [Boolean] :do_display
|
7
|
+
# Whether or not to update the display after closure
|
8
|
+
# @return [Boolean] true iff the buffer was successfully switched to
|
9
|
+
def switch_to( buffer, opts = {} )
|
10
|
+
return false if buffer.nil?
|
11
|
+
do_display = opts.fetch( :do_display, true )
|
12
|
+
|
13
|
+
@buffer_stack -= [ @buffer_current ]
|
14
|
+
if @buffer_current
|
15
|
+
@buffer_stack.push @buffer_current
|
16
|
+
end
|
17
|
+
@buffer_current = buffer
|
18
|
+
@session.buffer_current = buffer_to_number( buffer )
|
19
|
+
run_hook_procs( :after_buffer_switch, buffer )
|
20
|
+
if do_display
|
21
|
+
update_status_line
|
22
|
+
update_context_line
|
23
|
+
display_buffer buffer
|
24
|
+
end
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [Integer] buffer_number should be 1-based, not zero-based.
|
30
|
+
# @return nil if no such buffer exists.
|
31
|
+
def buffer_number_to_name( buffer_number )
|
32
|
+
return nil if buffer_number < 1
|
33
|
+
|
34
|
+
b = @buffers[ buffer_number - 1 ]
|
35
|
+
if b
|
36
|
+
b.name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Integer] 1-based, not zero-based.
|
41
|
+
# @return nil if no such buffer exists.
|
42
|
+
def buffer_to_number( buffer )
|
43
|
+
i = @buffers.index( buffer )
|
44
|
+
if i
|
45
|
+
i + 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def show_buffer_file_diff( buffer = @buffer_current )
|
50
|
+
current_text_file = @diakonos_home + '/current-buffer'
|
51
|
+
buffer.save_copy( current_text_file )
|
52
|
+
`#{@settings[ 'diff_command' ]} #{current_text_file} #{buffer.name} > #{@diff_filename}`
|
53
|
+
diff_buffer = open_file( @diff_filename )
|
54
|
+
yield diff_buffer
|
55
|
+
close_buffer diff_buffer
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|