remi-vimilicious 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vimilicious.rb +34 -0
- data/vimilicious.gemspec +1 -1
- metadata +1 -1
data/lib/vimilicious.rb
CHANGED
@@ -77,6 +77,38 @@ def current_line
|
|
77
77
|
current_buffer.line
|
78
78
|
end
|
79
79
|
|
80
|
+
# deletes the current buffer (closes the file)
|
81
|
+
#
|
82
|
+
# :ruby clear
|
83
|
+
def clear
|
84
|
+
cmd 'bd!'
|
85
|
+
end
|
86
|
+
|
87
|
+
# create a vim user command that calls a ruby method or block
|
88
|
+
#
|
89
|
+
# :ruby create_command :test # creates a :Test command that calls a 'test' method
|
90
|
+
# :ruby create_command 'test', :hi # creates a :Test command that calls a 'hi' method
|
91
|
+
# :ruby create_command(:test){ puts 'hi' } # creates a :Test command that calls the block passed in
|
92
|
+
#
|
93
|
+
# BLOCKS NOT YET SUPPORTED
|
94
|
+
def create_command name, method = nil, &block
|
95
|
+
command_name = name.to_s.capitalize
|
96
|
+
method_name = (method.nil?) ? name.to_s : method.to_s
|
97
|
+
function_name = command_name + 'AutoGeneratedFunction'
|
98
|
+
|
99
|
+
# create a function that calls method (or block)
|
100
|
+
if block.nil?
|
101
|
+
cmd %[fu! #{ function_name }(...)\n ruby #{ method_name } *eval("\#{ vim_eval('string(a:000)') }")\nendfu]
|
102
|
+
else
|
103
|
+
generated_method = command_name + '_auto_generated_method'
|
104
|
+
Kernel.module_eval { define_method generated_method, block }
|
105
|
+
cmd %[fu! #{ function_name }(...)\n ruby #{ generated_method } *eval("\#{ vim_eval('string(a:000)') }")\nendfu]
|
106
|
+
end
|
107
|
+
|
108
|
+
# create a vim command that calls the vim function
|
109
|
+
cmd %{command! -nargs=* #{ command_name } call #{ function_name }(<f-args>)}
|
110
|
+
end
|
111
|
+
|
80
112
|
# get the word under the cursor
|
81
113
|
#
|
82
114
|
# :ruby puts "the cursor is on top of the word: #{current_word}"
|
@@ -89,3 +121,5 @@ def current_word filter=/[,'`\.:\(\)\[\]\}\{]/, replace_with=''
|
|
89
121
|
word.gsub!(filter,replace_with) unless word.empty?
|
90
122
|
word
|
91
123
|
end
|
124
|
+
|
125
|
+
### COMMANDS ###
|
data/vimilicious.gemspec
CHANGED