blob: 52768d67f5a726f48f69d8f31fd1073ef7680b3c [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
D. Ben Knoble8e013b12024-11-13 19:45:38 +01006" Last Change: 2024 Jun 01
Bram Moolenaar9b03d3e2022-08-30 20:26:34 +01007
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
D. Ben Knoble8e013b12024-11-13 19:45:38 +010019setlocal shiftwidth=2 softtabstop=2
20
Bram Moolenaar9b03d3e2022-08-30 20:26:34 +010021" Enable auto begin new comment line when continuing from an old comment line
22setlocal comments=:;;;;,:;;;,:;;,:;
23setlocal formatoptions+=r
24
D. Ben Knoble8e013b12024-11-13 19:45:38 +010025setlocal commentstring=;;\ %s
Bram Moolenaar9b03d3e2022-08-30 20:26:34 +010026
27setlocal formatprg=raco\ fmt
28
29" Undo our settings when the filetype changes away from Racket
30" (this should be amended if settings/mappings are added above!)
31let b:undo_ftplugin =
D. Ben Knoble8e013b12024-11-13 19:45:38 +010032 \ "setlocal iskeyword< shiftwidth< softtabstop< comments< formatoptions< formatprg<"
Bram Moolenaar9b03d3e2022-08-30 20:26:34 +010033 \. " | setlocal commentstring<"
34
35if !exists("no_plugin_maps") && !exists("no_racket_maps")
36 " Simply setting keywordprg like this works:
37 " setlocal keywordprg=raco\ docs
38 " but then vim says:
39 " "press ENTER or type a command to continue"
40 " We avoid the annoyance of having to hit enter by remapping K directly.
41 function s:RacketDoc(word) abort
42 execute 'silent !raco docs --' shellescape(a:word)
43 redraw!
44 endfunction
45 nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>
46 nmap <buffer> K <Plug>RacketDoc
47
48 " For the visual mode K mapping, it's slightly more convoluted to get the
49 " selected text:
50 function! s:Racket_visual_doc()
51 try
52 let l:old_a = @a
53 normal! gv"ay
54 call system("raco docs '". @a . "'")
55 redraw!
56 return @a
57 finally
58 let @a = l:old_a
59 endtry
60 endfunction
61
62 xnoremap <buffer> <Plug>RacketDoc :call <SID>Racket_visual_doc()<cr>
63 xmap <buffer> K <Plug>RacketDoc
64
65 let b:undo_ftplugin .=
66 \ " | silent! execute 'nunmap <buffer> K'"
67 \. " | silent! execute 'xunmap <buffer> K'"
68endif
69
70if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
71 let b:browsefilter =
Doug Kearns93197fd2024-01-14 20:59:02 +010072 \ "Racket Source Files (*.rkt, *.rktl)\t*.rkt;*.rktl\n"
73 if has("win32")
74 let b:browsefilter .= "All Files (*.*)\t*\n"
75 else
76 let b:browsefilter .= "All Files (*)\t*\n"
77 endif
Bram Moolenaar9b03d3e2022-08-30 20:26:34 +010078 let b:undo_ftplugin .= " | unlet! b:browsefilter"
79endif
80
81if exists("loaded_matchit") && !exists("b:match_words")
82 let b:match_words = '#|:|#'
83 let b:undo_ftplugin .= " | unlet! b:match_words"
84endif
85
86let &cpo = s:cpo_save
87unlet s:cpo_save