diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2021-09-09 12:42:18 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2021-09-09 12:42:18 +0200 |
commit | b147123070e5d7418fe67e315a53599cfde38d58 (patch) | |
tree | b4ed260a622235d320310094d329fc6604a47345 /indent | |
parent | 7f98e949d4922ba2109304bd4cabe9578a8062fb (diff) | |
download | vim-polyglot-b147123070e5d7418fe67e315a53599cfde38d58.tar.gz vim-polyglot-b147123070e5d7418fe67e315a53599cfde38d58.zip |
Ensure some files are compied from each package
Diffstat (limited to 'indent')
-rw-r--r-- | indent/lilypond.vim | 81 | ||||
-rw-r--r-- | indent/mermaid.vim | 64 |
2 files changed, 145 insertions, 0 deletions
diff --git a/indent/lilypond.vim b/indent/lilypond.vim new file mode 100644 index 00000000..da836dbb --- /dev/null +++ b/indent/lilypond.vim @@ -0,0 +1,81 @@ +if polyglot#init#is_disabled(expand('<sfile>:p'), 'lilypond', 'indent/lilypond.vim') + finish +endif + +" LilyPond indent file +" Language: LilyPond +" Maintainer: Heikki Junes <hjunes@cc.hut.fi> +" License: This file is part of LilyPond, the GNU music typesetter. +" +" Copyright (C) 2004, 2010 Heikki Junes <hjunes@cc.hut.fi> +" +" LilyPond is free software: you can redistribute it and/or modify +" it under the terms of the GNU General Public License as published by +" the Free Software Foundation, either version 3 of the License, or +" (at your option) any later version. +" +" LilyPond is distributed in the hope that it will be useful, +" but WITHOUT ANY WARRANTY; without even the implied warranty of +" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +" GNU General Public License for more details. +" +" You should have received a copy of the GNU General Public License +" along with LilyPond. If not, see <http://www.gnu.org/licenses/>. +" +" Last Change: 2010 Jul 26 +" +" Installed As: vim/indent/lilypond.vim +" +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetLilyPondIndent() +setlocal indentkeys=o,O,},>>,!^F + +" Only define the function once. +if exists("*GetLilyPondIndent") + finish +endif + +function GetLilyPondIndent() + if v:lnum == 1 + return 0 + endif + + "Find a non-blank line above the current line. + let lnum = prevnonblank(v:lnum - 1) + "Check if a block was started: '{' or '<<' is the last non-blank character of the previous line. + if getline(lnum) =~ '^.*\({\|<<\)\s*$' + let ind = indent(lnum) + &sw + else + let ind = indent(lnum) + endif + + "Check if a block was ended: '}' or '>>' is the first non-blank character of the current line. + if getline(v:lnum) =~ '^\s*\(}\|>>\)' + let ind = ind - &sw + endif + + " Check if the first character from the previous line is within + " a `lilyScheme' region, and if so, use lisp-style indentation + " for the current line. + " + " TODO: + " - Only works in version 7.1.215 or later, though it should + " silently fail in older versions. + " - We should support `lilyScheme' regions that begin in the + " middle of the line, too. + for id in synstack(lnum, 1) + if synIDattr(id, "name") == "lilyScheme" + let ind = lispindent(v:lnum) + endif + endfor + + return ind +endfunction +" +" +" diff --git a/indent/mermaid.vim b/indent/mermaid.vim new file mode 100644 index 00000000..e1ade711 --- /dev/null +++ b/indent/mermaid.vim @@ -0,0 +1,64 @@ +if polyglot#init#is_disabled(expand('<sfile>:p'), 'mermaid', 'indent/mermaid.vim') + finish +endif + +let s:indent_next_line_keywords = [ + \ '^classDiagram', + \ '^classDiagram-v2', + \ '^erDiagram', + \ '^gantt', + \ '^graph', + \ '^flowchart', + \ '^pie', + \ '^sequenceDiagram', + \ '^stateDiagram', + \ '^stateDiagram-v2', + \ 'class.*{', + \ 'subgraph', + \ 'loop', + \ 'alt', + \ 'else', + \ 'opt', + \ 'par', + \ 'and', + \ 'rect', + \ '[^a-z]activate', + \ ] + +let s:deindent_current_line_keywords = [ + \ '^\s\+classDiagram', + \ '^\s\+classDiagram-v2', + \ '^\s\+erDiagram', + \ '^\s\+gantt', + \ '^\s\+graph', + \ '^\s\+flowchart', + \ '^\s\+pie', + \ '^\s\+sequenceDiagram', + \ '^\s\+stateDiagram', + \ '^\s\+stateDiagram-v2', + \ '^\s\+end$', + \ '^\s\+}$', + \ '^\s\+deactivate$' + \ ] + +function! s:matches_any_word_in(text, list) + return empty(filter(copy(a:list), {_idx, val -> matchstr(a:text, val) != ""})) == v:false +endfunction + +function! MermaidIndent() + let sw = shiftwidth() + let indent_level = indent(v:lnum - 1) / sw + let current_line = getline(v:lnum) + let line_above = getline(v:lnum - 1) + + " TODO don't incorrect indent when has empty lines inside graph + if s:matches_any_word_in(current_line, s:deindent_current_line_keywords) + return (indent_level - 1) * sw + endif + + if s:matches_any_word_in(line_above, s:indent_next_line_keywords) + return (indent_level + 1) * sw + endif + + return indent_level * sw +endfunction |