lib/sup/mode.rb in sup-0.0.6 vs lib/sup/mode.rb in sup-0.0.7
- old
+ new
@@ -46,16 +46,13 @@
nil
end
def handle_input c
- if(action = resolve_input c)
- send action
- true
- else
- false
- end
+ action = resolve_input(c) or return false
+ send action
+ true
end
def help_text
used_keys = {}
ancestors.map do |klass|
@@ -72,9 +69,22 @@
rescue ArgumentError
raise km.keysyms.inspect
end
s
end.compact.join "\n"
+ end
+
+ ## helper function
+ def save_to_file fn
+ if File.exists? fn
+ return unless BufferManager.ask_yes_or_no "File exists. Overwrite?"
+ end
+ begin
+ File.open(fn, "w") { |f| yield f }
+ BufferManager.flash "Successfully wrote #{fn}."
+ rescue SystemCallError => e
+ BufferManager.flash "Error writing to file: #{e.message}"
+ end
end
end
end