7 def self.register_keymap keymap=nil, &b
8 keymap = Keymap.new(&b) if keymap.nil?
9 @@keymaps[self] = keymap
16 def self.make_name s; s.gsub(/.*::/, "").camel_to_hyphy; end
17 def name; Mode.make_name self.class.name; end
19 def self.load_all_modes dir
20 Dir[File.join(dir, "*.rb")].each do |f|
21 $stderr.puts "## loading mode #{f}"
26 def killable?; true; end
30 def cancel_search!; end
31 def in_search?; false end
33 def resize rows, cols; end
39 ancestors.each do |klass| # try all keymaps in order of ancestry
40 next unless @@keymaps.member?(klass)
41 action = BufferManager.resolve_input_with_keymap c, @@keymaps[klass]
42 return action if action
48 action = resolve_input(c) or return false
55 ancestors.map do |klass|
56 km = @@keymaps[klass] or next
57 title = "Keybindings from #{Mode.make_name klass.name}"
62 #{km.help_text used_keys}
65 used_keys.merge! km.keysyms.to_boolean_h
67 raise km.keysyms.inspect
77 return unless BufferManager.ask_yes_or_no "File exists. Overwrite?"
80 File.open(fn, "w") { |f| yield f }
81 BufferManager.flash "Successfully wrote #{fn}."
82 rescue SystemCallError, IOError => e
83 BufferManager.flash "Error writing to file: #{e.message}"
87 def pipe_to_process command
88 Open3.popen3(command) do |input, output, error|
89 err, data, * = IO.select [error], [input], nil
92 message = err.first.read
94 Redwood::log "error running #{command} (but no error message)"
95 BufferManager.flash "Error running #{command}!"
97 Redwood::log "error running #{command}: #{message}"
98 BufferManager.flash "Error: #{message}"
104 data.sync = false # buffer input
107 data.close # output will block unless input is closed
109 ## BUG?: shows errors or output but not both....
110 data, * = IO.select [output, error], nil, nil
114 BufferManager.flash "'#{command}' done!"