• R/O
  • HTTP
  • SSH
  • HTTPS

kink.vim: Commit

Vim Plugins for Kink Programming Language


Commit MetaInfo

Revisãoa4c25fd4e56c01384e4f89a995a8f94c5681f7e5 (tree)
Hora2017-04-12 17:18:50
AutorMiyakawa Taku <miyakawa.taku@gmai...>
CommiterMiyakawa Taku

Mensagem de Log

better handling of comments and strings

Mudança Sumário

Diff

--- a/indent/kink.vim
+++ b/indent/kink.vim
@@ -1,7 +1,7 @@
11 " Vim indent file for Kink
22 " Language: Kink (https://bitbucket.org/kink/kink)
33 " Maintainer: Miyakawa Taku <miyakawa.taku@gmail.com>
4-" Last Change: 2017-04-10
4+" Last Change: 2017-04-12
55
66 " Copyright (c) 2013- Miyakawa Taku
77 "
@@ -39,12 +39,12 @@ setlocal indentkeys=0},0),0=],!^F,o,O
3939 let s:save_cpo = &cpo
4040 set cpo&vim
4141
42-let s:skip = 'has("syntax_items") && synIDattr(synID(line("."), col("."), 1), "name") =~ "String\\|Comment"'
42+let s:skip = 'has("syntax_items") && synIDattr(synID(line("."), col("."), 1), "name") =~ "String\\|Quote\\|Comment"'
4343
4444 " Returns the indent
4545 function! GetKinkIndent(line_no)
4646 let prev_line_no = prevnonblank(a:line_no - 1)
47- if s:in_comment_or_string() || prev_line_no == 0
47+ if prev_line_no == 0 || s:head_in_string(a:line_no)
4848 return -1
4949 endif
5050
@@ -62,8 +62,8 @@ function! GetKinkIndent(line_no)
6262 endif
6363 else
6464 " Indent based on the previous line
65- let [base_linenno, base_indent] = s:get_base_lineno_and_indent(prev_line_no)
66- let openers = s:get_openers_till(base_linenno, a:line_no)
65+ let [base_lineno, base_indent] = s:get_base_lineno_and_indent(prev_line_no)
66+ let openers = s:get_openers_till(base_lineno, a:line_no)
6767 return base_indent + &shiftwidth * openers
6868 endif
6969 endfunction
@@ -92,7 +92,7 @@ function! s:patterns_for_closing(closing)
9292 endfunction
9393
9494 " Returns [base_lineno, base_indent].
95-function!s:get_base_lineno_and_indent(line_no)
95+function! s:get_base_lineno_and_indent(line_no)
9696 call cursor(a:line_no, 1)
9797 call cursor(a:line_no, col('$'))
9898 let ln = a:line_no
@@ -117,7 +117,7 @@ function!s:get_base_lineno_and_indent(line_no)
117117 endif
118118 endwhile
119119
120- if s:in_string(line('.'), 1)
120+ if s:head_in_string(line('.'))
121121 return s:get_base_lineno_and_indent(a:line_no - 1)
122122 else
123123 return [a:line_no, indent(a:line_no)]
@@ -181,12 +181,35 @@ endfunction
181181
182182 " Returns true if the cursor is in a string or a comment.
183183 function! s:in_comment_or_string()
184- return has('syntax_items') && synIDattr(synID(line('.'), col('.'), 1), "name") =~ 'String\|Comment'
184+ return has('syntax_items') && synIDattr(synID(line('.'), col('.'), 1), "name") =~ 'String\|Quote\|Comment'
185185 endfunction
186186
187-" Returns true if the position is in a string.
188-function! s:in_string(lineno, colno)
189- return has('syntax_items') && synIDattr(synID(a:lineno, a:colno, 1), "name") =~ 'String'
187+" Returns true if the line starts in a string.
188+function! s:head_in_string(lineno)
189+ if ! has('syntax_items')
190+ return 0
191+ endif
192+
193+ if getline(a:lineno) != ''
194+ return synIDattr(synID(a:lineno, 1, 1), "name") =~ 'String\|QuoteEnd'
195+ end
196+
197+ let ln = a:lineno
198+ while 1
199+ if ln == 0
200+ return 0
201+ endif
202+
203+ if getline(ln) != ""
204+ break
205+ endif
206+
207+ let ln = ln - 1
208+ endwhile
209+
210+ call cursor(ln, 1)
211+ let endcol = col('$') - 1
212+ return synIDattr(synID(ln, endcol, 1), "name") =~ 'String\|QuoteStart'
190213 endfunction
191214
192215 let &cpo = s:save_cpo
--- a/syntax/kink.vim
+++ b/syntax/kink.vim
@@ -1,7 +1,7 @@
11 " Vim syntax file
22 " Language: Kink (http://code.google.com/p/kink-lang/)
33 " Maintainer: Miyakawa Taku <miyakawa.taku@gmail.com>
4-" Last Change: 2017-04-10
4+" Last Change: 2017-04-12
55
66 " Copyright (c) 2013- Miyakawa Taku
77 "
@@ -40,9 +40,9 @@ syntax match kinkNounDeref "[A-Z][a-zA-Z_0-9?]*"
4040
4141 syntax keyword kinkTodo contained TODO FIXME XXX
4242 syntax match kinkComment "#.*" contains=kinkTodo
43-syntax region kinkString start=+'+ skip=+''+ end=+'+
44-syntax region kinkString start=+"+ skip=+\\.+ end=+"+ contains=kinkStringEscape
45-syntax region kinkString start=+(\z(=\+\)'+ end=+'\z1)+
43+syntax region kinkString skip=+''+ matchgroup=kinkQuoteStart start=+'+ matchgroup=kinkQuoteEnd end=+'+
44+syntax region kinkString skip=+\\.+ matchgroup=kinkQuoteStart start=+"+ matchgroup=kinkQuoteEnd end=+"+ contains=kinkStringEscape
45+syntax region kinkString matchgroup=kinkQuoteStart start=+(\z(=\+\)'+ matchgroup=kinkQuoteEnd end=+'\z1)+
4646 syntax match kinkStringEscape contained +\\[0tnrabefv"\\]\|\\u[0-9a-f]\{4}\|\\x{[0-9a-f]\{1,6}}+
4747 syntax match kinkPseudoVariable "\\\(env\|recv\|args\|[0-9][0-9_]*\|0x[0-9a-f_]*\|0b[01_]*\)\>"
4848 syntax match kinkInteger "0x[0-9a-f_]*\|0b[01_]*\|[0-9][0-9_]*"
@@ -56,6 +56,8 @@ highlight default link kinkNounDeref Identifier
5656 highlight default link kinkComment Comment
5757 highlight default link kinkTodo Todo
5858 highlight default link kinkString String
59+highlight default link kinkQuoteStart String
60+highlight default link kinkQuoteEnd String
5961 highlight default link kinkStringEscape SpecialChar
6062 highlight default link kinkPseudoVariable Special
6163 highlight default link kinkInteger Number
Show on old repository browser