diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2020-11-02 18:19:06 +0100 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-11-02 18:19:15 +0100 |
commit | 0738ad654d4f2f89b77dcb4197011a293e4dfcf3 (patch) | |
tree | 25de763b5adbc53b997085bcf8f49d6b09a45cd0 /ftplugin | |
parent | 05e21a9e252b283b2d71568ad3b671d7f28fe0bc (diff) | |
download | vim-polyglot-0738ad654d4f2f89b77dcb4197011a293e4dfcf3.tar.gz vim-polyglot-0738ad654d4f2f89b77dcb4197011a293e4dfcf3.zip |
Update
Diffstat (limited to 'ftplugin')
-rw-r--r-- | ftplugin/make.vim | 6 | ||||
-rw-r--r-- | ftplugin/typescript.vim | 65 |
2 files changed, 68 insertions, 3 deletions
diff --git a/ftplugin/make.vim b/ftplugin/make.vim index 95556e54..ee4157f1 100644 --- a/ftplugin/make.vim +++ b/ftplugin/make.vim @@ -5,7 +5,7 @@ endif " Vim filetype plugin file " Language: Make " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2019 Apr 02 +" Last Change: 2020 Oct 16 " Only do this when not done yet for this buffer if exists("b:did_ftplugin") @@ -13,10 +13,10 @@ if exists("b:did_ftplugin") endif let b:did_ftplugin = 1 -let b:undo_ftplugin = "setl et< sts< fo< com< cms< inc<" +let b:undo_ftplugin = "setl et< sts< sw< fo< com< cms< inc<" " Make sure a hard tab is used, required for most make programs -setlocal noexpandtab softtabstop=0 +setlocal noexpandtab softtabstop=0 shiftwidth=0 " Set 'formatoptions' to break comment lines but not other lines, " and insert the comment leader when hitting <CR> or using "o". diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index b0df5f45..963d0fe4 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -19,11 +19,76 @@ setlocal commentstring=//\ %s " " and insert the comment leader when hitting <CR> or using "o". setlocal formatoptions-=t formatoptions+=croql +if !&l:formatexpr && !&l:formatprg + setlocal formatprg=Fixedgq(v:lnum,v:count) +endif + " setlocal foldmethod=syntax let &cpo = s:cpo_save unlet s:cpo_save +function! Fixedgq(lnum, count) + let l:tw = &tw ? &tw : 80 + + let l:count = a:count + let l:first_char = indent(a:lnum) + 1 + + if mode() == 'i' " gq was not pressed, but tw was set + return 1 + endif + + " This gq is only meant to do code with strings, not comments + if yats#IsLineComment(a:lnum, l:first_char) || yats#IsInMultilineComment(a:lnum, l:first_char) + return 1 + endif + + if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq + return 1 + endif + + " Put all the lines on one line and do normal spliting after that + if l:count > 1 + while l:count > 1 + let l:count -= 1 + normal! J + endwhile + endif + + let l:winview = winsaveview() + + call cursor(a:lnum, l:tw + 1) + let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum) + call cursor(a:lnum, l:tw + 1) + let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum) + + " No need for special treatment, normal gq handles edgecases better + if breakpoint[1] == orig_breakpoint[1] + call winrestview(l:winview) + return 1 + endif + + " Try breaking after string + if breakpoint[1] <= indent(a:lnum) + call cursor(a:lnum, l:tw + 1) + let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum) + endif + + + if breakpoint[1] != 0 + call feedkeys("r\<CR>") + else + let l:count = l:count - 1 + endif + + " run gq on new lines + if l:count == 1 + call feedkeys("gqq") + endif + + return 0 +endfunction + function! TsIncludeExpr(file) if (filereadable(a:file)) return l:file |