]> git.cworth.org Git - sup/blobdiff - lib/sup.rb
detect character set correctly (but unix-centrically)
[sup] / lib / sup.rb
index 7702953aa9bf12efd80d7582d91e0fd0b349f474..5bb27bab27153f4bba115b830f2c907c7d765b87 100644 (file)
@@ -32,7 +32,7 @@ class Module
 end
 
 module Redwood
-  VERSION = "0.2"
+  VERSION = "0.3"
 
   BASE_DIR   = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
   CONFIG_FN  = File.join(BASE_DIR, "config.yaml")
@@ -49,19 +49,8 @@ module Redwood
   YAML_DOMAIN = "masanjin.net"
   YAML_DATE = "2006-10-01"
 
-## determine encoding and character set
-## probably a better way to do this
-  $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8"
-  $encoding =
-    if $ctype =~ /\.(.*)?/
-      $1
-    else
-      "utf-8"
-    end
-
 ## record exceptions thrown in threads nicely
-  $exception = nil
-  def reporting_thread
+  def reporting_thread name
     if $opts[:no_threads]
       yield
     else
@@ -69,7 +58,8 @@ module Redwood
         begin
           yield
         rescue Exception => e
-          $exception ||= e
+          $exceptions ||= []
+          $exceptions << [e, name]
           raise
         end
       end
@@ -120,12 +110,16 @@ module Redwood
   end
 
   ## not really a good place for this, so I'll just dump it here.
+  ##
+  ## a source error is either a FatalSourceError or an OutOfSyncSourceError.
+  ## the superclass SourceError is just a generic.
   def report_broken_sources opts={}
     return unless BufferManager.instantiated?
 
-    broken_sources = Index.usual_sources.select { |s| s.error.is_a? FatalSourceError }
+    broken_sources = Index.sources.select { |s| s.error.is_a? FatalSourceError }
     unless broken_sources.empty?
-      BufferManager.spawn "Broken source notification", TextMode.new(<<EOM), opts
+      BufferManager.spawn_unless_exists("Broken source notification for #{broken_sources.join(',')}", opts) do
+        TextMode.new(<<EOM)
 Source error notification
 -------------------------
 
@@ -136,11 +130,13 @@ be viewed, and new messages will not be detected.
 #{broken_sources.map { |s| "Source: " + s.to_s + "\n Error: " + s.error.message.wrap(70).join("\n        ")}.join("\n\n")}
 EOM
 #' stupid ruby-mode
+      end
     end
 
-    desynced_sources = Index.usual_sources.select { |s| s.error.is_a? OutOfSyncSourceError }
+    desynced_sources = Index.sources.select { |s| s.error.is_a? OutOfSyncSourceError }
     unless desynced_sources.empty?
-      BufferManager.spawn "Out-of-sync source notification", TextMode.new(<<EOM), opts
+      BufferManager.spawn_unless_exists("Out-of-sync source notification for #{broken_sources.join(',')}", opts) do
+        TextMode.new(<<EOM)
 Out-of-sync source notification
 -------------------------------
 
@@ -158,6 +154,7 @@ and new messages will not be detected. Luckily, this is easy to correct!
   end}
 EOM
 #' stupid ruby-mode
+      end
     end
   end
 
@@ -197,6 +194,7 @@ else
     :ask_for_subject => true,
     :confirm_no_attachments => true,
     :confirm_top_posting => true,
+    :discard_snippets_from_encrypted_messages => false,
   }
   begin
     FileUtils.mkdir_p Redwood::BASE_DIR
@@ -214,6 +212,30 @@ require "sup/hook"
 ## time.
 Redwood::HookManager.new Redwood::HOOK_DIR
 
+## everything we need to get logging working
+require "sup/buffer"
+require "sup/keymap"
+require "sup/mode"
+require "sup/modes/scroll-mode"
+require "sup/modes/text-mode"
+require "sup/modes/log-mode"
+require "sup/logger"
+module Redwood
+  def log s; Logger.log s; end
+  module_function :log
+end
+
+## determine encoding and character set. there MUST be a better way to
+## do this.
+  $encoding = `locale -c LC_CTYPE|head -6|tail -1`.chomp
+  if $encoding
+    Redwood::log "using character set encoding #{$encoding.inspect}"
+  else
+    Redwood::log "warning: can't find character set by using locale, defaulting to utf-8"
+    $encoding = "utf-8"
+  end
+
+## now everything else (which can feel free to call Redwood::log at load time)
 require "sup/update"
 require "sup/suicide"
 require "sup/message-chunks"
@@ -227,9 +249,6 @@ require "sup/account"
 require "sup/thread"
 require "sup/index"
 require "sup/textfield"
-require "sup/buffer"
-require "sup/keymap"
-require "sup/mode"
 require "sup/colormap"
 require "sup/label"
 require "sup/contact"
@@ -237,8 +256,7 @@ require "sup/tagger"
 require "sup/draft"
 require "sup/poll"
 require "sup/crypto"
-require "sup/modes/scroll-mode"
-require "sup/modes/text-mode"
+require "sup/horizontal-selector"
 require "sup/modes/line-cursor-mode"
 require "sup/modes/help-mode"
 require "sup/modes/edit-message-mode"
@@ -255,18 +273,11 @@ require "sup/modes/search-results-mode"
 require "sup/modes/person-search-results-mode"
 require "sup/modes/inbox-mode"
 require "sup/modes/buffer-list-mode"
-require "sup/modes/log-mode"
 require "sup/modes/poll-mode"
 require "sup/modes/file-browser-mode"
 require "sup/modes/completion-mode"
-require "sup/logger"
 require "sup/sent"
 
-module Redwood
-  def log s; Logger.log s; end
-  module_function :log
-end
-
 $:.each do |base|
   d = File.join base, "sup/share/modes/"
   Redwood::Mode.load_all_modes d if File.directory? d