Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add and update comments

  • Loading branch information...
commit 725e93affce642ea64cfa4ae9aa1f90b3c9f3a17 1 parent d8233f5
Adnan Zafar authored

Showing 1 changed file with 18 additions and 17 deletions. Show diff stats Hide diff stats

  1. +18 17 plugin/snipMate.vim
35 plugin/snipMate.vim
@@ -68,6 +68,7 @@ function! s:CreateSnippets(...)
68 68 endfor
69 69 endfunction
70 70
  71 +" Parses a snippets file
71 72 function! s:ExtractSnipsFile(file, scope)
72 73 if !filereadable(a:file) | return | endif
73 74 let text = readfile(a:file)
@@ -270,8 +271,9 @@ endfunction
270 271
271 272 let s:state_proto = {}
272 273
  274 +" Removes snippet state info
273 275 function! s:state_proto.remove()
274   - " Remove all buflocal in group snipmate_changes in the current buffer
  276 + " Remove all autocmds in group snipmate_changes in the current buffer
275 277 au! snipmate_changes * <buffer>
276 278 unl! b:snipstate
277 279 endfunction
@@ -332,6 +334,7 @@ function! snipMate#expandSnip(snip, col)
332 334 return ''
333 335 endfunction
334 336
  337 +" Update state information to correspond to the given tab stop
335 338 function! s:state_proto.set_stop(stop)
336 339 let self.stop_no = a:stop
337 340 let self.cur_stop = self.stops[self.stop_no]
@@ -461,12 +464,10 @@ endfunction
461 464 " 2.) The tab stop's column number
462 465 " (by getting the length of the string between the last "\n" and the
463 466 " tab stop).
464   -" 3.) The length of the text after the colon for the current tab stop
465   -" (e.g. "${1:foo}" would return 3). If there is no text, -1 is returned.
466   -" 4.) If the "${#:}" construct is given, another list containing all
467   -" the matches of "$#", to be replaced with the placeholder. This list is
468   -" composed the same way as the parent; the first item is the line number,
469   -" and the second is the column.
  467 +" 3.) The length of the placeholder for the current tab stop or 0 for no
  468 +" placeholder. "${1}" would be 0; "${1:foo}" would be 3.
  469 +" 4.) A list of [line, column] representing any mirrors for the tab stop. The
  470 +" list is empty if there are no mirrors.
470 471 function! s:BuildTabStops(snip, lnum, col, indent)
471 472 let snipPos = []
472 473 let i = 1
@@ -505,7 +506,9 @@ function! s:BuildTabStops(snip, lnum, col, indent)
505 506 return [snipPos, i - 1]
506 507 endfunction
507 508
  509 +" Jump to the next/previous tab stop
508 510 function! s:state_proto.jump_stop(backwards)
  511 + " Update the locations of tab stops for any changes made
509 512 if self.has_mirrors
510 513 call self.update_placeholders()
511 514 else
@@ -532,6 +535,7 @@ function! s:state_proto.jump_stop(backwards)
532 535 return self.select_word()
533 536 endfunction
534 537
  538 +" Updates tab stops/mirrors
535 539 function! s:state_proto.update_placeholders()
536 540 let changeLen = self.endCol - self.cur_stop[2] - self.startCol
537 541 if !exists('self.oldVars') | return | endif
@@ -577,6 +581,7 @@ function! s:state_proto.update_placeholders()
577 581 unl self.oldVars
578 582 endfunction
579 583
  584 +" Updates tab stops/mirrors
580 585 function! s:state_proto.update_stops()
581 586 let changeCol = self.endCol - self.cur_stop[2] - self.startCol
582 587 let lnum = self.cur_stop[0]
@@ -599,6 +604,7 @@ function! s:state_proto.update_stops()
599 604 endif
600 605 endfunction
601 606
  607 +" Select the placeholder for the current tab stop
602 608 function! s:state_proto.select_word()
603 609 let len = self.cur_stop[2]
604 610 if !len | return '' | endif
@@ -609,14 +615,9 @@ function! s:state_proto.select_word()
609 615 return len == 1 ? "\<esc>".l.'gh' : "\<esc>".l.'v'.(len - 1)."l\<c-g>"
610 616 endfunction
611 617
612   -" This updates the snippet as you type when text needs to be inserted
613   -" into multiple places (e.g. in "${1:default text}foo$1bar$1",
614   -" "default text" would be highlighted, and if the user types something,
615   -" UpdateChangedSnip() would be called so that the text after "foo" & "bar"
616   -" are updated accordingly)
617   -"
618   -" It also automatically quits the snippet if the cursor is moved out of it
619   -" while in insert mode.
  618 +" Update the snippet as text is typed. The self.update_mirrors() function does
  619 +" the actual work.
  620 +" If the cursor moves outside of a placeholder, call self.remove()
620 621 function! s:state_proto.update_changes()
621 622 " If tab stop has been modified, delete any nested placeholders it has.
622 623 if !exists('self.nested_count') &&
@@ -646,6 +647,7 @@ function! s:state_proto.update_changes()
646 647 let self.prevLen = col('$')
647 648 endfunction
648 649
  650 +" Delete any nested tab stops
649 651 function! s:state_proto.delete_nested()
650 652 let self.nested_count = 0
651 653 let lnum = line('.')
@@ -660,8 +662,7 @@ function! s:state_proto.delete_nested()
660 662 endfor
661 663 endfunction
662 664
663   -" This updates the variables in a snippet when a placeholder has been edited.
664   -" (e.g., each "$1" in "${1:foo} $1bar $1bar")
  665 +" Actually update the mirrors for any changed text
665 666 function! s:state_proto.update_mirrors(change)
666 667 let newWordLen = self.endCol - self.startCol
667 668 let newWord = strpart(getline('.'), self.startCol - 1, newWordLen)

0 comments on commit 725e93a

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