Module: VER::Methods::Macro
- Defined in:
- lib/ver/methods/macro.rb
Class Method Summary collapse
- .current(buffer) ⇒ Object
- .enter(buffer, old_mode, new_mode) ⇒ Object
- .leave(buffer, old_mode, new_mode) ⇒ Object
- .play(buffer, name) ⇒ Object
- .repeat(buffer) ⇒ Object
Class Method Details
.current(buffer) ⇒ Object
40 41 42 |
# File 'lib/ver/methods/macro.rb', line 40 def current(buffer) buffer.store(self, :current) end |
.enter(buffer, old_mode, new_mode) ⇒ Object
6 7 8 9 |
# File 'lib/ver/methods/macro.rb', line 6 def enter(buffer, old_mode, new_mode) name = buffer.events.last.unicode buffer.store(self, :current, name) end |
.leave(buffer, old_mode, new_mode) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ver/methods/macro.rb', line 11 def leave(buffer, old_mode, new_mode) history = [] name = buffer.store(self, :current) macro_invocation = [:minor_mode, MinorMode[:control], :macro] buffer.actions.reverse_each do |, mode, action| break if action.invocation == macro_invocation history << ->{ action.call() } end buffer.store(self, name, history.reverse) end |
.play(buffer, name) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/ver/methods/macro.rb', line 32 def play(buffer, name) if actions = buffer.store(self, name) actions.each(&:call) else buffer.warn("No macro called %p" % [name]) end end |
.repeat(buffer) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/ver/methods/macro.rb', line 24 def repeat(buffer) if actions = buffer.store(self, current(buffer)) actions.each(&:call) else buffer.warn("No macro used yet") end end |