From: Rich Lane Date: Fri, 12 Jun 2009 19:35:52 +0000 (-0700) Subject: fixes for ruby1.9 X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=190852d60bca1dbb2da240e373d417516267ce6c;p=sup fixes for ruby1.9 Change colons in case statements to 'then' Fix a block that didn't take enough arguments Rename variables to avoid shadowing warnings Use String.ord (and define it for 1.8) Use DL::Importer on 1.9 Make require 'fastthread' optional Copy in RE_UTF8 --- diff --git a/bin/sup b/bin/sup index 0af3d11..2ea39c6 100755 --- a/bin/sup +++ b/bin/sup @@ -5,7 +5,6 @@ require 'ncurses' require 'curses' require 'fileutils' require 'trollop' -require 'fastthread' require "sup" BIN_VERSION = "git" @@ -89,7 +88,7 @@ end ## BSD users: if libc.so.6 is not found, try installing compat6x. require 'dl/import' module LibC - extend DL::Importable + extend DL.const_defined?(:Importer) ? DL::Importer : DL::Importable setlocale_lib = case Config::CONFIG['arch'] when /darwin/; "libc.dylib" when /cygwin/; "cygwin1.dll" @@ -203,7 +202,7 @@ begin end end unless $opts[:no_initial_poll] - imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread("poll after loading inbox") { sleep 1; PollManager.poll } unless $opts[:no_threads] || $opts[:no_initial_poll] } + imode.load_threads :num => ibuf.content_height, :when_done => lambda { |num| reporting_thread("poll after loading inbox") { sleep 1; PollManager.poll } unless $opts[:no_threads] || $opts[:no_initial_poll] } if $opts[:compose] ComposeMode.spawn_nicely :to_default => $opts[:compose] diff --git a/lib/sup.rb b/lib/sup.rb index 7444df0..991bd2d 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -5,6 +5,10 @@ require 'thread' require 'fileutils' require 'gettext' require 'curses' +begin + require 'fastthread' +rescue LoadError +end class Object ## this is for debugging purposes because i keep calling #id on the diff --git a/lib/sup/index.rb b/lib/sup/index.rb index e403570..ca01ee7 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -2,7 +2,6 @@ require 'fileutils' require 'ferret' -require 'fastthread' begin require 'chronic' diff --git a/lib/sup/keymap.rb b/lib/sup/keymap.rb index 76c7139..cb039e4 100644 --- a/lib/sup/keymap.rb +++ b/lib/sup/keymap.rb @@ -9,22 +9,22 @@ class Keymap def self.keysym_to_keycode k case k - when :down: Curses::KEY_DOWN - when :up: Curses::KEY_UP - when :left: Curses::KEY_LEFT - when :right: Curses::KEY_RIGHT - when :page_down: Curses::KEY_NPAGE - when :page_up: Curses::KEY_PPAGE - when :backspace: Curses::KEY_BACKSPACE - when :home: Curses::KEY_HOME - when :end: Curses::KEY_END - when :ctrl_l: "\f"[0] - when :ctrl_g: "\a"[0] - when :tab: "\t"[0] - when :enter, :return: 10 #Curses::KEY_ENTER + when :down then Curses::KEY_DOWN + when :up then Curses::KEY_UP + when :left then Curses::KEY_LEFT + when :right then Curses::KEY_RIGHT + when :page_down then Curses::KEY_NPAGE + when :page_up then Curses::KEY_PPAGE + when :backspace then Curses::KEY_BACKSPACE + when :home then Curses::KEY_HOME + when :end then Curses::KEY_END + when :ctrl_l then "\f".ord + when :ctrl_g then "\a".ord + when :tab then "\t".ord + when :enter, :return then 10 #Curses::KEY_ENTER else if k.is_a?(String) && k.length == 1 - k[0] + k.ord else raise ArgumentError, "unknown key name '#{k}'" end @@ -33,18 +33,18 @@ class Keymap def self.keysym_to_string k case k - when :down: "" - when :up: "" - when :left: "" - when :right: "" - when :page_down: "" - when :page_up: "" - when :backspace: "" - when :home: "" - when :end: "" - when :enter, :return: "" - when :tab: "tab" - when " ": "" + when :down then "" + when :up then "" + when :left then "" + when :right then "" + when :page_down then "" + when :page_up then "" + when :backspace then "" + when :home then "" + when :end then "" + when :enter, :return then "" + when :tab then "tab" + when " " then "" else Curses::keyname(keysym_to_keycode(k)) end diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb index e817744..0d742d9 100644 --- a/lib/sup/message-chunks.rb +++ b/lib/sup/message-chunks.rb @@ -240,8 +240,8 @@ EOS def patina_color case status - when :valid: :cryptosig_valid_color - when :invalid: :cryptosig_invalid_color + when :valid then :cryptosig_valid_color + when :invalid then :cryptosig_invalid_color else :cryptosig_unknown_color end end diff --git a/lib/sup/message.rb b/lib/sup/message.rb index 5372fc7..ded577a 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -405,8 +405,8 @@ private elsif m.header["Content-Type"] && m.header["Content-Type"] !~ /^text\/plain/ extension = case m.header["Content-Type"] - when /text\/html/: "html" - when /image\/(.*)/: $1 + when /text\/html/ then "html" + when /image\/(.*)/ then $1 end ["sup-attachment-#{Time.now.to_i}-#{rand 10000}", extension].join(".") diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb index d7bd41c..74bdfb7 100644 --- a/lib/sup/modes/edit-message-mode.rb +++ b/lib/sup/modes/edit-message-mode.rb @@ -2,7 +2,10 @@ require 'tempfile' require 'socket' # just for gethostname! require 'pathname' require 'rmail' -require 'jcode' # for RE_UTF8 + +# from jcode.rb, not included in ruby 1.9 +PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]' +RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n') module Redwood diff --git a/lib/sup/util.rb b/lib/sup/util.rb index ece52ba..8f60cc4 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -133,8 +133,8 @@ class Object ## clone of java-style whole-method synchronization ## assumes a @mutex variable ## TODO: clean up, try harder to avoid namespace collisions - def synchronized *meth - meth.each do + def synchronized *methods + methods.each do |meth| class_eval <<-EOF alias unsynchronized_#{meth} #{meth} def #{meth}(*a, &b) @@ -144,8 +144,8 @@ class Object end end - def ignore_concurrent_calls *meth - meth.each do + def ignore_concurrent_calls *methods + methods.each do |meth| mutex = "@__concurrent_protector_#{meth}" flag = "@__concurrent_flag_#{meth}" oldmeth = "__unprotected_#{meth}" @@ -213,7 +213,7 @@ class String region_start = 0 while pos <= length newpos = case state - when :escaped_instring, :escaped_outstring: pos + when :escaped_instring, :escaped_outstring then pos else index(/[,"\\]/, pos) end @@ -227,26 +227,26 @@ class String case char when ?" state = case state - when :outstring: :instring - when :instring: :outstring - when :escaped_instring: :instring - when :escaped_outstring: :outstring + when :outstring then :instring + when :instring then :outstring + when :escaped_instring then :instring + when :escaped_outstring then :outstring end when ?,, nil state = case state - when :outstring, :escaped_outstring: + when :outstring, :escaped_outstring then ret << self[region_start ... newpos].gsub(/^\s+|\s+$/, "") region_start = newpos + 1 :outstring - when :instring: :instring - when :escaped_instring: :instring + when :instring then :instring + when :escaped_instring then :instring end when ?\\ state = case state - when :instring: :escaped_instring - when :outstring: :escaped_outstring - when :escaped_instring: :instring - when :escaped_outstring: :outstring + when :instring then :escaped_instring + when :outstring then :escaped_outstring + when :escaped_instring then :instring + when :escaped_outstring then :outstring end end pos = newpos + 1 @@ -282,6 +282,12 @@ class String gsub(/\t/, " ").gsub(/\r/, "") end + if not defined? ord + def ord + self[0] + end + end + ## takes a space-separated list of words, and returns an array of symbols. ## typically used in Sup for translating Ferret's representation of a list ## of labels (a string) to an array of label symbols. @@ -636,10 +642,10 @@ class Iconv def self.easy_decode target, charset, text return text if charset =~ /^(x-unknown|unknown[-_ ]?8bit|ascii[-_ ]?7[-_ ]?bit)$/i charset = case charset - when /UTF[-_ ]?8/i: "utf-8" - when /(iso[-_ ])?latin[-_ ]?1$/i: "ISO-8859-1" - when /iso[-_ ]?8859[-_ ]?15/i: 'ISO-8859-15' - when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i: "utf-7" + when /UTF[-_ ]?8/i then "utf-8" + when /(iso[-_ ])?latin[-_ ]?1$/i then "ISO-8859-1" + when /iso[-_ ]?8859[-_ ]?15/i then 'ISO-8859-15' + when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i then "utf-7" else charset end