vimdb 0.2.0 → 0.3.0

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.
@@ -1,3 +1,8 @@
1
+ = 0.3.0
2
+ * Several fixes to key parsing
3
+ * Add all + not search options
4
+ * Fix reloading
5
+
1
6
  = 0.2.0
2
7
  * Several bug fixes
3
8
  * Add support for commands
data/README.md CHANGED
@@ -31,6 +31,9 @@ Usage
31
31
  # List keys with Leader
32
32
  $ vimdb keys L-
33
33
 
34
+ # List keys with no Leader - not of last search
35
+ $ vimdb keys L- -n
36
+
34
37
  # List insert mode keys
35
38
  $ vimdb keys -m=i
36
39
 
@@ -51,8 +54,8 @@ Usage
51
54
  # List options that contain window in description
52
55
  $ vimdb opts window -f=desc
53
56
 
54
- # List commands about buffers
55
- $ vimdb commands buffer -f=desc
57
+ # List commands mentioning 'buffer' in any field
58
+ $ vimdb commands buffer -a
56
59
 
57
60
  # Info about how vim items were made
58
61
  $ vimdb info keys
@@ -61,6 +64,13 @@ Usage
61
64
  # For more
62
65
  $ vimdb help
63
66
 
67
+ Configuration
68
+ =============
69
+
70
+ Configure vimdb with a ~/.vimdbrc, which is loaded before every command request. Use it to define
71
+ additional commands. For an example, [see my rc
72
+ file](https://github.com/cldwalker/dotfiles/blob/master/.vimdbrc).
73
+
64
74
  Key Modes
65
75
  =========
66
76
 
@@ -94,8 +104,5 @@ Contributing
94
104
  Todo
95
105
  ====
96
106
 
97
- * Fix test coupling
98
- * More tests!
99
- * Fix keys - index.txt edge cases
100
107
  * Add support for more vim items - variables, functions
101
108
  * Considering user annotation for vim items
data/Rakefile CHANGED
@@ -29,6 +29,7 @@ end
29
29
 
30
30
  desc 'Run tests'
31
31
  task :test do |t|
32
+ ENV['RUBYLIB'] = 'lib:' + ENV['RUBYLIB']
32
33
  sh 'testrb spec/*_spec.rb'
33
34
  end
34
35
 
@@ -48,8 +48,8 @@ class Vimdb::Commands < Vimdb::Item
48
48
  cmd = {}
49
49
 
50
50
  cmd[:file] = arr[1].to_s[%r{Last set from (\S+)}, 1] or next
51
- cmd[:from] = cmd[:file].to_s[%r{/#{@plugins_dir}/([^/]+)\S+}, 1] || 'user'
52
- cmd[:from] << ' plugin' if cmd[:from] != 'user'
51
+ match = cmd[:file].to_s.match(%r{/#{@plugins_dir}/(?<plugin>[^/]+)})
52
+ cmd[:from] = match ? match[:plugin] + ' plugin' : 'user'
53
53
  cmd[:name] = arr[0][/^(?:[!b" ]+)(\S+)/, 1]
54
54
  cmd[:desc] = arr[0][/^(?:[!b" ]+)\S+\s*(.*)$/, 1]
55
55
  if cmd[:desc][/^(\*|\+|\?|\d)\s+(\dc?|%|\.)?\s*(#{completions})?\s*(.*)/]
@@ -60,7 +60,7 @@ class Vimdb::Commands < Vimdb::Item
60
60
  end.compact
61
61
  end
62
62
 
63
- def display_fields
63
+ def fields
64
64
  [:name, :alias, :from, :desc]
65
65
  end
66
66
 
@@ -24,7 +24,15 @@ module Vimdb
24
24
  if query
25
25
  query = Regexp.escape(query) unless options[:regexp]
26
26
  regex = Regexp.new(query, options[:ignore_case])
27
- items.select! {|e| e[options[:field].to_sym] =~ regex }
27
+
28
+ if options[:all]
29
+ items.select! {|item|
30
+ fields.any? {|field| item[field] =~ regex }
31
+ }
32
+ else
33
+ search_field = options[:field] ? options[:field].to_sym : default_field
34
+ items.select! {|item| item[search_field] =~ regex }
35
+ end
28
36
  end
29
37
  items
30
38
  end
@@ -42,10 +50,14 @@ module Vimdb
42
50
  raise NotImplementedError
43
51
  end
44
52
 
45
- def display_fields
53
+ def fields
46
54
  raise NotImplementedError
47
55
  end
48
56
 
57
+ def default_field
58
+ fields[0]
59
+ end
60
+
49
61
  private
50
62
 
51
63
  def vim(*cmds)
@@ -31,7 +31,7 @@ class Vimdb::Keys < Vimdb::Item
31
31
  "Created using index.txt and :map"
32
32
  end
33
33
 
34
- def display_fields
34
+ def fields
35
35
  [:key, :mode, :from, :desc]
36
36
  end
37
37
 
@@ -70,22 +70,43 @@ class Vimdb::Keys < Vimdb::Item
70
70
  #drop section header
71
71
  section_lines = section_lines.drop_while {|e| e !~ /^\|/ }
72
72
 
73
- section_lines.each do |e|
74
- cols = e.split(/\t+/)
73
+ section_lines.each do |line|
74
+ cols = line.split(/\t+/)
75
75
  if cols.size >= 3
76
- key = translate_index_key cols[-2]
77
- keys << {mode: mode, key: key, desc: cols[-1].strip, :from => 'default'}
78
- # add desc from following lines
79
- elsif cols.size == 2 && cols[0] == ''
80
- keys[-1][:desc] += ' ' + cols[1].strip
81
- # else
82
- # TODO: parse few edge cases
76
+ desc = cols[-1] == '"' ? keys[-1][:desc] : cols[-1]
77
+ keys << create_index_key(mode, cols[-2], desc)
78
+ keys.pop if keys[-1][:desc] == 'not used'
79
+ elsif cols.size == 2
80
+ # add desc from following lines
81
+ if cols[0] == ''
82
+ if cols[1] !~ /^(Meta characters|not used)/
83
+ keys[-1][:desc] += ' ' + cols[1].strip
84
+ end
85
+ else
86
+ keys << create_index_key(mode, cols[1])
87
+ end
88
+ elsif cols.size == 1
89
+ tag, key = line.split(/\s+/, 2)
90
+ if tag == '|i_CTRL-V_digit|'
91
+ key, desc = key.split(/(?<=})/)
92
+ keys << create_index_key(mode, key, desc)
93
+ elsif tag == '|CTRL-W_g_CTRL-]|'
94
+ key, desc = key.split(/(?<=\])/)
95
+ keys << create_index_key(mode, key, desc)
96
+ else
97
+ keys << create_index_key(mode, key)
98
+ end
83
99
  end
84
100
  end
85
101
  end
86
102
  keys
87
103
  end
88
104
 
105
+ def create_index_key(mode, key, desc = nil)
106
+ desc = desc ? desc.strip : ''
107
+ { mode: mode, key: translate_index_key(key), desc: desc, from: 'default' }
108
+ end
109
+
89
110
  def translate_index_key(key)
90
111
  key.gsub(/CTRL-(\S)/) {|s| "C-#{$1.downcase}" }
91
112
  end
@@ -103,8 +124,8 @@ class Vimdb::Keys < Vimdb::Item
103
124
  key = {}
104
125
 
105
126
  key[:file] = arr[1].to_s[%r{Last set from (\S+)}, 1] or next
106
- key[:from] = key[:file].to_s[%r{/#{@plugins_dir}/([^/]+)\S+}, 1] || 'user'
107
- key[:from] += ' plugin' if key[:from] != 'user'
127
+ match = key[:file].to_s.match(%r{/#{@plugins_dir}/(?<plugin>[^/]+)})
128
+ key[:from] = match ? match[:plugin] + ' plugin' : 'user'
108
129
 
109
130
  key[:key] = arr[0][/^\S*\s+(\S+)/, 1]
110
131
  next if key[:key][/^(<Plug>|<SNR>)/]
@@ -1,5 +1,5 @@
1
1
  class Vimdb::Options < Vimdb::Item
2
- def display_fields
2
+ def fields
3
3
  [:name, :alias, :desc]
4
4
  end
5
5
 
@@ -13,16 +13,18 @@ class Vimdb::Runner < Thor
13
13
  super
14
14
  end
15
15
 
16
- def self.common_options
16
+ def self.common_search_options
17
17
  method_option :reload, :type => :boolean, :desc => 'reloads items'
18
18
  method_option :sort, :type => :string, :desc => 'sort by field', :aliases => '-s'
19
19
  method_option :reverse_sort, :type => :boolean, :aliases => '-R'
20
20
  method_option :ignore_case, :type => :boolean, :aliases => '-i'
21
21
  method_option :regexp, :type => :boolean, :aliases => '-r', :desc => 'query is a regexp'
22
+ method_option :not, :type => :boolean, :aliases => '-n', :desc => 'return non-matching results'
23
+ method_option :all, :type => :boolean, :aliases => '-a', :desc => 'search all fields'
24
+ method_option :field, :type => :string, :desc => 'field to query', :aliases => '-f'
22
25
  end
23
26
 
24
- common_options
25
- method_option :field, :default => 'key', :desc => 'field to query', :aliases => '-f'
27
+ common_search_options
26
28
  method_option :mode, :type => :string, :desc => 'search by mode, multiple modes are ORed', :aliases => '-m'
27
29
  desc 'keys [QUERY]', 'List vim keys'
28
30
  def keys(query = nil)
@@ -30,23 +32,21 @@ class Vimdb::Runner < Thor
30
32
  search_item(query)
31
33
  end
32
34
 
33
- common_options
34
- method_option :field, :default => 'name', :desc => 'field to query', :aliases => '-f'
35
+ common_search_options
35
36
  desc 'opts [QUERY]', 'List vim options'
36
37
  def opts(query = nil)
37
38
  Vimdb.item('options')
38
39
  search_item(query)
39
40
  end
40
41
 
41
- common_options
42
- method_option :field, :default => 'name', :desc => 'field to query', :aliases => '-f'
42
+ common_search_options
43
43
  desc 'commands [QUERY]', 'List vim commands'
44
44
  def commands(query = nil)
45
45
  Vimdb.item('commands')
46
46
  search_item(query)
47
47
  end
48
48
 
49
- desc 'info', 'Prints info about an item'
49
+ desc 'info [ITEM]', 'Prints info about an item'
50
50
  def info(item = nil)
51
51
  puts Vimdb.item(item).info
52
52
  end
@@ -55,6 +55,6 @@ class Vimdb::Runner < Thor
55
55
  def search_item(query = nil)
56
56
  Vimdb.user.reload if options[:reload]
57
57
  keys = Vimdb.user.search(query, options)
58
- puts Hirb::Helpers::Table.render(keys, fields: Vimdb.item.display_fields)
58
+ puts Hirb::Helpers::Table.render(keys, fields: Vimdb.item.fields)
59
59
  end
60
60
  end
@@ -2,24 +2,25 @@ module Vimdb
2
2
  class User
3
3
  def initialize(item, db)
4
4
  @item, @db = item, db
5
- @db_exists = File.exists?(@db.file)
5
+ @reload = !File.exists?(@db.file)
6
6
  end
7
7
 
8
8
  def items
9
- @db_exists ? @db.get(@item.key) :
10
- @db.set(@item.key, @item.create).tap { @db_exists = true }
9
+ !@reload && @db.get(@item.key) ||
10
+ @db.set(@item.key, @item.create).tap { @reload = false }
11
11
  end
12
12
 
13
13
  def search(query, options = {})
14
- results = @item.search(items, query, options)
15
- sort = options[:sort] || options[:field]
14
+ results = @item.search(items.dup, query, options)
15
+ results = items - results if options[:not]
16
+ sort = options[:sort] || options[:field] || @item.default_field
16
17
  results.sort_by! {|e| e[sort.to_sym] || '' }
17
18
  results.reverse! if options[:reverse_sort]
18
19
  results
19
20
  end
20
21
 
21
22
  def reload
22
- @db_exists = false
23
+ @reload = true
23
24
  end
24
25
  end
25
26
  end
@@ -1,3 +1,3 @@
1
1
  module Vimdb
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1 +1 @@
1
- Vimdb.plugins_dir = 'plugins'
1
+ Vimdb.plugins_dir = '(plugins|autoload)'
@@ -43,6 +43,13 @@ STR
43
43
  vimdb 'commands', 'Gist'
44
44
  stdout.must_include <<-STR
45
45
  | Gist | | gist-vim plugin | :call Gist(<line1>, <line2>, <f-args>) |
46
+ STR
47
+ end
48
+
49
+ it "lists plugin commands using plugin_dir regexp correctly" do
50
+ vimdb 'commands', 'Vopen'
51
+ stdout.must_include <<-STR
52
+ | Vopen | | pathogen.vim plugin | :execute s:find(<count>,'edit<bang>',<q-args>,1) |
46
53
  STR
47
54
  end
48
55
  end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ describe "common search options" do
4
+ it "with --field option searches another field" do
5
+ vimdb 'keys', 'L-z' ,'-f=desc'
6
+ stdout.must_match /^0 rows/
7
+ end
8
+
9
+ it "with --reverse_sort option reverse sorts field" do
10
+ vimdb 'keys', '-R'
11
+ stdout.must_match /gq.*'\]/m
12
+ end
13
+
14
+ it "with --regexp option converts search to regexp" do
15
+ vimdb 'keys', '^C-', '-r'
16
+ stdout.wont_match /^0 rows/
17
+ stdout.must_match /C-a.*C-z/m
18
+ end
19
+
20
+ it "with --ignore-case option ignores case" do
21
+ vimdb 'keys', 'Q:', '-i'
22
+ stdout.must_match /q:.*1 row/m
23
+ end
24
+
25
+ it "with --not option returns all non-matching results" do
26
+ vimdb 'keys', 'blarg', '-n'
27
+ stdout.must_match /928 rows/
28
+ end
29
+
30
+ it "with --all option searches all fields" do
31
+ vimdb 'keys', 'C', '-a'
32
+ stdout.must_match /365 rows/
33
+ # from desc field
34
+ stdout.must_include ' :TComment<CR>'
35
+ end
36
+ end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
3
3
  describe "vimdb keys" do
4
4
  it "lists all keys by default" do
5
5
  vimdb 'keys'
6
- stdout.must_match /903 rows/
6
+ stdout.must_match /928 rows/
7
7
  end
8
8
 
9
9
  it 'searches :key field by default' do
@@ -11,27 +11,6 @@ describe "vimdb keys" do
11
11
  stdout.must_match /1 row/
12
12
  end
13
13
 
14
- it "with --field option searches another field" do
15
- vimdb 'keys', 'L-z' ,'-f=desc'
16
- stdout.must_match /0 rows/
17
- end
18
-
19
- it "with --reverse_sort option reverse sorts field" do
20
- vimdb 'keys', '-R'
21
- stdout.must_match /gq.*'\]/m
22
- end
23
-
24
- it "with --regexp option converts search to regexp" do
25
- vimdb 'keys', '^C-', '-r'
26
- stdout.wont_match /0 rows/
27
- stdout.must_match /C-a.*C-z/m
28
- end
29
-
30
- it "with --ignore-case option ignores case" do
31
- vimdb 'keys', 'Q:', '-i'
32
- stdout.must_match /q:.*1 row/m
33
- end
34
-
35
14
  it 'with --mode option ANDs mode to search' do
36
15
  vimdb 'keys', 'gm', '-m=n'
37
16
  stdout.must_match /1 row/
@@ -40,13 +19,13 @@ describe "vimdb keys" do
40
19
  describe "edge cases" do
41
20
  it "converts control key to C-" do
42
21
  vimdb 'keys', 'C-z'
43
- stdout.wont_match /0 rows/
22
+ stdout.wont_match /^0 rows/
44
23
  stdout.must_match /C-z/
45
24
  end
46
25
 
47
26
  it "converts escape key to E-" do
48
27
  vimdb 'keys', 'E-x'
49
- stdout.wont_match /0 rows/
28
+ stdout.wont_match /^0 rows/
50
29
  stdout.must_match /E-x/
51
30
  end
52
31
 
@@ -74,7 +53,52 @@ describe "vimdb keys" do
74
53
 
75
54
  it "doesn't list Plug keys" do
76
55
  vimdb 'keys', 'Plug'
77
- stdout.must_match /0 rows/
56
+ stdout.must_match /^0 rows/
57
+ end
58
+
59
+ it "doesn't list not used keys" do
60
+ vimdb 'keys', '^not used$', '-f=desc', '-r'
61
+ stdout.must_match /^0 rows/
62
+ end
63
+
64
+ it "lists keys with description on following line" do
65
+ vimdb 'keys', 'digraph', '-a'
66
+ stdout.must_include <<-STR
67
+ | {char1}<BS>{char2} | i | default | enter digraph (only when 'digraph' option set) |
68
+ STR
69
+ end
70
+
71
+ it "lists keys with no tabs and no description" do
72
+ vimdb 'keys', 'C-r C-r'
73
+ stdout.must_include <<-STR
74
+ | C-r C-r {0-9a-z"%#*:=} | i | default | insert the contents of a register literally |
75
+ STR
76
+ end
77
+
78
+ it "lists keys with no tabs but a description" do
79
+ vimdb 'keys', 'C-v {number}'
80
+ stdout.must_include <<-STR
81
+ | C-v {number} | i | default | insert three digit decimal number as a single byte. |
82
+ STR
83
+
84
+ vimdb 'keys', 'C-w g C-]'
85
+ stdout.must_include <<-STR
86
+ | C-w g C-] | n | default | split window and do |:tjump| to tag under cursor |
87
+ STR
88
+ end
89
+
90
+ it "lists key without unrelated sentences after it" do
91
+ vimdb 'keys', 'delete character under', '-a'
92
+ stdout.must_include <<-STR
93
+ | <Del> | i | default | delete character under the cursor |
94
+ STR
95
+ end
96
+
97
+ it "lists keys correctly that have desc from previous key" do
98
+ vimdb 'keys', '2$', '-r'
99
+ stdout.must_include <<-STR
100
+ | 2 | n | default | prepend to command to give a count |
101
+ STR
78
102
  end
79
103
  end
80
104
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: vimdb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gabriel Horner
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-24 00:00:00 -04:00
13
+ date: 2011-11-07 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -66,6 +66,7 @@ files:
66
66
  - lib/vimdb/version.rb
67
67
  - lib/vimdb.rb
68
68
  - spec/commands_spec.rb
69
+ - spec/common_search_options_spec.rb
69
70
  - spec/helper.rb
70
71
  - spec/keys_spec.rb
71
72
  - spec/options_spec.rb