* [sup-talk] [PATCH] fixes for ruby1.9
@ 2009-06-12 19:35 Rich Lane
2009-06-15 16:32 ` William Morgan
0 siblings, 1 reply; 2+ messages in thread
From: Rich Lane @ 2009-06-12 19:35 UTC (permalink / raw)
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
---
bin/sup | 5 +--
lib/sup.rb | 4 +++
lib/sup/index.rb | 1 -
lib/sup/keymap.rb | 52 ++++++++++++++++++------------------
lib/sup/message-chunks.rb | 4 +-
lib/sup/message.rb | 4 +-
lib/sup/modes/edit-message-mode.rb | 5 +++-
lib/sup/util.rb | 46 ++++++++++++++++++--------------
8 files changed, 66 insertions(+), 55 deletions(-)
diff --git a/bin/sup b/bin/sup
index 9abe1b5..302ad7c 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"
@@ -202,7 +201,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 4f59eaa..dea9355 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: "<down arrow>"
- when :up: "<up arrow>"
- when :left: "<left arrow>"
- when :right: "<right arrow>"
- when :page_down: "<page down>"
- when :page_up: "<page up>"
- when :backspace: "<backspace>"
- when :home: "<home>"
- when :end: "<end>"
- when :enter, :return: "<enter>"
- when :tab: "tab"
- when " ": "<space>"
+ when :down then "<down arrow>"
+ when :up then "<up arrow>"
+ when :left then "<left arrow>"
+ when :right then "<right arrow>"
+ when :page_down then "<page down>"
+ when :page_up then "<page up>"
+ when :backspace then "<backspace>"
+ when :home then "<home>"
+ when :end then "<end>"
+ when :enter, :return then "<enter>"
+ when :tab then "tab"
+ when " " then "<space>"
else
Curses::keyname(keysym_to_keycode(k))
end
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
index ba07d35..a9f1a77 100644
--- a/lib/sup/message-chunks.rb
+++ b/lib/sup/message-chunks.rb
@@ -252,8 +252,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 805c2f7..8525fdf 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -414,8 +414,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 8a3004f..1513c42 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}"
@@ -205,7 +205,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
@@ -219,26 +219,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
@@ -274,6 +274,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.
@@ -628,10 +634,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
--
1.6.0.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* [sup-talk] [PATCH] fixes for ruby1.9
2009-06-12 19:35 [sup-talk] [PATCH] fixes for ruby1.9 Rich Lane
@ 2009-06-15 16:32 ` William Morgan
0 siblings, 0 replies; 2+ messages in thread
From: William Morgan @ 2009-06-15 16:32 UTC (permalink / raw)
Reformatted excerpts from Rich Lane's message of 2009-06-12:
> 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
Thanks for this. I've applied it directly to master. Now if someone
would just upgrade Ferret to 1.9, we might be able to actually run Sup!
--
William <wmorgan-sup at masanjin.net>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-06-15 16:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-12 19:35 [sup-talk] [PATCH] fixes for ruby1.9 Rich Lane
2009-06-15 16:32 ` William Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox