Skip to content
Browse files

Make Vim::ImprovedBuffer more Ruby-like.

  • Loading branch information...
1 parent fc3ab76 commit 8f30078ba4001cccc94d714856d6b687cd745f8c Rob Gleeson committed Jun 4, 2011
Showing with 13 additions and 8 deletions.
  1. +1 −1 plugin/hammer.vim/hammer.vim
  2. +12 −7 plugin/hammer.vim/lib/vim/improvedbuffer.rb
View
2 plugin/hammer.vim/hammer.vim
@@ -28,7 +28,7 @@ REQUIRE_GHMARKUP
path = File.join Hammer::ENV.directory, "#{buffer.basename}.html"
File.open path, 'w' do |f|
- f.write Hammer.render { GitHub::Markup.render(buffer.basename, buffer[1..-1]) }
+ f.write Hammer.render { GitHub::Markup.render(buffer.basename, buffer[0..-1]) }
end
Hammer.open_browser path
View
19 plugin/hammer.vim/lib/vim/improvedbuffer.rb
@@ -2,28 +2,33 @@ module Vim
module ImprovedBuffer
+ # Adds a more Ruby-like interface to Vim::Buffer#[].
+ #
+ # @param [Fixnum, Range] key
+ # @return [String]
def [] key
if key.is_a? Range
- if key.end < 0
- key = key.begin .. self.count - (key.end + 1).abs
- end
+ bufsize = self.count
+ key = bufsize - (key.begin).abs .. key.end if key.begin < 0
+ key = key.begin .. bufsize - (key.end).abs if key.end < 0
- key.map do |number|
- super number
- end.join "\n"
+ key.map { |number| super number + 1 }.join "\n"
else
- super
+ super number + 1
end
end
+ # @return [String] Returns the filename of the buffer.
def basename
File.basename self.name.to_s
end
+ # @return [String] Returns the file extension of the buffer.
def extname
File.extname self.name.to_s
end
+ # @return [Boolean] Returns true if the buffer has been saved to disk.
def saved?
File.exist? self.name.to_s
end

0 comments on commit 8f30078

Please sign in to comment.
Something went wrong with that request. Please try again.