blob: 3aa413397e11c95a88bc4efa4ff21d63a9d12c2d [file] [log] [blame]
Bram Moolenaar9b03d3e2022-08-30 20:26:34 +01001" Vim filetype plugin
2" Language: Racket
3" Maintainer: D. Ben Knoble <ben.knoble+github@gmail.com>
4" Previous Maintainer: Will Langstroth <will@langstroth.com>
5" URL: https://github.com/benknoble/vim-racket
6" Last Change: 2022 Aug 29
7
8if exists("b:did_ftplugin")
9 finish
10endif
11let b:did_ftplugin = 1
12
13let s:cpo_save = &cpo
14set cpo&vim
15
16" quick hack to allow adding values
17setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94
18
19" Enable auto begin new comment line when continuing from an old comment line
20setlocal comments=:;;;;,:;;;,:;;,:;
21setlocal formatoptions+=r
22
23"setlocal commentstring=;;%s
24setlocal commentstring=#\|\ %s\ \|#
25
26setlocal formatprg=raco\ fmt
27
28" Undo our settings when the filetype changes away from Racket
29" (this should be amended if settings/mappings are added above!)
30let b:undo_ftplugin =
31 \ "setlocal iskeyword< lispwords< lisp< comments< formatoptions< formatprg<"
32 \. " | setlocal commentstring<"
33
34if !exists("no_plugin_maps") && !exists("no_racket_maps")
35 " Simply setting keywordprg like this works:
36 " setlocal keywordprg=raco\ docs
37 " but then vim says:
38 " "press ENTER or type a command to continue"
39 " We avoid the annoyance of having to hit enter by remapping K directly.
40 function s:RacketDoc(word) abort
41 execute 'silent !raco docs --' shellescape(a:word)
42 redraw!
43 endfunction
44 nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>
45 nmap <buffer> K <Plug>RacketDoc
46
47 " For the visual mode K mapping, it's slightly more convoluted to get the
48 " selected text:
49 function! s:Racket_visual_doc()
50 try
51 let l:old_a = @a
52 normal! gv"ay
53 call system("raco docs '". @a . "'")
54 redraw!
55 return @a
56 finally
57 let @a = l:old_a
58 endtry
59 endfunction
60
61 xnoremap <buffer> <Plug>RacketDoc :call <SID>Racket_visual_doc()<cr>
62 xmap <buffer> K <Plug>RacketDoc
63
64 let b:undo_ftplugin .=
65 \ " | silent! execute 'nunmap <buffer> K'"
66 \. " | silent! execute 'xunmap <buffer> K'"
67endif
68
69if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
70 let b:browsefilter =
71 \ "Racket Source Files (*.rkt *.rktl)\t*.rkt;*.rktl\n"
72 \. "All Files (*.*)\t*.*\n"
73 let b:undo_ftplugin .= " | unlet! b:browsefilter"
74endif
75
76if exists("loaded_matchit") && !exists("b:match_words")
77 let b:match_words = '#|:|#'
78 let b:undo_ftplugin .= " | unlet! b:match_words"
79endif
80
81let &cpo = s:cpo_save
82unlet s:cpo_save