Module: VER::Methods::Bookmark
- Defined in:
- lib/ver/methods/bookmark.rb
Class Method Summary collapse
- .add_char(buffer, name = nil) ⇒ Object
- .add_named(buffer, name = nil) ⇒ Object
- .ask(buffer) ⇒ Object
- .bookmarks ⇒ Object
- .next(buffer) ⇒ Object
- .open(buffer, bookmark, use_col = true) ⇒ Object
- .prev(buffer) ⇒ Object
- .remove_named(buffer, name = nil) ⇒ Object
- .toggle(buffer) ⇒ Object
- .value(buffer) ⇒ Object
- .visit_char(buffer, name = nil) ⇒ Object
- .visit_named(buffer, name = nil) ⇒ Object
Class Method Details
.add_char(buffer, name = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ver/methods/bookmark.rb', line 28 def add_char(buffer, name = nil) if name add_named(buffer, name) else ask(buffer){|answer| add_named(buffer, answer) } end end |
.add_named(buffer, name = nil) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ver/methods/bookmark.rb', line 36 def add_named(buffer, name = nil) if name bm = bookmarks.add_named(name, value(buffer)) buffer.("Added bookmark [%s|%s:%d,%d]." % bm.to_a) else ask(buffer){|answer| add_named(buffer, answer) } end end |
.ask(buffer) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ver/methods/bookmark.rb', line 6 def ask(buffer) buffer.ask 'Bookmark name: ' do |answer, action| case action when :modified, :attempt if name = answer[0] yield name :abort else buffer. 'Need a bookmark name' end end end end |
.bookmarks ⇒ Object
91 92 93 |
# File 'lib/ver/methods/bookmark.rb', line 91 def bookmarks VER.bookmarks end |
.next(buffer) ⇒ Object
83 84 85 |
# File 'lib/ver/methods/bookmark.rb', line 83 def next(buffer) open(buffer, bookmarks.next_from(value(buffer))) end |
.open(buffer, bookmark, use_col = true) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/ver/methods/bookmark.rb', line 99 def open(buffer, bookmark, use_col = true) return unless bookmark.respond_to?(:file) && bookmark.respond_to?(:index) line, col = use_col ? bookmark.index : [bookmark.line, 0] VER.find_or_create_buffer(bookmark.file, line, col) end |
.prev(buffer) ⇒ Object
87 88 89 |
# File 'lib/ver/methods/bookmark.rb', line 87 def prev(buffer) open(buffer, bookmarks.prev_from(value(buffer))) end |
.remove_named(buffer, name = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ver/methods/bookmark.rb', line 45 def remove_named(buffer, name = nil) if name if bm = bookmarks.delete(name) buffer.("Removed bookmark [%s|%s:%d,%d]." % bm.to_a) else buffer.("No Bookmark named %p." % [name]) end else ask(buffer){|answer| remove_named(buffer, answer) } end end |
.toggle(buffer) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ver/methods/bookmark.rb', line 69 def toggle(buffer) pos = value(buffer) if bm = bookmarks.at(pos) bookmarks.delete(bm) ("Removed bookmark [%s|%s:%d,%d]." % bm.to_a) else bm = bookmarks.add_unnamed(pos) ("Added bookmark [%s|%s:%d,%d]." % bm.to_a) end rescue => ex VER.error(ex) end |
.value(buffer) ⇒ Object
95 96 97 |
# File 'lib/ver/methods/bookmark.rb', line 95 def value(buffer) [buffer.filename, *buffer.index(:insert)] end |
.visit_char(buffer, name = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/ver/methods/bookmark.rb', line 20 def visit_char(buffer, name = nil) if name visit_named(buffer, name) else ask(buffer){|answer| visit_named(buffer, answer) } end end |
.visit_named(buffer, name = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ver/methods/bookmark.rb', line 57 def visit_named(buffer, name = nil) if name if bm = bookmarks[name] open(buffer, bm) else buffer.("No Bookmark named %p." % [name]) end else ask(buffer){|answer| visit_named(buffer, answer) } end end |