diff options
Diffstat (limited to 'base/vim/ftplugin')
-rw-r--r-- | base/vim/ftplugin/json.vim | 37 | ||||
-rw-r--r-- | base/vim/ftplugin/php.vim | 240 |
2 files changed, 123 insertions, 154 deletions
diff --git a/base/vim/ftplugin/json.vim b/base/vim/ftplugin/json.vim index 3ee1062..1ae1b99 100644 --- a/base/vim/ftplugin/json.vim +++ b/base/vim/ftplugin/json.vim @@ -1,40 +1,33 @@ -" Vim syntax file -" Language: JSON -" Maintainer: Eli Parra <[email protected]> https://github.com/elzr/vim-json -" Last Change: 2014-05-20 added warning toggle - -"uncomment to enable folding of `{...}` and `[...]` blocks -"setlocal foldmethod=syntax - "conceal by default if !exists("g:vim_json_syntax_conceal") - let g:vim_json_syntax_conceal = 1 + let g:vim_json_syntax_conceal = 1 end "have warnings by default if !exists("g:vim_json_warnings") - let g:vim_json_warnings = 1 + let g:vim_json_warnings = 1 end "set concealcursor blank by default "this should turn off the concealing in the current line (where the cursor is at), "on all modes (normal, visual, insert) if !exists("g:vim_json_syntax_concealcursor") - let g:vim_json_syntax_concealcursor = "" + let g:vim_json_syntax_concealcursor = "" end if has('conceal') - if (g:vim_json_syntax_conceal == 1) - "level 2 means concealed text gets completely hidden unless a - "replacement is defined (none is defined by us) - setlocal conceallevel=2 - let &l:concealcursor = g:vim_json_syntax_concealcursor - else - "level 0 means text is shown normally = no concealing - setlocal conceallevel=0 - endif - "maybe g:vim_json_syntax_conceal could be settable to 0,1,2 to map - "directly to vim's conceallevels? unsure if anyone cares + if (g:vim_json_syntax_conceal == 1) + "level 2 means concealed text gets completely hidden unless a + "replacement is defined (none is defined by us) + setlocal conceallevel=2 + let &l:concealcursor = g:vim_json_syntax_concealcursor + else + "level 0 means text is shown normally = no concealing + setlocal conceallevel=0 + endif + "maybe g:vim_json_syntax_conceal could be settable to 0,1,2 to map + "directly to vim's conceallevels? unsure if anyone cares endif setlocal foldmethod=syntax +normal zR diff --git a/base/vim/ftplugin/php.vim b/base/vim/ftplugin/php.vim index c5cba58..3eeb884 100644 --- a/base/vim/ftplugin/php.vim +++ b/base/vim/ftplugin/php.vim @@ -1,34 +1,10 @@ -" Vim indent file -" Language: Php -" Authors: Miles Lott <[email protected]>, Johannes Zellner <[email protected]>, Pim Snel <[email protected]> -" URL: http://lingewoud.nl/downloads.php -" Last Change: 23 feb 2004 -" Version: 0.3 -" Notes: This is a combination of the PHP indent file of Miles Lott with -" the HTML indent file of Johannes Zellner. Usefull for editing -" php-files with html parts in it. -" -" Changelog: -" 0.3 - 25 mar 2004 -" - fixed wrong indention when a php-tag is opened and closed on -" one single line. -" 0.2 - 23 feb 2004 -" - applied patch from Holger Dzeik <[email protected]> -" - added changelog -" - added default indention of 3 spaces after the <?php for better -" reading -" - replaced URL -" - reformatted the options section -" 0.1 - 27 mar 2003 -" - initial creation of html-enhanced php indent-file - " Options: let php_noindent_switch=0 " set this to '1' to not try to indent switch/case statements "set sw=3 " default shiftwidth of 3 spaces if exists("b:did_indent") - finish + finish endif let b:did_indent = 1 @@ -38,83 +14,83 @@ setlocal indentkeys+=0=,0),=EO,o,O,*<Return>,<>>,<bs>,{,} " Only define the function once. if exists("*GetPhpIndent") - finish + finish endif " Handle option(s) if exists("php_noindent_switch") - let b:php_noindent_switch=1 + let b:php_noindent_switch=1 endif if exists('g:html_indent_tags') - unlet g:html_indent_tags + unlet g:html_indent_tags endif function GetPhpIndent() - " Find a non-empty line above the current line. - let lnum = prevnonblank(v:lnum - 1) - - " Hit the start of the file, use zero indent. - if lnum == 0 - return 0 - endif - - let line = getline(lnum) " last line - let cline = getline(v:lnum) " current line - let pline = getline(lnum - 1) " previous to last line - let ind = indent(lnum) - - let restore_ic=&ic - let &ic=1 " ignore case - - let ind = <SID>HtmlIndentSum(lnum, -1) - let ind = ind + <SID>HtmlIndentSum(v:lnum, 0) - - let &ic=restore_ic - - let ind = indent(lnum) + (&sw * ind) - - " Indent after php open tags - if line =~ '<?php' && line !~ '?>' - let ind = ind + &sw - endif - if cline =~ '^\s*[?>]' " // Fix from Holger Dzeik <[email protected]> Thanks! - let ind = ind - &sw - endif - - - if exists("b:php_noindent_switch") " version 1 behavior, diy switch/case,etc - " Indent blocks enclosed by {} or () - if line =~ '[{(]\s*\(#[^)}]*\)\=$' - let ind = ind + &sw - endif - if cline =~ '^\s*[)}]' - let ind = ind - &sw - endif - return ind - else " Try to indent switch/case statements as well - " Indent blocks enclosed by {} or () or case statements, with some anal requirements - if line =~ 'case.*:\|[{(]\s*\(#[^)}]*\)\=$' - let ind = ind + &sw - " return if the current line is not another case statement of the previous line is a bracket open - if cline !~ '.*case.*:\|default:' || line =~ '[{(]\s*\(#[^)}]*\)\=$' - return ind - endif - endif - if cline =~ '^\s*case.*:\|^\s*default:\|^\s*[)}]' - let ind = ind - &sw - " if the last line is a break or return, or the current line is a close bracket, - " or if the previous line is a default statement, subtract another - if line =~ '^\s*break;\|^\s*return\|' && cline =~ '^\s*[)}]' && pline =~ 'default:' - let ind = ind - &sw - endif - endif - - if line =~ 'default:' - let ind = ind + &sw - endif - return ind - endif + " Find a non-empty line above the current line. + let lnum = prevnonblank(v:lnum - 1) + + " Hit the start of the file, use zero indent. + if lnum == 0 + return 0 + endif + + let line = getline(lnum) " last line + let cline = getline(v:lnum) " current line + let pline = getline(lnum - 1) " previous to last line + let ind = indent(lnum) + + let restore_ic=&ic + let &ic=1 " ignore case + + let ind = <SID>HtmlIndentSum(lnum, -1) + let ind = ind + <SID>HtmlIndentSum(v:lnum, 0) + + let &ic=restore_ic + + let ind = indent(lnum) + (&sw * ind) + + " Indent after php open tags + if line =~ '<?php' && line !~ '?>' + let ind = ind + &sw + endif + if cline =~ '^\s*[?>]' " // Fix from Holger Dzeik <[email protected]> Thanks! + let ind = ind - &sw + endif + + + if exists("b:php_noindent_switch") " version 1 behavior, diy switch/case,etc + " Indent blocks enclosed by {} or () + if line =~ '[{(]\s*\(#[^)}]*\)\=$' + let ind = ind + &sw + endif + if cline =~ '^\s*[)}]' + let ind = ind - &sw + endif + return ind + else " Try to indent switch/case statements as well + " Indent blocks enclosed by {} or () or case statements, with some anal requirements + if line =~ 'case.*:\|[{(]\s*\(#[^)}]*\)\=$' + let ind = ind + &sw + " return if the current line is not another case statement of the previous line is a bracket open + if cline !~ '.*case.*:\|default:' || line =~ '[{(]\s*\(#[^)}]*\)\=$' + return ind + endif + endif + if cline =~ '^\s*case.*:\|^\s*default:\|^\s*[)}]' + let ind = ind - &sw + " if the last line is a break or return, or the current line is a close bracket, + " or if the previous line is a default statement, subtract another + if line =~ '^\s*break;\|^\s*return\|' && cline =~ '^\s*[)}]' && pline =~ 'default:' + let ind = ind - &sw + endif + endif + + if line =~ 'default:' + let ind = ind + &sw + endif + return ind + endif endfunction @@ -126,11 +102,11 @@ endfunction " [-- helper function to assemble tag list --] fun! <SID>HtmlIndentPush(tag) - if exists('g:html_indent_tags') - let g:html_indent_tags = g:html_indent_tags.'\|'.a:tag - else - let g:html_indent_tags = a:tag - endif + if exists('g:html_indent_tags') + let g:html_indent_tags = g:html_indent_tags.'\|'.a:tag + else + let g:html_indent_tags = a:tag + endif endfun @@ -201,20 +177,20 @@ call <SID>HtmlIndentPush('var') " [-- <ELEMENT ? O O ...> --] if !exists('g:html_indent_strict') - call <SID>HtmlIndentPush('body') - call <SID>HtmlIndentPush('head') - call <SID>HtmlIndentPush('html') - call <SID>HtmlIndentPush('tbody') + call <SID>HtmlIndentPush('body') + call <SID>HtmlIndentPush('head') + call <SID>HtmlIndentPush('html') + call <SID>HtmlIndentPush('tbody') endif " [-- <ELEMENT ? O - ...> --] if !exists('g:html_indent_strict_table') - call <SID>HtmlIndentPush('th') - call <SID>HtmlIndentPush('td') - call <SID>HtmlIndentPush('tr') - call <SID>HtmlIndentPush('tfoot') - call <SID>HtmlIndentPush('thead') + call <SID>HtmlIndentPush('th') + call <SID>HtmlIndentPush('td') + call <SID>HtmlIndentPush('tr') + call <SID>HtmlIndentPush('tfoot') + call <SID>HtmlIndentPush('thead') endif delfun <SID>HtmlIndentPush @@ -223,50 +199,50 @@ set cpo-=C " [-- count indent-increasing tags of line a:lnum --] fun! <SID>HtmlIndentOpen(lnum) - let s = substitute('x'.getline(a:lnum), - \ '.\{-}\(\(<\)\('.g:html_indent_tags.'\)\>\)', "\1", 'g') - let s = substitute(s, "[^\1].*$", '', '') - return strlen(s) + let s = substitute('x'.getline(a:lnum), + \ '.\{-}\(\(<\)\('.g:html_indent_tags.'\)\>\)', "\1", 'g') + let s = substitute(s, "[^\1].*$", '', '') + return strlen(s) endfun " [-- count indent-decreasing tags of line a:lnum --] fun! <SID>HtmlIndentClose(lnum) - let s = substitute('x'.getline(a:lnum), - \ '.\{-}\(\(<\)/\('.g:html_indent_tags.'\)\>>\)', "\1", 'g') - let s = substitute(s, "[^\1].*$", '', '') - return strlen(s) + let s = substitute('x'.getline(a:lnum), + \ '.\{-}\(\(<\)/\('.g:html_indent_tags.'\)\>>\)', "\1", 'g') + let s = substitute(s, "[^\1].*$", '', '') + return strlen(s) endfun " [-- count indent-increasing '{' of (java|css) line a:lnum --] fun! <SID>HtmlIndentOpenAlt(lnum) - return strlen(substitute(getline(a:lnum), '[^{]\+', '', 'g')) + return strlen(substitute(getline(a:lnum), '[^{]\+', '', 'g')) endfun " [-- count indent-decreasing '}' of (java|css) line a:lnum --] fun! <SID>HtmlIndentCloseAlt(lnum) - return strlen(substitute(getline(a:lnum), '[^}]\+', '', 'g')) + return strlen(substitute(getline(a:lnum), '[^}]\+', '', 'g')) endfun " [-- return the sum of indents respecting the syntax of a:lnum --] fun! <SID>HtmlIndentSum(lnum, style) - if a:style == match(getline(a:lnum), '^\s*</') - if a:style == match(getline(a:lnum), '^\s*</\<\('.g:html_indent_tags.'\)\>') - let open = <SID>HtmlIndentOpen(a:lnum) - let close = <SID>HtmlIndentClose(a:lnum) - if 0 != open || 0 != close - return open - close - endif - endif + if a:style == match(getline(a:lnum), '^\s*</') + if a:style == match(getline(a:lnum), '^\s*</\<\('.g:html_indent_tags.'\)\>') + let open = <SID>HtmlIndentOpen(a:lnum) + let close = <SID>HtmlIndentClose(a:lnum) + if 0 != open || 0 != close + return open - close + endif endif - if '' != &syntax && - \ synIDattr(synID(a:lnum, 1, 1), 'name') =~ '\(css\|java\).*' && - \ synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name') - \ =~ '\(css\|java\).*' - if a:style == match(getline(a:lnum), '^\s*}') - return <SID>HtmlIndentOpenAlt(a:lnum) - <SID>HtmlIndentCloseAlt(a:lnum) - endif + endif + if '' != &syntax && + \ synIDattr(synID(a:lnum, 1, 1), 'name') =~ '\(css\|java\).*' && + \ synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name') + \ =~ '\(css\|java\).*' + if a:style == match(getline(a:lnum), '^\s*}') + return <SID>HtmlIndentOpenAlt(a:lnum) - <SID>HtmlIndentCloseAlt(a:lnum) endif - return 0 + endif + return 0 endfun " vim: set ts=3 sw=3: |