vimamsa 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vma_project +0 -0
- data/README.md +110 -16
- data/exe/vimamsa +30 -22
- data/ext/vmaext/vmaext.c +0 -3
- data/lib/vimamsa.rb +1 -31
- data/lib/vimamsa/ack.rb +0 -4
- data/lib/vimamsa/actions.rb +20 -32
- data/lib/vimamsa/buffer.rb +84 -48
- data/lib/vimamsa/buffer_list.rb +4 -4
- data/lib/vimamsa/debug.rb +6 -6
- data/lib/vimamsa/easy_jump.rb +129 -125
- data/lib/vimamsa/editor.rb +51 -28
- data/lib/vimamsa/file_finder.rb +2 -2
- data/lib/vimamsa/file_history.rb +12 -5
- data/lib/vimamsa/gui.rb +561 -0
- data/lib/vimamsa/gui_gtk_sourceview.rb +294 -0
- data/lib/vimamsa/gui_menu.rb +100 -0
- data/lib/vimamsa/gui_select_window.rb +177 -0
- data/lib/vimamsa/gui_sourceview.rb +294 -0
- data/lib/vimamsa/{default_key_bindings.rb → key_actions.rb} +67 -189
- data/lib/vimamsa/key_binding_tree.rb +21 -9
- data/lib/vimamsa/key_bindings_vimlike.rb +259 -0
- data/lib/vimamsa/macro.rb +1 -1
- data/lib/vimamsa/main.rb +1 -2
- data/lib/vimamsa/rbvma.rb +17 -966
- data/lib/vimamsa/search.rb +0 -4
- data/lib/vimamsa/search_replace.rb +1 -2
- data/lib/vimamsa/util.rb +1 -1
- data/lib/vimamsa/version.rb +1 -1
- data/vimamsa.gemspec +4 -2
- metadata +43 -10
- data/ext/vimamsa/extconf.rb +0 -11
- data/ext/vimamsa/vimamsa.c +0 -174
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82ad35212b7d75bfd5b702943ff3ed3180f7f1bd0b3912840e9ecfdf6126e467
|
4
|
+
data.tar.gz: 8eff2ee35e1ecc2d791ff1fbf4a881e6aada9b38d35ce11e356b316b536bc642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 440d5d3b5b537fc9d3848d0f187df77dd045cde34643db356cd88ae5591e4e8c1c8596aac50f170ef7124dbd8784deddaff2d436f46dac0a8a180ccfeae4a9aa
|
7
|
+
data.tar.gz: c058e9db468553e29f617186ea0d65d04014307b7797c5dad013b5b3738fab57c0f7a44e7401ae9606e88581ac4f557fad3665c6dc8f784781619a310c114b95
|
data/.vma_project
ADDED
File without changes
|
data/README.md
CHANGED
@@ -1,35 +1,129 @@
|
|
1
1
|
# Vimamsa
|
2
2
|
|
3
|
-
|
3
|
+
Vi/Vim -inspired experimental GUI-oriented text editor written with Ruby and GTK.
|
4
4
|
|
5
|
-
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
- Ruby 2.0+
|
8
|
+
- GTK 3
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
9
|
-
Add this line to your application's Gemfile:
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
On Ubuntu:
|
14
|
+
```
|
15
|
+
sudo apt install ruby-dev
|
16
|
+
sudo gem install vimamsa
|
13
17
|
```
|
14
18
|
|
15
|
-
|
19
|
+
Run:
|
20
|
+
```
|
21
|
+
vimamsa
|
22
|
+
```
|
16
23
|
|
17
|
-
|
24
|
+
Packages for optional features:
|
25
|
+
```
|
26
|
+
sudo apt install ack-grep clang-format
|
27
|
+
```
|
18
28
|
|
19
|
-
|
29
|
+
For customization, edit dot_vimamsarc.rb and copy to ~/.vimamsarc
|
20
30
|
|
21
|
-
|
31
|
+
## Key bindings
|
22
32
|
|
23
|
-
|
33
|
+
Key bindings are very much like in VIm. For details, see file lib/vimamsa/key_bindings.rb and lib/vimamsa/default_bindings.rb
|
24
34
|
|
25
|
-
|
35
|
+
Keys that work somewhat similarly as in Vim:
|
26
36
|
|
27
|
-
|
37
|
+
In Command mode:
|
38
|
+
```
|
39
|
+
j k l h w b p P G f F ; 0 $ v i o J * / a A I u ctrl-r x
|
40
|
+
zz dd dw gg <linenum>G r<char>
|
41
|
+
```
|
42
|
+
|
43
|
+
In Visual mode:
|
44
|
+
```
|
45
|
+
d y gU gu
|
46
|
+
```
|
28
47
|
|
29
|
-
|
48
|
+
Keys that work differently to Vim are documented in the tables below
|
49
|
+
|
50
|
+
Syntax:
|
51
|
+
ctrl! means press and immediate release of ctrl key. Triggered by key up event.
|
52
|
+
ctrl-x means press and hold ctrl key, press x
|
53
|
+
|
54
|
+
<table>
|
55
|
+
<colgroup>
|
56
|
+
<col style="text-align:center;"/>
|
57
|
+
<col style="text-align:left;"/>
|
58
|
+
</colgroup>
|
59
|
+
|
60
|
+
<thead> <tr> <th style="text-align:center;" colspan="4">Command mode keys</th> </tr> </thead>
|
61
|
+
|
62
|
+
<tbody>
|
63
|
+
<tr><th>Key</th><th>Action</th></tr>
|
64
|
+
<tr><td style="text-align:center;">ctrl!</td> <td style="text-align:left;">switch between command and insert modes</td> </tr>
|
65
|
+
<tr> <td style="text-align:center;">z</td> <td style="text-align:left;"> enter into BROWSE mode</td></tr>
|
66
|
+
<tr> <td style="text-align:center;">shift!</td> <td style="text-align:left;">save file</td> </tr>
|
67
|
+
<tr> <td style="text-align:center;">s</td> <td style="text-align:left;">Easy jump (Similar to Vim EasyMotion https://github.com/easymotion/vim-easymotion ) </td> </tr>
|
68
|
+
<tr> <td style="text-align:center;">tab</td> <td style="text-align:left;">switch betwen current and previous buffer/file</td></tr>
|
69
|
+
<tr> <td style="text-align:center;">enter</td> <td style="text-align:left;"> (when cursor on link) open url in browser </td></tr>
|
70
|
+
<tr> <td style="text-align:center;">enter</td> <td style="text-align:left;">(when cursor on /path/to/file.txt:linenum ) open file in editor, jump to linenum </td></tr>
|
71
|
+
<tr> <td style="text-align:center;">,a</td> <td style="text-align:left;">Search for string using ack
|
72
|
+
</td></tr>
|
73
|
+
<tr> <td style="text-align:center;">,b</td> <td style="text-align:left;"> Switch buffer (jump to other open file)</td></tr>
|
74
|
+
<tr> <td style="text-align:center;">,g</td> <td style="text-align:left;">search for input string inside current buffer</td></tr>
|
75
|
+
<tr> <td style="text-align:center;">,f</td> <td style="text-align:left;">Fuzzy filename search</td></tr>
|
76
|
+
<tr> <td style="text-align:center;">space c</td> <td style="text-align:left;">insert character "c"</td></tr>
|
77
|
+
</tbody>
|
78
|
+
</table>
|
79
|
+
|
80
|
+
<table>
|
81
|
+
<colgroup>
|
82
|
+
<col style="text-align:center;"/>
|
83
|
+
<col style="text-align:left;"/>
|
84
|
+
</colgroup>
|
85
|
+
|
86
|
+
<thead> <tr> <th style="text-align:center;" colspan="4">Insert mode keys (similar to bash or emacs)</th> </tr> </thead>
|
87
|
+
|
88
|
+
<tbody>
|
89
|
+
<tr> <td style="text-align:center;">ctrl! OR esc</td> <td style="text-align:left;">Switch to command mode</td></tr>
|
90
|
+
<tr> <td style="text-align:center;">ctrl-n</td> <td style="text-align:left;">Move to next line</td></tr>
|
91
|
+
<tr> <td style="text-align:center;">ctrl-p</td> <td style="text-align:left;">Move to previous line</td></tr>
|
92
|
+
<tr> <td style="text-align:center;">ctrl-a</td> <td style="text-align:left;">Move beginning of line</td></tr>
|
93
|
+
<tr> <td style="text-align:center;">ctrl-e</td> <td style="text-align:left;">Move to end of line</td></tr>
|
94
|
+
<tr> <td style="text-align:center;">ctrl-b</td> <td style="text-align:left;">Move backward one char</td></tr>
|
95
|
+
<tr> <td style="text-align:center;">ctrl-f</td> <td style="text-align:left;">Move forward one char</td></tr>
|
96
|
+
<tr> <td style="text-align:center;">alt-f</td> <td style="text-align:left;">Move forward one word</td></tr>
|
97
|
+
<tr> <td style="text-align:center;">alt-b</td> <td style="text-align:left;">Move backward one word</td></tr>
|
98
|
+
</tbody>
|
99
|
+
</table>
|
100
|
+
|
101
|
+
|
102
|
+
<table>
|
103
|
+
<colgroup>
|
104
|
+
<col style="text-align:center;"/>
|
105
|
+
<col style="text-align:left;"/>
|
106
|
+
</colgroup>
|
107
|
+
|
108
|
+
<thead> <tr> <th style="text-align:center;" colspan="4">Browse mode keys</th> </tr> </thead>
|
109
|
+
|
110
|
+
<tbody>
|
111
|
+
<tr> <td style="text-align:center;">h</td> <td style="text-align:left;">jump to previous buffer in history</td></tr>
|
112
|
+
<tr> <td style="text-align:center;">l</td> <td style="text-align:left;">jump to next buffer in history</td></tr>
|
113
|
+
<tr> <td style="text-align:center;">q</td> <td style="text-align:left;">jump to previous edited position</td></tr>
|
114
|
+
<tr> <td style="text-align:center;">w</td> <td style="text-align:left;">jump to next edited position</td></tr>
|
115
|
+
<tr> <td style="text-align:center;">j OR esc</td> <td style="text-align:left;">switch from browse to command mode</td></tr>
|
116
|
+
</tbody>
|
117
|
+
</table>
|
118
|
+
|
119
|
+
Bindings can be customized in ~/.vimamsarc
|
120
|
+
For example, to bind ctrl-n to action "create new file":
|
121
|
+
```
|
122
|
+
bindkey 'C ctrl-n', 'create_new_file()'
|
123
|
+
```
|
30
124
|
|
31
|
-
|
125
|
+
## Current limitations
|
126
|
+
- UTF8 only
|
127
|
+
- Line endings with "\n"
|
32
128
|
|
33
|
-
## Contributing
|
34
129
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vimamsa.
|
data/exe/vimamsa
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
-
require
|
2
|
+
require "ripl/multi_line"
|
3
|
+
require "tempfile"
|
3
4
|
# Ripl.config[:multi_line_prompt] = ' > '
|
4
5
|
require "pathname"
|
5
6
|
|
@@ -7,28 +8,35 @@ ENV["GTK_THEME"] = "Adwaita:dark"
|
|
7
8
|
|
8
9
|
selfpath = __FILE__
|
9
10
|
selfpath = File.readlink(selfpath) if File.lstat(selfpath).symlink?
|
10
|
-
scriptdir = File.expand_path(File.dirname(selfpath)+"/..")
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
11
|
+
scriptdir = File.expand_path(File.dirname(selfpath) + "/..")
|
12
|
+
|
13
|
+
|
14
|
+
# If process is already running, open the parameter file in the running process and exit.
|
15
|
+
listen_dir = File.expand_path("~/.vimamsa/listen")
|
16
|
+
if File.exist?(listen_dir) and !ARGV[0].nil?
|
17
|
+
tmpf = Tempfile.new("vmarun", listen_dir)
|
18
|
+
fp = tmpf.path
|
19
|
+
paramfn = File.expand_path(ARGV[0])
|
20
|
+
puts paramfn
|
21
|
+
tmpf.write(paramfn)
|
22
|
+
tmpf.close
|
23
|
+
tstart = Time.new
|
24
|
+
timeout = false
|
25
|
+
while File.exist?(fp)
|
26
|
+
sleep 0.001
|
27
|
+
if Time.new - tstart > 0.5
|
28
|
+
timeout = true
|
29
|
+
break
|
30
|
+
end
|
31
|
+
end
|
32
|
+
exit(0) if !timeout
|
33
|
+
end
|
34
|
+
|
35
|
+
$LOAD_PATH.unshift(File.expand_path("lib"))
|
36
|
+
$LOAD_PATH.unshift(File.expand_path("ext"))
|
27
37
|
|
28
38
|
require "vimamsa"
|
29
|
-
# Ilib:ext
|
39
|
+
# Ilib:ext
|
30
40
|
# r rbvma -e "puts VMA.new.run"
|
31
|
-
$vmag =
|
41
|
+
$vmag = VMAgui.new()
|
32
42
|
$vmag.run
|
33
|
-
|
34
|
-
|
data/ext/vmaext/vmaext.c
CHANGED
data/lib/vimamsa.rb
CHANGED
@@ -1,42 +1,12 @@
|
|
1
1
|
require "vimamsa/version"
|
2
2
|
require "vmaext"
|
3
3
|
|
4
|
-
|
5
|
-
# require "vimamsa/constants"
|
6
|
-
# require "vimamsa/debug"
|
7
|
-
# require "vimamsa/actions"
|
8
|
-
# require "vimamsa/key_binding_tree"
|
9
|
-
# require "vimamsa/default_key_bindings"
|
10
|
-
|
11
|
-
# require "vimamsa/ack"
|
12
|
-
# require "vimamsa/buffer"
|
13
|
-
# require "vimamsa/buffer_list"
|
14
|
-
|
15
|
-
|
16
|
-
# require "vimamsa/easy_jump"
|
17
|
-
# require "vimamsa/editor"
|
18
|
-
# require "vimamsa/encrypt"
|
19
|
-
# require "vimamsa/file_finder"
|
20
|
-
# require "vimamsa/file_history"
|
21
|
-
# require "vimamsa/file_manager"
|
22
|
-
# require "vimamsa/hook"
|
23
|
-
# require "vimamsa/hyper_plain_text"
|
24
|
-
# require "vimamsa/macro"
|
25
|
-
# require "vimamsa/rbvma"
|
26
|
-
# require "vimamsa/search"
|
27
|
-
# require "vimamsa/search_replace"
|
28
|
-
# require "vimamsa/text_transforms"
|
29
|
-
# require "vimamsa/util"
|
30
|
-
# # require "version"
|
31
|
-
|
32
|
-
# require "vimamsa/main"
|
33
|
-
|
34
4
|
require "vimamsa/rbvma"
|
35
5
|
|
36
6
|
module Vimamsa
|
37
7
|
# Your code goes here...
|
38
8
|
def self.test
|
39
9
|
puts "Vimamsa test"
|
40
|
-
puts srn_dst("foobar","baz")
|
10
|
+
puts srn_dst("foobar", "baz")
|
41
11
|
end
|
42
12
|
end
|
data/lib/vimamsa/ack.rb
CHANGED
data/lib/vimamsa/actions.rb
CHANGED
@@ -1,73 +1,62 @@
|
|
1
1
|
class Action
|
2
|
-
attr_accessor :id, :method_name, :method
|
2
|
+
attr_accessor :id, :method_name, :method, :opt
|
3
3
|
|
4
|
-
def initialize(id, method_name, method,
|
4
|
+
def initialize(id, method_name, method, opt = {})
|
5
5
|
@method_name = method_name
|
6
6
|
@id = id
|
7
7
|
@method = method
|
8
|
+
@opt = opt
|
9
|
+
|
8
10
|
$actions[id] = self
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
14
|
$actions = {}
|
13
15
|
|
14
|
-
|
15
|
-
# if callfunc.class == Proc
|
16
|
-
# a = Action.new(id, name, callfunc, scope)
|
17
|
-
# else
|
18
|
-
# a = Action.new(id, name, method(callfunc), scope)
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
|
22
|
-
def reg_act(id, callfunc, name = "", scope = [])
|
16
|
+
def reg_act(id, callfunc, name = "", opt = {})
|
23
17
|
if callfunc.class == Proc
|
24
|
-
a = Action.new(id, name, callfunc,
|
18
|
+
a = Action.new(id, name, callfunc, opt)
|
25
19
|
else
|
26
20
|
begin
|
27
21
|
m = method(callfunc)
|
28
22
|
rescue NameError
|
29
23
|
m = method("missing_callfunc")
|
30
24
|
end
|
31
|
-
a = Action.new(id, name, m,
|
25
|
+
a = Action.new(id, name, m, opt)
|
32
26
|
end
|
27
|
+
return a
|
33
28
|
end
|
34
29
|
|
35
30
|
def missing_callfunc
|
36
31
|
puts "missing_callfunc"
|
37
32
|
end
|
38
33
|
|
39
|
-
|
34
|
+
#TODO: remove
|
40
35
|
def call(id)
|
36
|
+
call_action(id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def call_action(id)
|
41
40
|
a = $actions[id]
|
42
41
|
if a
|
43
|
-
# Ripl.start :binding => binding
|
44
42
|
a.method.call()
|
43
|
+
else
|
44
|
+
message("Unknown action: " + id.inspect)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def search_actions()
|
49
49
|
l = []
|
50
50
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
52
|
+
"search_actions_select_callback",
|
53
|
+
"search_actions_update_callback")
|
54
54
|
end
|
55
55
|
|
56
56
|
$item_list = []
|
57
57
|
|
58
58
|
def search_actions_update_callback(search_str = "")
|
59
|
-
# item_list = $actions.collect {|x| x[1].id.to_s}
|
60
59
|
return [] if search_str == ""
|
61
|
-
# item_list = $action_list.collect { |x|
|
62
|
-
# actname = x[:action].to_s
|
63
|
-
# if x[:action].class == Symbol
|
64
|
-
# mn = $actions[x[:action]].method_name
|
65
|
-
# actname = mn if mn.size > 0
|
66
|
-
# end
|
67
|
-
# r = { :str => actname, :key => x[:key], :action => x[:action] }
|
68
|
-
# }
|
69
|
-
|
70
|
-
# => {:str=>"insert_new_line", :key=>"I return", :action=>:insert_new_line}
|
71
60
|
|
72
61
|
item_list2 = []
|
73
62
|
for act_id in $actions.keys
|
@@ -81,7 +70,7 @@ def search_actions_update_callback(search_str = "")
|
|
81
70
|
end
|
82
71
|
item_list2 << item
|
83
72
|
end
|
84
|
-
|
73
|
+
|
85
74
|
item_list = item_list2
|
86
75
|
|
87
76
|
a = filter_items(item_list, 0, search_str)
|
@@ -90,7 +79,6 @@ def search_actions_update_callback(search_str = "")
|
|
90
79
|
r = a.collect { |x| [x[0][0], 0, x] }
|
91
80
|
puts r.inspect
|
92
81
|
$item_list = r
|
93
|
-
# Ripl.start :binding => binding
|
94
82
|
|
95
83
|
r = a.collect { |x| ["[#{x[0][:key]}] #{x[0][:str]}", 0, x] }
|
96
84
|
return r
|
@@ -101,7 +89,7 @@ def search_actions_select_callback(search_str, idx)
|
|
101
89
|
acc = item[0][:action]
|
102
90
|
|
103
91
|
puts "Selected:" + acc.to_s
|
104
|
-
|
92
|
+
gui_select_window_close(0)
|
105
93
|
|
106
94
|
if acc.class == String
|
107
95
|
eval(acc)
|
data/lib/vimamsa/buffer.rb
CHANGED
@@ -15,7 +15,7 @@ class Buffer < String
|
|
15
15
|
|
16
16
|
attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang
|
17
17
|
attr_writer :call_func, :update_highlight
|
18
|
-
attr_accessor :
|
18
|
+
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
|
19
19
|
|
20
20
|
@@num_buffers = 0
|
21
21
|
|
@@ -26,10 +26,9 @@ class Buffer < String
|
|
26
26
|
@lang = nil
|
27
27
|
@id = @@num_buffers
|
28
28
|
@@num_buffers += 1
|
29
|
-
|
29
|
+
gui_create_buffer(@id)
|
30
30
|
puts "NEW BUFFER fn=#{fname} ID:#{@id}"
|
31
31
|
|
32
|
-
#
|
33
32
|
@module = nil
|
34
33
|
|
35
34
|
@crypt = nil
|
@@ -47,7 +46,21 @@ class Buffer < String
|
|
47
46
|
@hl_queue = []
|
48
47
|
@line_action_handler = nil
|
49
48
|
|
49
|
+
@dirname = nil
|
50
|
+
@title = "*buf-#{@id}*"
|
51
|
+
@subtitle = ""
|
52
|
+
|
53
|
+
if @fname
|
54
|
+
@title = File.basename(@fname)
|
55
|
+
@dirname = File.dirname(@fname)
|
56
|
+
userhome = File.expand_path("~")
|
57
|
+
@subtitle = @dirname.gsub(/^#{userhome}/, "~")
|
58
|
+
end
|
59
|
+
|
50
60
|
t1 = Time.now
|
61
|
+
gui_set_current_buffer(@id)
|
62
|
+
gui_set_window_title(@title, @subtitle)
|
63
|
+
|
51
64
|
set_content(str)
|
52
65
|
debug "init time:#{Time.now - t1}"
|
53
66
|
|
@@ -63,7 +76,7 @@ class Buffer < String
|
|
63
76
|
else
|
64
77
|
$kbd.set_mode_to_default
|
65
78
|
end
|
66
|
-
|
79
|
+
# gui_set_current_buffer(@id)
|
67
80
|
end
|
68
81
|
|
69
82
|
def detect_file_language
|
@@ -73,6 +86,20 @@ class Buffer < String
|
|
73
86
|
@lang = "ruby" if @fname.match(/\.(rb)$/)
|
74
87
|
@lang = "hyperplaintext" if @fname.match(/\.(txt)$/)
|
75
88
|
@lang = "php" if @fname.match(/\.(php)$/)
|
89
|
+
|
90
|
+
lm = GtkSource::LanguageManager.new
|
91
|
+
|
92
|
+
lm.set_search_path(lm.search_path << ppath("lang/"))
|
93
|
+
lang = lm.guess_language(@fname)
|
94
|
+
# lang.get_metadata("line-comment-start")
|
95
|
+
# lang.get_metadata("block-comment-start")
|
96
|
+
# lang.get_metadata("block-comment-end")
|
97
|
+
@lang_nfo = lang
|
98
|
+
if !lang.nil? and !lang.id.nil?
|
99
|
+
puts "Guessed LANG: #{lang.id}"
|
100
|
+
@lang = lang.id
|
101
|
+
end
|
102
|
+
|
76
103
|
if @lang
|
77
104
|
gui_set_file_lang(@id, @lang)
|
78
105
|
end
|
@@ -81,8 +108,7 @@ class Buffer < String
|
|
81
108
|
def add_image(imgpath, pos)
|
82
109
|
return if !is_legal_pos(pos)
|
83
110
|
# insert_txt_at(" ", pos)
|
84
|
-
|
85
|
-
qt_add_image(imgpath, pos)
|
111
|
+
gui_add_image(imgpath, pos)
|
86
112
|
end
|
87
113
|
|
88
114
|
def is_legal_pos(pos, op = :read)
|
@@ -114,7 +140,6 @@ class Buffer < String
|
|
114
140
|
b = " \n"
|
115
141
|
txt = a + b
|
116
142
|
insert_txt_at(txt, lr.end + 1)
|
117
|
-
qt_process_deltas
|
118
143
|
imgpos = lr.end + 1 + a.size
|
119
144
|
add_image(fname, imgpos)
|
120
145
|
end
|
@@ -134,21 +159,7 @@ class Buffer < String
|
|
134
159
|
end
|
135
160
|
|
136
161
|
def get_file_type()
|
137
|
-
|
138
|
-
if !@fname
|
139
|
-
@syntax_detect_failed = true
|
140
|
-
return ""
|
141
|
-
end
|
142
|
-
if @ftype == nil
|
143
|
-
@ftype = VER::Syntax::Detector.detect(@fname)
|
144
|
-
if @ftype == nil
|
145
|
-
@syntax_detect_failed = true
|
146
|
-
else
|
147
|
-
@syntax_detect_failed = false
|
148
|
-
end
|
149
|
-
end
|
150
|
-
debug "ftype=#{@ftype.inspect}"
|
151
|
-
return @ftype
|
162
|
+
return @lang
|
152
163
|
end
|
153
164
|
|
154
165
|
def revert()
|
@@ -196,7 +207,7 @@ class Buffer < String
|
|
196
207
|
|
197
208
|
def set_content(str)
|
198
209
|
@encrypted_str = nil
|
199
|
-
@
|
210
|
+
@gui_update_highlight = true
|
200
211
|
@ftype = nil
|
201
212
|
if str[0..10] == "VMACRYPT001"
|
202
213
|
@encrypted_str = str[11..-1]
|
@@ -250,7 +261,7 @@ class Buffer < String
|
|
250
261
|
@update_hl_startpos = 0 #TODO
|
251
262
|
@update_hl_endpos = self.size - 1
|
252
263
|
|
253
|
-
|
264
|
+
gui_set_buffer_contents(@id, self.to_s)
|
254
265
|
|
255
266
|
# add_hl_update(@update_hl_startpos, @update_hl_endpos)
|
256
267
|
end
|
@@ -259,6 +270,12 @@ class Buffer < String
|
|
259
270
|
@fname = filename
|
260
271
|
@pathname = Pathname.new(fname) if @fname
|
261
272
|
@basename = @pathname.basename if @fname
|
273
|
+
|
274
|
+
@title = File.basename(@fname)
|
275
|
+
@dirname = File.dirname(@fname)
|
276
|
+
userhome = File.expand_path("~")
|
277
|
+
@subtitle = @dirname.gsub(/^#{userhome}/, "~")
|
278
|
+
|
262
279
|
detect_file_language
|
263
280
|
end
|
264
281
|
|
@@ -488,16 +505,26 @@ class Buffer < String
|
|
488
505
|
end
|
489
506
|
|
490
507
|
def get_com_str()
|
491
|
-
return nil if @syntax_detect_failed
|
508
|
+
# return nil if @syntax_detect_failed
|
492
509
|
|
493
510
|
com_str = nil
|
494
|
-
if get_file_type() == "
|
495
|
-
|
496
|
-
elsif get_file_type() == "
|
497
|
-
|
498
|
-
else
|
499
|
-
|
511
|
+
# if get_file_type() == "c" or get_file_type() == "java"
|
512
|
+
# com_str = "//"
|
513
|
+
# elsif get_file_type() == "ruby"
|
514
|
+
# com_str = "#"
|
515
|
+
# else
|
516
|
+
# com_str = "//"
|
517
|
+
# end
|
518
|
+
|
519
|
+
if !@lang_nfo.nil?
|
520
|
+
com_str = @lang_nfo.get_metadata("line-comment-start")
|
500
521
|
end
|
522
|
+
|
523
|
+
# lang.get_metadata("block-comment-start")
|
524
|
+
# lang.get_metadata("block-comment-end")
|
525
|
+
|
526
|
+
com_str = "//" if com_str.nil?
|
527
|
+
|
501
528
|
return com_str
|
502
529
|
end
|
503
530
|
|
@@ -729,7 +756,7 @@ class Buffer < String
|
|
729
756
|
elsif new_pos >= 0
|
730
757
|
@pos = new_pos
|
731
758
|
end
|
732
|
-
|
759
|
+
gui_set_cursor_pos(@id, @pos)
|
733
760
|
calculate_line_and_column_pos
|
734
761
|
end
|
735
762
|
|
@@ -1262,6 +1289,7 @@ class Buffer < String
|
|
1262
1289
|
end
|
1263
1290
|
|
1264
1291
|
def jump_to_next_instance_of_char(char, direction = FORWARD)
|
1292
|
+
|
1265
1293
|
#return if at_end_of_line?
|
1266
1294
|
if direction == FORWARD
|
1267
1295
|
position_of_next_char = self.index(char, @pos + 1)
|
@@ -1457,7 +1485,6 @@ class Buffer < String
|
|
1457
1485
|
def start_visual_mode()
|
1458
1486
|
@visual_mode = true
|
1459
1487
|
@selection_start = @pos
|
1460
|
-
qt_set_selection_start(@id, selection_start)
|
1461
1488
|
$kbd.set_mode(:visual)
|
1462
1489
|
end
|
1463
1490
|
|
@@ -1613,17 +1640,17 @@ class Buffer < String
|
|
1613
1640
|
savepath = buflist.get_last_dir
|
1614
1641
|
end
|
1615
1642
|
# Ripl.start :binding => binding
|
1616
|
-
|
1643
|
+
gui_file_saveas(savepath)
|
1617
1644
|
# calls back to file_saveas
|
1618
|
-
# TODO:?
|
1619
1645
|
end
|
1620
1646
|
|
1621
|
-
def
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1647
|
+
def save_as_callback(fpath)
|
1648
|
+
set_filename(fpath)
|
1649
|
+
save()
|
1650
|
+
gui_set_window_title(@title, @subtitle) #TODO: if not active buffer?
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
def write_contents_to_file(fpath)
|
1627
1654
|
if @crypt != nil
|
1628
1655
|
mode = "wb+"
|
1629
1656
|
contents = "VMACRYPT001" + @crypt.encrypt(self.to_s)
|
@@ -1633,7 +1660,7 @@ class Buffer < String
|
|
1633
1660
|
end
|
1634
1661
|
|
1635
1662
|
Thread.new {
|
1636
|
-
File.open(
|
1663
|
+
File.open(fpath, mode) do |io|
|
1637
1664
|
#io.set_encoding(self.encoding)
|
1638
1665
|
|
1639
1666
|
begin
|
@@ -1653,6 +1680,15 @@ class Buffer < String
|
|
1653
1680
|
}
|
1654
1681
|
end
|
1655
1682
|
|
1683
|
+
def save()
|
1684
|
+
if !@fname
|
1685
|
+
save_as()
|
1686
|
+
return
|
1687
|
+
end
|
1688
|
+
message("Saving file #{@fname}")
|
1689
|
+
write_contents_to_file(@fname)
|
1690
|
+
end
|
1691
|
+
|
1656
1692
|
# Indents whole buffer using external program
|
1657
1693
|
def indent()
|
1658
1694
|
file = Tempfile.new("out")
|
@@ -1665,7 +1701,7 @@ class Buffer < String
|
|
1665
1701
|
|
1666
1702
|
message("Auto format #{@fname}")
|
1667
1703
|
|
1668
|
-
if
|
1704
|
+
if ["chdr", "c", "cpp"].include?(get_file_type())
|
1669
1705
|
|
1670
1706
|
#C/C++/Java/JavaScript/Objective-C/Protobuf code
|
1671
1707
|
system("clang-format -style='{BasedOnStyle: LLVM, ColumnLimit: 100, SortIncludes: false}' #{file.path} > #{infile.path}")
|
@@ -1675,7 +1711,7 @@ class Buffer < String
|
|
1675
1711
|
debug cmd
|
1676
1712
|
system(cmd)
|
1677
1713
|
bufc = IO.read(infile.path)
|
1678
|
-
elsif get_file_type() == "
|
1714
|
+
elsif get_file_type() == "ruby"
|
1679
1715
|
cmd = "rufo #{file.path}"
|
1680
1716
|
debug cmd
|
1681
1717
|
system(cmd)
|
@@ -1692,21 +1728,21 @@ class Buffer < String
|
|
1692
1728
|
def backup()
|
1693
1729
|
fname = @fname
|
1694
1730
|
return if !@fname
|
1695
|
-
message("Backup buffer #{fname}")
|
1696
1731
|
spfx = fname.gsub("=", "==").gsub("/", "=:")
|
1697
|
-
spath = File.expand_path("
|
1732
|
+
spath = File.expand_path("~/.vimamsa/backup")
|
1698
1733
|
return false if !can_save_to_directory?(spath)
|
1699
1734
|
datetime = DateTime.now().strftime("%d%m%Y:%H%M%S")
|
1700
1735
|
savepath = "#{spath}/#{spfx}_#{datetime}"
|
1736
|
+
message("Backup buffer #{fname} TO: #{savepath}")
|
1701
1737
|
if is_path_writable(savepath)
|
1702
|
-
|
1703
|
-
IO.write(savepath, self.to_s) if @crypt == nil #TODO: For encrypted
|
1738
|
+
write_contents_to_file(savepath)
|
1704
1739
|
else
|
1705
1740
|
message("PATH NOT WRITABLE: #{savepath}")
|
1706
1741
|
end
|
1707
1742
|
end
|
1708
1743
|
end
|
1709
1744
|
|
1745
|
+
#TODO
|
1710
1746
|
def write_to_file(savepath, s)
|
1711
1747
|
if is_path_writable(savepath)
|
1712
1748
|
IO.write(savepath, $buffer.to_s)
|