Permalink
Browse files

Single-quoted strings

  • Loading branch information...
1 parent 59c84b1 commit c0162e1cf29068fdc35fa75abed3d0d8db4e2934 @AndrewRadev committed Apr 8, 2012
Showing with 19 additions and 12 deletions.
  1. +17 −11 autoload/sj/coffee.vim
  2. +2 −1 examples/test.coffee
View
@@ -108,37 +108,43 @@ function! sj#coffee#JoinObjectLiteral()
endfunction
function! sj#coffee#SplitString()
- if search('"', 'Wb', line('.')) <= 0
+ if search('["'']', 'Wb', line('.')) <= 0
return 0
endif
- let body = sj#GetMotion('vi"')
- let new_body = substitute(body, '\\"', '"', 'g')
- let new_body = "\"\"\n".new_body."\n\"\"" " Note: only two double quotes
+ let quote = getline('.')[col('.') - 1]
+ let multi_quote = repeat(quote, 2) " Note: only two quotes
- call sj#ReplaceMotion('vi"', new_body)
+ let body = sj#GetMotion('vi'.quote)
+ let new_body = substitute(body, '\\'.quote, quote, 'g')
+ let new_body = multi_quote."\n".new_body."\n".multi_quote
+
+ call sj#ReplaceMotion('vi'.quote, new_body)
normal! j>>
return 1
endfunction
function! sj#coffee#JoinString()
- if search('"""', 'Wbc') <= 0
+ if search('"""\|''''''', 'Wbc') <= 0
return 0
endif
- let start = getpos('.')
+ let start = getpos('.')
+ let multi_quote = expand('<cword>')
+ let quote = multi_quote[0]
+
normal! j
- if search('"""', 'Wce') <= 0
+ if search(multi_quote, 'Wce') <= 0
return 0
endif
let end = getpos('.')
let body = sj#GetByPosition(start, end)
- let new_body = substitute(body, '^"""\_s*\(.*\)\_s*"""', '\1', 'g')
- let new_body = substitute(new_body, '"', '\\"', 'g')
+ let new_body = substitute(body, '^'.multi_quote.'\_s*\(.*\)\_s*'.multi_quote.'$', '\1', 'g')
+ let new_body = substitute(new_body, quote, '\\'.quote, 'g')
let new_body = sj#Trim(new_body)
- let new_body = '"'.new_body.'"'
+ let new_body = quote.new_body.quote
call sj#ReplaceByPosition(start, end, new_body)
View
@@ -12,5 +12,6 @@ foo = "example"
foo = "example with #{interpolation}"
foo = "example with \"nested\" quotes"
-# TODO (2012-04-07) Implement
foo = 'example with single quotes'
+foo = 'example with \'escaped\' single quotes'
+# TODO odd problem with last line

0 comments on commit c0162e1

Please sign in to comment.