commit 58b16ca5e8ca2aaaedfac26545f5aaa7864a3598
parent c2fb246a2853609f7a068306f29764937568c6e5
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Tue, 18 Jan 2011 19:04:27 -0800
Merge branch 'scrolling'
Diffstat:
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -282,7 +282,8 @@ EOS
:sent_source => "sup://sent",
:poll_interval => 300,
:wrap_width => 0,
- :slip_rows => 0
+ :slip_rows => 0,
+ :col_jump => 2
}
begin
Redwood::save_yaml_obj config, filename
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
@@ -220,6 +220,8 @@ class Colormap
Colormap.new unless @@instance
@@instance.send meth, *a
end
+ # Performance shortcut
+ def self.color_for *a; @@instance.color_for *a; end
end
end
diff --git a/lib/sup/modes/scroll-mode.rb b/lib/sup/modes/scroll-mode.rb
@@ -12,8 +12,6 @@ class ScrollMode < Mode
attr_reader :status, :topline, :botline, :leftcol
- COL_JUMP = 2
-
register_keymap do |k|
k.add :line_down, "Down one line", :down, 'j', 'J', "\C-e"
k.add :line_up, "Up one line", :up, 'k', 'K', "\C-y"
@@ -98,19 +96,23 @@ class ScrollMode < Mode
def search_start_line; @topline end
def search_goto_line line; jump_to_line line end
+ def col_jump
+ $config[:col_jump] || 2
+ end
+
def col_left
return unless @leftcol > 0
- @leftcol -= COL_JUMP
+ @leftcol -= col_jump
buffer.mark_dirty
end
def col_right
- @leftcol += COL_JUMP
+ @leftcol += col_jump
buffer.mark_dirty
end
def jump_to_col col
- col = col - (col % COL_JUMP)
+ col = col - (col % col_jump)
buffer.mark_dirty unless @leftcol == col
@leftcol = col
end
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -212,7 +212,8 @@ class String
## the utf8 regex and count those. otherwise, use the byte length.
def display_length
if RUBY_VERSION < '1.9.1' && ($encoding == "UTF-8" || $encoding == "utf8")
- scan(/./u).size
+ # scan hack is somewhat slow, worth trying to cache
+ @display_length ||= scan(/./u).size
else
size
end