robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #37529 from zeertzjq/vim-95bb4ef138922497f

master
2.3 KiB82 linesraw
1" Vim filetype plugin file
2" Language:		csh
3" Maintainer:		Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer:	Dan Sharp
5" Contributor:		Johannes Zellner <johannes@zellner.org>
6" 			Riley Bruins <ribru17@gmail.com>
7" Last Change:		2026 Jan 16
8
9if exists("b:did_ftplugin")
10  finish
11endif
12let b:did_ftplugin = 1
13
14let s:save_cpo = &cpo
15set cpo-=C
16
17setlocal comments=:#
18setlocal commentstring=#\ %s
19setlocal formatoptions-=t
20setlocal formatoptions+=crql
21
22let b:undo_ftplugin = "setlocal com< cms< fo<"
23
24if exists("loaded_matchit") && !exists("b:match_words")
25  let b:match_ignorecase = 0
26  let b:match_words = "CshMatchWords()"
27  let b:match_skip = "CshMatchSkip()"
28  let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_skip b:match_words"
29endif
30
31" skip single line 'if' commands
32function CshMatchSkip()
33  return getline(".") =~# '^\s*if\>' && !s:CshIsIfThenCommand()
34endfunction
35
36function CshMatchWords()
37  let line_start = '\%(^\s*\)\@<='
38  let match_words =
39	\ line_start .. '\%(foreach\s\+\h\w*\s*(\|while\>\):' ..
40	\   '\<break\>:\<continue\>:' ..
41	\   line_start .. 'end\>,' ..
42	\ line_start .. 'switch\s*(:' ..
43	\   line_start .. 'case\s\+:' .. line_start .. 'default\>:\<breaksw\>:' ..
44	\   line_start .. 'endsw\>'
45
46  if expand("<cword>") =~# '\<if\>' && !s:CshIsIfThenCommand()
47    return match_words
48  else
49    return match_words .. "," ..
50	\ line_start .. 'if\>:' ..
51	\   line_start .. 'else\s\+if\>:' .. line_start .. 'else\>:' ..
52	\   line_start .. 'endif\>'
53  endif
54endfunction
55
56function s:CshIsIfThenCommand()
57  let lnum = line(".")
58  let line = getline(lnum)
59
60  " join continued lines
61  while lnum < line("$") && line =~ '^\%([^\\]\|\\\\\)*\\$'
62    let lnum += 1
63    let line = substitute(line, '\\$', '', '') .. getline(lnum)
64  endwhile
65
66  " TODO: confirm with syntax checks when the highlighting is more accurate
67  return line =~# '^\s*if\>.*\<then\s*\%(#.*\)\=$'
68endfunction
69
70if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
71  let b:browsefilter = "csh Scripts (*.csh)\t*.csh\n"
72  if has("win32")
73    let b:browsefilter ..= "All Files (*.*)\t*\n"
74  else
75    let b:browsefilter ..= "All Files (*)\t*\n"
76  endif
77  let b:csh_set_browsefilter = 1
78  let b:undo_ftplugin ..= " | unlet! b:browsefilter b:csh_set_browsefilter"
79endif
80
81let &cpo = s:save_cpo
82unlet s:save_cpo