neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

csh.vim (2316B)


      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 
      9 if exists("b:did_ftplugin")
     10  finish
     11 endif
     12 let b:did_ftplugin = 1
     13 
     14 let s:save_cpo = &cpo
     15 set cpo-=C
     16 
     17 setlocal comments=:#
     18 setlocal commentstring=#\ %s
     19 setlocal formatoptions-=t
     20 setlocal formatoptions+=crql
     21 
     22 let b:undo_ftplugin = "setlocal com< cms< fo<"
     23 
     24 if 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"
     29 endif
     30 
     31 " skip single line 'if' commands
     32 function CshMatchSkip()
     33  return getline(".") =~# '^\s*if\>' && !s:CshIsIfThenCommand()
     34 endfunction
     35 
     36 function 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
     54 endfunction
     55 
     56 function 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*\%(#.*\)\=$'
     68 endfunction
     69 
     70 if (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"
     79 endif
     80 
     81 let &cpo = s:save_cpo
     82 unlet s:save_cpo