From: William Morgan Date: Tue, 18 Aug 2009 18:01:06 +0000 (-0400) Subject: Merge branch 'console-mode' into next X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=ed7ec99d5a1c42c53ad94c81832a7ba73b14fadc;p=sup Merge branch 'console-mode' into next Conflicts: bin/sup --- ed7ec99d5a1c42c53ad94c81832a7ba73b14fadc diff --cc bin/sup index a217557,2b4fee7..3d5b6c1 --- a/bin/sup +++ b/bin/sup @@@ -78,7 -78,7 +78,8 @@@ global_keymap = Keymap.new do |k k.add :compose, "Compose new message", 'm', 'c' k.add :nothing, "Do nothing", :ctrl_g k.add :recall_draft, "Edit most recent draft message", 'R' + k.add :show_inbox, "Show the Inbox buffer", 'I' + k.add :show_console, "Show the Console buffer", '~' end ## the following magic enables wide characters when used with a ruby @@@ -293,8 -297,9 +294,11 @@@ begi b, new = BufferManager.spawn_unless_exists("All drafts") { LabelSearchResultsMode.new [:draft] } b.mode.load_threads :num => b.content_height if new end + when :show_inbox + BufferManager.raise_to_front ibuf + when :show_console + b, new = bm.spawn_unless_exists("Console", :system => true) { ConsoleMode.new } + b.mode.run when :nothing, InputSequenceAborted when :redraw bm.completely_redraw_screen diff --cc lib/sup/modes/console-mode.rb index 0000000,372a466..d65e391 mode 000000,100644..100644 --- a/lib/sup/modes/console-mode.rb +++ b/lib/sup/modes/console-mode.rb @@@ -1,0 -1,92 +1,92 @@@ + require 'pp' + + module Redwood + + class Console + def initialize mode + @mode = mode + end + + def query(query) + Enumerable::Enumerator.new(Index, :each_message, Index.parse_query(query)) + end + + def add_labels(query, *labels) + query(query).each { |m| m.labels += labels; m.save Index } + end + + def remove_labels(query, *labels) + query(query).each { |m| m.labels -= labels; m.save Index } + end + + def xapian; Index.instance.instance_variable_get :@xapian; end + def ferret; Index.instance.instance_variable_get :@index; end + + ## files that won't cause problems when reloaded + ## TODO expand this list / convert to blacklist + RELOAD_WHITELIST = %w(sup/xapian_index.rb sup/modes/console-mode.rb) + + def reload + old_verbose = $VERBOSE + $VERBOSE = nil + old_features = $".dup + begin + fs = $".grep(/^sup\//) + fs.reject! { |f| not RELOAD_WHITELIST.member? f } + fs.each { |f| $".delete f } + fs.each do |f| + @mode << "reloading #{f}\n" + begin + require f + rescue LoadError => e + raise unless e.message =~ /no such file to load/ + end + end + rescue Exception + $".clear + $".concat old_features + raise + ensure + $VERBOSE = old_verbose + end + true + end + + def clear_hooks + HookManager.clear + nil + end + end + + class ConsoleMode < LogMode + def initialize - super ++ super "console" + @binding = Console.new(self).instance_eval { binding } + end + + def execute cmd + begin + self << ">> #{cmd}\n" + ret = eval cmd, @binding + self << "=> #{ret.pretty_inspect}\n" + rescue Exception + self << "#{$!.class}: #{$!.message}\n" + clean_backtrace = [] + $!.backtrace.each { |l| break if l =~ /console-mode/; clean_backtrace << l } + clean_backtrace.each { |l| self << "#{l}\n" } + end + end + + def prompt + BufferManager.ask :console, "eval: " + end + + def run + while true + cmd = prompt or return + execute cmd + end + end + end + + end