From ad924bb3f53c99884b8ef8f35401962957c4ad17 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sun, 6 Dec 2020 20:07:10 -0500 Subject: [PATCH 01/47] syntax: give parentheses their own group This way I can `highlight link racketParen` without affecting Delimiter everywhere. --- syntax/racket.vim | 57 ++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index aae6723..6d9b8e5 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -489,12 +489,12 @@ syn region racketQuotedStruc start="#\["rs=s+2 end="\]"re=e-1 contains=@racketQ syn cluster racketQuotedStuff add=racketQuotedStruc " Non-quoted lists, and strings -syn region racketStruc matchgroup=Delimiter start="("rs=s+1 matchgroup=Delimiter end=")"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=Delimiter start="#("rs=s+2 matchgroup=Delimiter end=")"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=Delimiter start="{"rs=s+1 matchgroup=Delimiter end="}"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=Delimiter start="#{"rs=s+2 matchgroup=Delimiter end="}"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=Delimiter start="\["rs=s+1 matchgroup=Delimiter end="\]"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=Delimiter start="#\["rs=s+2 matchgroup=Delimiter end="\]"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="("rs=s+1 matchgroup=racketParen end=")"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="#("rs=s+2 matchgroup=racketParen end=")"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="{"rs=s+1 matchgroup=racketParen end="}"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="#{"rs=s+2 matchgroup=racketParen end="}"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="\["rs=s+1 matchgroup=racketParen end="\]"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="#\["rs=s+2 matchgroup=racketParen end="\]"re=e-1 contains=@racketNormal " Simple literals syn region racketString start=/\%(\\\)\@= 508 || !exists("did_racket_syntax_inits") HiLink racketSymbol Structure HiLink racketDelimiter Delimiter + HiLink racketParen Delimiter HiLink racketConstant Constant HiLink racketComment Comment From bae5e6a34ba1232d7fe44f2f4a964329cf9285d0 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sun, 6 Dec 2020 20:07:54 -0500 Subject: [PATCH 02/47] ftdetect: make #lang detection more robust - The dict is used to map "bad" filetypes to work-able filetypes ('filetype' cannot contain certain characters). See also the substitute function invocation. - old_ft is not necessary; but, we do need to redo the syntax (if syntax is on), the ftplugin, and the filetype-indent autocommands to make sure the syntax, &c., works out. We can safely do the ftplugin/indent commands because they are "off" the groups are empty (a silent[!] might be necessary to avoid "no matching autocommands" or something similar). - It is possible we can go back to "let &l:filetype" instead of "execute 'set filetypes='", but this is working. --- ftdetect/racket.vim | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index d5ccd8b..d8022af 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -1,18 +1,28 @@ -" let g:racket_hash_lang_regexp = '^#lang\s\+\([^][)(}{[:space:]]\+\)' +let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', + \ { + \ 'racket/base': 'racket', + \ 'typed/racket': 'racket', + \ 'scribble/base': 'scribble', + \ 'scribble/manual': 'scribble', + \ }) " Tries to detect filetype from #lang line; defaults to ft=racket. function! RacketDetectHashLang() - let old_ft = &filetype - + let redo_autocommands = !empty(&filetype) let matches = matchlist(getline(1), g:racket_hash_lang_regexp) if ! empty(matches) - let &l:filetype = matches[1] - endif - - if &filetype == old_ft + execute 'set filetype='.get(g:racket_hash_lang_dict, matches[1], substitute(matches[1], '[/\*?[|<>]', '', 'g')) + else set filetype=racket endif + if redo_autocommands + if g:syntax_on + execute 'doautocmd syntaxset FileType' &filetype + endif + execute 'doautocmd filetypeplugin FileType' &filetype + execute 'doautocmd filetypeindent FileType' &filetype + endif endfunction au BufRead,BufNewFile *.rkt,*.rktl call RacketDetectHashLang() From f7975549d02359296c340f787b2c540065238f62 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 12 Dec 2020 16:52:50 -0500 Subject: [PATCH 03/47] ftplugin: add more values to iskeyword --- ftplugin/racket.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 40d8741..db05532 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -7,7 +7,9 @@ if exists("b:did_ftplugin") endif let b:did_ftplugin = 1 -setl iskeyword+=#,%,^ +" quick hack to allow adding values +setlocal iskeyword-=^ +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 From 9e1deddab8eb1ef6d85231ab7778ba3cd3e617aa Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 28 Dec 2020 13:01:11 -0500 Subject: [PATCH 04/47] syntax: simplify matchgroup usage --- syntax/racket.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index 6d9b8e5..6b692f8 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -489,12 +489,12 @@ syn region racketQuotedStruc start="#\["rs=s+2 end="\]"re=e-1 contains=@racketQ syn cluster racketQuotedStuff add=racketQuotedStruc " Non-quoted lists, and strings -syn region racketStruc matchgroup=racketParen start="("rs=s+1 matchgroup=racketParen end=")"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="#("rs=s+2 matchgroup=racketParen end=")"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="{"rs=s+1 matchgroup=racketParen end="}"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="#{"rs=s+2 matchgroup=racketParen end="}"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="\["rs=s+1 matchgroup=racketParen end="\]"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="#\["rs=s+2 matchgroup=racketParen end="\]"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="("rs=s+1 end=")"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="#("rs=s+2 end=")"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="{"rs=s+1 end="}"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="#{"rs=s+2 end="}"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="\["rs=s+1 end="\]"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="#\["rs=s+2 end="\]"re=e-1 contains=@racketNormal " Simple literals syn region racketString start=/\%(\\\)\@ Date: Mon, 28 Dec 2020 13:16:33 -0500 Subject: [PATCH 05/47] syntax: add hash and regex literals --- syntax/racket.vim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/syntax/racket.vim b/syntax/racket.vim index 6b692f8..97cbe8b 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -496,6 +496,16 @@ syn region racketStruc matchgroup=racketParen start="#{"rs=s+2 end="}"re=e-1 con syn region racketStruc matchgroup=racketParen start="\["rs=s+1 end="\]"re=e-1 contains=@racketNormal syn region racketStruc matchgroup=racketParen start="#\["rs=s+2 end="\]"re=e-1 contains=@racketNormal +for lit in ['hash', 'hasheq', 'hasheqv'] + execute printf('syntax match racketLit "\<%s\>" nextgroup=@racketParen containedin=ALLBUT,.*String,.*Comment', '#'.lit) +endfor + +for lit in ['rx', 'rx#', 'px', 'px#'] + execute printf('syntax match racketRe "\<%s\>" nextgroup=@racketString containedin=ALLBUT,.*String,.*Comment,', '#'.lit) +endfor + +unlet lit + " Simple literals syn region racketString start=/\%(\\\)\@= 508 || !exists("did_racket_syntax_inits") HiLink racketParen Delimiter HiLink racketConstant Constant + HiLink racketLit Type + HiLink racketRe Type + HiLink racketComment Comment HiLink racketMultilineComment Comment HiLink racketTodo Todo From 88d23ac712be5d2e40288ef31e6247179c68878d Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 28 Dec 2020 14:43:03 -0500 Subject: [PATCH 06/47] ftdetect: remove autocommand nonsense it turns out, the rest is not necessary --- ftdetect/racket.vim | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index d8022af..6a3703b 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -9,20 +9,12 @@ let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', " Tries to detect filetype from #lang line; defaults to ft=racket. function! RacketDetectHashLang() - let redo_autocommands = !empty(&filetype) let matches = matchlist(getline(1), g:racket_hash_lang_regexp) if ! empty(matches) execute 'set filetype='.get(g:racket_hash_lang_dict, matches[1], substitute(matches[1], '[/\*?[|<>]', '', 'g')) else set filetype=racket endif - if redo_autocommands - if g:syntax_on - execute 'doautocmd syntaxset FileType' &filetype - endif - execute 'doautocmd filetypeplugin FileType' &filetype - execute 'doautocmd filetypeindent FileType' &filetype - endif endfunction au BufRead,BufNewFile *.rkt,*.rktl call RacketDetectHashLang() From 25386d92070a3839125bd29a0bfab0696bfb26bb Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 28 Dec 2020 15:44:49 -0500 Subject: [PATCH 07/47] syntax: greatly simplify quoting and nesting Quotes and unquotes match the special characters and leave everything else untouched (like the Clojure syntax). This leads to fewer edge cases. --- syntax/racket.vim | 74 ++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 53 deletions(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index 97cbe8b..d47a71d 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -472,29 +472,18 @@ syn match racketDelimiter !\<\.\>! syn match racketSymbol ,\k+, contained -syn cluster racketNormal contains=racketSyntax,racketFunc,racketDelimiter -syn cluster racketQuotedStuff contains=racketSymbol -syn cluster racketQuotedOrNormal contains=racketDelimiter +syn cluster racketTop contains=racketSyntax,racketFunc,racketDelimiter syn match racketConstant ,\<\*\k\+\*\>, syn match racketConstant ,\<<\k\+>\>, -syn region racketQuotedStruc start="("rs=s+1 end=")"re=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal contained -syn region racketQuotedStruc start="#("rs=s+2 end=")"re=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal contained -syn region racketQuotedStruc start="{"rs=s+1 end="}"re=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal contained -syn region racketQuotedStruc start="#{"rs=s+2 end="}"re=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal contained -syn region racketQuotedStruc start="\["rs=s+1 end="\]"re=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal contained -syn region racketQuotedStruc start="#\["rs=s+2 end="\]"re=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal contained - -syn cluster racketQuotedStuff add=racketQuotedStruc - " Non-quoted lists, and strings -syn region racketStruc matchgroup=racketParen start="("rs=s+1 end=")"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="#("rs=s+2 end=")"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="{"rs=s+1 end="}"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="#{"rs=s+2 end="}"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="\["rs=s+1 end="\]"re=e-1 contains=@racketNormal -syn region racketStruc matchgroup=racketParen start="#\["rs=s+2 end="\]"re=e-1 contains=@racketNormal +syn region racketStruc matchgroup=racketParen start="("rs=s+1 end=")"re=e-1 contains=@racketTop +syn region racketStruc matchgroup=racketParen start="#("rs=s+2 end=")"re=e-1 contains=@racketTop +syn region racketStruc matchgroup=racketParen start="{"rs=s+1 end="}"re=e-1 contains=@racketTop +syn region racketStruc matchgroup=racketParen start="#{"rs=s+2 end="}"re=e-1 contains=@racketTop +syn region racketStruc matchgroup=racketParen start="\["rs=s+1 end="\]"re=e-1 contains=@racketTop +syn region racketStruc matchgroup=racketParen start="#\["rs=s+2 end="\]"re=e-1 contains=@racketTop for lit in ['hash', 'hasheq', 'hasheqv'] execute printf('syntax match racketLit "\<%s\>" nextgroup=@racketParen containedin=ALLBUT,.*String,.*Comment', '#'.lit) @@ -510,8 +499,7 @@ unlet lit syn region racketString start=/\%(\\\)\@" syn match racketChar "\<#\\x[0-9a-f]\{1,2}\>" syn match racketChar "\<#\\u[0-9a-f]\{1,6}\>" -syn cluster racketNormal add=racketNumber,racketBoolean,racketChar -syn cluster racketQuotedOrNormal add=racketNumber,racketBoolean +syn cluster racketTop add=racketNumber,racketBoolean,racketChar " Command-line parsing syn keyword racketExtFunc command-line current-command-line-arguments once-any help-labels multi once-each @@ -584,34 +571,17 @@ syn keyword racketExtFunc command-line current-command-line-arguments once-any h syn match racketSyntax "#lang " syn match racketExtSyntax "#:\k\+" -syn cluster racketNormal add=racketExtFunc,racketExtSyntax +syn cluster racketTop add=racketExtFunc,racketExtSyntax " syntax quoting, unquoting and quasiquotation -syn region racketQuoted matchgroup=racketParen start="['`]" end=![ \t()\[\]";]!me=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal -syn region racketQuoted matchgroup=racketParen start="['`](" matchgroup=racketParen end=")" contains=@racketQuotedStuff,@racketQuotedOrNormal -syn region racketQuoted matchgroup=racketParen start="['`]\?#(" matchgroup=racketParen end=")" contains=@racketQuotedStuff,@racketQuotedOrNormal - -syn region racketUnquote matchgroup=racketParen start="#,"rs=s+2 end=![ \t\[\]()";]!re=e-1,me=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start="#,@"rs=s+3 end=![ \t\[\]()";]!re=e-1,me=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start="#,("rs=s+3 end=")"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start="#,@("rs=s+4 end=")"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start="#,\["rs=s+3 end="\]"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start="#,@\["rs=s+4 end="\]"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=","rs=s+1 end=![ \t\[\]()";]!re=e-1,me=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",@"rs=s+2 end=![ \t\[\]()";]!re=e-1,me=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",("rs=s+2 end=")"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",@("rs=s+3 end=")"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",#("rs=s+3 end=")"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",@#("rs=s+4 end=")"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",\["rs=s+2 end="\]"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",@\["rs=s+3 end="\]"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",#\["rs=s+3 end="\]"re=e-1 contained contains=@racketNormal -syn region racketUnquote matchgroup=racketParen start=",@#\["rs=s+4 end="\]"re=e-1 contained contains=@racketNormal - -syn cluster racketQuotedStuff add=racketUnquote - -syn region racketQuoted matchgroup=racketParen start="#['`]"rs=s+2 end=![ \t()\[\]";]!re=e-1,me=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal -syn region racketQuoted matchgroup=racketParen start="#['`]("rs=s+3 matchgroup=racketParen end=")"re=e-1 contains=@racketQuotedStuff,@racketQuotedOrNormal +syn match racketQuote "#\?['`]" + +syn match racketUnquote "#," +syn match racketUnquote "#,@" +syn match racketUnquote "," +syn match racketUnquote ",#" +syn match racketUnquote ",@" +syn match racketUnquote ",@#" " Comments syn match racketComment /;.*$/ contains=racketTodo,racketNote,@Spell @@ -620,9 +590,7 @@ syn region racketMultilineComment start=/#|/ end=/|#/ contains=racketMultilineCo syn keyword racketTodo FIXME TODO XXX contained syntax match racketNote /\CNOTE\ze:\?/ contained -syn cluster racketNormal add=racketQuoted,racketComment,racketMultilineComment -syn cluster racketQuotedOrNormal add=racketComment,racketMultilineComment - +syn cluster racketTop add=racketQuote,racketUnquote,racketComment,racketMultilineComment " Synchronization and the wrapping up... syn sync match matchPlace grouphere NONE "^[^ \t]" @@ -650,8 +618,8 @@ if version >= 508 || !exists("did_racket_syntax_inits") HiLink racketNumberError Error HiLink racketContainedNumberError Error - HiLink racketQuoted Structure - HiLink racketQuotedStruc Structure + HiLink racketQuote SpecialChar + HiLink racketUnquote SpecialChar HiLink racketSymbol Structure HiLink racketDelimiter Delimiter From c75129df358bcc98c66cccc6798fc6a55cd172c7 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 28 Dec 2020 16:10:42 -0500 Subject: [PATCH 08/47] syntax: add simple form-level comment (#;) --- syntax/racket.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index d47a71d..54a7622 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -586,11 +586,12 @@ syn match racketUnquote ",@#" " Comments syn match racketComment /;.*$/ contains=racketTodo,racketNote,@Spell syn region racketMultilineComment start=/#|/ end=/|#/ contains=racketMultilineComment,racketTodo,racketNote,@Spell +syn match racketFormComment "#;" nextgroup=@racketTop syn keyword racketTodo FIXME TODO XXX contained syntax match racketNote /\CNOTE\ze:\?/ contained -syn cluster racketTop add=racketQuote,racketUnquote,racketComment,racketMultilineComment +syn cluster racketTop add=racketQuote,racketUnquote,racketComment,racketMultilineComment,racketFormComment " Synchronization and the wrapping up... syn sync match matchPlace grouphere NONE "^[^ \t]" @@ -631,6 +632,7 @@ if version >= 508 || !exists("did_racket_syntax_inits") HiLink racketComment Comment HiLink racketMultilineComment Comment + HiLink racketFormComment SpecialChar HiLink racketTodo Todo HiLink racketNote SpecialComment HiLink racketError Error From 9d9cab22ebaf287c949dd3a0c73ad4f8a518ede1 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Tue, 29 Dec 2020 13:53:07 -0500 Subject: [PATCH 09/47] syntax: remove incorrect unquote forms --- syntax/racket.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index 54a7622..0bb2cd7 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -579,9 +579,7 @@ syn match racketQuote "#\?['`]" syn match racketUnquote "#," syn match racketUnquote "#,@" syn match racketUnquote "," -syn match racketUnquote ",#" syn match racketUnquote ",@" -syn match racketUnquote ",@#" " Comments syn match racketComment /;.*$/ contains=racketTodo,racketNote,@Spell From 5e0346be317f5d55370a3ec07b56ec2ec656db1c Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 11 Jan 2021 17:18:00 -0500 Subject: [PATCH 10/47] syntax: fix char function names --- syntax/racket.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index 0bb2cd7..4b226dd 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -213,7 +213,7 @@ syn keyword racketFunc locale-string-encoding syn keyword racketFunc char? char->integer integer->char syn keyword racketFunc char=? char? char>=? syn keyword racketFunc char-ci=? char-ci? char-ci>=? -syn keyword racketFunc char-alphabetic? char-lowercase? char-uppercase? char-title-case? +syn keyword racketFunc char-alphabetic? char-lower-case? char-upper-case? char-title-case? syn keyword racketFunc char-numeric? char-symbolic? char-punctuation? char-graphic? syn keyword racketFunc char-whitespace? char-blank? syn keyword racketFunc char-iso-control? char-general-category From 111c8bf4e8006a8b28a980bbb867e12b98ffd2c0 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 11 Jan 2021 17:18:21 -0500 Subject: [PATCH 11/47] ftplugin: update lispwords --- ftplugin/racket.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index db05532..2f67903 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -11,6 +11,9 @@ let b:did_ftplugin = 1 setlocal iskeyword-=^ setl iskeyword+=*,+,/,!,<,=,>,?,#,%,^ setl lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local +setl lispwords+=define/contract +setl lispwords+=λ +setl lispwords+=with-handlers 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 @@ -24,7 +27,7 @@ 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+=for/hash,for/sum,for/flvector,for*/flvector,for/vector,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 From 8a3c1b0b666e4ae72e3c02778ebfff179e30441e Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 11 Jan 2021 17:18:46 -0500 Subject: [PATCH 12/47] ftplugin: shellescape K word --- ftplugin/racket.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 2f67903..40e393f 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -45,7 +45,11 @@ setl makeprg=raco\ make\ --\ % " 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 RacketDoc :silent !raco docs :redraw! +function s:RacketDoc(word) abort + execute 'silent !raco docs --' shellescape(a:word) + redraw! +endfunction +nnoremap RacketDoc :call RacketDoc(expand('')) if maparg("K", "n") == "" nmap K RacketDoc endif From 415f7817f4e9917164dc773331dc4a5c685b2a39 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 11 Jan 2021 17:23:54 -0500 Subject: [PATCH 13/47] ftdetect: support beautiful racket --- ftdetect/racket.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 6a3703b..1379eb0 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -3,6 +3,8 @@ let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', \ { \ 'racket/base': 'racket', \ 'typed/racket': 'racket', + \ 'br': 'racket', + \ 'br/quicklang': 'racket', \ 'scribble/base': 'scribble', \ 'scribble/manual': 'scribble', \ }) From e2019c4b254f0b4c93291b823c5bcb73029bf953 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Tue, 26 Jan 2021 09:06:05 -0500 Subject: [PATCH 14/47] comments: support more forms --- ftplugin/racket.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 40e393f..ac5ee97 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -35,7 +35,7 @@ setl lispwords+=match-letrec,match-define,match-define-values setl lisp " Enable auto begin new comment line when continuing from an old comment line -setl comments+=:; +setl comments+=:;;;;,:;;;,:;;,:; setl formatoptions+=r setl makeprg=raco\ make\ --\ % From b6e743e0253eaa84f7c5b229091e1da1f7faafe4 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Fri, 5 Feb 2021 11:03:54 -0500 Subject: [PATCH 15/47] ftplugin: add define-test-suite to lispwords --- ftplugin/racket.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index ac5ee97..63c7a68 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -17,6 +17,7 @@ setl lispwords+=with-handlers 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+=define-test-suite setl lispwords+=struct " Racket OOP From 3f010325532e43eb20b172bd09305bec307b3d7d Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Fri, 5 Feb 2021 11:04:16 -0500 Subject: [PATCH 16/47] syntax: racket is case-sensitive --- syntax/racket.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index 4b226dd..be11735 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -11,8 +11,6 @@ elseif exists("b:current_syntax") finish endif -syn case ignore - " Highlight unmatched parens syn match racketError ,[]})], From 902d56b1c07324f95016efa57df334b44781fccf Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 27 Mar 2021 11:41:14 -0400 Subject: [PATCH 17/47] add typed/racket/base -> racket --- ftdetect/racket.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 1379eb0..4a9ff08 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -3,6 +3,7 @@ let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', \ { \ 'racket/base': 'racket', \ 'typed/racket': 'racket', + \ 'typed/racket/base': 'racket', \ 'br': 'racket', \ 'br/quicklang': 'racket', \ 'scribble/base': 'scribble', From 23bf58ae90e969e97d494de31829fdc0b0d60a50 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Tue, 15 Jun 2021 14:15:23 -0400 Subject: [PATCH 18/47] syntax: don't set iskeyword This actually breaks inclusion of this syntax in other files, e.g., markdown. Instead, use syntax iskeyword to set a keyword pattern for the syntax. I took the liberty of making things slightly more readable. --- syntax/racket.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index be11735..f5c2f1a 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -17,7 +17,13 @@ syn match racketError ,[]})], if version < 600 set iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_ else - setlocal iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_ + " 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 + syntax iskeyword !,#-',*-:,<-Z,a-z,~,_,^ + " expanded + " syntax iskeyword !,#,$,%,&,',*,+,,,-,.,/,0-9,:,<,=,>,?,@,A-Z,_,a-z,~,^ endif " Forms in order of appearance at From 96527cb31ea83f04b7b57af47c3c76e0f06854e6 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Tue, 15 Jun 2021 14:16:17 -0400 Subject: [PATCH 19/47] ftplugin: sync iskeyword with syntax --- ftplugin/racket.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 63c7a68..740085d 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -8,8 +8,7 @@ endif let b:did_ftplugin = 1 " quick hack to allow adding values -setlocal iskeyword-=^ -setl iskeyword+=*,+,/,!,<,=,>,?,#,%,^ +setlocal iskeyword=!,#-',*-:,<-Z,a-z,~,_,^ setl lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local setl lispwords+=define/contract setl lispwords+=λ From 0dae068c42680adfdc8fdc347b3d2039fced19c3 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Tue, 15 Jun 2021 14:17:01 -0400 Subject: [PATCH 20/47] iskeyword: add @ (isalpha) --- ftplugin/racket.vim | 2 +- syntax/racket.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 740085d..ed1351e 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -8,7 +8,7 @@ endif let b:did_ftplugin = 1 " quick hack to allow adding values -setlocal iskeyword=!,#-',*-:,<-Z,a-z,~,_,^ +setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,^ setl lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local setl lispwords+=define/contract setl lispwords+=λ diff --git a/syntax/racket.vim b/syntax/racket.vim index f5c2f1a..c5c320e 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -21,7 +21,7 @@ else " converted from decimal to char " :s/\d\+/\=submatch(0)->str2nr()->nr2char()/g " but corrected to remove duplicate _, move ^ to end - syntax iskeyword !,#-',*-:,<-Z,a-z,~,_,^ + syntax iskeyword @,!,#-',*-:,<-Z,a-z,~,_,^ " expanded " syntax iskeyword !,#,$,%,&,',*,+,,,-,.,/,0-9,:,<,=,>,?,@,A-Z,_,a-z,~,^ endif From baef81854d91be5471d808641d8171ccc91c6759 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Tue, 15 Jun 2021 14:22:28 -0400 Subject: [PATCH 21/47] raco: split makeprg settings to compiler plugins --- compiler/raco.vim | 7 +++++++ compiler/racomake.vim | 7 +++++++ compiler/racotest.vim | 8 ++++++++ ftplugin/racket.vim | 2 -- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 compiler/raco.vim create mode 100644 compiler/racomake.vim create mode 100644 compiler/racotest.vim diff --git a/compiler/raco.vim b/compiler/raco.vim new file mode 100644 index 0000000..d5d1d0f --- /dev/null +++ b/compiler/raco.vim @@ -0,0 +1,7 @@ +let current_compiler = 'raco' + +if exists(":CompilerSet") != 2 + command -nargs=* CompilerSet setlocal +endif + +CompilerSet makeprg=raco diff --git a/compiler/racomake.vim b/compiler/racomake.vim new file mode 100644 index 0000000..f542a33 --- /dev/null +++ b/compiler/racomake.vim @@ -0,0 +1,7 @@ +let current_compiler = 'racomake' + +if exists(":CompilerSet") != 2 + command -nargs=* CompilerSet setlocal +endif + +CompilerSet makeprg=raco\ make\ --\ % diff --git a/compiler/racotest.vim b/compiler/racotest.vim new file mode 100644 index 0000000..54cc796 --- /dev/null +++ b/compiler/racotest.vim @@ -0,0 +1,8 @@ +let current_compiler = 'racotest' + +if exists(":CompilerSet") != 2 + command -nargs=* CompilerSet setlocal +endif + +CompilerSet makeprg=raco\ test\ % +CompilerSet errorformat=location:%f:%l:%c diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index ed1351e..d97cdf8 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -38,8 +38,6 @@ setl lisp setl comments+=:;;;;,:;;;,:;;,:; setl formatoptions+=r -setl makeprg=raco\ make\ --\ % - " Simply setting keywordprg like this works: " setl keywordprg=raco\ docs " but then vim says: From e4e7e99143616bdfa831a7bc617290e0c8917743 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 19 Jun 2021 14:38:28 -0400 Subject: [PATCH 22/47] syntax: fix racketChar uppercase letters are allowed, so use the character classes built to handle this --- syntax/racket.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index c5c320e..744e655 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -563,9 +563,9 @@ syn match racketChar "\<#\\linefeed\>" syn match racketChar "\<#\\vtab\>" syn match racketChar "\<#\\page\>" syn match racketChar "\<#\\rubout\>" -syn match racketChar "\<#\\[0-7]\{1,3}\>" -syn match racketChar "\<#\\x[0-9a-f]\{1,2}\>" -syn match racketChar "\<#\\u[0-9a-f]\{1,6}\>" +syn match racketChar "\<#\\\o\{1,3}\>" +syn match racketChar "\<#\\x\x\{1,2}\>" +syn match racketChar "\<#\\u\x\{1,6}\>" syn cluster racketTop add=racketNumber,racketBoolean,racketChar From 96bbfba83b91e8ca52bec8f390341ed049a771ef Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 19 Jun 2021 14:58:52 -0400 Subject: [PATCH 23/47] syntax: add racket-info for #lang info https://docs.racket-lang.org/raco/info_rkt.html?q=info --- ftdetect/racket.vim | 2 + syntax/racket-info.vim | 209 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 syntax/racket-info.vim diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 4a9ff08..3c620e7 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -8,6 +8,8 @@ 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', \ }) " Tries to detect filetype from #lang line; defaults to ft=racket. diff --git a/syntax/racket-info.vim b/syntax/racket-info.vim new file mode 100644 index 0000000..a2deb07 --- /dev/null +++ b/syntax/racket-info.vim @@ -0,0 +1,209 @@ +" Vim syntax file +" Language: #lang info + +" Initializing: +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" Highlight unmatched parens +syntax match infoError ,[]})], + +syntax match fallbackError /./ + +if version < 600 + set iskeyword=33,35-39,42-58,60-90,94,95,97-122,126,_ +else + " 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 + syntax iskeyword @,!,#-',*-:,<-Z,a-z,~,_,^ + " expanded + " syntax iskeyword !,#,$,%,&,',*,+,,,-,.,/,0-9,:,<,=,>,?,@,A-Z,_,a-z,~,^ +endif + +" https://docs.racket-lang.org/raco/info_rkt.html?q=info + +syntax keyword infoSyntax define quote quasiquote if + +syntax keyword infoPrimitive cons car cdr list list* reverse append equal? +syntax keyword infoPrimitive string-append make-immutable-hash hash hash-set +syntax keyword infoPrimitive hash-set* hash-remove hash-clear hash-update +syntax keyword infoPrimitive path->string build-path collection-path +syntax keyword infoPrimitive system-library-subpath getenv + +syntax match datumDelimiter !\<\.\>! + +syntax match infoSymbol ,\k+, contained + +syntax cluster infoTop contains=infoSyntax,infoPrimitive,datumDelimiter + +syntax match infoConstant ,\<\*\k\+\*\>, +syntax match infoConstant ,\<<\k\+>\>, + +" Non-quoted lists, and strings +syntax region infoStruc matchgroup=infoParen start="("rs=s+1 end=")"re=e-1 contains=@infoTop +syntax region infoStruc matchgroup=infoParen start="#("rs=s+2 end=")"re=e-1 contains=@infoTop +syntax region infoStruc matchgroup=infoParen start="{"rs=s+1 end="}"re=e-1 contains=@infoTop +syntax region infoStruc matchgroup=infoParen start="#{"rs=s+2 end="}"re=e-1 contains=@infoTop +syntax region infoStruc matchgroup=infoParen start="\["rs=s+1 end="\]"re=e-1 contains=@infoTop +syntax region infoStruc matchgroup=infoParen start="#\["rs=s+2 end="\]"re=e-1 contains=@infoTop + +for lit in ['hash', 'hasheq', 'hasheqv'] + execute printf('syntax match infoLit "\<%s\>" nextgroup=@infoParen containedin=ALLBUT,.*String,.*Comment', '#'.lit) +endfor + +for lit in ['rx', 'rx#', 'px', 'px#'] + execute printf('syntax match infoRe "\<%s\>" nextgroup=@infoString containedin=ALLBUT,.*String,.*Comment,', '#'.lit) +endfor + +unlet lit + +" Simple literals +syntax region infoString start=/\%(\\\)\@" +syntax match infoContainedNumberError "\<#b\k*[^-+01delfinas#./@]\>" +syntax match infoContainedNumberError "\<#[ei]#[ei]" +syntax match infoContainedNumberError "\<#[xdob]#[xdob]" + +" start with the simpler sorts +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\?\d\+/\d\+\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\?\d\+/\d\+[-+]\d\+\(/\d\+\)\?i\>" contains=infoContainedNumberError + +" different possible ways of expressing complex values +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?i\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?[-+]\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?i\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\(inf\|nan\)\.[0f][-+]\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?i\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?[-+]\(inf\|nan\)\.[0f]i\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?@[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\(inf\|nan\)\.[0f]@[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[dobie]\)\{0,2}[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?\([sdlef][-+]\?\d\+#*\)\?@[-+]\(inf\|nan\)\.[0f]\>" contains=infoContainedNumberError + +" hex versions of the above (separate because of the different possible exponent markers) +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\?\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\?\x\+/\x\+\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\?\x\+/\x\+[-+]\x\+\(/\x\+\)\?i\>" + +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?i\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\?\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?[-+]\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?i\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\(inf\|nan\)\.[0f][-+]\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?i\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\?\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?[-+]\(inf\|nan\)\.[0f]i\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\?\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?@[-+]\?\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\(inf\|nan\)\.[0f]@[-+]\?\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?\>" +syntax match infoNumber "\<\(#x\|#[ei]#x\|#x#[ei]\)[-+]\?\(\x\+\|\x\+#*\.\|\x*\.\x\+\)#*\(/\x\+#*\)\?\([sl][-+]\?\x\+#*\)\?@[-+]\(inf\|nan\)\.[0f]\>" + +" these work for any radix +syntax match infoNumber "\<\(#[xdobie]\)\{0,2}[-+]\(inf\|nan\)\.[0f]i\?\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[xdobie]\)\{0,2}[-+]\(inf\|nan\)\.[0f][-+]\(inf\|nan\)\.[0f]i\>" contains=infoContainedNumberError +syntax match infoNumber "\<\(#[xdobie]\)\{0,2}[-+]\(inf\|nan\)\.[0f]@[-+]\(inf\|nan\)\.[0f]\>" contains=infoContainedNumberError + +syntax keyword infoBoolean #t #f #true #false #T #F + +syntax match infoError "\<#\\\k*\>" + +syntax match infoChar "\<#\\.\w\@!" +syntax match infoChar "\<#\\space\>" +syntax match infoChar "\<#\\newline\>" +syntax match infoChar "\<#\\return\>" +syntax match infoChar "\<#\\null\?\>" +syntax match infoChar "\<#\\backspace\>" +syntax match infoChar "\<#\\tab\>" +syntax match infoChar "\<#\\linefeed\>" +syntax match infoChar "\<#\\vtab\>" +syntax match infoChar "\<#\\page\>" +syntax match infoChar "\<#\\rubout\>" +syntax match infoChar "\<#\\\o\{1,3}\>" +syntax match infoChar "\<#\\x\x\{1,2}\>" +syntax match infoChar "\<#\\u\x\{1,6}\>" + +syntax cluster infoTop add=infoNumber,infoBoolean,infoChar + +syntax match infoSyntax "#lang " nextgroup=infoLang +syntax keyword infoLang info setup/infotab +syntax match infoExtSyntax "#:\k\+" + +syntax cluster infoTop add=infoExtFunc,infoExtSyntax + +" syntax quoting, unquoting and quasiquotation +syntax match infoQuote "#\?['`]" + +syntax match infoUnquote "#," +syntax match infoUnquote "#,@" +syntax match infoUnquote "," +syntax match infoUnquote ",@" + +" Comments +syntax match infoComment /;.*$/ contains=infoTodo,infoNote,@Spell +syntax region infoMultilineComment start=/#|/ end=/|#/ contains=infoMultilineComment,infoTodo,infoNote,@Spell +syntax match infoFormComment "#;" nextgroup=@infoTop + +syntax keyword infoTodo FIXME TODO XXX contained +syntax match infoNote /\CNOTE\ze:\?/ contained + +syntax cluster infoTop add=infoQuote,infoUnquote,infoComment,infoMultilineComment,infoFormComment + +" Synchronization and the wrapping up... +syntax sync match matchPlace grouphere NONE "^[^ \t]" +" ... i.e. synchronize on a line that starts at the left margin + +" Define the default highlighting. +" For version 5.7 and earlier: only when not done already +" For version 5.8 and later: only when an item doesn't have highlighting yet +if version >= 508 || !exists("did_info_syntax_inits") + if version < 508 + let did_info_syntax_inits = 1 + command -nargs=+ HiLink highlight link + else + command -nargs=+ HiLink highlight def link + endif + + HiLink infoSyntax Statement + HiLink infoPrimitive Function + + HiLink infoString String + HiLink infoChar Character + HiLink infoBoolean Boolean + + HiLink infoNumber Number + HiLink infoNumberError Error + HiLink infoContainedNumberError Error + + HiLink infoQuote SpecialChar + HiLink infoUnquote SpecialChar + HiLink infoSymbol Structure + + HiLink datumDelimiter Delimiter + HiLink infoParen Delimiter + HiLink infoConstant Constant + + HiLink infoLit Type + HiLink infoRe Type + + HiLink infoComment Comment + HiLink infoMultilineComment Comment + HiLink infoFormComment SpecialChar + HiLink infoTodo Todo + HiLink infoNote SpecialComment + HiLink infoError Error + HiLink fallbackError Error + + HiLink infoExtSyntax Type + HiLink infoExtFunc PreProc + delcommand HiLink +endif + +let b:current_syntax = "racket-info" From cfdf6669fda8146d8460e9fef0ebd51ccff7d978 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Sat, 10 Apr 2021 21:43:27 -0400 Subject: [PATCH 24/47] Use = instead of += for comment specification --- ftplugin/racket.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index d97cdf8..c17741f 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -35,7 +35,7 @@ setl lispwords+=match-letrec,match-define,match-define-values setl lisp " Enable auto begin new comment line when continuing from an old comment line -setl comments+=:;;;;,:;;;,:;;,:; +setl comments=:;;;;,:;;;,:;;,:; setl formatoptions+=r " Simply setting keywordprg like this works: From 26e54d93f368c68ab8814f58f2f42fe38d63c454 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Wed, 23 Jun 2021 10:29:38 -0400 Subject: [PATCH 25/47] fixup! raco: split makeprg settings to compiler plugins --- ftplugin/racket.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index c17741f..15301a8 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -78,6 +78,6 @@ setl commentstring=#\|\ %s\ \|# " (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 K" \. "| vunmap K" From 304d2d755b18cb8dfddb86dabd73b798e5a1b97e Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Wed, 23 Jun 2021 10:56:05 -0400 Subject: [PATCH 26/47] lispwords: add define-syntax-parse-rule --- ftplugin/racket.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 15301a8..141e802 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -14,6 +14,7 @@ setl lispwords+=define/contract setl lispwords+=λ setl lispwords+=with-handlers setl lispwords+=define-values,opt-lambda,case-lambda,syntax-rules,with-syntax,syntax-case,syntax-parse +setl lispwords+=define-syntax-parse-rule 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+=define-test-suite From 7a03becbe0598785520440faa2b77a5e856fd4d4 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Wed, 23 Jun 2021 14:08:06 -0400 Subject: [PATCH 27/47] lispwords: add for/async --- ftplugin/racket.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 141e802..6e2c500 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -29,6 +29,7 @@ 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,for*/vector +setl lispwords+=for/async 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 From d05c3fefe8c7f44f8b2f71a7ed6b82ae732ba20b Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 2 Aug 2021 16:36:00 -0400 Subject: [PATCH 28/47] lispwords: add more syntax-related forms --- ftplugin/racket.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 6e2c500..be0d6c5 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -14,7 +14,7 @@ setl lispwords+=define/contract setl lispwords+=λ setl lispwords+=with-handlers setl lispwords+=define-values,opt-lambda,case-lambda,syntax-rules,with-syntax,syntax-case,syntax-parse -setl lispwords+=define-syntax-parse-rule +setl lispwords+=define-for-syntax,define-syntax-parser,define-syntax-parse-rule,define-syntax-class,define-splicing-syntax-class 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+=define-test-suite From a7fc8694891aa4384a6de11ac8c27c7cab7b36cc Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 2 Aug 2021 16:36:15 -0400 Subject: [PATCH 29/47] lispwords: add I/O related forms --- ftplugin/racket.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index be0d6c5..1f14f6c 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -19,6 +19,7 @@ setl lispwords+=define-signature,unit,unit/sig,compund-unit/sig,define-values/in setl lispwords+=define-opt/c,define-syntax-rule setl lispwords+=define-test-suite setl lispwords+=struct +setl lispwords+=with-input-from-file,with-output-to-file " Racket OOP setl lispwords+=class,define/public,define/private From b122720d4d8ea99b108da3a17b6532da467fa89f Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Fri, 6 Aug 2021 16:02:41 -0400 Subject: [PATCH 30/47] ftplugin: set options for info --- ftplugin/racket-info.vim | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ftplugin/racket-info.vim diff --git a/ftplugin/racket-info.vim b/ftplugin/racket-info.vim new file mode 100644 index 0000000..6172772 --- /dev/null +++ b/ftplugin/racket-info.vim @@ -0,0 +1,59 @@ +" Language: info + +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +setlocal lisp +" quick hack to allow adding values +setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,^ +setlocal lispwords=define + +" 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 RacketDoc :call RacketDoc(expand('')) +if maparg("K", "n") == "" + nmap K 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 RacketDoc :call Racket_visual_doc() +if maparg("K", "v") == "" + vmap K RacketDoc +endif + +"setl commentstring=;;%s +setl commentstring=#\|\ %s\ \|# + +" 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 K" + \. "| vunmap K" From 845500967d74aca16d0311c01fb284af7db281d7 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 7 Aug 2021 17:45:25 -0400 Subject: [PATCH 31/47] syntax: remove useless Symbol It was never matched (literal +), and not contained in anything? --- syntax/racket-info.vim | 3 --- syntax/racket.vim | 3 --- 2 files changed, 6 deletions(-) diff --git a/syntax/racket-info.vim b/syntax/racket-info.vim index a2deb07..2d2cb0c 100644 --- a/syntax/racket-info.vim +++ b/syntax/racket-info.vim @@ -37,8 +37,6 @@ syntax keyword infoPrimitive system-library-subpath getenv syntax match datumDelimiter !\<\.\>! -syntax match infoSymbol ,\k+, contained - syntax cluster infoTop contains=infoSyntax,infoPrimitive,datumDelimiter syntax match infoConstant ,\<\*\k\+\*\>, @@ -184,7 +182,6 @@ if version >= 508 || !exists("did_info_syntax_inits") HiLink infoQuote SpecialChar HiLink infoUnquote SpecialChar - HiLink infoSymbol Structure HiLink datumDelimiter Delimiter HiLink infoParen Delimiter diff --git a/syntax/racket.vim b/syntax/racket.vim index 744e655..aab2ccd 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -474,8 +474,6 @@ syn keyword racketFunc seconds->date current-milliseconds syn match racketDelimiter !\<\.\>! -syn match racketSymbol ,\k+, contained - syn cluster racketTop contains=racketSyntax,racketFunc,racketDelimiter syn match racketConstant ,\<\*\k\+\*\>, @@ -623,7 +621,6 @@ if version >= 508 || !exists("did_racket_syntax_inits") HiLink racketQuote SpecialChar HiLink racketUnquote SpecialChar - HiLink racketSymbol Structure HiLink racketDelimiter Delimiter HiLink racketParen Delimiter From e262c790816b1d4df74740fe02fede5ecdea4a49 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sun, 8 Aug 2021 16:35:38 -0400 Subject: [PATCH 32/47] isk: use number for ^ to avoid += errors --- ftplugin/racket-info.vim | 2 +- ftplugin/racket.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ftplugin/racket-info.vim b/ftplugin/racket-info.vim index 6172772..3cba288 100644 --- a/ftplugin/racket-info.vim +++ b/ftplugin/racket-info.vim @@ -7,7 +7,7 @@ let b:did_ftplugin = 1 setlocal lisp " quick hack to allow adding values -setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,^ +setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94 setlocal lispwords=define " Enable auto begin new comment line when continuing from an old comment line diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 1f14f6c..7ebb1f3 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -8,7 +8,7 @@ endif let b:did_ftplugin = 1 " quick hack to allow adding values -setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,^ +setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94 setl lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local setl lispwords+=define/contract setl lispwords+=λ From 66e87cf2fdbd85871f80bd936985f4cd02e559a9 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sun, 8 Aug 2021 16:41:27 -0400 Subject: [PATCH 33/47] add #lang jsond --- ftdetect/racket.vim | 1 + ftplugin/jsond.vim | 19 ++++++++++++ syntax/jsond.vim | 70 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 ftplugin/jsond.vim create mode 100644 syntax/jsond.vim diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 3c620e7..c69cdc0 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -10,6 +10,7 @@ let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', \ 'scribble/manual': 'scribble', \ 'info': 'racket-info', \ 'setup/infotab': 'racket-info', + \ 'jsond': 'jsond', \ }) " Tries to detect filetype from #lang line; defaults to ft=racket. diff --git a/ftplugin/jsond.vim b/ftplugin/jsond.vim new file mode 100644 index 0000000..8515364 --- /dev/null +++ b/ftplugin/jsond.vim @@ -0,0 +1,19 @@ +" 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\ \|# + +" 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<" diff --git a/syntax/jsond.vim b/syntax/jsond.vim new file mode 100644 index 0000000..a003073 --- /dev/null +++ b/syntax/jsond.vim @@ -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" From 51de1c095125ab2d2e633a7f685b9ef57f89f21c Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sun, 8 Aug 2021 16:52:25 -0400 Subject: [PATCH 34/47] add ale aliases to non-racket filetypes --- ftplugin/jsond.vim | 3 +++ ftplugin/racket-info.vim | 3 +++ 2 files changed, 6 insertions(+) diff --git a/ftplugin/jsond.vim b/ftplugin/jsond.vim index 8515364..53608da 100644 --- a/ftplugin/jsond.vim +++ b/ftplugin/jsond.vim @@ -12,8 +12,11 @@ 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" diff --git a/ftplugin/racket-info.vim b/ftplugin/racket-info.vim index 3cba288..df1fdd3 100644 --- a/ftplugin/racket-info.vim +++ b/ftplugin/racket-info.vim @@ -50,6 +50,8 @@ 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 = @@ -57,3 +59,4 @@ let b:undo_ftplugin = \. "| setl commentstring<" \. "| nunmap K" \. "| vunmap K" + \. "| unlet b:ale_linter_aliases" From c45942e3abb1983a7f1643c96cb015f23ea3c282 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sun, 8 Aug 2021 17:00:46 -0400 Subject: [PATCH 35/47] ftdetect: mapping jsond not necessary --- ftdetect/racket.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index c69cdc0..3c620e7 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -10,7 +10,6 @@ let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', \ 'scribble/manual': 'scribble', \ 'info': 'racket-info', \ 'setup/infotab': 'racket-info', - \ 'jsond': 'jsond', \ }) " Tries to detect filetype from #lang line; defaults to ft=racket. From 906972cb0bd7c08fe1fad7fc4cdbc4ab5c725a23 Mon Sep 17 00:00:00 2001 From: Ryan Sundberg Date: Sun, 8 Aug 2021 15:03:23 -0700 Subject: [PATCH 36/47] ftdetect: Support #lang at-exp chains Modifies the regular expression to ignore `at-exp` when present in the #lang statement, and use the next language in the chain. See documentation for #lang at-exp at https://docs.racket-lang.org/scribble/reader-internals.html#%28part._at-exp-lang%29 --- ftdetect/racket.vim | 2 +- test/at-exp.rkt | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/at-exp.rkt diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 4a9ff08..6ef1c78 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -1,4 +1,4 @@ -let g:racket_hash_lang_regexp = '^#lang\s\+\([^][)(}{[:space:]]\+\)' +let g:racket_hash_lang_regexp = '^#lang\s\+\%\(\\s\+\)\?\([^][)(}{[:space:]]\+\)' let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', \ { \ 'racket/base': 'racket', diff --git a/test/at-exp.rkt b/test/at-exp.rkt new file mode 100644 index 0000000..9f98a78 --- /dev/null +++ b/test/at-exp.rkt @@ -0,0 +1,9 @@ +#lang at-exp racket + +(define (bar) + "BAR") + +(define (foo) + (displayln @~a{Foo is a @(bar)})) + +(foo) From 6e90a7995c78d8668be18bd9c6f5abe23e69f784 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 14 Aug 2021 11:53:18 -0400 Subject: [PATCH 37/47] ftdetect: make skipped #lang modifiers more flexible add to g:racket_hash_lang_modifiers to support more modifiers TODO: should be get() calls, to allow user overrides. --- ftdetect/racket.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 19b15e4..66816f0 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -1,4 +1,10 @@ -let g:racket_hash_lang_regexp = '^#lang\s\+\%\(\\s\+\)\?\([^][)(}{[:space:]]\+\)' +let g:racket_hash_lang_modifiers = [ + \ 'at-exp', + \ ] + +let g:racket_hash_lang_modifiers_regex = '\%('.mapnew(g:racket_hash_lang_modifiers, {_, v -> printf('\<%s\>', escape(v, '\'))})->join('\|').'\)' + +let g:racket_hash_lang_regexp = '^#lang\s\+\%\('.g:racket_hash_lang_modifiers_regex.'\s\+\)\?\([^][)(}{[:space:]]\+\)' let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', \ { \ 'racket/base': 'racket', From 6ede9a49eb08ed4a58439d3627047dff6ef5d040 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 14 Aug 2021 11:53:33 -0400 Subject: [PATCH 38/47] ftdetect: skip pollen/mode --- ftdetect/racket.vim | 1 + test/pollen-mode.rkt | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 test/pollen-mode.rkt diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 66816f0..81d2fb7 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -1,5 +1,6 @@ let g:racket_hash_lang_modifiers = [ \ 'at-exp', + \ 'pollen/mode', \ ] let g:racket_hash_lang_modifiers_regex = '\%('.mapnew(g:racket_hash_lang_modifiers, {_, v -> printf('\<%s\>', escape(v, '\'))})->join('\|').'\)' diff --git a/test/pollen-mode.rkt b/test/pollen-mode.rkt new file mode 100644 index 0000000..3017055 --- /dev/null +++ b/test/pollen-mode.rkt @@ -0,0 +1,9 @@ +#lang pollen/mode racket + +(define (bar) + "BAR") + +(define (foo) + (displayln ◊~a{Foo is a ◊(bar)})) + +(foo) From f2bb3154a54c636b669456fe8e1817afcc00238e Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 14 Aug 2021 11:57:37 -0400 Subject: [PATCH 39/47] ftdetect: support user-overrides more thoroughly Using let g:var = get(g:, 'var', default) is an idiom for allowing a user to set the variable themselves but have a default intact. In the case of lists/dictionaries, I use an empty default and then extend() with the actual default: this essentially merges the default with the user value. In the list case, there is no way to not get the defaults; here, this should not be harmful. In the dictionary case, I specify the 'keep' argument so that user values override the defaults in case of a collision on keys. Note that it is probably silly to override g:racket_hash_lang_modifiers_regex or g:racket_hash_lang_regexp, but I allow it anyway. Related: https://github.com/wlangstroth/vim-racket/issues/62 --- ftdetect/racket.vim | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index 81d2fb7..e036df3 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -1,13 +1,14 @@ -let g:racket_hash_lang_modifiers = [ +let g:racket_hash_lang_modifiers = get(g:, 'racket_hash_lang_modifiers', [])->extend([ \ 'at-exp', \ 'pollen/mode', - \ ] + \ ]) -let g:racket_hash_lang_modifiers_regex = '\%('.mapnew(g:racket_hash_lang_modifiers, {_, v -> printf('\<%s\>', escape(v, '\'))})->join('\|').'\)' +let g:racket_hash_lang_modifiers_regex = get(g:, 'racket_hash_lang_modifiers_regex', + \ '\%('.mapnew(g:racket_hash_lang_modifiers, {_, v -> printf('\<%s\>', escape(v, '\'))})->join('\|').'\)') -let g:racket_hash_lang_regexp = '^#lang\s\+\%\('.g:racket_hash_lang_modifiers_regex.'\s\+\)\?\([^][)(}{[:space:]]\+\)' -let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', - \ { +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 = get(g:, 'racket_hash_lang_dict', #{})->extend({ \ 'racket/base': 'racket', \ 'typed/racket': 'racket', \ 'typed/racket/base': 'racket', @@ -17,7 +18,7 @@ let g:racket_hash_lang_dict = get(g:, 'racket_hash_lang_dict', \ '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() From 95c446ae8e79d8ff4114e93ea47f3eecd9919071 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 26 Aug 2021 16:49:51 -0400 Subject: [PATCH 40/47] fix mapnew not available in neovim/older vims Use deepcopy+map over mapnew as a workaround. --- ftdetect/racket.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index e036df3..e2ac9a6 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -4,7 +4,7 @@ let g:racket_hash_lang_modifiers = get(g:, 'racket_hash_lang_modifiers', [])->ex \ ]) let g:racket_hash_lang_modifiers_regex = get(g:, 'racket_hash_lang_modifiers_regex', - \ '\%('.mapnew(g:racket_hash_lang_modifiers, {_, v -> printf('\<%s\>', escape(v, '\'))})->join('\|').'\)') + \ '\%('.deepcopy(g:racket_hash_lang_modifiers)->map({_, v -> printf('\<%s\>', escape(v, '\'))})->join('\|').'\)') let g:racket_hash_lang_regexp = get(g:, 'racket_hash_lang_regexp', \ '^#lang\s\+\%\('.g:racket_hash_lang_modifiers_regex.'\s\+\)\?\([^][)(}{[:space:]]\+\)') From 8e6707e114fea6e3f1f7b77cd9a0fe4e9f39deaa Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 26 Aug 2021 16:54:11 -0400 Subject: [PATCH 41/47] syntax: match todo notes even when followed by colons --- syntax/racket.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/racket.vim b/syntax/racket.vim index aab2ccd..107a46c 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -588,7 +588,7 @@ syn match racketComment /;.*$/ contains=racketTodo,racketNote,@Spell syn region racketMultilineComment start=/#|/ end=/|#/ contains=racketMultilineComment,racketTodo,racketNote,@Spell syn match racketFormComment "#;" nextgroup=@racketTop -syn keyword racketTodo FIXME TODO XXX contained +syn match racketTodo /\C\<\(FIXME\|TODO\|XXX\)\ze:\?\>/ contained syntax match racketNote /\CNOTE\ze:\?/ contained syn cluster racketTop add=racketQuote,racketUnquote,racketComment,racketMultilineComment,racketFormComment From 757e7e1c4010378e96b9b79f369797e70faa7482 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Fri, 27 Aug 2021 14:52:29 -0400 Subject: [PATCH 42/47] ftdetect: remove unsupported -> syntax for neovim --- ftdetect/racket.vim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index e2ac9a6..bd3e291 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -1,14 +1,21 @@ -let g:racket_hash_lang_modifiers = get(g:, 'racket_hash_lang_modifiers', [])->extend([ +let g:racket_hash_lang_modifiers = + \ extend(get(g:, 'racket_hash_lang_modifiers', []), [ \ 'at-exp', \ 'pollen/mode', \ ]) -let g:racket_hash_lang_modifiers_regex = get(g:, 'racket_hash_lang_modifiers_regex', - \ '\%('.deepcopy(g:racket_hash_lang_modifiers)->map({_, v -> printf('\<%s\>', escape(v, '\'))})->join('\|').'\)') +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 = get(g:, 'racket_hash_lang_dict', #{})->extend({ +let g:racket_hash_lang_dict = + \ extend(get(g:, 'racket_hash_lang_dict', #{}), { \ 'racket/base': 'racket', \ 'typed/racket': 'racket', \ 'typed/racket/base': 'racket', From 28d24420eb4268fe78bfa45a58c1ca1f1bbccaea Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 4 Sep 2021 23:05:48 +1000 Subject: [PATCH 43/47] Add matchit support for block comment delimiters --- ftplugin/racket.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index 7ebb1f3..ffea3b6 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -77,6 +77,10 @@ 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 = @@ -84,3 +88,4 @@ let b:undo_ftplugin = \. "| setl commentstring<" \. "| nunmap K" \. "| vunmap K" + \. "| unlet! b:match_words" From 425eb4548703410edf9d5f99b1e4622502723a98 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Wed, 1 Sep 2021 00:40:59 +1000 Subject: [PATCH 44/47] Highlight shebang lines as comments --- syntax/racket.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syntax/racket.vim b/syntax/racket.vim index 107a46c..e82d75b 100644 --- a/syntax/racket.vim +++ b/syntax/racket.vim @@ -584,6 +584,7 @@ syn match racketUnquote "," syn match racketUnquote ",@" " Comments +syn match racketSharpBang "\%^#![ /].*" display syn match racketComment /;.*$/ contains=racketTodo,racketNote,@Spell syn region racketMultilineComment start=/#|/ end=/|#/ contains=racketMultilineComment,racketTodo,racketNote,@Spell syn match racketFormComment "#;" nextgroup=@racketTop @@ -632,6 +633,7 @@ if version >= 508 || !exists("did_racket_syntax_inits") HiLink racketComment Comment HiLink racketMultilineComment Comment HiLink racketFormComment SpecialChar + HiLink racketSharpBang Comment HiLink racketTodo Todo HiLink racketNote SpecialComment HiLink racketError Error From d51d647f82058fa5563ea8a8cc6c6b62e5668ec6 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 11 Sep 2021 16:40:27 -0400 Subject: [PATCH 45/47] ftdetect: accept errortrace #lang modifier --- ftdetect/racket.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftdetect/racket.vim b/ftdetect/racket.vim index bd3e291..07288dd 100644 --- a/ftdetect/racket.vim +++ b/ftdetect/racket.vim @@ -1,6 +1,7 @@ let g:racket_hash_lang_modifiers = \ extend(get(g:, 'racket_hash_lang_modifiers', []), [ \ 'at-exp', + \ 'errortrace', \ 'pollen/mode', \ ]) From 1429c959591483002c8727448d088116377fb0fe Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Wed, 22 Sep 2021 15:06:41 -0400 Subject: [PATCH 46/47] =?UTF-8?q?Move=20+lispindent=20options=20to=20the?= =?UTF-8?q?=20indent=20plugin=20=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These can now be appropriately enabled/disabled via :filetype indent [on|off] Co-authored-by: @dkearns cf. https://github.com/wlangstroth/vim-racket/pull/73 --- ftplugin/racket.vim | 27 --------------------------- indent/racket.vim | 31 +++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/ftplugin/racket.vim b/ftplugin/racket.vim index ffea3b6..9e514bc 100644 --- a/ftplugin/racket.vim +++ b/ftplugin/racket.vim @@ -9,33 +9,6 @@ let b:did_ftplugin = 1 " quick hack to allow adding values setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94 -setl lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local -setl lispwords+=define/contract -setl lispwords+=λ -setl lispwords+=with-handlers -setl lispwords+=define-values,opt-lambda,case-lambda,syntax-rules,with-syntax,syntax-case,syntax-parse -setl lispwords+=define-for-syntax,define-syntax-parser,define-syntax-parse-rule,define-syntax-class,define-splicing-syntax-class -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+=define-test-suite -setl lispwords+=struct -setl lispwords+=with-input-from-file,with-output-to-file - -" Racket OOP -setl lispwords+=class,define/public,define/private - -" 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,for*/vector -setl lispwords+=for/async - -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 " Enable auto begin new comment line when continuing from an old comment line setl comments=:;;;;,:;;;,:;;,:; diff --git a/indent/racket.vim b/indent/racket.vim index 279e185..0f8deea 100644 --- a/indent/racket.vim +++ b/indent/racket.vim @@ -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 + +" 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<" From 1d612b6eb499cf64de8e940d1e0df3b83e3f5a77 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Wed, 22 Sep 2021 15:10:02 -0400 Subject: [PATCH 47/47] Move more indent settings to indent from ftplugin cf. commit 1429c959591483002c8727448d088116377fb0fe --- ftplugin/racket-info.vim | 2 -- indent/racket-info.vim | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 indent/racket-info.vim diff --git a/ftplugin/racket-info.vim b/ftplugin/racket-info.vim index df1fdd3..8c17c9f 100644 --- a/ftplugin/racket-info.vim +++ b/ftplugin/racket-info.vim @@ -5,10 +5,8 @@ if exists("b:did_ftplugin") endif let b:did_ftplugin = 1 -setlocal lisp " quick hack to allow adding values setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94 -setlocal lispwords=define " Enable auto begin new comment line when continuing from an old comment line setl comments=:;;;;,:;;;,:;;,:; diff --git a/indent/racket-info.vim b/indent/racket-info.vim new file mode 100644 index 0000000..b72d361 --- /dev/null +++ b/indent/racket-info.vim @@ -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<"