Method: Textbringer::Mode.define_generic_command

Defined in:
lib/textbringer/mode.rb

.define_generic_command(name, **options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/textbringer/mode.rb', line 25

def self.define_generic_command(name, **options)
  command_name = (name.to_s + "_command").intern
  define_command(command_name, **options) do |*args|
    begin
      Buffer.current.mode.send(name, *args)
    rescue NoMethodError => e
      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