Class: RuVim::ConfigDSL
- Inherits:
- BasicObject
- Defined in:
- lib/ruvim/config_dsl.rb
Instance Method Summary collapse
- #command(id, desc: "user command", &block) ⇒ Object
- #ex_command(name, desc: "user ex", aliases: [], nargs: :any, bang: false, &block) ⇒ Object
-
#ex_command_call(name, command_id, desc: "user ex", aliases: [], nargs: :any, bang: false) ⇒ Object
Convenience: define an Ex command that forwards to an existing internal command ID.
- #imap(seq, command_id = nil, desc: "user keymap", **opts, &block) ⇒ Object
-
#initialize(command_registry:, ex_registry:, keymaps:, command_host:, editor: nil, filetype: nil) ⇒ ConfigDSL
constructor
A new instance of ConfigDSL.
- #map_global(seq, command_id = nil, mode: :normal, desc: "user keymap", **opts, &block) ⇒ Object
- #nmap(seq, command_id = nil, desc: "user keymap", **opts, &block) ⇒ Object
- #set(option_expr) ⇒ Object
- #setglobal(option_expr) ⇒ Object
- #setlocal(option_expr) ⇒ Object
Constructor Details
#initialize(command_registry:, ex_registry:, keymaps:, command_host:, editor: nil, filetype: nil) ⇒ ConfigDSL
Returns a new instance of ConfigDSL.
5 6 7 8 9 10 11 12 13 |
# File 'lib/ruvim/config_dsl.rb', line 5 def initialize(command_registry:, ex_registry:, keymaps:, command_host:, editor: nil, filetype: nil) @command_registry = command_registry @ex_registry = ex_registry @keymaps = keymaps @command_host = command_host @editor = editor @filetype = filetype&.to_s @inline_map_command_seq = 0 end |
Instance Method Details
#command(id, desc: "user command", &block) ⇒ Object
48 49 50 51 52 |
# File 'lib/ruvim/config_dsl.rb', line 48 def command(id, desc: "user command", &block) raise ::ArgumentError, "block required" unless block @command_registry.register(id.to_s, call: block, desc:, source: :user) end |
#ex_command(name, desc: "user ex", aliases: [], nargs: :any, bang: false, &block) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/ruvim/config_dsl.rb', line 54 def ex_command(name, desc: "user ex", aliases: [], nargs: :any, bang: false, &block) raise ::ArgumentError, "block required" unless block @ex_registry.unregister(name.to_s) if @ex_registry.registered?(name.to_s) @ex_registry.register(name.to_s, call: block, desc:, aliases:, nargs:, bang:, source: :user) end |
#ex_command_call(name, command_id, desc: "user ex", aliases: [], nargs: :any, bang: false) ⇒ Object
Convenience: define an Ex command that forwards to an existing internal command ID.
62 63 64 65 66 67 |
# File 'lib/ruvim/config_dsl.rb', line 62 def ex_command_call(name, command_id, desc: "user ex", aliases: [], nargs: :any, bang: false) ex_command(name, desc:, aliases:, nargs:, bang:) do |ctx, argv:, kwargs:, bang:, count:| spec = @command_registry.fetch(command_id.to_s) @command_host.call(spec.call, ctx, argv:, kwargs:, bang:, count:) end end |
#imap(seq, command_id = nil, desc: "user keymap", **opts, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruvim/config_dsl.rb', line 26 def imap(seq, command_id = nil, desc: "user keymap", **opts, &block) command_id = inline_map_command_id(:insert, seq, desc:, &block) if block raise ::ArgumentError, "command_id or block required" if command_id.nil? if @filetype && !@filetype.empty? @keymaps.bind_filetype(@filetype, seq, command_id.to_s, mode: :insert, **opts) else @keymaps.bind(:insert, seq, command_id.to_s, **opts) end end |
#map_global(seq, command_id = nil, mode: :normal, desc: "user keymap", **opts, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruvim/config_dsl.rb', line 37 def map_global(seq, command_id = nil, mode: :normal, desc: "user keymap", **opts, &block) command_id = inline_map_command_id(mode || :global, seq, desc:, &block) if block raise ::ArgumentError, "command_id or block required" if command_id.nil? if mode @keymaps.bind(mode.to_sym, seq, command_id.to_s, **opts) else @keymaps.bind_global(seq, command_id.to_s, **opts) end end |
#nmap(seq, command_id = nil, desc: "user keymap", **opts, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruvim/config_dsl.rb', line 15 def nmap(seq, command_id = nil, desc: "user keymap", **opts, &block) command_id = inline_map_command_id(:normal, seq, desc:, &block) if block raise ::ArgumentError, "command_id or block required" if command_id.nil? if @filetype && !@filetype.empty? @keymaps.bind_filetype(@filetype, seq, command_id.to_s, mode: :normal, **opts) else @keymaps.bind(:normal, seq, command_id.to_s, **opts) end end |
#set(option_expr) ⇒ Object
69 70 71 |
# File 'lib/ruvim/config_dsl.rb', line 69 def set(option_expr) apply_option_expr(option_expr, scope: :auto) end |
#setglobal(option_expr) ⇒ Object
77 78 79 |
# File 'lib/ruvim/config_dsl.rb', line 77 def setglobal(option_expr) apply_option_expr(option_expr, scope: :global) end |
#setlocal(option_expr) ⇒ Object
73 74 75 |
# File 'lib/ruvim/config_dsl.rb', line 73 def setlocal(option_expr) apply_option_expr(option_expr, scope: :local) end |