vimamsa 0.1.0 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97b4b0a7b81410ecd6f7160ba4c8fa9e5d2bb125bccaeb501d3f3bb4d098d0ab
4
- data.tar.gz: 60ad13b4c18d779fc6ace8748932fa6d385d9f4956d138bc50ab14d3851907a3
3
+ metadata.gz: 4f68b029a6b5f374740c9afa2cb7c4ac628db4c4b9295b7e64db8294dac89659
4
+ data.tar.gz: c7c72c69ec7cd513e976caff3b0b1f2e619d890d8d84e616fcd747e4ab1193be
5
5
  SHA512:
6
- metadata.gz: c983fab629336a92be306b261835a72b1bccf98214e5be01f28dc4bc25b9c0c2e4a619e0bc256ca439680c1b12e5d510c12e52fe7b7cb9b34bdcc89ad7030670
7
- data.tar.gz: 97b140540ca2951ffdef4627bcf907dc3408392ca1cdd123868f4d4cc03ead689973527a485240bd0232414ffbb26eadaacf9401c742633b62ddb7f5543898c9
6
+ metadata.gz: 892b4011a44310ad05becbf108fce73d4cdda3a25d6241435b03519ad0dd264daa856502956f02f47386bce251aef3e0296cc682fc35b01fefa375fbffd5ee4a
7
+ data.tar.gz: 25c97fde0e225c7cb273bc0fa97d0db4d74376ea2ddca2baea8823dbb1e01d31334fabbaa8e319cc37d40eca23d37b3d64f2cbbbdcbbce88f7d30435cfb44a6f
data/.vma_project ADDED
File without changes
data/README.md CHANGED
@@ -1,35 +1,129 @@
1
1
  # Vimamsa
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vimamsa`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Vi/Vim -inspired experimental GUI-oriented text editor written with Ruby and GTK.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- ```ruby
12
- gem 'vimamsa'
13
+ On Ubuntu:
14
+ ```
15
+ sudo apt install ruby-dev
16
+ sudo gem install vimamsa
13
17
  ```
14
18
 
15
- And then execute:
19
+ Run:
20
+ ```
21
+ vimamsa
22
+ ```
16
23
 
17
- $ bundle
24
+ Packages for optional features:
25
+ ```
26
+ sudo apt install ack-grep clang-format
27
+ ```
18
28
 
19
- Or install it yourself as:
29
+ For customization, edit dot_vimamsarc.rb and copy to ~/.vimamsarc
20
30
 
21
- $ gem install vimamsa
31
+ ## Key bindings
22
32
 
23
- ## Usage
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
- TODO: Write usage instructions here
35
+ Keys that work somewhat similarly as in Vim:
26
36
 
27
- ## Development
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
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby
2
+ require "ripl/multi_line"
3
+ require "tempfile"
4
+ # Ripl.config[:multi_line_prompt] = ' > '
5
+ require "pathname"
6
+
7
+ ENV["GTK_THEME"] = "Adwaita:dark"
8
+
9
+ selfpath = __FILE__
10
+ selfpath = File.readlink(selfpath) if File.lstat(selfpath).symlink?
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
+ tmpf.write(ARGV[0])
20
+ tmpf.close
21
+ tstart = Time.new
22
+ timeout = false
23
+ while File.exist?(fp)
24
+ sleep 0.001
25
+ if Time.new - tstart > 0.5
26
+ timeout = true
27
+ break
28
+ end
29
+ end
30
+ exit(0) if !timeout
31
+ end
32
+
33
+ $LOAD_PATH.unshift(File.expand_path("lib"))
34
+ $LOAD_PATH.unshift(File.expand_path("ext"))
35
+
36
+ require "vimamsa"
37
+ # Ilib:ext
38
+ # r rbvma -e "puts VMA.new.run"
39
+ $vmag = VMAg.new()
40
+ $vmag.run
data/ext/vmaext/vmaext.c CHANGED
@@ -3,11 +3,8 @@
3
3
  #include "ruby/ruby.h"
4
4
 
5
5
  #include <stdio.h>
6
- #include <string.h>
7
6
  #include <stdlib.h>
8
7
 
