mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-13 14:03:50 -05:00
Some major updates including heuristics
- Allow to define heuristics in heuristics.yaml - Migrate all filetypes from vim beginning with "a" - Remove enhanced cpp syntax (it was too slow to load) - Use setf instead of set ft for setting filetype (faster) - Override native hauristics with au! - Add globbing of files for packages - Replace predefined dirs with extra_dirs and ignored_dirs - Allow to define proper order of packages with topological sort - Fix powershell detection - Lint and fix many packages.yaml issues - etc etd
This commit is contained in:
16
indent/aap.vim
Normal file
16
indent/aap.vim
Normal file
@@ -0,0 +1,16 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'aap') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Aap recipe
|
||||
" Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||
" Last Change: 2005 Jun 24
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" Works mostly like Python.
|
||||
runtime! indent/python.vim
|
||||
|
||||
endif
|
||||
312
indent/ada.vim
Normal file
312
indent/ada.vim
Normal file
@@ -0,0 +1,312 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ada') == -1
|
||||
|
||||
"------------------------------------------------------------------------------
|
||||
" Description: Vim Ada indent file
|
||||
" Language: Ada (2005)
|
||||
" $Id: ada.vim 887 2008-07-08 14:29:01Z krischik $
|
||||
" Copyright: Copyright (C) 2006 Martin Krischik
|
||||
" Maintainer: Martin Krischik <krischik@users.sourceforge.net>
|
||||
" Neil Bird <neil@fnxweb.com>
|
||||
" Ned Okie <nokie@radford.edu>
|
||||
" $Author: krischik $
|
||||
" $Date: 2008-07-08 16:29:01 +0200 (Di, 08 Jul 2008) $
|
||||
" Version: 4.6
|
||||
" $Revision: 887 $
|
||||
" $HeadURL: https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/tools/vim/indent/ada.vim $
|
||||
" History: 24.05.2006 MK Unified Headers
|
||||
" 16.07.2006 MK Ada-Mode as vim-ball
|
||||
" 15.10.2006 MK Bram's suggestion for runtime integration
|
||||
" 05.11.2006 MK Bram suggested to save on spaces
|
||||
" 19.09.2007 NO g: missing before ada#Comment
|
||||
" Help Page: ft-vim-indent
|
||||
"------------------------------------------------------------------------------
|
||||
" ToDo:
|
||||
" Verify handling of multi-line exprs. and recovery upon the final ';'.
|
||||
" Correctly find comments given '"' and "" ==> " syntax.
|
||||
" Combine the two large block-indent functions into one?
|
||||
"------------------------------------------------------------------------------
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent") || version < 700
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 45
|
||||
|
||||
setlocal indentexpr=GetAdaIndent()
|
||||
setlocal indentkeys-=0{,0}
|
||||
setlocal indentkeys+=0=~then,0=~end,0=~elsif,0=~when,0=~exception,0=~begin,0=~is,0=~record
|
||||
|
||||
" Only define the functions once.
|
||||
if exists("*GetAdaIndent")
|
||||
finish
|
||||
endif
|
||||
let s:keepcpo= &cpo
|
||||
set cpo&vim
|
||||
|
||||
if exists("g:ada_with_gnat_project_files")
|
||||
let s:AdaBlockStart = '^\s*\(if\>\|while\>\|else\>\|elsif\>\|loop\>\|for\>.*\<\(loop\|use\)\>\|declare\>\|begin\>\|type\>.*\<is\>[^;]*$\|\(type\>.*\)\=\<record\>\|procedure\>\|function\>\|accept\>\|do\>\|task\>\|package\>\|project\>\|then\>\|when\>\|is\>\)'
|
||||
else
|
||||
let s:AdaBlockStart = '^\s*\(if\>\|while\>\|else\>\|elsif\>\|loop\>\|for\>.*\<\(loop\|use\)\>\|declare\>\|begin\>\|type\>.*\<is\>[^;]*$\|\(type\>.*\)\=\<record\>\|procedure\>\|function\>\|accept\>\|do\>\|task\>\|package\>\|then\>\|when\>\|is\>\)'
|
||||
endif
|
||||
|
||||
" Section: s:MainBlockIndent {{{1
|
||||
"
|
||||
" Try to find indent of the block we're in
|
||||
" prev_indent = the previous line's indent
|
||||
" prev_lnum = previous line (to start looking on)
|
||||
" blockstart = expr. that indicates a possible start of this block
|
||||
" stop_at = if non-null, if a matching line is found, gives up!
|
||||
" No recursive previous block analysis: simply look for a valid line
|
||||
" with a lesser or equal indent than we currently (on prev_lnum) have.
|
||||
" This shouldn't work as well as it appears to with lines that are currently
|
||||
" nowhere near the correct indent (e.g., start of line)!
|
||||
" Seems to work OK as it 'starts' with the indent of the /previous/ line.
|
||||
function s:MainBlockIndent (prev_indent, prev_lnum, blockstart, stop_at)
|
||||
let lnum = a:prev_lnum
|
||||
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
|
||||
while lnum > 1
|
||||
if a:stop_at != '' && line =~ '^\s*' . a:stop_at && indent(lnum) < a:prev_indent
|
||||
return a:prev_indent
|
||||
elseif line =~ '^\s*' . a:blockstart
|
||||
let ind = indent(lnum)
|
||||
if ind < a:prev_indent
|
||||
return ind
|
||||
endif
|
||||
endif
|
||||
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
" Get previous non-blank/non-comment-only line
|
||||
while 1
|
||||
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
|
||||
if line !~ '^\s*$' && line !~ '^\s*#'
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
if lnum <= 0
|
||||
return a:prev_indent
|
||||
endif
|
||||
endwhile
|
||||
endwhile
|
||||
" Fallback - just move back one
|
||||
return a:prev_indent - shiftwidth()
|
||||
endfunction MainBlockIndent
|
||||
|
||||
" Section: s:EndBlockIndent {{{1
|
||||
"
|
||||
" Try to find indent of the block we're in (and about to complete),
|
||||
" including handling of nested blocks. Works on the 'end' of a block.
|
||||
" prev_indent = the previous line's indent
|
||||
" prev_lnum = previous line (to start looking on)
|
||||
" blockstart = expr. that indicates a possible start of this block
|
||||
" blockend = expr. that indicates a possible end of this block
|
||||
function s:EndBlockIndent( prev_indent, prev_lnum, blockstart, blockend )
|
||||
let lnum = a:prev_lnum
|
||||
let line = getline(lnum)
|
||||
let ends = 0
|
||||
while lnum > 1
|
||||
if getline(lnum) =~ '^\s*' . a:blockstart
|
||||
let ind = indent(lnum)
|
||||
if ends <= 0
|
||||
if ind < a:prev_indent
|
||||
return ind
|
||||
endif
|
||||
else
|
||||
let ends = ends - 1
|
||||
endif
|
||||
elseif getline(lnum) =~ '^\s*' . a:blockend
|
||||
let ends = ends + 1
|
||||
endif
|
||||
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
" Get previous non-blank/non-comment-only line
|
||||
while 1
|
||||
let line = getline(lnum)
|
||||
let line = substitute( line, g:ada#Comment, '', '' )
|
||||
if line !~ '^\s*$'
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
if lnum <= 0
|
||||
return a:prev_indent
|
||||
endif
|
||||
endwhile
|
||||
endwhile
|
||||
" Fallback - just move back one
|
||||
return a:prev_indent - shiftwidth()
|
||||
endfunction EndBlockIndent
|
||||
|
||||
" Section: s:StatementIndent {{{1
|
||||
"
|
||||
" Return indent of previous statement-start
|
||||
" (after we've indented due to multi-line statements).
|
||||
" This time, we start searching on the line *before* the one given (which is
|
||||
" the end of a statement - we want the previous beginning).
|
||||
function s:StatementIndent( current_indent, prev_lnum )
|
||||
let lnum = a:prev_lnum
|
||||
while lnum > 0
|
||||
let prev_lnum = lnum
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
" Get previous non-blank/non-comment-only line
|
||||
while 1
|
||||
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
|
||||
|
||||
if line !~ '^\s*$' && line !~ '^\s*#'
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
if lnum <= 0
|
||||
return a:current_indent
|
||||
endif
|
||||
endwhile
|
||||
" Leave indent alone if our ';' line is part of a ';'-delineated
|
||||
" aggregate (e.g., procedure args.) or first line after a block start.
|
||||
if line =~ s:AdaBlockStart || line =~ '(\s*$'
|
||||
return a:current_indent
|
||||
endif
|
||||
if line !~ '[.=(]\s*$'
|
||||
let ind = indent(prev_lnum)
|
||||
if ind < a:current_indent
|
||||
return ind
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
" Fallback - just use current one
|
||||
return a:current_indent
|
||||
endfunction StatementIndent
|
||||
|
||||
|
||||
" Section: GetAdaIndent {{{1
|
||||
"
|
||||
" Find correct indent of a new line based upon what went before
|
||||
"
|
||||
function GetAdaIndent()
|
||||
" Find a non-blank line above the current line.
|
||||
let lnum = prevnonblank(v:lnum - 1)
|
||||
let ind = indent(lnum)
|
||||
let package_line = 0
|
||||
|
||||
" Get previous non-blank/non-comment-only/non-cpp line
|
||||
while 1
|
||||
let line = substitute( getline(lnum), g:ada#Comment, '', '' )
|
||||
if line !~ '^\s*$' && line !~ '^\s*#'
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
if lnum <= 0
|
||||
return ind
|
||||
endif
|
||||
endwhile
|
||||
|
||||
" Get default indent (from prev. line)
|
||||
let ind = indent(lnum)
|
||||
let initind = ind
|
||||
|
||||
" Now check what's on the previous line
|
||||
if line =~ s:AdaBlockStart || line =~ '(\s*$'
|
||||
" Check for false matches to AdaBlockStart
|
||||
let false_match = 0
|
||||
if line =~ '^\s*\(procedure\|function\|package\)\>.*\<is\s*new\>'
|
||||
" Generic instantiation
|
||||
let false_match = 1
|
||||
elseif line =~ ')\s*;\s*$' || line =~ '^\([^(]*([^)]*)\)*[^(]*;\s*$'
|
||||
" forward declaration
|
||||
let false_match = 1
|
||||
endif
|
||||
" Move indent in
|
||||
if ! false_match
|
||||
let ind = ind + shiftwidth()
|
||||
endif
|
||||
elseif line =~ '^\s*\(case\|exception\)\>'
|
||||
" Move indent in twice (next 'when' will move back)
|
||||
let ind = ind + 2 * shiftwidth()
|
||||
elseif line =~ '^\s*end\s*record\>'
|
||||
" Move indent back to tallying 'type' preceeding the 'record'.
|
||||
" Allow indent to be equal to 'end record's.
|
||||
let ind = s:MainBlockIndent( ind+shiftwidth(), lnum, 'type\>', '' )
|
||||
elseif line =~ '\(^\s*new\>.*\)\@<!)\s*[;,]\s*$'
|
||||
" Revert to indent of line that started this parenthesis pair
|
||||
exe lnum
|
||||
exe 'normal! $F)%'
|
||||
if getline('.') =~ '^\s*('
|
||||
" Dire layout - use previous indent (could check for g:ada#Comment here)
|
||||
let ind = indent( prevnonblank( line('.')-1 ) )
|
||||
else
|
||||
let ind = indent('.')
|
||||
endif
|
||||
exe v:lnum
|
||||
elseif line =~ '[.=(]\s*$'
|
||||
" A statement continuation - move in one
|
||||
let ind = ind + shiftwidth()
|
||||
elseif line =~ '^\s*new\>'
|
||||
" Multiple line generic instantiation ('package blah is\nnew thingy')
|
||||
let ind = s:StatementIndent( ind - shiftwidth(), lnum )
|
||||
elseif line =~ ';\s*$'
|
||||
" Statement end (but not 'end' ) - try to find current statement-start indent
|
||||
let ind = s:StatementIndent( ind, lnum )
|
||||
endif
|
||||
|
||||
" Check for potential argument list on next line
|
||||
let continuation = (line =~ '[A-Za-z0-9_]\s*$')
|
||||
|
||||
|
||||
" Check current line; search for simplistic matching start-of-block
|
||||
let line = getline(v:lnum)
|
||||
if line =~ '^\s*#'
|
||||
" Start of line for ada-pp
|
||||
let ind = 0
|
||||
elseif continuation && line =~ '^\s*('
|
||||
" Don't do this if we've already indented due to the previous line
|
||||
if ind == initind
|
||||
let ind = ind + shiftwidth()
|
||||
endif
|
||||
elseif line =~ '^\s*\(begin\|is\)\>'
|
||||
let ind = s:MainBlockIndent( ind, lnum, '\(procedure\|function\|declare\|package\|task\)\>', 'begin\>' )
|
||||
elseif line =~ '^\s*record\>'
|
||||
let ind = s:MainBlockIndent( ind, lnum, 'type\>\|for\>.*\<use\>', '' ) + shiftwidth()
|
||||
elseif line =~ '^\s*\(else\|elsif\)\>'
|
||||
let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
|
||||
elseif line =~ '^\s*when\>'
|
||||
" Align 'when' one /in/ from matching block start
|
||||
let ind = s:MainBlockIndent( ind, lnum, '\(case\|exception\)\>', '' ) + shiftwidth()
|
||||
elseif line =~ '^\s*end\>\s*\<if\>'
|
||||
" End of if statements
|
||||
let ind = s:EndBlockIndent( ind, lnum, 'if\>', 'end\>\s*\<if\>' )
|
||||
elseif line =~ '^\s*end\>\s*\<loop\>'
|
||||
" End of loops
|
||||
let ind = s:EndBlockIndent( ind, lnum, '\(\(while\|for\)\>.*\)\?\<loop\>', 'end\>\s*\<loop\>' )
|
||||
elseif line =~ '^\s*end\>\s*\<record\>'
|
||||
" End of records
|
||||
let ind = s:EndBlockIndent( ind, lnum, '\(type\>.*\)\=\<record\>', 'end\>\s*\<record\>' )
|
||||
elseif line =~ '^\s*end\>\s*\<procedure\>'
|
||||
" End of procedures
|
||||
let ind = s:EndBlockIndent( ind, lnum, 'procedure\>.*\<is\>', 'end\>\s*\<procedure\>' )
|
||||
elseif line =~ '^\s*end\>\s*\<case\>'
|
||||
" End of case statement
|
||||
let ind = s:EndBlockIndent( ind, lnum, 'case\>.*\<is\>', 'end\>\s*\<case\>' )
|
||||
elseif line =~ '^\s*end\>'
|
||||
" General case for end
|
||||
let ind = s:MainBlockIndent( ind, lnum, '\(if\|while\|for\|loop\|accept\|begin\|record\|case\|exception\|package\)\>', '' )
|
||||
elseif line =~ '^\s*exception\>'
|
||||
let ind = s:MainBlockIndent( ind, lnum, 'begin\>', '' )
|
||||
elseif line =~ '^\s*then\>'
|
||||
let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction GetAdaIndent
|
||||
|
||||
let &cpo = s:keepcpo
|
||||
unlet s:keepcpo
|
||||
|
||||
finish " 1}}}
|
||||
|
||||
"------------------------------------------------------------------------------
|
||||
" Copyright (C) 2006 Martin Krischik
|
||||
"
|
||||
" Vim is Charityware - see ":help license" or uganda.txt for licence details.
|
||||
"------------------------------------------------------------------------------
|
||||
" vim: textwidth=78 wrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
|
||||
" vim: foldmethod=marker
|
||||
|
||||
endif
|
||||
16
indent/ant.vim
Normal file
16
indent/ant.vim
Normal file
@@ -0,0 +1,16 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ant') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: ANT files
|
||||
" Maintainer: David Fishburn <fishburn@ianywhere.com>
|
||||
" Last Change: Thu May 15 2003 10:02:54 PM
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" Use XML formatting rules
|
||||
runtime! indent/xml.vim
|
||||
|
||||
endif
|
||||
15
indent/automake.vim
Normal file
15
indent/automake.vim
Normal file
@@ -0,0 +1,15 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'automake') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: automake
|
||||
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
|
||||
" Latest Revision: 2006-04-19
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" same as makefile indenting for now.
|
||||
runtime! indent/make.vim
|
||||
|
||||
endif
|
||||
236
indent/awk.vim
Normal file
236
indent/awk.vim
Normal file
@@ -0,0 +1,236 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'awk') == -1
|
||||
|
||||
" vim: set sw=3 sts=3:
|
||||
|
||||
" Awk indent script. It can handle multi-line statements and expressions.
|
||||
" It works up to the point where the distinction between correct/incorrect
|
||||
" and personal taste gets fuzzy. Drop me an e-mail for bug reports and
|
||||
" reasonable style suggestions.
|
||||
"
|
||||
" Bugs:
|
||||
" =====
|
||||
" - Some syntax errors may cause erratic indentation.
|
||||
" - Same for very unusual but syntacticly correct use of { }
|
||||
" - In some cases it's confused by the use of ( and { in strings constants
|
||||
" - This version likes the closing brace of a multiline pattern-action be on
|
||||
" character position 1 before the following pattern-action combination is
|
||||
" formatted
|
||||
|
||||
" Author:
|
||||
" =======
|
||||
" Erik Janssen, ejanssen@itmatters.nl
|
||||
"
|
||||
" History:
|
||||
" ========
|
||||
" 26-04-2002 Got initial version working reasonably well
|
||||
" 29-04-2002 Fixed problems in function headers and max line width
|
||||
" Added support for two-line if's without curly braces
|
||||
" Fixed hang: 2011 Aug 31
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=GetAwkIndent()
|
||||
" Mmm, copied from the tcl indent program. Is this okay?
|
||||
setlocal indentkeys-=:,0#
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetAwkIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" This function contains a lot of exit points. It checks for simple cases
|
||||
" first to get out of the function as soon as possible, thereby reducing the
|
||||
" number of possibilities later on in the difficult parts
|
||||
|
||||
function! GetAwkIndent()
|
||||
|
||||
" Find previous line and get its indentation
|
||||
let prev_lineno = s:Get_prev_line( v:lnum )
|
||||
if prev_lineno == 0
|
||||
return 0
|
||||
endif
|
||||
let prev_data = getline( prev_lineno )
|
||||
let ind = indent( prev_lineno )
|
||||
|
||||
" Increase indent if the previous line contains an opening brace. Search
|
||||
" for this brace the hard way to prevent errors if the previous line is a
|
||||
" 'pattern { action }' (simple check match on /{/ increases the indent then)
|
||||
|
||||
if s:Get_brace_balance( prev_data, '{', '}' ) > 0
|
||||
return ind + shiftwidth()
|
||||
endif
|
||||
|
||||
let brace_balance = s:Get_brace_balance( prev_data, '(', ')' )
|
||||
|
||||
" If prev line has positive brace_balance and starts with a word (keyword
|
||||
" or function name), align the current line on the first '(' of the prev
|
||||
" line
|
||||
|
||||
if brace_balance > 0 && s:Starts_with_word( prev_data )
|
||||
return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
|
||||
endif
|
||||
|
||||
" If this line starts with an open brace bail out now before the line
|
||||
" continuation checks.
|
||||
|
||||
if getline( v:lnum ) =~ '^\s*{'
|
||||
return ind
|
||||
endif
|
||||
|
||||
" If prev line seems to be part of multiline statement:
|
||||
" 1. Prev line is first line of a multiline statement
|
||||
" -> attempt to indent on first ' ' or '(' of prev line, just like we
|
||||
" indented the positive brace balance case above
|
||||
" 2. Prev line is not first line of a multiline statement
|
||||
" -> copy indent of prev line
|
||||
|
||||
let continue_mode = s:Seems_continuing( prev_data )
|
||||
if continue_mode > 0
|
||||
if s:Seems_continuing( getline(s:Get_prev_line( prev_lineno )) )
|
||||
" Case 2
|
||||
return ind
|
||||
else
|
||||
" Case 1
|
||||
if continue_mode == 1
|
||||
" Need continuation due to comma, backslash, etc
|
||||
return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
|
||||
else
|
||||
" if/for/while without '{'
|
||||
return ind + shiftwidth()
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" If the previous line doesn't need continuation on the current line we are
|
||||
" on the start of a new statement. We have to make sure we align with the
|
||||
" previous statement instead of just the previous line. This is a bit
|
||||
" complicated because the previous statement might be multi-line.
|
||||
"
|
||||
" The start of a multiline statement can be found by:
|
||||
"
|
||||
" 1 If the previous line contains closing braces and has negative brace
|
||||
" balance, search backwards until cumulative brace balance becomes zero,
|
||||
" take indent of that line
|
||||
" 2 If the line before the previous needs continuation search backward
|
||||
" until that's not the case anymore. Take indent of one line down.
|
||||
|
||||
" Case 1
|
||||
if prev_data =~ ')' && brace_balance < 0
|
||||
while brace_balance != 0 && prev_lineno > 0
|
||||
let prev_lineno = s:Get_prev_line( prev_lineno )
|
||||
let prev_data = getline( prev_lineno )
|
||||
let brace_balance=brace_balance+s:Get_brace_balance(prev_data,'(',')' )
|
||||
endwhile
|
||||
let ind = indent( prev_lineno )
|
||||
else
|
||||
" Case 2
|
||||
if s:Seems_continuing( getline( prev_lineno - 1 ) )
|
||||
let prev_lineno = prev_lineno - 2
|
||||
let prev_data = getline( prev_lineno )
|
||||
while prev_lineno > 0 && (s:Seems_continuing( prev_data ) > 0)
|
||||
let prev_lineno = s:Get_prev_line( prev_lineno )
|
||||
let prev_data = getline( prev_lineno )
|
||||
endwhile
|
||||
let ind = indent( prev_lineno + 1 )
|
||||
endif
|
||||
endif
|
||||
|
||||
" Decrease indent if this line contains a '}'.
|
||||
if getline(v:lnum) =~ '^\s*}'
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
" Find the open and close braces in this line and return how many more open-
|
||||
" than close braces there are. It's also used to determine cumulative balance
|
||||
" across multiple lines.
|
||||
|
||||
function! s:Get_brace_balance( line, b_open, b_close )
|
||||
let line2 = substitute( a:line, a:b_open, "", "g" )
|
||||
let openb = strlen( a:line ) - strlen( line2 )
|
||||
let line3 = substitute( line2, a:b_close, "", "g" )
|
||||
let closeb = strlen( line2 ) - strlen( line3 )
|
||||
return openb - closeb
|
||||
endfunction
|
||||
|
||||
" Find out whether the line starts with a word (i.e. keyword or function
|
||||
" call). Might need enhancements here.
|
||||
|
||||
function! s:Starts_with_word( line )
|
||||
if a:line =~ '^\s*[a-zA-Z_0-9]\+\s*('
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Find the length of the first word in a line. This is used to be able to
|
||||
" align a line relative to the 'print ' or 'if (' on the previous line in case
|
||||
" such a statement spans multiple lines.
|
||||
" Precondition: only to be used on lines where 'Starts_with_word' returns 1.
|
||||
|
||||
function! s:First_word_len( line )
|
||||
let white_end = matchend( a:line, '^\s*' )
|
||||
if match( a:line, '^\s*func' ) != -1
|
||||
let word_end = matchend( a:line, '[a-z]\+\s\+[a-zA-Z_0-9]\+[ (]*' )
|
||||
else
|
||||
let word_end = matchend( a:line, '[a-zA-Z_0-9]\+[ (]*' )
|
||||
endif
|
||||
return word_end - white_end
|
||||
endfunction
|
||||
|
||||
" Determine if 'line' completes a statement or is continued on the next line.
|
||||
" This one is far from complete and accepts illegal code. Not important for
|
||||
" indenting, however.
|
||||
|
||||
function! s:Seems_continuing( line )
|
||||
" Unfinished lines
|
||||
if a:line =~ '\(--\|++\)\s*$'
|
||||
return 0
|
||||
endif
|
||||
if a:line =~ '[\\,\|\&\+\-\*\%\^]\s*$'
|
||||
return 1
|
||||
endif
|
||||
" if/for/while (cond) eol
|
||||
if a:line =~ '^\s*\(if\|while\|for\)\s*(.*)\s*$' || a:line =~ '^\s*else\s*'
|
||||
return 2
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Get previous relevant line. Search back until a line is that is no
|
||||
" comment or blank and return the line number
|
||||
|
||||
function! s:Get_prev_line( lineno )
|
||||
let lnum = a:lineno - 1
|
||||
let data = getline( lnum )
|
||||
while lnum > 0 && (data =~ '^\s*#' || data =~ '^\s*$')
|
||||
let lnum = lnum - 1
|
||||
let data = getline( lnum )
|
||||
endwhile
|
||||
return lnum
|
||||
endfunction
|
||||
|
||||
" This function checks whether an indented line exceeds a maximum linewidth
|
||||
" (hardcoded 80). If so and it is possible to stay within 80 positions (or
|
||||
" limit num of characters beyond linewidth) by decreasing the indent (keeping
|
||||
" it > base_indent), do so.
|
||||
|
||||
function! s:Safe_indent( base, wordlen, this_line )
|
||||
let line_base = matchend( a:this_line, '^\s*' )
|
||||
let line_len = strlen( a:this_line ) - line_base
|
||||
let indent = a:base
|
||||
if (indent + a:wordlen + line_len) > 80
|
||||
" Simple implementation good enough for the time being
|
||||
let indent = indent + 3
|
||||
endif
|
||||
return indent + a:wordlen
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -23,18 +23,19 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1
|
||||
" Language: GraphQL
|
||||
" Maintainer: Jon Parise <jon@indelible.org>
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
" Set our local options if indentation hasn't already been set up.
|
||||
" This generally means we've been detected as the primary filetype.
|
||||
if !exists('b:did_indent')
|
||||
setlocal autoindent
|
||||
setlocal nocindent
|
||||
setlocal nolisp
|
||||
setlocal nosmartindent
|
||||
|
||||
setlocal indentexpr=GetGraphQLIndent()
|
||||
setlocal indentkeys=0{,0},0),0[,0],0#,!^F,o,O
|
||||
|
||||
let b:did_indent = 1
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal autoindent
|
||||
setlocal nocindent
|
||||
setlocal nolisp
|
||||
setlocal nosmartindent
|
||||
|
||||
setlocal indentexpr=GetGraphQLIndent()
|
||||
setlocal indentkeys=0{,0},0),0[,0],0#,!^F,o,O
|
||||
|
||||
" If our indentation function already exists, we have nothing more to do.
|
||||
if exists('*GetGraphQLIndent')
|
||||
@@ -46,7 +47,7 @@ set cpoptions&vim
|
||||
|
||||
" Check if the character at lnum:col is inside a string.
|
||||
function s:InString(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') is# 'graphqlString'
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') ==# 'graphqlString'
|
||||
endfunction
|
||||
|
||||
function GetGraphQLIndent()
|
||||
|
||||
Reference in New Issue
Block a user