lib/textbringer/mode.rb in textbringer-0.2.2 vs lib/textbringer/mode.rb in textbringer-0.2.3

- old
+ new

@@ -18,23 +18,29 @@ attr_accessor :file_name_pattern attr_accessor :interpreter_name_pattern attr_reader :syntax_table end - def self.define_generic_command(name) + def self.define_generic_command(name, **options) command_name = (name.to_s + "_command").intern - define_command(command_name) do |*args| + define_command(command_name, **options) do |*args| begin Buffer.current.mode.send(name, *args) rescue NoMethodError => e - if e.receiver == Buffer.current.mode && e.name == name + if (e.receiver rescue nil) == Buffer.current.mode && e.name == name raise EditorError, "#{command_name} is not supported in the current mode" else raise end end end + end + + def self.define_local_command(name, **options, &block) + define_generic_command(name, **options) + define_method(name, &block) + name end def self.define_syntax(face_name, re) @syntax_table[face_name] = re end