9
- #warning "C Preprocessor got here!"
10
-
11
8
  typedef struct node {
12
9
  int i;
13
10
  void * next;
@@ -0,0 +1,129 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+
4
+ This file is part of GtkSourceView
5
+
6
+ Authors: Marco Barisione, Emanuele Aina
7
+ Copyright (C) 2005-2007 Marco Barisione <barisione@gmail.com>
8
+ Copyright (C) 2005-2007 Emanuele Aina
9
+
10
+ GtkSourceView is free software; you can redistribute it and/or
11
+ modify it under the terms of the GNU Lesser General Public
12
+ License as published by the Free Software Foundation; either
13
+ version 2.1 of the License, or (at your option) any later version.
14
+
15
+ GtkSourceView is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ Lesser General Public License for more details.
19
+
20
+ You should have received a copy of the GNU Lesser General Public License
21
+ along with this library; if not, see <http://www.gnu.org/licenses/>.
22
+
23
+ -->
24
+ <language id="hyperplaintext" name="HyperPlainText" version="2.0" _section="Source">
25
+ <metadata>
26
+ <property name="mimetypes">text/x-c;text/x-csrc;image/x-xpixmap</property>
27
+ <property name="globs">*.txt</property>
28
+ </metadata>
29
+
30
+ <styles>
31
+ <style id="comment" name="Comment" map-to="def:comment"/>
32
+ <style id="title" name="title" map-to="def:title"/>
33
+ <style id="hyperlink" name="hyperlink" map-to="def:hyperlink"/>
34
+ <style id="heading1" name="heading1" map-to="def:heading1"/>
35
+ <style id="heading2" name="heading1" map-to="def:heading2"/>
36
+ <style id="heading3" name="heading1" map-to="def:heading3"/>
37
+ <style id="heading4" name="heading1" map-to="def:heading4"/>
38
+ <style id="string" name="String" map-to="def:string"/>
39
+ <style id="floating-point" name="Floating point number" map-to="def:floating-point"/>
40
+ </styles>
41
+
42
+ <definitions>
43
+
44
+ <!--regexs-->
45
+ <define-regex id="preproc-start">^\s*#\s*</define-regex>
46
+ <define-regex id="escaped-character" extended="true">
47
+ \\( # leading backslash
48
+ [\\\"\'nrbtfav\?] | # escaped character
49
+ [0-7]{1,3} | # one, two, or three octal digits
50
+ x[0-9A-Fa-f]+ # 'x' followed by hex digits
51
+ )
52
+ </define-regex>
53
+
54
+ <!--contexts NOT used on the main context-->
55
+ <!-- TODO: what about scanf ? -->
56
+ <!-- man 3 printf -->
57
+ <context id="printf" style-ref="printf" extend-parent="false">
58
+ <match extended="true">
59
+ \%\%|\%
60
+ (?:[1-9][0-9]*\$)? # argument
61
+ [#0\-\ \+\'I]* # flags
62
+ (?:[1-9][0-9]*|\*)? # width
63
+ (?:\.\-?(?:[0-9]+|\*))? # precision
64
+ (?:hh|ll|[hlLqjzt])? # length modifier
65
+ [diouxXeEfFgGaAcsCSpnm] # conversion specifier
66
+ </match>
67
+ </context>
68
+
69
+
70
+ <context id="heading1" style-ref="heading1">
71
+ <match>(^◼[^◼].*)*</match>
72
+ </context>
73
+
74
+ <context id="heading2" style-ref="heading2">
75
+ <match>(^◼◼[^◼].*)*</match>
76
+ </context>
77
+
78
+ <context id="heading3" style-ref="heading3">
79
+ <match>(^◼◼◼[^◼].*)*</match>
80
+ </context>
81
+
82
+ <context id="heading4" style-ref="heading4">
83
+ <match>(^◼◼◼◼[^◼].*)*</match>
84
+ </context>
85
+
86
+ <context id="title" style-ref="title">
87
+ <match>(^❙.*❙)</match>
88
+ </context>
89
+
90
+ <context id="hyperlink" style-ref="hyperlink">
91
+ <match>(⟦.*⟧)</match>
92
+ </context>
93
+
94
+
95
+ <!-- http://www.lysator.liu.se/c/ANSI-C-grammar-l.html -->
96
+ <context id="float" style-ref="floating-point">
97
+ <match extended="true">
98
+ (?&lt;![\w\.])
99
+ ((\.[0-9]+ | [0-9]+\.[0-9]*) ([Ee][+-]?[0-9]*)? |
100
+ ([0-9]+[Ee][+-]?[0-9]*))
101
+ [fFlL]?
102
+ (?![\w\.])
103
+ </match>
104
+ </context>
105
+
106
+ <context id="decimal" style-ref="decimal">
107
+ <match extended="true">
108
+ (?&lt;![\w\.])
109
+ (0|[1-9][0-9]*)[uUlL]*
110
+ (?![\w\.])
111
+ </match>
112
+ </context>
113
+
114
+
115
+ <!--Main context-->
116
+ <context id="hyperplaintext" class="no-spell-check">
117
+ <include>
118
+ <context ref="title"/>
119
+ <context ref="hyperlink"/>
120
+ <context ref="heading1"/>
121
+ <context ref="heading2"/>
122
+ <context ref="heading3"/>
123
+ <context ref="heading4"/>
124
+ <context ref="float"/>
125
+ </include>
126
+ </context>
127
+
128
+ </definitions>
129
+ </language>
data/lib/vimamsa.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require "vimamsa/version"
2
2
  require "vmaext"
3
3
 
4
+ require "vimamsa/rbvma"
5
+
4
6
  module Vimamsa
5
7
  # Your code goes here...
6
8
  def self.test
7
9
  puts "Vimamsa test"
8
- puts srn_dst("foobar","baz")
10
+ puts srn_dst("foobar", "baz")
9
11
  end
10
12
  end
@@ -0,0 +1,35 @@
1
+ # Interface for ack! https://beyondgrep.com/
2
+
3
+ def gui_ack()
4
+ nfo = "<html><h2>Search contents of all files using ack</h2>
5
+ <div style='width:300px'>
6
+ <p>Hint: add empty file named .vma_project to dirs you want to search.</p>\n<p>If .vma_project exists in parent dir of current file, searches within that dir</p></div></html>"
7
+
8
+ nfo = "<span size='x-large'>Search contents of all files using ack</span>
9
+
10
+ <span>Hint: add empty file named .vma_project to directories you want to search in.
11
+ If .vma_project exists in parent directory of current file, searches within that directory.
12
+ </span>"
13
+
14
+
15
+ callback = proc{|x| ack_buffer(x)}
16
+ gui_one_input_action(nfo, "Search:", "search", callback)
17
+ end
18
+
19
+ def invoke_ack_search()
20
+ start_minibuffer_cmd("", "", :ack_buffer)
21
+ end
22
+
23
+ def ack_buffer(instr, b = nil)
24
+ instr = instr.gsub("'", ".") # TODO
25
+ bufstr = ""
26
+ for path in $vma.get_content_search_paths
27
+ bufstr += run_cmd("ack -Q --type-add=gd=.gd -k --nohtml --nojs --nojson '#{instr}' #{path}")
28
+ end
29
+ if bufstr.size > 5
30
+ create_new_file(nil, bufstr)
31
+ else
32
+ message("No results for input:#{instr}")
33
+ end
34
+ end
35
+
@@ -0,0 +1,125 @@
1
+ class Action
2
+ attr_accessor :id, :method_name, :method
3
+
4
+ def initialize(id, method_name, method, scope = [])
5
+ @method_name = method_name
6
+ @id = id
7
+ @method = method
8
+ $actions[id] = self
9
+ end
10
+ end
11
+
12
+ $actions = {}
13
+
14
+ # def reg_act(id, callfunc, name = "", scope = [])
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 = [])
23
+ if callfunc.class == Proc
24
+ a = Action.new(id, name, callfunc, scope)
25
+ else
26
+ begin
27
+ m = method(callfunc)
28
+ rescue NameError
29
+ m = method("missing_callfunc")
30
+ end
31
+ a = Action.new(id, name, m, scope)
32
+ end
33
+ end
34
+
35
+ def missing_callfunc
36
+ puts "missing_callfunc"
37
+ end
38
+
39
+
40
+ def call(id)
41
+ a = $actions[id]
42
+ if a
43
+ # Ripl.start :binding => binding
44
+ a.method.call()
45
+ end
46
+ end
47
+
48
+ def search_actions()
49
+ l = []
50
+ $select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
51
+ qt_select_update_window(l, $select_keys.collect { |x| x.upcase },
52
+ "search_actions_select_callback",
53
+ "search_actions_update_callback")
54
+ end
55
+
56
+ $item_list = []
57
+
58
+ def search_actions_update_callback(search_str = "")
59
+ # item_list = $actions.collect {|x| x[1].id.to_s}
60
+ 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
+
72
+ item_list2 = []
73
+ for act_id in $actions.keys
74
+ act = $actions[act_id]
75
+ item = {}
76
+ item[:key] = ""
77
+ item[:action] = act_id
78
+ item[:str] = act_id.to_s
79
+ if $actions[act_id].method_name != ""
80
+ item[:str] = $actions[act_id].method_name
81
+ end
82
+ item_list2 << item
83
+ end
84
+ # Ripl.start :binding => binding
85
+ item_list = item_list2
86
+
87
+ a = filter_items(item_list, 0, search_str)
88
+ puts a.inspect
89
+
90
+ r = a.collect { |x| [x[0][0], 0, x] }
91
+ puts r.inspect
92
+ $item_list = r
93
+ # Ripl.start :binding => binding
94
+
95
+ r = a.collect { |x| ["[#{x[0][:key]}] #{x[0][:str]}", 0, x] }
96
+ return r
97
+ end
98
+
99
+ def search_actions_select_callback(search_str, idx)
100
+ item = $item_list[idx][2]
101
+ acc = item[0][:action]
102
+
103
+ puts "Selected:" + acc.to_s
104
+ qt_select_window_close(0)
105
+
106
+ if acc.class == String
107
+ eval(acc)
108
+ elsif acc.class == Symbol
109
+ puts "Symbol"
110
+ call(acc)
111
+ end
112
+ end
113
+
114
+ def filter_items(item_list, item_key, search_str)
115
+ # Ripl.start :binding => binding
116
+ item_hash = {}
117
+ scores = Parallel.map(item_list, in_threads: 8) do |item|
118
+ [item, srn_dst(search_str, item[:str])]
119
+ end
120
+ scores.sort_by! { |x| -x[1] }
121
+ puts scores.inspect
122
+ scores = scores[0..30]
123
+
124
+ return scores
125
+ end