Class: Line
Class Method Summary collapse
- .<(txt) ⇒ Object
- .<<(txt, options = {}) ⇒ Object
- .=~(regex) ⇒ Object
-
.[](regex, index = 0) ⇒ Object
Text on current line (minus linebreak).
-
.add_slash(options = {}) ⇒ Object
Add slash to end of line, and optionally a string as well.
- .at_left? ⇒ Boolean
- .at_right? ⇒ Boolean
- .before_cursor ⇒ Object
- .beginning ⇒ Object (also: start)
- .blank? ⇒ Boolean
- .bounds ⇒ Object
- .delete(leave_linebreak = nil) ⇒ Object
- .do_lines_sort ⇒ Object
- .do_lines_toggle ⇒ Object
- .duplicate_line ⇒ Object
- .end ⇒ Object
- .enter_docs ⇒ Object
- .gsub!(from, to) ⇒ Object
- .indent(line = nil) ⇒ Object
- .init ⇒ Object
- .is_bullet?(line = nil) ⇒ Boolean
- .label(line = nil) ⇒ Object
- .left(down = 1) ⇒ Object
-
.matches(o, line = nil) ⇒ Object
Whether line matches pattern.
- .menu ⇒ Object
- .move(direction) ⇒ Object
-
.next(times = nil) ⇒ Object
Moves down, going to first column.
-
.next_matches(pattern) ⇒ Object
Whether next line matches pattern.
-
.next_value(n = 2) ⇒ Object
Return value of next line.
- .number ⇒ Object
-
.previous(times = nil) ⇒ Object
Moves up, going to first column.
- .right ⇒ Object
- .sub!(from, to) ⇒ Object
-
.symbol(options = {}) ⇒ Object
Gets symbol at point.
- .to_beginning(options = {}) ⇒ Object
- .to_blank ⇒ Object
- .to_end ⇒ Object
- .to_left ⇒ Object
-
.to_next(times = nil) ⇒ Object
Moves down, going to first column.
-
.to_previous(times = nil) ⇒ Object
Moves up, going to first column.
- .to_right ⇒ Object
- .to_start ⇒ Object
- .to_words ⇒ Object
- .txt ⇒ Object
- .value ⇒ Object
- .without_indent(txt = nil) ⇒ Object
- .without_label(options = {}) ⇒ Object (also: content)
Class Method Details
.<(txt) ⇒ Object
317 318 319 320 |
# File 'lib/xiki/line.rb', line 317 def self.< txt self.delete :leave View.insert txt end |
.<<(txt, options = {}) ⇒ Object
309 310 311 312 313 314 315 |
# File 'lib/xiki/line.rb', line 309 def self.<< txt, ={} orig = View.cursor Keys.clear_prefix Move.to_end View.insert txt View.cursor = orig if [:dont_move] end |
.=~(regex) ⇒ Object
217 218 219 |
# File 'lib/xiki/line.rb', line 217 def self.=~ regex self.value =~ regex end |
.[](regex, index = 0) ⇒ Object
Text on current line (minus linebreak)
28 29 30 |
# File 'lib/xiki/line.rb', line 28 def self.[] regex, index=0 self.value[regex, index] end |
.add_slash(options = {}) ⇒ Object
Add slash to end of line, and optionally a string as well
Line.add_slash Line.add_slash “hi”
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/xiki/line.rb', line 328 def self.add_slash ={} line = Line.value line =~ /\/$/ || line.blank? ? Move.to_end : Line << "/" txt = .is_a?(String) ? : [:txt] orig = View.cursor Line << txt if txt View.cursor = orig if [:left] nil end |
.at_left? ⇒ Boolean
84 85 86 |
# File 'lib/xiki/line.rb', line 84 def self.at_left? $el.point_at_bol == $el.point end |
.at_right? ⇒ Boolean
72 73 74 |
# File 'lib/xiki/line.rb', line 72 def self.at_right? $el.point_at_eol == $el.point end |
.before_cursor ⇒ Object
344 345 346 |
# File 'lib/xiki/line.rb', line 344 def self.before_cursor View.txt self.left, View.cursor end |
.beginning ⇒ Object Also known as: start
144 145 146 147 |
# File 'lib/xiki/line.rb', line 144 def self.beginning $el.forward_line 0 nil end |
.blank? ⇒ Boolean
76 77 78 |
# File 'lib/xiki/line.rb', line 76 def self.blank? self.matches /^$/ end |
.bounds ⇒ Object
97 98 99 |
# File 'lib/xiki/line.rb', line 97 def self.bounds [$el.point_at_bol, $el.point_at_eol] end |
.delete(leave_linebreak = nil) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/xiki/line.rb', line 101 def self.delete leave_linebreak=nil value = self.value bol, eol = $el.point_at_bol, $el.point_at_eol eol += 1 unless leave_linebreak $el.delete_region(bol, eol) value end |
.do_lines_sort ⇒ Object
348 349 350 351 352 353 |
# File 'lib/xiki/line.rb', line 348 def self.do_lines_sort old = $el.elvar.sort_fold_case# rescue true $el.elvar.sort_fold_case = true $el.sort_lines(nil, $el.region_beginning, $el.region_end) $el.elvar.sort_fold_case = old end |
.do_lines_toggle ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/xiki/line.rb', line 355 def self.do_lines_toggle prefix = Keys.prefix :clear=>1 prefix ||= 1 # Default to one line if prefix.is_a? Fixnum # If number, grab that many lines line_a = [Line.left, Line.left(1+prefix)] line_b = [Line.left(1+prefix), Line.left(1+prefix*2)] Effects.glow :fade_out=>1, :what=>line_b txt = View.delete *line_b View.to line_a[0] View.<< txt, :dont_move=>1 line_a_size = line_a[1] - line_a[0] line_b.map! {|o| o - line_a_size} Effects.glow :fade_in=>1, :what=>line_b return end end |
.duplicate_line ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/xiki/line.rb', line 239 def self.duplicate_line prefix = Keys.prefix # If in file tree, actually duplicate file if prefix == :u && FileTree.handles? Location.as_spot FileTree.copy_to :prefix=>1 return end column = View.column line = "#{Line.value}\n" Line.to_left Code.comment(:line) if prefix == :u times = if prefix.nil? 1 elsif prefix == :u 1 # Put commented line after # 0 # Put commented line before elsif prefix == 0 0 elsif prefix > 0 prefix + 1 elsif prefix < 0 prefix end Line.next times View.insert line Line.previous View.column = column end |
.end ⇒ Object
153 154 155 |
# File 'lib/xiki/line.rb', line 153 def self.end $el.end_of_line end |
.enter_docs ⇒ Object
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/xiki/line.rb', line 393 def self.enter_docs line = Line.value if line.blank? # If blank line, prompt for menu return Launcher.insert "docs" elsif line =~ /^(\w+\.\w+| +([+-] )?\.)/i # If a method, grab docs from source and insert orig = Location.new txt = nil $el.with(:save_window_excursion) do Launcher.as_open # Grab comments right = View.cursor Move.to_previous_paragraph txt = View.txt View.cursor, right orig.go end if txt =~ /^ *[^ #]/ # Do nothing if it wasn't one big comment return View.flash "- No docs found for this method!" end txt = txt.gsub /^ *#( )?/, "@\\1" Tree.<< txt, :no_slash=>1, :no_search=>1 return end Line.add_slash :txt=>"docs/", :unless_blank=>1 Launcher.launch end |
.gsub!(from, to) ⇒ Object
299 300 301 302 303 304 305 306 307 |
# File 'lib/xiki/line.rb', line 299 def self.gsub! from, to orig = Location.new value = Line.value return unless value.gsub! from, to self.delete :leave View.insert value orig.go :assume_file=>1 value end |
.indent(line = nil) ⇒ Object
63 64 65 66 |
# File 'lib/xiki/line.rb', line 63 def self.indent line=nil line ||= self.value line[/^\s*/].gsub("\t", ' ') end |
.init ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/xiki/line.rb', line 377 def self.init return if ! $el # Do nothing if not running under el4r # Define lisp function to get list of displayed lines # In case something has been done to change them $el.el4r_lisp_eval %q` (defun xiki-line-number (pos) (save-excursion (goto-char pos) (forward-line 0) (1+ (count-lines 1 (point)))) ) ` end |
.is_bullet?(line = nil) ⇒ Boolean
226 227 228 229 |
# File 'lib/xiki/line.rb', line 226 def self.is_bullet? line=nil line ||= self.value self.matches /^\s*[+-] /, line end |
.label(line = nil) ⇒ Object
192 193 194 195 196 197 |
# File 'lib/xiki/line.rb', line 192 def self.label line=nil line ||= self.value # Space or blank can follow colon label = line[/^\s*[+-] (.+?): /, 1] label ||= line[/^\s*[+-] (.+?):$/, 1] end |
.left(down = 1) ⇒ Object
80 81 82 |
# File 'lib/xiki/line.rb', line 80 def self.left down=1 $el.point_at_bol down end |
.matches(o, line = nil) ⇒ Object
Whether line matches pattern
48 49 50 51 |
# File 'lib/xiki/line.rb', line 48 def self.matches o, line=nil line ||= self.value line[o] end |
.menu ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/xiki/line.rb', line 3 def self. " - api/ > Moving @ Line.previous # up @ Line.next # down | > Getting text @ p Line.value # line text @ p Line.indent # indent @ p Line.without_indent # without indent @ p Line.label # label @ p Line.without_label # without label | > Getting Positions @ p Line.left # line start @ p Line.right # line ending | > Tests @ p Line.blank? # blank @ Line[/s...thing/] # matches something " end |
.move(direction) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/xiki/line.rb', line 275 def self.move direction column = View.column many = Keys.prefix_times many = (0 - many) if direction == :previous line = Line.value 1, :include_linebreak=>true, :delete=>true # Get line Line.to_next many View.insert line Line.previous View.column = column end |
.next(times = nil) ⇒ Object
Moves down, going to first column
130 131 132 133 |
# File 'lib/xiki/line.rb', line 130 def self.next times=nil $el.forward_line times nil end |
.next_matches(pattern) ⇒ Object
Whether next line matches pattern
59 60 61 |
# File 'lib/xiki/line.rb', line 59 def self.next_matches pattern self.next_value =~ pattern end |
.next_value(n = 2) ⇒ Object
Return value of next line
54 55 56 |
# File 'lib/xiki/line.rb', line 54 def self.next_value n=2 #buffer_substring(point_at_bol(n), point_at_eol(n)) end |
.number ⇒ Object
231 232 233 |
# File 'lib/xiki/line.rb', line 231 def self.number pos=nil $el.xiki_line_number pos || $el.point end |
.previous(times = nil) ⇒ Object
Moves up, going to first column
136 137 138 139 140 141 142 |
# File 'lib/xiki/line.rb', line 136 def self.previous times=nil times = times ? -times : -1 $el.forward_line times nil end |
.right ⇒ Object
68 69 70 |
# File 'lib/xiki/line.rb', line 68 def self.right $el.point_at_eol end |
.sub!(from, to) ⇒ Object
289 290 291 292 293 294 295 296 297 |
# File 'lib/xiki/line.rb', line 289 def self.sub! from, to orig = Location.new value = Line.value return unless value.sub! from, to self.delete :leave View.insert value orig.go :assume_file=>1 value end |
.symbol(options = {}) ⇒ Object
Gets symbol at point
110 111 112 113 114 115 116 117 |
# File 'lib/xiki/line.rb', line 110 def self.symbol ={} symbol = $el.thing_at_point(:symbol) # Delete if option passed if [:delete] $el.delete_region(* $el.bounds_of_thing_at_point(:symbol)) end symbol end |
.to_beginning(options = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/xiki/line.rb', line 174 def self.to_beginning ={} down = [:down] prefix = [:prefix] || Keys.prefix down ||= prefix # If prefix go down n lines first Line.next down if down.is_a? Fixnum Line.to_left prefix == :u || [:quote]? $el.skip_chars_forward("[^ \t]") : $el.skip_chars_forward("[^ \t|]") # If quoted, skip quote unless :u nil end |
.to_blank ⇒ Object
235 236 237 |
# File 'lib/xiki/line.rb', line 235 def self.to_blank $el.re_search_forward "^[ \t]*$" end |
.to_end ⇒ Object
161 162 163 |
# File 'lib/xiki/line.rb', line 161 def self.to_end self.to_right end |
.to_left ⇒ Object
149 150 151 |
# File 'lib/xiki/line.rb', line 149 def self.to_left self.beginning end |
.to_next(times = nil) ⇒ Object
Moves down, going to first column
120 121 122 |
# File 'lib/xiki/line.rb', line 120 def self.to_next times=nil self.next times end |
.to_previous(times = nil) ⇒ Object
Moves up, going to first column
125 126 127 |
# File 'lib/xiki/line.rb', line 125 def self.to_previous times=nil self.previous times end |
.to_right ⇒ Object
157 158 159 |
# File 'lib/xiki/line.rb', line 157 def self.to_right $el.end_of_line end |
.to_start ⇒ Object
165 166 167 |
# File 'lib/xiki/line.rb', line 165 def self.to_start self.to_left end |
.to_words ⇒ Object
169 170 171 172 |
# File 'lib/xiki/line.rb', line 169 def self.to_words $el.beginning_of_line $el.skip_chars_forward "[^ \t]" end |
.txt ⇒ Object
93 94 95 |
# File 'lib/xiki/line.rb', line 93 def self.txt self.without_indent end |
.value ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/xiki/line.rb', line 32 def self.value n=1, ={} eol = "(point-at-eol #{n})" # Optionally include linebreak eol = "(+ 1 #{eol})" if [:include_linebreak] result = $el.el4r_lisp_eval("(buffer-substring (point-at-bol #{n}) #{eol})") if [:delete] $el.el4r_lisp_eval("(delete-region (point-at-bol #{n}) #{eol})") end result end |
.without_indent(txt = nil) ⇒ Object
88 89 90 91 |
# File 'lib/xiki/line.rb', line 88 def self.without_indent txt=nil txt ||= self.value txt.sub(/^\s+/, "") end |
.without_label(options = {}) ⇒ Object Also known as: content
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/xiki/line.rb', line 199 def self.without_label ={} line = .has_key?(:line) ? [:line] : self.value return nil if line.nil? # Delete comment (parenthesis) line = line.sub /^(\s*)(?:[+-]|<+) [^\n\(]+\) (.*)/, "\\1\\2" # If paren at end of line, delete label line.sub! /^(\s*)(?:[+-]|<+) [^\n\(]+?\)$/, "\\1" # If just bullet line.sub! /^(\s*)(?:[+-]|<+) (.+)/, "\\1\\2" # Remove whitespace by default line.sub!(/^ */, '') unless [:leave_indent] line end |