vimamsa 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/vimamsa +1 -4
- data/lib/vimamsa/ack.rb +4 -3
- data/lib/vimamsa/actions.rb +13 -6
- data/lib/vimamsa/audio.rb +58 -0
- data/lib/vimamsa/buffer.rb +59 -32
- data/lib/vimamsa/buffer_manager.rb +2 -1
- data/lib/vimamsa/easy_jump.rb +1 -1
- data/lib/vimamsa/editor.rb +24 -51
- data/lib/vimamsa/file_finder.rb +8 -8
- data/lib/vimamsa/gui.rb +114 -142
- data/lib/vimamsa/gui_menu.rb +4 -0
- data/lib/vimamsa/gui_select_window.rb +9 -8
- data/lib/vimamsa/gui_sourceview.rb +189 -38
- data/lib/vimamsa/hyper_plain_text.rb +11 -4
- data/lib/vimamsa/key_actions.rb +4 -0
- data/lib/vimamsa/key_binding_tree.rb +8 -2
- data/lib/vimamsa/key_bindings_vimlike.rb +16 -2
- data/lib/vimamsa/main.rb +0 -7
- data/lib/vimamsa/rbvma.rb +0 -6
- data/lib/vimamsa/search_replace.rb +33 -9
- data/lib/vimamsa/util.rb +64 -1
- data/lib/vimamsa/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bd13f53f2d774550226da6e379842c2d54bde6e8ffa5362d4769940d93a033e
|
4
|
+
data.tar.gz: 5f2db7ad2c5402a816f186e266194f1a7545b1a2a71fd532f9140634835fc3f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d41917d0e0cfa9a876579bea6aaaafee3b3eff3757d74c399922a5db71220889f278df03bd1bc3e1177002fa906e3d30792280004dd5270d2b135dd6006f51ca
|
7
|
+
data.tar.gz: c4935e09ecb5a714cb481ac00386e698aee72583030f03cf9b7c182c71066513339c2c0c4aa6f723e00630e659704e95a107007a76af936d08e67a8e6ded5c5f
|
data/exe/vimamsa
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
require "ripl/multi_line"
|
3
3
|
require "tempfile"
|
4
4
|
# Ripl.config[:multi_line_prompt] = ' > '
|
5
5
|
require "pathname"
|
6
6
|
|
7
|
-
ENV["GTK_THEME"] = "Adwaita:dark"
|
8
|
-
# ENV["GTK_THEME"] = "Adwaita:light"
|
9
|
-
|
10
7
|
selfpath = __FILE__
|
11
8
|
selfpath = File.readlink(selfpath) if File.lstat(selfpath).symlink?
|
12
9
|
scriptdir = File.expand_path(File.dirname(selfpath) + "/..")
|
data/lib/vimamsa/ack.rb
CHANGED
@@ -111,14 +111,15 @@ Will search the following directories:
|
|
111
111
|
gui_one_input_action(nfo, "Search:", "search", callback)
|
112
112
|
end
|
113
113
|
|
114
|
-
def ack_buffer(
|
115
|
-
instr = Shellwords.escape(
|
114
|
+
def ack_buffer(_instr, b = nil)
|
115
|
+
instr = Shellwords.escape(_instr)
|
116
116
|
bufstr = ""
|
117
117
|
for path in vma.get_content_search_paths
|
118
118
|
bufstr += run_cmd("ack -Q --type-add=gd=.gd -ki --nohtml --nojs --nojson #{instr} #{path}")
|
119
119
|
end
|
120
120
|
if bufstr.size > 5
|
121
|
-
create_new_buffer(bufstr,"ack")
|
121
|
+
b = create_new_buffer(bufstr,"ack")
|
122
|
+
highlight_match(b, _instr, color: "#10bd8e")
|
122
123
|
else
|
123
124
|
message("No results for input:#{instr}")
|
124
125
|
end
|
data/lib/vimamsa/actions.rb
CHANGED
@@ -32,11 +32,14 @@ def missing_callfunc
|
|
32
32
|
end
|
33
33
|
|
34
34
|
#TODO: remove
|
35
|
-
def call(id)
|
36
|
-
call_action(id)
|
37
|
-
end
|
35
|
+
# def call(id)
|
36
|
+
# call_action(id)
|
37
|
+
# end
|
38
|
+
|
39
|
+
$acth = []
|
38
40
|
|
39
41
|
def call_action(id)
|
42
|
+
$acth << id
|
40
43
|
a = $actions[id]
|
41
44
|
if a
|
42
45
|
a.method.call()
|
@@ -45,11 +48,15 @@ def call_action(id)
|
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
51
|
+
def last_action
|
52
|
+
return $acth[-1]
|
53
|
+
end
|
54
|
+
|
48
55
|
def search_actions()
|
49
56
|
l = []
|
50
|
-
opt = { :title => "Search actions
|
57
|
+
opt = { :title => "Search for actions", :desc => "Fuzzy search for actions. <up> or <down> to change selcted. <enter> to select current." }
|
51
58
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
52
|
-
|
59
|
+
|
53
60
|
gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
54
61
|
"search_actions_select_callback",
|
55
62
|
"search_actions_update_callback",
|
@@ -109,7 +116,7 @@ def search_actions_select_callback(search_str, idx)
|
|
109
116
|
eval(acc)
|
110
117
|
elsif acc.class == Symbol
|
111
118
|
debug "Symbol"
|
112
|
-
|
119
|
+
call_action(acc)
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "gstreamer"
|
2
|
+
|
3
|
+
# following the example gstreamer-4.2.0/sample/helloworld_e.rb
|
4
|
+
class Audio
|
5
|
+
@@playbin = nil
|
6
|
+
|
7
|
+
def self.stop
|
8
|
+
@@playbin.stop if !@@playbin.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.play(fn)
|
12
|
+
playbin = @@playbin
|
13
|
+
if playbin.nil?
|
14
|
+
playbin = Gst::ElementFactory.make("playbin")
|
15
|
+
if playbin.nil?
|
16
|
+
puts "'playbin' gstreamer plugin missing"
|
17
|
+
return
|
18
|
+
end
|
19
|
+
else
|
20
|
+
if playbin.current_state == "playing"
|
21
|
+
playbin.stop # Stop previous play
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# playbin.volume
|
26
|
+
# playbin.volume=1.0
|
27
|
+
# playbin.stream_time
|
28
|
+
# playbin.current_state
|
29
|
+
|
30
|
+
# take the commandline argument and ensure that it is a uri
|
31
|
+
if Gst.valid_uri?(fn)
|
32
|
+
uri = fn
|
33
|
+
else
|
34
|
+
uri = Gst.filename_to_uri(fn)
|
35
|
+
end
|
36
|
+
playbin.uri = uri
|
37
|
+
@@playbin = playbin
|
38
|
+
|
39
|
+
bus = playbin.bus
|
40
|
+
bus.add_watch do |bus, message|
|
41
|
+
|
42
|
+
case message.type
|
43
|
+
when Gst::MessageType::EOS
|
44
|
+
puts "End-of-stream"
|
45
|
+
when Gst::MessageType::ERROR
|
46
|
+
error, debug = message.parse_error
|
47
|
+
puts "Debugging info: #{debug || "none"}"
|
48
|
+
puts "Error: #{error.message}"
|
49
|
+
end
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
message("Start playing audio: #{fn}")
|
54
|
+
|
55
|
+
# start play back and listed to events
|
56
|
+
playbin.play
|
57
|
+
end
|
58
|
+
end
|
data/lib/vimamsa/buffer.rb
CHANGED
@@ -5,7 +5,6 @@ require "pathname"
|
|
5
5
|
require "openssl"
|
6
6
|
require "ripl/multi_line"
|
7
7
|
|
8
|
-
$paste_lines = false
|
9
8
|
$buffer_history = []
|
10
9
|
|
11
10
|
$update_highlight = false
|
@@ -13,10 +12,9 @@ $update_highlight = false
|
|
13
12
|
$ifuncon = false
|
14
13
|
|
15
14
|
class Buffer < String
|
16
|
-
|
17
15
|
attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :dirname, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang, :images, :last_save
|
18
16
|
attr_writer :call_func, :update_highlight
|
19
|
-
attr_accessor :gui_update_highlight, :update_hl_startpos, :update_hl_endpos, :hl_queue, :syntax_parser, :highlights, :gui_reset_highlight, :is_parsing_syntax, :line_ends, :bt, :line_action_handler, :module, :active_kbd_mode, :title, :subtitle
|
17
|
+
attr_accessor :gui_update_highlight, :update_hl_startpos, :update_hl_endpos, :hl_queue, :syntax_parser, :highlights, :gui_reset_highlight, :is_parsing_syntax, :line_ends, :bt, :line_action_handler, :module, :active_kbd_mode, :title, :subtitle, :paste_lines
|
20
18
|
|
21
19
|
@@num_buffers = 0
|
22
20
|
|
@@ -33,6 +31,9 @@ class Buffer < String
|
|
33
31
|
gui_create_buffer(@id, self)
|
34
32
|
debug "NEW BUFFER fn=#{fname} ID:#{@id}"
|
35
33
|
|
34
|
+
# If true, we will create new line after this and paste there
|
35
|
+
@paste_lines = false
|
36
|
+
|
36
37
|
@module = nil
|
37
38
|
|
38
39
|
@last_save = @last_asked_from_user = @file_last_cheked = Time.now
|
@@ -207,9 +208,7 @@ class Buffer < String
|
|
207
208
|
# If this is done too early, the gutter is not yet drawn which
|
208
209
|
# will result in wrong position
|
209
210
|
if @audiofiles.size == 1
|
210
|
-
|
211
|
-
GLib::Idle.add(proc { self.reset_audio_widget_positions })
|
212
|
-
}
|
211
|
+
run_as_idle proc { self.reset_audio_widget_positions }
|
213
212
|
end
|
214
213
|
$audiof = mf
|
215
214
|
end
|
@@ -401,7 +400,6 @@ class Buffer < String
|
|
401
400
|
gui_set_buffer_contents(@id, self.to_s)
|
402
401
|
@images = [] #TODO: if reload
|
403
402
|
hpt_scan_images(self)
|
404
|
-
hpt_scan_audio(self)
|
405
403
|
|
406
404
|
# add_hl_update(@update_hl_startpos, @update_hl_endpos)
|
407
405
|
end
|
@@ -806,7 +804,7 @@ class Buffer < String
|
|
806
804
|
end
|
807
805
|
|
808
806
|
def copy(range_id)
|
809
|
-
|
807
|
+
@paste_lines = false
|
810
808
|
debug "range_id: #{range_id}"
|
811
809
|
debug range_id.inspect
|
812
810
|
range = get_range(range_id)
|
@@ -969,9 +967,14 @@ class Buffer < String
|
|
969
967
|
set_line_and_column_pos(nil, nil)
|
970
968
|
end
|
971
969
|
|
972
|
-
def delete2(range_id)
|
973
|
-
|
974
|
-
|
970
|
+
def delete2(range_id, mark = nil)
|
971
|
+
# if mark != nil
|
972
|
+
# debug mark, 2
|
973
|
+
# return
|
974
|
+
# end
|
975
|
+
|
976
|
+
@paste_lines = false
|
977
|
+
range = get_range(range_id, mark: mark)
|
975
978
|
return if range == nil
|
976
979
|
debug "RANGE"
|
977
980
|
debug range.inspect
|
@@ -983,7 +986,7 @@ class Buffer < String
|
|
983
986
|
end
|
984
987
|
|
985
988
|
def delete(op, x = nil)
|
986
|
-
|
989
|
+
@paste_lines = false
|
987
990
|
# Delete selection
|
988
991
|
if op == SELECTION && visual_mode?
|
989
992
|
(startpos, endpos) = get_visual_mode_range2
|
@@ -1031,7 +1034,7 @@ class Buffer < String
|
|
1031
1034
|
end
|
1032
1035
|
|
1033
1036
|
# Ranges to use in delete or copy operations
|
1034
|
-
def get_range(range_id)
|
1037
|
+
def get_range(range_id, mark: nil)
|
1035
1038
|
range = nil
|
1036
1039
|
if range_id == :to_word_end
|
1037
1040
|
# TODO: better way to make the search than + 150 from current position
|
@@ -1048,6 +1051,16 @@ class Buffer < String
|
|
1048
1051
|
range = get_range(:to_word_end)
|
1049
1052
|
end
|
1050
1053
|
# Ripl.start :binding => binding
|
1054
|
+
|
1055
|
+
elsif range_id == :to_mark
|
1056
|
+
debug "TO MARK"
|
1057
|
+
start = @line_ends[@lpos]
|
1058
|
+
mpos = @marks[mark]
|
1059
|
+
if !mpos.nil?
|
1060
|
+
range = start..mpos
|
1061
|
+
else
|
1062
|
+
return nil
|
1063
|
+
end
|
1051
1064
|
elsif range_id == :to_line_end
|
1052
1065
|
debug "TO LINE END"
|
1053
1066
|
range = @pos..(@line_ends[@lpos] - 1)
|
@@ -1071,15 +1084,18 @@ class Buffer < String
|
|
1071
1084
|
end
|
1072
1085
|
return range if range == nil
|
1073
1086
|
if range.last < range.first
|
1074
|
-
range
|
1087
|
+
range = range.last..range.first
|
1088
|
+
# range.last = range.first
|
1075
1089
|
end
|
1076
1090
|
if range.first < 0
|
1077
|
-
range.first = 0
|
1091
|
+
# range.first = 0
|
1092
|
+
range = 0..range.last
|
1078
1093
|
end
|
1079
1094
|
if range.last >= self.size
|
1080
|
-
range.last = self.size - 1
|
1095
|
+
# range.last = self.size - 1
|
1096
|
+
range = range.first..(self.size - 1)
|
1081
1097
|
end
|
1082
|
-
|
1098
|
+
debug range, 2
|
1083
1099
|
return range
|
1084
1100
|
end
|
1085
1101
|
|
@@ -1490,6 +1506,10 @@ class Buffer < String
|
|
1490
1506
|
end
|
1491
1507
|
|
1492
1508
|
def insert_txt_at(c, pos)
|
1509
|
+
if c.nil? or pos.nil?
|
1510
|
+
error("input c=nil || pos=nil")
|
1511
|
+
return
|
1512
|
+
end
|
1493
1513
|
c = c.force_encoding("UTF-8"); #TODO:correct?
|
1494
1514
|
c = "\n" if c == "\r"
|
1495
1515
|
add_delta([pos, INSERT, c.size, c], true)
|
@@ -1611,26 +1631,32 @@ class Buffer < String
|
|
1611
1631
|
@clipboard_paste_running = true
|
1612
1632
|
clipboard = vma.gui.window.display.clipboard
|
1613
1633
|
clipboard.read_text_async do |_clipboard, result|
|
1614
|
-
|
1615
|
-
|
1634
|
+
begin
|
1635
|
+
text = clipboard.read_text_finish(result)
|
1636
|
+
rescue Gio::IOError::NotSupported
|
1637
|
+
# Happens when pasting from KeePassX and clipboard cleared
|
1638
|
+
debug Gio::IOError::NotSupported
|
1639
|
+
else
|
1640
|
+
paste_finish(text, at, register)
|
1641
|
+
end
|
1616
1642
|
end
|
1617
1643
|
end
|
1618
1644
|
|
1619
1645
|
def paste_finish(text, at, register)
|
1620
|
-
# if text == ""
|
1621
|
-
# return if !$clipboard.any?
|
1622
|
-
# if register == nil
|
1623
|
-
# text = $clipboard[-1]
|
1624
|
-
# else
|
1625
|
-
# text = $register[register]
|
1626
|
-
# end
|
1627
|
-
# end
|
1628
1646
|
debug "PASTE: #{text}"
|
1647
|
+
|
1648
|
+
# If we did not put this text to clipboard
|
1649
|
+
if text != $clipboard[-1]
|
1650
|
+
@paste_lines = false
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
text = sanitize_input(text)
|
1654
|
+
|
1629
1655
|
$clipboard << text
|
1630
1656
|
|
1631
1657
|
return if text == ""
|
1632
1658
|
|
1633
|
-
if
|
1659
|
+
if @paste_lines
|
1634
1660
|
debug "PASTE LINES"
|
1635
1661
|
put_to_new_next_line(text)
|
1636
1662
|
else
|
@@ -1672,7 +1698,7 @@ class Buffer < String
|
|
1672
1698
|
add_delta([lrange.begin, DELETE, lrange.end - lrange.begin + 1], true)
|
1673
1699
|
set_clipboard(s)
|
1674
1700
|
update_pos(lrange.begin)
|
1675
|
-
|
1701
|
+
@paste_lines = true
|
1676
1702
|
#recalc_line_ends
|
1677
1703
|
end
|
1678
1704
|
|
@@ -1689,7 +1715,7 @@ class Buffer < String
|
|
1689
1715
|
|
1690
1716
|
def copy_active_selection(x = nil)
|
1691
1717
|
debug "!COPY SELECTION"
|
1692
|
-
|
1718
|
+
@paste_lines = false
|
1693
1719
|
return if !@visual_mode
|
1694
1720
|
|
1695
1721
|
debug "COPY SELECTION"
|
@@ -1769,7 +1795,7 @@ class Buffer < String
|
|
1769
1795
|
debug "copy num_lines:#{num_lines}"
|
1770
1796
|
end
|
1771
1797
|
set_clipboard(self[line_range(@lpos, num_lines)])
|
1772
|
-
|
1798
|
+
@paste_lines = true
|
1773
1799
|
end
|
1774
1800
|
|
1775
1801
|
def put_file_path_to_clipboard
|
@@ -1789,6 +1815,7 @@ class Buffer < String
|
|
1789
1815
|
end
|
1790
1816
|
|
1791
1817
|
def end_visual_mode()
|
1818
|
+
return if !visual_mode?
|
1792
1819
|
debug "End visual mode"
|
1793
1820
|
#TODO:take previous mode (insert|command) from stack?
|
1794
1821
|
$kbd.set_mode(:command)
|
@@ -2028,7 +2055,7 @@ class Buffer < String
|
|
2028
2055
|
end
|
2029
2056
|
end
|
2030
2057
|
|
2031
|
-
#TODO
|
2058
|
+
#TODO: function not used
|
2032
2059
|
def write_to_file(savepath, s)
|
2033
2060
|
if is_path_writable(savepath)
|
2034
2061
|
IO.write(savepath, self.to_s)
|
@@ -15,6 +15,7 @@ class BufferManager
|
|
15
15
|
|
16
16
|
bindkey "bmgr enter", :bmgr_select
|
17
17
|
bindkey "bmgr c", :bmgr_close
|
18
|
+
bindkey "bmgr x", :close_current_buffer
|
18
19
|
end
|
19
20
|
|
20
21
|
def initialize()
|
@@ -60,7 +61,7 @@ class BufferManager
|
|
60
61
|
@@cur = self
|
61
62
|
@header = []
|
62
63
|
@header << "Current buffers:"
|
63
|
-
@header << "keys: <enter> to select, <c> to close buffer"
|
64
|
+
@header << "keys: <enter> to select, <c> to close buffer, <x> exit"
|
64
65
|
@header << "=" * 40
|
65
66
|
|
66
67
|
s = ""
|
data/lib/vimamsa/easy_jump.rb
CHANGED
data/lib/vimamsa/editor.rb
CHANGED
@@ -26,10 +26,6 @@ def handle_drag_and_drop(fname)
|
|
26
26
|
buf.handle_drag_and_drop(fname)
|
27
27
|
end
|
28
28
|
|
29
|
-
def mkdir_if_not_exists(_dirpath)
|
30
|
-
dirpath = File.expand_path(_dirpath)
|
31
|
-
Dir.mkdir(dirpath) unless File.exist?(dirpath)
|
32
|
-
end
|
33
29
|
|
34
30
|
class Editor
|
35
31
|
attr_reader :file_content_search_paths, :file_name_search_paths, :gui, :hook, :macro
|
@@ -49,6 +45,7 @@ class Editor
|
|
49
45
|
@converters = {}
|
50
46
|
@paint_stack = []
|
51
47
|
@_plugins = {}
|
48
|
+
@errors
|
52
49
|
end
|
53
50
|
|
54
51
|
def open_file_listener(added)
|
@@ -96,7 +93,7 @@ class Editor
|
|
96
93
|
|
97
94
|
FileManager.init
|
98
95
|
BufferManager.init
|
99
|
-
|
96
|
+
|
100
97
|
@gui.init_menu
|
101
98
|
|
102
99
|
mkdir_if_not_exists("~/.vimamsa")
|
@@ -135,10 +132,11 @@ class Editor
|
|
135
132
|
|
136
133
|
if conf(:enable_lsp)
|
137
134
|
require "vimamsa/langservp"
|
135
|
+
require "vimamsa/audio" # TODO:config
|
138
136
|
@langsrv["ruby"] = LangSrv.new("ruby")
|
139
137
|
@langsrv["cpp"] = LangSrv.new("cpp")
|
140
138
|
end
|
141
|
-
|
139
|
+
|
142
140
|
# build_options
|
143
141
|
|
144
142
|
fname = nil
|
@@ -169,7 +167,6 @@ class Editor
|
|
169
167
|
#Load plugins
|
170
168
|
require "vimamsa/file_history.rb"
|
171
169
|
@fh = FileHistory.new
|
172
|
-
# @_plugins[:FileFinder] = FileFinder.new
|
173
170
|
@_plugins[:FileHistory] = @fh
|
174
171
|
|
175
172
|
register_plugin(:FileHistory, @fh)
|
@@ -282,6 +279,11 @@ class Editor
|
|
282
279
|
debug "CAN OPEN?: #{can_open}"
|
283
280
|
return can_open
|
284
281
|
end
|
282
|
+
|
283
|
+
def error(message)
|
284
|
+
debug "ERORR #{caller[0]} #{str}", 2
|
285
|
+
@errors << [message, caller]
|
286
|
+
end
|
285
287
|
end
|
286
288
|
|
287
289
|
def _quit()
|
@@ -389,7 +391,7 @@ def show_key_bindings()
|
|
389
391
|
kbd_s << vma.kbd.to_s
|
390
392
|
kbd_s << "\n"
|
391
393
|
kbd_s << "===============================================\n"
|
392
|
-
b =
|
394
|
+
b = create_new_buffer(kbd_s, "key-bindings")
|
393
395
|
gui_set_file_lang(b.id, "hyperplaintext")
|
394
396
|
#
|
395
397
|
end
|
@@ -456,6 +458,11 @@ def minibuffer_delete()
|
|
456
458
|
$minibuffer.delete(BACKWARD_CHAR)
|
457
459
|
end
|
458
460
|
|
461
|
+
def error(str)
|
462
|
+
puts caller[0]
|
463
|
+
debug "#{caller[0]} ERROR: #{str}", 2
|
464
|
+
end
|
465
|
+
|
459
466
|
def message(s)
|
460
467
|
s = "[#{DateTime.now().strftime("%H:%M")}] #{s}"
|
461
468
|
debug s
|
@@ -502,18 +509,18 @@ def create_new_file(filename = nil, file_contents = "\n")
|
|
502
509
|
vma.kbd.set_mode_to_default
|
503
510
|
vma.buffers.set_current_buffer_by_id(buffer.id)
|
504
511
|
|
505
|
-
# Do set_content twice (once in Buffer.new) to force redraw and work around a bug
|
512
|
+
# Do set_content twice (once in Buffer.new) to force redraw and work around a bug
|
506
513
|
# The bug: if switching a child of scrolledWindow to a textview with a file smaller than the window, it won't get drawn properly if in previous (larger) file the ScrolledWindow was scrolled down.
|
507
514
|
buffer.set_content(file_contents)
|
508
515
|
|
509
516
|
return buffer
|
510
517
|
end
|
511
518
|
|
512
|
-
def create_new_buffer(file_contents = "\n",prefix="buf")
|
519
|
+
def create_new_buffer(file_contents = "\n", prefix = "buf", setcurrent = true)
|
513
520
|
debug "NEW BUFFER CREATED"
|
514
|
-
buffer = Buffer.new(file_contents,nil,prefix)
|
521
|
+
buffer = Buffer.new(file_contents, nil, prefix)
|
515
522
|
vma.buffers.add(buffer)
|
516
|
-
vma.buffers.set_current_buffer_by_id(buffer.id)
|
523
|
+
vma.buffers.set_current_buffer_by_id(buffer.id) if setcurrent
|
517
524
|
buffer.set_content(file_contents)
|
518
525
|
|
519
526
|
return buffer
|
@@ -585,6 +592,10 @@ def open_new_file(filename, file_contents = "")
|
|
585
592
|
message "Switching to: #{filename}"
|
586
593
|
vma.buffers.set_current_buffer(b)
|
587
594
|
else
|
595
|
+
if !is_path_writable(filename)
|
596
|
+
message("Path #{filename} cannot be written to")
|
597
|
+
return false
|
598
|
+
end
|
588
599
|
message "New file opened: #{filename}"
|
589
600
|
fname = filename
|
590
601
|
bf = load_buffer(fname)
|
@@ -622,45 +633,7 @@ def get_file_line_pointer(s)
|
|
622
633
|
return nil
|
623
634
|
end
|
624
635
|
|
625
|
-
|
626
|
-
system("xdg-open", url)
|
627
|
-
end
|
628
|
-
|
629
|
-
def open_with_default_program(url)
|
630
|
-
system("xdg-open", url)
|
631
|
-
end
|
632
|
-
|
633
|
-
def run_cmd(cmd)
|
634
|
-
tmpf = Tempfile.new("vmarun", "/tmp").path
|
635
|
-
cmd = "#{cmd} > #{tmpf}"
|
636
|
-
debug "CMD:\n#{cmd}"
|
637
|
-
system("bash", "-c", cmd)
|
638
|
-
res_str = File.read(tmpf)
|
639
|
-
return res_str
|
640
|
-
end
|
641
|
-
|
642
|
-
require "open3"
|
643
|
-
|
644
|
-
def exec_cmd(bin_name, arg1 = nil, arg2 = nil, arg3 = nil, arg4 = nil, arg5 = nil)
|
645
|
-
assert_binary_exists(bin_name)
|
646
|
-
if !arg5.nil?
|
647
|
-
p = Open3.popen2(bin_name, arg1, arg2, arg3, arg4, arg5)
|
648
|
-
elsif !arg4.nil?
|
649
|
-
p = Open3.popen2(bin_name, arg1, arg2, arg3, arg4)
|
650
|
-
elsif !arg3.nil?
|
651
|
-
p = Open3.popen2(bin_name, arg1, arg2, arg3)
|
652
|
-
elsif !arg2.nil?
|
653
|
-
p = Open3.popen2(bin_name, arg1, arg2)
|
654
|
-
elsif !arg1.nil?
|
655
|
-
p = Open3.popen2(bin_name, arg1)
|
656
|
-
else
|
657
|
-
p = Open3.popen2(bin_name)
|
658
|
-
end
|
659
|
-
|
660
|
-
ret_str = p[1].read
|
661
|
-
return ret_str
|
662
|
-
end
|
663
|
-
|
636
|
+
# TODO: Implement using https://github.com/blackwinter/ruby-filemagic
|
664
637
|
def file_is_text_file(fpath)
|
665
638
|
debug "file_is_text_file(#{fpath})"
|
666
639
|
fpath = File.expand_path(fpath)
|
data/lib/vimamsa/file_finder.rb
CHANGED
@@ -15,12 +15,12 @@ class FileFinder
|
|
15
15
|
|
16
16
|
def initialize()
|
17
17
|
vma.hook.register(:shutdown, self.method("save"))
|
18
|
-
|
18
|
+
@@dir_list = vma.marshal_load("file_index")
|
19
19
|
end
|
20
20
|
|
21
21
|
def save()
|
22
22
|
debug "SAVE FILE INDEX", 2
|
23
|
-
vma.marshal_save("file_index",
|
23
|
+
vma.marshal_save("file_index", @@dir_list)
|
24
24
|
end
|
25
25
|
|
26
26
|
def start_gui()
|
@@ -30,7 +30,7 @@ class FileFinder
|
|
30
30
|
end
|
31
31
|
l = []
|
32
32
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
33
|
-
if
|
33
|
+
if @@dir_list == nil
|
34
34
|
Thread.new { FileFinder.recursively_find_files() }
|
35
35
|
end
|
36
36
|
|
@@ -71,16 +71,16 @@ class FileFinder
|
|
71
71
|
debug("FIND FILEs IN #{d}")
|
72
72
|
dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and $find_extensions.include?(File.extname(e)) }
|
73
73
|
debug("FIND FILEs IN #{d} END")
|
74
|
-
end
|
75
|
-
|
76
|
-
@dir_list = dlist
|
74
|
+
end
|
75
|
+
@@dir_list = dlist
|
77
76
|
debug("END find files")
|
78
|
-
return
|
77
|
+
return @@dir_list
|
79
78
|
end
|
80
79
|
|
81
80
|
def filter_files(search_str)
|
82
81
|
dir_hash = {}
|
83
|
-
|
82
|
+
|
83
|
+
scores = Parallel.map(@@dir_list, in_threads: 8) do |file|
|
84
84
|
[file, srn_dst(search_str, file)]
|
85
85
|
end
|
86
86
|
for s in scores
|