Module: VER::Methods::Delete
- Defined in:
- lib/ver/methods/delete.rb
Class Method Summary collapse
-
.change_line(text, count = text.prefix_count) ⇒ Object
Wrapper for [kill_line] that starts insert mode after killing
count
lines. - .change_motion(text, motion, count = text.prefix_count) ⇒ Object
-
.change_word_right_end(text, count = text.prefix_count) ⇒ Object
- word_right_end
-
goes to the last character, that is, the insert mark is between the second to last and last character.
-
.delete(text, *indices) ⇒ Object
Delete text between
indices
. -
.delete_line(text, count = text.prefix_count) ⇒ Object
Delete current line and upto
count
subsequent lines. -
.delete_motion(text, motion, count = text.prefix_count) ⇒ Object
Given a
motion
, this method will execute a virtual movement with thecount
argument and [delete] the corresponding indices. -
.delete_trailing_whitespace(text) ⇒ Object
Tag and delete all trailing whitespace in the current buffer.
-
.kill(text, *indices) ⇒ Object
Copy text between
indices
and delete it. -
.kill_line(text, count = text.prefix_count) ⇒ Object
Copy current line and upto
count
subsequent lines and delete them. -
.kill_motion(text, motion, count = text.prefix_count) ⇒ Object
Given a
motion
, this method will execute a virtual movement with thecount
argument and [kill] the corresponding indices.
Class Method Details
.change_line(text, count = text.prefix_count) ⇒ Object
Wrapper for [kill_line] that starts insert mode after killing count
lines. It also doesn’t delete the newline.
78 79 80 81 82 83 84 |
# File 'lib/ver/methods/delete.rb', line 78 def change_line(text, count = text.prefix_count) count = count.abs - 1 from = text.index('insert linestart') to = "#{from.y + count}.#{from.x} lineend" kill(text, from, text.index(to)) text.minor_mode(:control, :insert) end |
.change_motion(text, motion, count = text.prefix_count) ⇒ Object
6 7 8 9 |
# File 'lib/ver/methods/delete.rb', line 6 def change_motion(text, motion, count = text.prefix_count) delete_motion(text, motion, count) text.minor_mode(:control, :insert) end |
.change_word_right_end(text, count = text.prefix_count) ⇒ Object
- word_right_end
-
goes to the last character, that is, the insert mark is
between the second to last and last character. This means that the range to delete is off by one, account for it here.
40 41 42 43 44 |
# File 'lib/ver/methods/delete.rb', line 40 def change_word_right_end(text, count = text.prefix_count) index = Move.index_at_word_right_end(text, count) delete(text, :insert, index + 1) text.minor_mode(:control, :insert) end |
.delete(text, *indices) ⇒ Object
Delete text between indices
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ver/methods/delete.rb', line 93 def delete(text, *indices) indices_size = indices.size return if indices_size == 0 Undo.record text do |record| if indices_size == 1 record.delete(indices.first) else indices.each_slice(2) do |from, to| next if from == to record.delete(from, to) end end end end |
.delete_line(text, count = text.prefix_count) ⇒ Object
Delete current line and upto count
subsequent lines.
52 53 54 55 56 57 |
# File 'lib/ver/methods/delete.rb', line 52 def delete_line(text, count = text.prefix_count) count = count.abs - 1 from = text.index('insert linestart') to = "#{from.y + count}.#{from.x} lineend + 1 char" delete(text, from, text.index(to)) end |
.delete_motion(text, motion, count = text.prefix_count) ⇒ Object
Given a motion
, this method will execute a virtual movement with the count
argument and [delete] the corresponding indices.
19 20 21 22 |
# File 'lib/ver/methods/delete.rb', line 19 def delete_motion(text, motion, count = text.prefix_count) movement = Move.virtual(text, motion, count) delete(text, *movement) end |
.delete_trailing_whitespace(text) ⇒ Object
Tag and delete all trailing whitespace in the current buffer.
87 88 89 90 |
# File 'lib/ver/methods/delete.rb', line 87 def delete_trailing_whitespace(text) ranges = text.tag_ranges('invalid.trailing-whitespace').flatten text.execute(:delete, *ranges) unless ranges.empty? end |
.kill(text, *indices) ⇒ Object
Copy text between indices
and delete it.
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ver/methods/delete.rb', line 114 def kill(text, *indices) if indices.size > 2 deleted = indices.each_slice(2).map{|left, right| text.get(left, right) } else deleted = text.get(*indices) end Clipboard.copy(text, deleted) delete(text, *indices) end |
.kill_line(text, count = text.prefix_count) ⇒ Object
Copy current line and upto count
subsequent lines and delete them.
65 66 67 68 69 70 |
# File 'lib/ver/methods/delete.rb', line 65 def kill_line(text, count = text.prefix_count) count = count.abs - 1 from = text.index('insert linestart') to = "#{from.y + count.to_i}.#{from.x} lineend + 1 char" kill(text, from, text.index(to)) end |
.kill_motion(text, motion, count = text.prefix_count) ⇒ Object
Given a motion
, this method will execute a virtual movement with the count
argument and [kill] the corresponding indices.
32 33 34 35 |
# File 'lib/ver/methods/delete.rb', line 32 def kill_motion(text, motion, count = text.prefix_count) movement = Move.virtual(text, motion, count) kill(text, *movement) end |