Skip to content

Commit

Permalink
Merge branch 'master' into pr-75-racket-gui
Browse files Browse the repository at this point in the history
Conflicts:
  ftplugin/racket.vim

  lispwords moved to indent/racket.vim. Resolution: add the new word
  there.
  • Loading branch information
benknoble committed Oct 23, 2021
2 parents 5637b3e + 1d612b6 commit 75dfb1b
Show file tree
Hide file tree
Showing 14 changed files with 519 additions and 94 deletions.
7 changes: 7 additions & 0 deletions compiler/raco.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let current_compiler = 'raco'

if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet makeprg=raco
7 changes: 7 additions & 0 deletions compiler/racomake.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let current_compiler = 'racomake'

if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet makeprg=raco\ make\ --\ %
8 changes: 8 additions & 0 deletions compiler/racotest.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let current_compiler = 'racotest'

if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet makeprg=raco\ test\ %
CompilerSet errorformat=location:%f:%l:%c
26 changes: 22 additions & 4 deletions ftdetect/racket.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
let g:racket_hash_lang_regexp = '^#lang\s\+\([^][)(}{[:space:]]\+\)'
let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict',
\ {
let g:racket_hash_lang_modifiers =
\ extend(get(g:, 'racket_hash_lang_modifiers', []), [
\ 'at-exp',
\ 'errortrace',
\ 'pollen/mode',
\ ])

let g:racket_hash_lang_modifiers_regex =
\ get(g:, 'racket_hash_lang_modifiers_regex',
\ '\%('.
\ join(map(deepcopy(g:racket_hash_lang_modifiers),
\ {_, v -> printf('\<%s\>', escape(v, '\'))}),
\ '\|')
\ .'\)')

let g:racket_hash_lang_regexp = get(g:, 'racket_hash_lang_regexp',
\ '^#lang\s\+\%\('.g:racket_hash_lang_modifiers_regex.'\s\+\)\?\([^][)(}{[:space:]]\+\)')
let g:racket_hash_lang_dict =
\ extend(get(g:, 'racket_hash_lang_dict', #{}), {
\ 'racket/base': 'racket',
\ 'racket/gui': 'racket',
\ 'typed/racket': 'racket',
Expand All @@ -9,7 +25,9 @@ let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict',
\ 'br/quicklang': 'racket',
\ 'scribble/base': 'scribble',
\ 'scribble/manual': 'scribble',
\ })
\ 'info': 'racket-info',
\ 'setup/infotab': 'racket-info',
\ }, 'keep') " keep prefers user dict to the default

" Tries to detect filetype from #lang line; defaults to ft=racket.
function! RacketDetectHashLang()
Expand Down
22 changes: 22 additions & 0 deletions ftplugin/jsond.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
" Language: jsond

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

" Enable auto begin new comment line when continuing from an old comment line
setl comments=:;;;;,:;;;,:;;,:;
setl formatoptions+=r

"setl commentstring=;;%s
setl commentstring=#\|\ %s\ \|#

let b:ale_linter_aliases = ['racket']

" Undo our settings when the filetype changes away from jsond
" (this should be amended if settings/mappings are added above!)
let b:undo_ftplugin =
\ "setl comments< formatoptions<"
\. "| setl commentstring<"
\. "| unlet b:ale_linter_aliases"
60 changes: 60 additions & 0 deletions ftplugin/racket-info.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
" Language: info

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

" quick hack to allow adding values
setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94

" Enable auto begin new comment line when continuing from an old comment line
setl comments=:;;;;,:;;;,:;;,:;
setl formatoptions+=r

" Simply setting keywordprg like this works:
" setl keywordprg=raco\ docs
" but then vim says:
" "press ENTER or type a command to continue"
" We avoid the annoyance of having to hit enter by remapping K directly.
function s:RacketDoc(word) abort
execute 'silent !raco docs --' shellescape(a:word)
redraw!
endfunction
nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>
if maparg("K", "n") == ""
nmap <buffer> K <Plug>RacketDoc
endif

" For the visual mode K mapping, it's slightly more convoluted to get the
" selected text:
function! s:Racket_visual_doc()
try
let l:old_a = @a
normal! gv"ay
call system("raco docs '". @a . "'")
redraw!
return @a
finally
let @a = l:old_a
endtry
endfunction

vnoremap <buffer> <Plug>RacketDoc :call <SID>Racket_visual_doc()<cr>
if maparg("K", "v") == ""
vmap <buffer> K <Plug>RacketDoc
endif

"setl commentstring=;;%s
setl commentstring=#\|\ %s\ \|#

let b:ale_linter_aliases = ['racket']

" Undo our settings when the filetype changes away from Racket
" (this should be amended if settings/mappings are added above!)
let b:undo_ftplugin =
\ "setl iskeyword< lispwords< lisp< comments< formatoptions<"
\. "| setl commentstring<"
\. "| nunmap <buffer> K"
\. "| vunmap <buffer> K"
\. "| unlet b:ale_linter_aliases"
38 changes: 13 additions & 25 deletions ftplugin/racket.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,23 @@ if exists("b:did_ftplugin")
endif
let b:did_ftplugin = 1

setl iskeyword+=#,%,^
setl lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local
setl lispwords+=define-values,opt-lambda,case-lambda,syntax-rules,with-syntax,syntax-case,syntax-parse
setl lispwords+=define-signature,unit,unit/sig,compund-unit/sig,define-values/invoke-unit/sig
setl lispwords+=define-opt/c,define-syntax-rule
setl lispwords+=struct

" Racket OOP
setl lispwords+=class,define/public,define/private,define/override

" kanren
setl lispwords+=fresh,run,run*,project,conde,condu

" loops
setl lispwords+=for,for/list,for/fold,for*,for*/list,for*/fold,for/or,for/and
setl lispwords+=for/hash,for/sum,for/flvector,for*/flvector,for/vector

setl lispwords+=match,match*,match/values,define/match,match-lambda,match-lambda*,match-lambda**
setl lispwords+=match-let,match-let*,match-let-values,match-let*-values
setl lispwords+=match-letrec,match-define,match-define-values
setl lisp
" quick hack to allow adding values
setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94

" Enable auto begin new comment line when continuing from an old comment line
setl comments=:;;;;,:;;;,:;;,:;
setl formatoptions+=r

setl makeprg=raco\ make\ --\ %

" Simply setting keywordprg like this works:
" setl keywordprg=raco\ docs
" but then vim says:
" "press ENTER or type a command to continue"
" We avoid the annoyance of having to hit enter by remapping K directly.
nnoremap <buffer> <Plug>RacketDoc :silent !raco docs <cword><cr>:redraw!<cr>
function s:RacketDoc(word) abort
execute 'silent !raco docs --' shellescape(a:word)
redraw!
endfunction
nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>
if maparg("K", "n") == ""
nmap <buffer> K <Plug>RacketDoc
endif
Expand All @@ -67,10 +50,15 @@ endif
"setl commentstring=;;%s
setl commentstring=#\|\ %s\ \|#

if exists("loaded_matchit") && !exists("b:match_words")
let b:match_words = '#|:|#'
endif

" Undo our settings when the filetype changes away from Racket
" (this should be amended if settings/mappings are added above!)
let b:undo_ftplugin =
\ "setl iskeyword< lispwords< lisp< comments< formatoptions<"
\. "| setl makeprg< commentstring<"
\. "| setl commentstring<"
\. "| nunmap <buffer> K"
\. "| vunmap <buffer> K"
\. "| unlet! b:match_words"
9 changes: 9 additions & 0 deletions indent/racket-info.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if exists("b:did_indent")
finish
endif
let b:did_indent = 1

setlocal lisp autoindent nosmartindent
setlocal lispwords=define

let b:undo_indent = "setlocal lisp< ai< si< lw<"
31 changes: 29 additions & 2 deletions indent/racket.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ if exists("b:did_indent")
endif
let b:did_indent = 1

setlocal ai nosi
setlocal lisp autoindent nosmartindent

let b:undo_indent = "setl ai< si<"
setlocal lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local
setlocal lispwords+=define/contract
setlocal lispwords+=λ
setlocal lispwords+=with-handlers
setlocal lispwords+=define-values,opt-lambda,case-lambda,syntax-rules,with-syntax,syntax-case,syntax-parse
setlocal lispwords+=define-for-syntax,define-syntax-parser,define-syntax-parse-rule,define-syntax-class,define-splicing-syntax-class
setlocal lispwords+=define-signature,unit,unit/sig,compund-unit/sig,define-values/invoke-unit/sig
setlocal lispwords+=define-opt/c,define-syntax-rule
setlocal lispwords+=define-test-suite
setlocal lispwords+=struct
setlocal lispwords+=with-input-from-file,with-output-to-file

" Racket OOP
setlocal lispwords+=class,define/public,define/private,define/override

" kanren
setlocal lispwords+=fresh,run,run*,project,conde,condu

" loops
setlocal lispwords+=for,for/list,for/fold,for*,for*/list,for*/fold,for/or,for/and
setlocal lispwords+=for/hash,for/sum,for/flvector,for*/flvector,for/vector,for*/vector
setlocal lispwords+=for/async

setlocal lispwords+=match,match*,match/values,define/match,match-lambda,match-lambda*,match-lambda**
setlocal lispwords+=match-let,match-let*,match-let-values,match-let*-values
setlocal lispwords+=match-letrec,match-define,match-define-values

let b:undo_indent = "setlocal lisp< ai< si< lw<"
70 changes: 70 additions & 0 deletions syntax/jsond.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
" Vim syntax file
" Language: #lang jsond

if exists("b:current_syntax")
finish
endif

" Hack: the syntax/json.vim file only permits numbers followed by blanks
" followed by some kind of object or array delimiter
" JSON the spec says a JSON is an element is a whitespace-delimited value, which
" can be any of an object, an array, a string, a number, or the keywords
" true/false/null
" Ref: https://www.json.org/json-en.html
syntax match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
syntax keyword jsonBoolean true false
syntax keyword jsonNull null

syntax cluster json contains=jsonObject,jsonArray,jsonNumber,jsonStringMatch,jsonBoolean,jsonNull

syntax region jsonArray matchgroup=jsonBraces start=/\[/ end=/]/ contains=@json fold
syntax region jsonObject matchgroup=jsonBraces start=/{/ end=/}/ contains=jsonKeyMatch fold

syntax match jsonKeyMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*:/ contains=jsonKey nextgroup=@json skipwhite
syntax region jsonKey start=/"/ end=/"\ze[[:blank:]\r\n]*:/ contained

syntax match jsonStringMatch /"\([^"]\|\\\"\)\+"/ contains=jsonString
syntax region jsonString oneline start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained

syntax match jsonEscape ,\\["\\/bfnrt], contained
syntax match jsonEscape /\\u\x\{4\}/ contained

" syntax iskeyword 33,35-39,42-58,60-90,94,95,97-122,126,_
" converted from decimal to char
" :s/\d\+/\=submatch(0)->str2nr()->nr2char()/g
" but corrected to remove duplicate _, move ^ to end
" also exclude comma, for JSON
syntax iskeyword @,!,#-',*-:,<-Z,a-z,~,_,^,,^
" expanded
" syntax iskeyword !,#,$,%,&,',*,+,,,-,.,/,0-9,:,<,=,>,?,@,A-Z,_,a-z,~,^,,^

syntax match jsondSyntax "#lang " nextgroup=jsondLang
syntax keyword jsondLang jsond

syntax keyword jsondName #:name nextgroup=jsondVarName skipwhite skipempty
syntax match jsondVarName ,\<\k\+\>, contained nextgroup=@json skipwhite skipempty

" Comments
syntax match jsondComment /;.*$/ contains=jsondTodo,jsondNote,@Spell
syntax region jsondMultilineComment start=/#|/ end=/|#/ contains=jsondMultilineComment,jsondTodo,jsondNote,@Spell

syntax keyword jsondTodo FIXME TODO XXX contained
syntax match jsondNote /\CNOTE\ze:\?/ contained

highlight default link jsondSyntax Statement
highlight default link jsondName Type

highlight default link jsondComment Comment
highlight default link jsondMultilineComment Comment

highlight default link jsondTodo Todo
highlight default link jsondNote SpecialComment

highlight default link jsonNumber Number
highlight default link jsonBoolean Boolean
highlight default link jsonNull Constant
highlight default link jsonString String
highlight default link jsonEscape Special
highlight default link jsonKey Label

let b:current_syntax = "jsond"
Loading

0 comments on commit 75dfb1b

Please sign in to comment.