lib/ver/methods/selection.rb in ver-2010.02 vs lib/ver/methods/selection.rb in ver-2010.08

- old
+ new

@@ -1,36 +1,40 @@ module VER module Methods module Selection module_function - def enter(text, old_mode, new_mode) - unless old_mode.name =~ /^select/ - text.store(self, :start, text.index(:insert)) - end + def pipe(buffer) + paths = ENV['PATH'].split(':').map{|path| Pathname(path).expand_path } - text.store(self, :mode, new_mode) - text.store(self, :refresh, true) - Undo.separator(text) - refresh(text) - end - - def leave(text, old_mode, new_mode) - return if new_mode.name =~ /^select/ - - text.store(self, :mode, new_mode) - text.store(self, :refresh, false) - Undo.separator(text) - clear(text) - end - - def select_mode(text) - if mode = text.store(self, :mode) - mode.to_sym + buffer.ask 'Pipe command: ' do |answer, action| + case action + when :complete + current = answer.split.last + paths.map{|path| + (path/"*#{current}*").glob.select{|file| + begin + file = File.readlink(file) if File.symlink?(file) + stat = File.stat(file) + stat.file? && stat.executable? + rescue Errno::ENOENT + end + } + }.flatten.compact + when :attempt + buffer.at_sel.pipe!(answer) + buffer.at_sel.finish + :abort + end end end + end + end +end +__END__ + def refresh(text) return unless text.store(self, :refresh) return unless start = text.store(self, :start) text.tag_remove(:sel, 1.0, :end) @@ -185,35 +189,11 @@ chunks = text.tag_ranges(:sel).map{|sel| text.get(*sel) } Clipboard.copy(text, chunks.size == 1 ? chunks.first : chunks) finish(text) end - def pipe(text) - paths = ENV['PATH'].split(':').map{|path| Pathname(path).expand_path } - text.ask 'Pipe command: ' do |answer, action| - case action - when :complete - current = answer.split.last - paths.map{|path| - (path/"*#{current}*").glob.select{|file| - begin - file = File.readlink(file) if File.symlink?(file) - stat = File.stat(file) - stat.file? && stat.executable? - rescue Errno::ENOENT - end - } - }.flatten.compact - when :attempt - pipe_execute(text, answer) - finish(text) - :abort - end - end - end - def comment(text) comment = "#{text.options.comment_line} " indent = nil lines = [] @@ -411,17 +391,9 @@ [*start.split, *text.index('insert').split] end from_y, to_y = [ly, ry].sort from_x, to_x = [lx, rx].sort - - code = [%(set win "#{text.tk_pathname}")] - - from_y.upto to_y do |y| - code << "$win tag add sel #{y}.#{from_x} #{y}.#{to_x + 1}" - end - - Tk.execute_only(Tk::TclString.new(code.join("\n"))) end def refresh_char(text, start) if text.compare('insert', '>', start) text.tag_add(:sel, start, "insert + 1 chars")