Skip to content

Commit

Permalink
Add support for gleam, closes #655
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff Kreeftmeijer <jeffkreeftmeijer@gmail.com>
  • Loading branch information
sheerun and jeffkreeftmeijer committed Jan 1, 2021
1 parent 1f4236d commit a817560
Show file tree
Hide file tree
Showing 23 changed files with 477 additions and 282 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A collection of language packs for Vim.
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
- It **installs and updates 120+ times faster** than the <!--Package Count-->601<!--/Package Count--> packages it consists of.
- It **installs and updates 120+ times faster** than the <!--Package Count-->602<!--/Package Count--> packages it consists of.
- It is also more secure (scripts loaded for every filetype are generated by vim-polyglot)
- Best syntax and indentation support (no other features). Hand-selected language packs.
- Automatically detects indentation (includes performance-optimized version of [vim-sleuth](https://github.com/tpope/vim-sleuth), can be disabled)
Expand Down Expand Up @@ -84,6 +84,7 @@ On top of all language packs from [vim repository](https://github.com/vim/vim/tr
- [gdscript](https://github.com/calviken/vim-gdscript3) (GDScript syntax highlighting for gd files)
- [git](https://github.com/tpope/vim-git) (Git Config syntax highlighting for gitconfig files)
- [gitignore](https://github.com/fszymanski/fzf-gitignore)
- [gleam](https://github.com/gleam-lang/gleam.vim) (Syntax highlighting for gleam files)
- [glsl](https://github.com/tikhomirov/vim-glsl) (GLSL syntax highlighting for glsl, fp, frag, frg, fs and 16 more files)
- [gmpl](https://github.com/maelvalais/gmpl.vim) (Syntax highlighting for mod files)
- [gnuplot](https://github.com/vim-scripts/gnuplot-syntax-highlighting) (Gnuplot syntax highlighting for gp, gnu, gnuplot, p, plot, plt and gpi files)
Expand Down
4 changes: 2 additions & 2 deletions after/syntax/cpp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ endif

" C++14 extensions {{{1
if !exists('cpp_no_cpp14')
syntax keyword cppSTLnamespace literals chrono_literals string_literals
syntax keyword cppSTLnamespace literals chrono_literals string_literals complex_literals

syntax keyword cppSTLfunction make_unique

Expand All @@ -117,7 +117,7 @@ endif

" C++17 extensions {{{1
if !exists('cpp_no_cpp17')
syntax keyword cppSTLnamespace filesystem execution
syntax keyword cppSTLnamespace filesystem execution string_view_literals

syntax keyword cppSTLtype
\ any is_execution_policy parallel_policy parallel_unsequenced_policy sequenced_policy directory_entry directory_iterator file_status file_time_type path recursive_directory_iterator space_info default_order default_searcher boyer_moore_searcher boyer_moore_horspool_searcher memory_resource monotonic_buffer_resource polymorphic_allocator pool_options synchronized_pool_resource unsynchronized_pool_resource scoped_lock optional shared_mutex basic_string_view string_view u16string_view u32string_view wstring_view bool_constant conjunction disjunction has_unique_object_representations invoke_result is_aggregate is_callable is_invocable is_invocable_r is_nothrow_invocable is_nothrow_invocable_r is_nothrow_swappable is_nothrow_swappable_with is_nowthrow_callable is_swappable is_swappable_with negation node_type insert_return_type in_place_tag monostate variant variant_size variant_alternative
Expand Down
1 change: 1 addition & 0 deletions autoload/polyglot/sleuth.vim
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ let s:globs = {
\ 'gitrebase': 'git-rebase-todo',
\ 'gitsendemail': '.gitsendemail.*',
\ 'gkrellmrc': 'gkrellmrc,gkrellmrc_?',
\ 'gleam': '*.gleam',
\ 'glsl': '*.glsl,*.fp,*.frag,*.frg,*.fs,*.fsh,*.fshader,*.geo,*.geom,*.glslf,*.glslv,*.gs,*.gshader,*.shader,*.tesc,*.tese,*.vert,*.vrx,*.vsh,*.vshader,*.comp',
\ 'gmpl': '*.mod',
\ 'gnash': 'gnashrc,.gnashrc,gnashpluginrc,.gnashpluginrc',
Expand Down
49 changes: 49 additions & 0 deletions compiler/gleam.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
if has_key(g:polyglot_is_disabled, 'gleam')
finish
endif

" Check we've not run already
if exists('current_compiler')
finish
endif

let current_compiler = "gleam"

" Defined CompilerSet command if it doesn't exist.
" Needed for older vim versions.
if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

" Tell vim to run 'gleam' when the user runs :make. So ':make build .' becomes
" 'gleam build .'
CompilerSet makeprg=gleam\ $*


" With the compiler set, we set the errorformat which is a set of rules that
" vim uses to parse the output of the current compiler program in order to
" extract file, line, column & error message information so that it can
" populate the quickfix list and the user can jump between the errors.
"
" This errorformat 'parser' will have to change if the output of the compiler
" changes.
"
" Written with the help of: https://flukus.github.io/vim-errorformat-demystified.html
"
CompilerSet errorformat=%Eerror:\ %m " use 'error:' to indicate the start of a new error
CompilerSet errorformat+=%C\ %#┌─%#\ %f:%l:%c\ %#-%# " pull out the file, line & column (matches optional spaces & dashes at the end in case they come back.)
CompilerSet errorformat+=%C " allow empty lines within an error
CompilerSet errorformat+=%C%.%#│%.%# " ignore any line with a vertial formatting pipe in it
CompilerSet errorformat+=%Z%m " assume any other line contributes to the error message


" Example error message
"
" error: Unknown variable
" ┌─ /home/michael/root/projects/tutorials/gleam/try/code/src/main.gleam:19:18
"
" 19 │ Ok(tuple(name, spot))
" │ ^^^^ did you mean `sport`?
"
" The name `spot` is not in scope here.

13 changes: 11 additions & 2 deletions extras/filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ au BufNewFile,BufRead *.com call polyglot#ft#BindzoneCheck('dcl')
" DOT
au BufNewFile,BufRead *.dot,*.gv setf dot

" Dune
au BufNewFile,BufRead jbuild,dune,dune-project,dune-workspace setf dune

" Dylan - lid files
au BufNewFile,BufRead *.lid setf dylanlid

Expand Down Expand Up @@ -1125,15 +1128,18 @@ au BufNewFile,BufRead *.nse setf lua
" NSIS
au BufNewFile,BufRead *.nsi,*.nsh setf nsis

" OCAML
au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly,.ocamlinit setf ocaml
" OCaml
au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly,.ocamlinit,*.mlt,*.mlp,*.mlip,*.mli.cppo,*.ml.cppo setf ocaml

" Occam
au BufNewFile,BufRead *.occ setf occam

" Omnimark
au BufNewFile,BufRead *.xom,*.xin setf omnimark

" OPAM
au BufNewFile,BufRead opam,*.opam,*.opam.template setf opam

" OpenROAD
au BufNewFile,BufRead *.or setf openroad

Expand Down Expand Up @@ -1547,6 +1553,9 @@ au BufNewFile,BufRead *.scm,*.ss,*.rkt setf scheme
" Screen RC
au BufNewFile,BufRead .screenrc,screenrc setf screen

" Sexplib
au BufNewFile,BufRead *.sexp setf sexplib

" Simula
au BufNewFile,BufRead *.sim setf simula

Expand Down
4 changes: 4 additions & 0 deletions ftdetect/polyglot.vim
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ let did_load_filetypes = 1

" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE

if !has_key(g:polyglot_is_disabled, 'gleam')
au BufNewFile,BufRead *.gleam setf gleam
endif

if !has_key(g:polyglot_is_disabled, 'jsonc')
au BufNewFile,BufRead *.cjson,*.jsonc,{.,}babelrc,{.,}eslintrc.json,{.,}jshintrc,{.,}jslintrc,{.,}mocharc.json,coc-settings.json,coffeelint.json,jsconfig.json,tsconfig.json setf jsonc
endif
Expand Down
10 changes: 10 additions & 0 deletions ftplugin/dune.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ if has_key(g:polyglot_is_disabled, 'ocaml')
finish
endif

" Language: Dune buildsystem
" Maintainer: Markus Mottl <markus.mottl@gmail.com>
" Anton Kochkov <anton.kochkov@gmail.com>
" URL: https://github.com/ocaml/vim-ocaml
" Last Change:
" 2018 Nov 3 - Added commentstring (Markus Mottl)
" 2017 Sep 6 - Initial version (Etienne Millon)

if exists("b:did_ftplugin")
finish
endif
Expand All @@ -12,3 +20,5 @@ set lisp
" Comment string
setl commentstring=;\ %s
setl comments=:;

setl iskeyword+=#,?,.,/
32 changes: 32 additions & 0 deletions ftplugin/gleam.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if has_key(g:polyglot_is_disabled, 'gleam')
finish
endif


if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1

compiler gleam

setlocal commentstring=//%s
setlocal formatoptions-=t formatoptions+=croqnl

setlocal comments=s0:/*!,ex:*/,s1:/*,mb:*,ex:*/,:////,:///,://

" j was only added in 7.3.541, so stop complaints about its nonexistence
silent! setlocal formatoptions+=j

" smartindent will be overridden by indentexpr if filetype indent is on, but
" otherwise it's better than nothing.
setlocal smartindent nocindent

setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab
setlocal textwidth=79

setlocal suffixesadd=.gleam

augroup gleam.vim
autocmd!
augroup END
2 changes: 1 addition & 1 deletion ftplugin/ocaml.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ endif
" Pierre Vittet <pierre-vittet@pvittet.com>
" Stefano Zacchiroli <zack@bononia.it>
" Vincent Aravantinos <firstname.name@imag.fr>
" URL: http://www.ocaml.info/vim/ftplugin/ocaml.vim
" URL: https://github.com/ocaml/vim-ocaml
" Last Change:
" 2013 Oct 27 - Added commentstring (MM)
" 2013 Jul 26 - load default compiler settings (MM)
Expand Down
3 changes: 2 additions & 1 deletion ftplugin/sexplib.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ if has_key(g:polyglot_is_disabled, 'ocaml')
finish
endif

" Vim filetype plugin file
" Language: Sexplib
" Maintainer: Markus Mottl <markus.mottl@gmail.com>
" URL: http://www.ocaml.info/vim/ftplugin/sexplib.vim
" URL: https://github.com/ocaml/vim-ocaml
" Last Change:
" 2017 Apr 12 - First version (MM)

Expand Down
3 changes: 3 additions & 0 deletions indent/dune.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ endif

" Vim indent file
" Language: dune
" Maintainers: Markus Mottl <markus.mottl@gmail.com>
" URL: https://github.com/ocaml/vim-ocaml
" Last Change: 2020 Dec 31

if exists("b:did_indent")
finish
Expand Down
14 changes: 7 additions & 7 deletions indent/ocaml.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ endif
" Maintainers: Jean-Francois Yuen <jfyuen@happycoders.org>
" Mike Leary <leary@nwlink.com>
" Markus Mottl <markus.mottl@gmail.com>
" URL: http://www.ocaml.info/vim/indent/ocaml.vim
" Last Change: 2013 Jun 29
" URL: https://github.com/ocaml/vim-ocaml
" Last Change: 2017 Jun 13
" 2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working
" 2005 May 09 - Added an option to not indent OCaml-indents specially (MM)
" 2013 June - commented textwidth (Marc Weber)
Expand Down Expand Up @@ -106,7 +106,7 @@ function! GetOCamlIndent()

" Return double 'shiftwidth' after lines matching:
if lline =~ '^\s*|.*->\s*$'
return ind + &sw + &sw
return ind + 2 * shiftwidth()
endif

let line = getline(v:lnum)
Expand Down Expand Up @@ -177,7 +177,7 @@ function! GetOCamlIndent()
" Indent if current line begins with 'and':
elseif line =~ '^\s*and\>'
if lline !~ '^\s*\(and\|let\|type\)\>\|\<end\s*$'
return ind - &sw
return ind - shiftwidth()
endif

" Indent if current line begins with 'with':
Expand All @@ -204,14 +204,14 @@ function! GetOCamlIndent()
" or 'method':
elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>'
if lline !~ s:obj
return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + &sw
return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + shiftwidth()
endif

endif

" Add a 'shiftwidth' after lines ending with:
if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|parser\|private\|sig\|struct\|then\|try\)\|\<object\s*(.*)\)\s*$'
let ind = ind + &sw
let ind = ind + shiftwidth()

" Back to normal indent after lines ending with ';;':
elseif lline =~ ';;\s*$' && lline !~ '^\s*;;'
Expand Down Expand Up @@ -268,7 +268,7 @@ function! GetOCamlIndent()

" Subtract a 'shiftwidth' after lines matching 'match ... with parser':
if lline =~ '\<match\>.*\<with\>\s*\<parser\s*$'
let ind = ind - &sw
let ind = ind - shiftwidth()
endif

return ind
Expand Down
7 changes: 7 additions & 0 deletions packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5562,3 +5562,10 @@ filetypes:
patterns:
- pattern: '*.cjson,coc-settings.json,*.jsonc,.eslintrc.json,.babelrc,.jshintrc,.jslintrc,.mocharc.json,coffeelint.json,tsconfig.json,jsconfig.json'
description: 'JSON with comments (https://komkom.github.io/)'
---
name: gleam
remote: gleam-lang/gleam.vim
filetypes:
- name: gleam
extensions:
- gleam
4 changes: 2 additions & 2 deletions syntax/basic/identifiers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ syntax match typescriptProp contained /\K\k*!\?/
\ nextgroup=@afterIdentifier
\ skipwhite skipempty

syntax region typescriptIndexExpr contained matchgroup=typescriptProperty start=/\[/rs=s+1 end=/]/he=e-1 contains=@typescriptValue nextgroup=@typescriptSymbols,typescriptDotNotation,typescriptFuncCallArg skipwhite skipempty
syntax region typescriptIndexExpr contained matchgroup=typescriptProperty start=/\[/rs=s+1 end=/]/he=e-1 contains=@typescriptValue,typescriptCastKeyword nextgroup=@typescriptSymbols,typescriptDotNotation,typescriptFuncCallArg skipwhite skipempty

syntax match typescriptDotNotation /\.\|?\.\|!\./ nextgroup=typescriptProp skipnl
syntax match typescriptDotStyleNotation /\.style\./ nextgroup=typescriptDOMStyle transparent
" syntax match typescriptFuncCall contained /[a-zA-Z]\k*\ze(/ nextgroup=typescriptFuncCallArg
syntax region typescriptParenExp matchgroup=typescriptParens start=/(/ end=/)/ contains=@typescriptComments,@typescriptValue,typescriptCastKeyword nextgroup=@typescriptSymbols skipwhite skipempty
syntax region typescriptFuncCallArg contained matchgroup=typescriptParens start=/(/ end=/)/ contains=@typescriptValue,@typescriptComments nextgroup=@typescriptSymbols,typescriptDotNotation skipwhite skipempty skipnl
syntax region typescriptFuncCallArg contained matchgroup=typescriptParens start=/(/ end=/)/ contains=@typescriptValue,@typescriptComments,typescriptCastKeyword nextgroup=@typescriptSymbols,typescriptDotNotation skipwhite skipempty skipnl
syntax region typescriptEventFuncCallArg contained matchgroup=typescriptParens start=/(/ end=/)/ contains=@typescriptEventExpression
syntax region typescriptEventString contained start=/\z(["']\)/ skip=/\\\\\|\\\z1\|\\\n/ end=/\z1\|$/ contains=typescriptASCII,@events

Expand Down
4 changes: 2 additions & 2 deletions syntax/basic/literal.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ syntax match typescriptASCII contained /\\\d\d\d/

syntax region typescriptTemplateSubstitution matchgroup=typescriptTemplateSB
\ start=/\${/ end=/}/
\ contains=@typescriptValue
\ contains=@typescriptValue,typescriptCastKeyword
\ contained


Expand All @@ -33,7 +33,7 @@ syntax region typescriptTemplate
"Array
syntax region typescriptArray matchgroup=typescriptBraces
\ start=/\[/ end=/]/
\ contains=@typescriptValue,@typescriptComments
\ contains=@typescriptValue,@typescriptComments,typescriptCastKeyword
\ nextgroup=@typescriptSymbols,typescriptDotNotation
\ skipwhite skipempty fold

Expand Down
2 changes: 1 addition & 1 deletion syntax/basic/object.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ endif

syntax region typescriptObjectLiteral matchgroup=typescriptBraces
\ start=/{/ end=/}/
\ contains=@typescriptComments,typescriptObjectLabel,typescriptStringProperty,typescriptComputedPropertyName,typescriptObjectAsyncKeyword,typescriptTernary
\ contains=@typescriptComments,typescriptObjectLabel,typescriptStringProperty,typescriptComputedPropertyName,typescriptObjectAsyncKeyword,typescriptTernary,typescriptCastKeyword
\ fold contained

syntax keyword typescriptObjectAsyncKeyword async contained
Expand Down
11 changes: 11 additions & 0 deletions syntax/dune.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ if has_key(g:polyglot_is_disabled, 'ocaml')
finish
endif

" Vim syntax file
" Language: Dune buildsystem
" Maintainer: Markus Mottl <markus.mottl@gmail.com>
" Anton Kochkov <anton.kochkov@gmail.com>
" URL: https://github.com/ocaml/vim-ocaml
" Last Change:
" 2019 Feb 27 - Add newer keywords to the syntax (Simon Cruanes)
" 2018 May 8 - Check current_syntax (Kawahara Satoru)
" 2018 Mar 29 - Extend jbuild syntax with more keywords (Petter A. Urkedal)
" 2017 Sep 6 - Initial version (Etienne Millon)

if exists("b:current_syntax")
finish
endif
Expand Down
Loading

0 comments on commit a817560

Please sign in to comment.