diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2020-10-04 23:25:48 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-10-04 23:25:48 +0200 |
commit | cbc460033329db8a1638e27830ad7264cd349a9d (patch) | |
tree | ed2e47e384c24d611dc8b7513c93d944cb2e0051 | |
parent | 32b097f67ed9c9b95a9ef1960399197434eb0bdf (diff) | |
download | vim-polyglot-cbc460033329db8a1638e27830ad7264cd349a9d.tar.gz vim-polyglot-cbc460033329db8a1638e27830ad7264cd349a9d.zip |
Update
-rw-r--r-- | after/indent/javascript-2.vim | 17 | ||||
-rw-r--r-- | after/indent/typescript.vim | 17 |
2 files changed, 16 insertions, 18 deletions
diff --git a/after/indent/javascript-2.vim b/after/indent/javascript-2.vim index 4e066e6f..85e52312 100644 --- a/after/indent/javascript-2.vim +++ b/after/indent/javascript-2.vim @@ -23,25 +23,24 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 " Language: GraphQL " Maintainer: Jon Parise <jon@indelible.org> -runtime! indent/graphql.vim - -" Don't redefine our function and also require the standard Javascript indent -" function to exist. -if exists('*GetJavascriptGraphQLIndent') || !exists('*GetJavascriptIndent') +if exists('*GetJavascriptGraphQLIndent') && !empty(&indentexpr) finish endif +runtime! indent/graphql.vim + " Set the indentexpr with our own version that will call GetGraphQLIndent when -" we're inside of a GraphQL string and otherwise defer to GetJavascriptIndent. +" we're inside of a GraphQL string and otherwise defer to the base function. +let b:indentexpr_base = &indentexpr setlocal indentexpr=GetJavascriptGraphQLIndent() function GetJavascriptGraphQLIndent() - let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val,'name')") - if !empty(l:stack) && l:stack[0] ==# 'graphqlTemplateString' + let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val, 'name')") + if get(l:stack, 0) ==# 'graphqlTemplateString' return GetGraphQLIndent() endif - return GetJavascriptIndent() + return eval(b:indentexpr_base) endfunction endif diff --git a/after/indent/typescript.vim b/after/indent/typescript.vim index 968517c8..45ef3492 100644 --- a/after/indent/typescript.vim +++ b/after/indent/typescript.vim @@ -23,25 +23,24 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 " Language: GraphQL " Maintainer: Jon Parise <jon@indelible.org> -runtime! indent/graphql.vim - -" Don't redefine our function and also require the standard Typescript indent -" function to exist. -if exists('*GetTypescriptGraphQLIndent') || !exists('*GetTypescriptIndent') +if exists('*GetTypescriptGraphQLIndent') && !empty(&indentexpr) finish endif +runtime! indent/graphql.vim + " Set the indentexpr with our own version that will call GetGraphQLIndent when -" we're inside of a GraphQL string and otherwise defer to GetTypescriptIndent. +" we're inside of a GraphQL string and otherwise defer to the base function. +let b:indentexpr_base = &indentexpr setlocal indentexpr=GetTypescriptGraphQLIndent() function GetTypescriptGraphQLIndent() - let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val,'name')") - if !empty(l:stack) && l:stack[0] ==# 'graphqlTemplateString' + let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val, 'name')") + if get(l:stack, 0) ==# 'graphqlTemplateString' return GetGraphQLIndent() endif - return GetTypescriptIndent() + return eval(b:indentexpr_base) endfunction endif |