From Colossal Guinea Pig, 4 Weeks ago, written in Plain Text.
  1. #!/bin/bash
  2. # Desc: Use vim as pager for man(1)
  3. # Usage: vman [SECTION] PAGE
  4. # Example: vman 1 man
  5.  
  6. # /* FUNCDEF */
  7. msg(){ printf -- "%s\n" "$@"; }
  8. emsg(){ printf -- "%s\n" "$@" >&2 ; }
  9. bail(){ emsg "$@"; usage; exit 1; }
  10. usage(){ awk -F '# ' 'NR>2{print $2};$0==""{exit}' <"$0"; }
  11.  
  12. validate(){
  13.   # desc: check if a manpage exists
  14.   # usage: validate manpath page [section]
  15.   # example: validate "$MANPATH" man 1
  16.  
  17.   local p s dir
  18.   p="$2"; s="${3:-}"
  19.   tr ':' '\n' <<<"$1" | while read -r dir; do
  20.     if [[ -z "$3" ]]; then
  21.       for i in 0 1 2 3 4 5 6 7 8 9; do
  22.         read -n0 -r <"${dir}/man${i}/${p}.${i}.gz" 2<&- \
  23.         && printf -- "%s" "${dir}/man${i}/${p}.${i}.gz" \
  24.         && return 0
  25.       done
  26.     else
  27.         read -n0 -r <"${dir}/man${s}/${p}.${s}.gz" 2<&- \
  28.         && printf -- "%s" "${dir}/man${s}/${p}.${s}.gz" \
  29.         && return 0
  30.      fi
  31.   done
  32. }
  33.  
  34. extract(){
  35.   # desc: extract files from the end of this script
  36.   # usage: extract filename
  37.   # example: extract man.vim <"$0" >~/.vim/syntax/man.vim
  38.  
  39.   awk -v be="#=begin:${1}=" -v en="#=end:${1}=" '
  40.     $1==be{while((getline)>0)
  41.       {if($1==en)
  42.         {break}
  43.       else
  44.         {$1=""; print}
  45.       }
  46.   }' <"$0"
  47. }
  48.  
  49.  
  50. # /* ENV */
  51. declare page section dir rul m
  52. declare -a manual
  53. MANPATH="${MANPATH:-/usr/share/man}"
  54.  
  55.  
  56. # /* INIT */
  57. # Argparse
  58. while (($#)); do
  59.   case "$1" in
  60.     --help) usage; exit 0;;
  61.     [0-9]|[0-9][pnl]) section="$1"; page="$2"; shift 2; break;;
  62.     *) page="$1"; shift; break;;
  63.   esac
  64. done
  65.  
  66. # Ensure requested page exists
  67. mapfile -t manual < <(validate "$MANPATH" "$page" "$section" 2<&-)
  68. [[ -f "${manual[0]}" ]] || bail "E!: page not found"
  69.  
  70. # Cut syntax files from bottom of $0 if they dont exist
  71. if [[ ! -f "$HOME/.vim/syntax/vman.vim" ]]; then
  72.   read -p "OOPS! No such file '$HOME/.vim/syntax/vman.vim'. Extract it?(y/n): " -r
  73.   if [[ "$REPLY" == "y" ]]; then
  74.     extract "vman" >"$HOME/.vim/syntax/vman.vim"
  75.   else emesg "W:! Continuing with fucky syntax!"; fi
  76. fi
  77.  
  78. # Set ruler len... or not since its to long anyway...
  79. let rul="(${#page}+36)";
  80.  
  81.  
  82. # /* MAIN */
  83. # Dump the page into vim
  84. # NOTE: Calling feedkeys() autodismisses more prompt \o/
  85. # NOTE: Use :only! just in case
  86. # NOTE: Extracts vimrc from $0
  87. for m in "${manual[@]}"; do
  88.   \command man -P cat "$m" 2>/dev/null| vim - -n -R --not-a-term -u <(extract vimrc) \
  89.     --cmd "let manpagename = \"${page}\"" \
  90.     -c "set rulerformat=%${rul}(%=%-1*\ Manual\:%-3*\ %{\$page}\ %-3*\ \ \ line\ %-l/%-L\ \ [%p%%]\ %<%4*%)" \
  91.     -c 'call feedkeys("jk", "t")' \
  92.      +'only!'
  93. done
  94.  
  95. exit
  96.  
  97.  
  98. #=begin:vimrc=
  99. # set nocompatible
  100. # set nonumber nocursorline nomore nomod nolist nonu nosc
  101. # set laststatus=0 virtualedit=all scrolloff=1000 sidescroll=1000 sidescrolloff=0
  102. # set ft=man dy=""
  103. # set ruler
  104. # syntax enable
  105. # colorscheme default
  106. #
  107. # nnoremap q :q!<cr>
  108. # nnoremap qq :q!<cr>
  109. #
  110. # hi User1 cterm=none ctermbg=8 ctermfg=231
  111. # hi User2 cterm=bold ctermbg=4 ctermfg=none
  112. # hi User3 cterm=none ctermbg=4 ctermfg=7
  113. # hi User4 ctermbg=none ctermfg=0
  114. #
  115. # hi Comment         cterm=none                                   ctermfg=8
  116. # hi Constant        cterm=none                                   ctermfg=5
  117. # hi Special         cterm=none                                   ctermfg=1
  118. # hi Identifier      cterm=none                                   ctermfg=14
  119. # hi Statement       cterm=none                                   ctermfg=6
  120. # hi PreProc         cterm=none                                   ctermfg=13
  121. # hi Type            cterm=none                                   ctermfg=10
  122. # hi Underlined      cterm=underline                              ctermfg=none
  123. # hi Ignore          cterm=none               ctermfg=none        ctermfg=12
  124. #
  125. # "#- Constant -#
  126. #  hi String          cterm=none                                   ctermfg=103
  127. #  hi Character       cterm=none                                   ctermfg=5
  128. #  hi Number          cterm=none                                   ctermfg=5
  129. #  hi Float           cterm=none                                   ctermfg=5
  130. #  hi Boolean         cterm=none                                   ctermfg=5
  131. # "#- Identifier -#
  132. #  hi Function        cterm=none                                   ctermfg=137
  133. # "#- Statement -#
  134. #  hi Conditional     cterm=none                                   ctermfg=7
  135. #  hi Repeat          cterm=underline                              ctermfg=7
  136. #  hi Label           cterm=none                                   ctermfg=6
  137. #  hi Operator        cterm=underline                              ctermfg=7
  138. #  hi Keyword         cterm=none                                   ctermfg=12
  139. #  hi Exception       cterm=none                                   ctermfg=7
  140. # "#- Preproc -#
  141. #  hi Include         cterm=none                                   ctermfg=13
  142. #  hi Define          cterm=none                                   ctermfg=5
  143. #  hi Macro           cterm=none                                   ctermfg=5
  144. #  hi PreConduit      cterm=none             ctermbg=5
  145. # "#- Type -#
  146. #  hi StorageClass    cterm=none                                   ctermfg=2
  147. #  hi Structure       cterm=none                                   ctermfg=137
  148. #  hi Typedef         cterm=none             ctermfg=28
  149. # "#- Special -#
  150. #  hi Tag             cterm=none             ctermfg=72
  151. #  hi SpecialCharacter cterm=underline                             ctermfg=231
  152. #  hi Delimiter       cterm=none                                   ctermfg=124
  153. #  hi SpecialComment  cterm=none                                   ctermfg=196
  154. #  hi Debug           cterm=none                                   ctermfg=196
  155. #
  156. #=end:vimrc=
  157.  
  158. #=begin:vman.vim=
  159. # if exists('b:current_syn')
  160. #   finish
  161. # endif
  162. # if exists('manpagename')
  163. # exe "syn match manPAGENAME /".manpagename."\ /"
  164. # exe "hi manPAGENAME ctermfg=14"
  165. # endif
  166. #
  167. #
  168. # syn case  ignore
  169. # syn match manReference       '\f\+(\%([0-8][a-z]\=\|n\))'
  170. # syn match manOptionDesc /-[[:alnum:]]\+/
  171. # syn match manOptionDesc /\.\.\./
  172. # syn match manOptionDesc /\ \|\[-[[:alnum:]]\+\(\ \+\|\)[[:alnum:]]\+/hs=s+1
  173. # syn match manOptionDesc /\[[[:alnum:]]\+\(\|\ \+\)[[:alnum:]]\+/hs=s+1
  174. # syn match manLongOptionDesc /--[[:alnum:]]\+/
  175. # syn match manLongOptionDesc /--[[:alnum:]]\+\ \|=[[:alnum:]]\+/
  176. # syn match manLongOptionDesc /--[[:alnum:]]\+\(\ \|-[[:alnum:]]\+\)/
  177. #
  178. #  " prevent manSectionHeading from matching last line
  179. # exe 'syn match manSectionHeading  "^\%(\%>1l\%<'.line('$').'l\)\%(\S.*\)\=\S$"'
  180. #
  181. # syn match manSubHeading      '^\s\{3\}\%(\S.*\)\=\S$'
  182. #
  183. # hi String ctermfg=6
  184. # hi manTitle          cterm=none ctermbg=0 ctermfg=250
  185. # hi manSectionHeading cterm=none ctermbg=none ctermfg=15
  186. # hi manOptionDesc     cterm=none ctermbg=none ctermfg=5
  187. # hi manLongOptionDesc cterm=none ctermbg=none ctermfg=5
  188. # hi manOptionOption cterm=none ctermbg=none ctermfg=62
  189. # hi manReference      cterm=none ctermbg=none ctermfg=2
  190. # hi manSubHeading     cterm=none ctermbg=none ctermfg=31
  191. # hi manNameSectionHeading cterm=none ctermbg=none ctermfg=32
  192. # hi manNameSectionHeadingText cterm=none ctermbg=none ctermfg=32
  193. # hi manOptionDescRLSqBrkt cterm=none ctermbg=none ctermfg=32
  194. # hi manOptionDescRSqBrkt cterm=none ctermbg=none ctermfg=32
  195. # hi manOptionDescLSqBrkt cterm=none ctermbg=none ctermfg=32
  196. #
  197. #
  198. #
  199. # if getline(1) =~ '^[a-zA-Z_]\+([23])'
  200. #   syn match manCFuncDefinition display '\<\h\w*\>\s*('me=e-1 contained
  201. #   syn region manSynopsis start="^SYNOPSIS"hs=s+8 end="^\u\+\s*$"me=e-12 keepend contains=manSectionHeading,@cCode,manCFuncDefinition
  202. #
  203. # let s:cpo_save = &cpo
  204. # set cpo&vim
  205. #
  206. # let s:ft = matchstr(&ft, '^\([^.]\)\+')
  207. #
  208. # " A bunch of useful C keywords
  209. # syn keyword   cStatement      goto break return continue asm
  210. # syn keyword   cLabel          case default
  211. # syn keyword   cConditional    if else switch
  212. # syn keyword   cRepeat         while for do
  213. #
  214. # syn keyword   cTodo           contained TODO FIXME XXX
  215. #
  216. # " It's easy to accidentally add a space after a backslash that was intended
  217. # " for line continuation.  Some compilers allow it, which makes it
  218. # " unpredictable and should be avoided.
  219. # syn match     cBadContinuation contained "\\\s\+$"
  220. #
  221. # " cCommentGroup allows adding matches for special things in comments
  222. # syn cluster   cCommentGroup   contains=cTodo,cBadContinuation
  223. #
  224. # " String and Character constants
  225. # " Highlight special characters (those which have a backslash) differently
  226. # syn match     cSpecial        display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)"
  227. # if !exists("c_no_utf")
  228. #   syn match   cSpecial        display contained "\\\(u\x\{4}\|U\x\{8}\)"
  229. # endif
  230. # if exists("c_no_cformat")
  231. #   syn region  cString         start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend
  232. #   " cCppString: same as cString, but ends at end of line
  233. #   if !exists("cpp_no_cpp11") " ISO C++11
  234. #     syn region cCppString     start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  235. #   else
  236. #     syn region cCppString     start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  237. #   endif
  238. #   syn region  cCppOut2        contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip
  239. #   syn region  cCppSkip        contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip
  240. # else
  241. #   if !exists("c_no_c99") " ISO C99
  242. #     syn match cFormat         display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  243. #   else
  244. #     syn match cFormat         display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  245. #   endif
  246. #   syn match   cFormat         display "%%" contained
  247. #   syn region  cString         start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  248. #   " cCppString: same as cString, but ends at end of line
  249. #   syn region  cCppString      start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  250. # endif
  251. #
  252. # syn match     cCharacter      "L\='[^\\]'"
  253. # syn match     cCharacter      "L'[^']*'" contains=cSpecial
  254. # if exists("c_gnu")
  255. #   syn match   cSpecialError   "L\='\\[^'\"?\\abefnrtv]'"
  256. #   syn match   cSpecialCharacter "L\='\\['\"?\\abefnrtv]'"
  257. # else
  258. #   syn match   cSpecialError   "L\='\\[^'\"?\\abfnrtv]'"
  259. #   syn match   cSpecialCharacter "L\='\\['\"?\\abfnrtv]'"
  260. # endif
  261. # syn match     cSpecialCharacter display "L\='\\\o\{1,3}'"
  262. # syn match     cSpecialCharacter display "'\\x\x\{1,2}'"
  263. # syn match     cSpecialCharacter display "L'\\x\x\+'"
  264. #
  265. # if !exists("c_no_c11") " ISO C11
  266. #   if exists("c_no_cformat")
  267. #     syn region        cString         start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend
  268. #   else
  269. #     syn region        cString         start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  270. #   endif
  271. #   syn match   cCharacter      "[Uu]'[^\\]'"
  272. #   syn match   cCharacter      "[Uu]'[^']*'" contains=cSpecial
  273. #   if exists("c_gnu")
  274. #     syn match cSpecialError   "[Uu]'\\[^'\"?\\abefnrtv]'"
  275. #     syn match cSpecialCharacter "[Uu]'\\['\"?\\abefnrtv]'"
  276. #   else
  277. #     syn match cSpecialError   "[Uu]'\\[^'\"?\\abfnrtv]'"
  278. #     syn match cSpecialCharacter "[Uu]'\\['\"?\\abfnrtv]'"
  279. #   endif
  280. #   syn match   cSpecialCharacter display "[Uu]'\\\o\{1,3}'"
  281. #   syn match   cSpecialCharacter display "[Uu]'\\x\x\+'"
  282. # endif
  283. #
  284. # "when wanted, highlight trailing white space
  285. # if exists("c_space_errors")
  286. #   if !exists("c_no_trail_space_error")
  287. #     syn match cSpaceError     display excludenl "\s\+$"
  288. #   endif
  289. #   if !exists("c_no_tab_space_error")
  290. #     syn match cSpaceError     display " \+\t"me=e-1
  291. #   endif
  292. # endif
  293. #
  294. # " This should be before cErrInParen to avoid problems with #define ({ xxx })
  295. # if exists("c_curly_error")
  296. #   syn match cCurlyError "}"
  297. #   syn region  cBlock          start="{" end="}" contains=ALLBUT,cBadBlock,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell fold
  298. # else
  299. #   syn region  cBlock          start="{" end="}" transparent fold
  300. # endif
  301. #
  302. # "catch errors caused by wrong parenthesis and brackets
  303. # " also accept <% for {, %> for }, <: for [ and :> for ] (C99)
  304. # " But avoid matching <::.
  305. # syn cluster   cParenGroup     contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  306. # if exists("c_no_curly_error")
  307. #   if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
  308. #     syn region        cParen          transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell
  309. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  310. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  311. #     syn match cParenError     display ")"
  312. #     syn match cErrInParen     display contained "^^<%\|^%>"
  313. #   else
  314. #     syn region        cParen          transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cCppString,@Spell
  315. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  316. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  317. #     syn match cParenError     display ")"
  318. #     syn match cErrInParen     display contained "^[{}]\|^<%\|^%>"
  319. #   endif
  320. # elseif exists("c_no_bracket_error")
  321. #   if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
  322. #     syn region        cParen          transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell
  323. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  324. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  325. #     syn match cParenError     display ")"
  326. #     syn match cErrInParen     display contained "<%\|%>"
  327. #   else
  328. #     syn region        cParen          transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cCppString,@Spell
  329. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  330. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  331. #     syn match cParenError     display ")"
  332. #     syn match cErrInParen     display contained "[{}]\|<%\|%>"
  333. #   endif
  334. # else
  335. #   if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
  336. #     syn region        cParen          transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell
  337. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  338. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
  339. #     syn match cParenError     display "[\])]"
  340. #     syn match cErrInParen     display contained "<%\|%>"
  341. #     syn region        cBracket        transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell
  342. #   else
  343. #     syn region        cParen          transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell
  344. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  345. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
  346. #     syn match cParenError     display "[\])]"
  347. #     syn match cErrInParen     display contained "[\]{}]\|<%\|%>"
  348. #     syn region        cBracket        transparent start='\[\|<::\@!' end=']\|:>' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell
  349. #   endif
  350. #   " cCppBracket: same as cParen but ends at end-of-line; used in cDefine
  351. #   syn region  cCppBracket     transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell
  352. #   syn match   cErrInBracket   display contained "[);{}]\|<%\|%>"
  353. # endif
  354. #
  355. # if s:ft ==# 'c' || exists("cpp_no_cpp11")
  356. #   syn region  cBadBlock       keepend start="{" end="}" contained containedin=cParen,cBracket,cBadBlock transparent fold
  357. # endif
  358. #
  359. # "integer number, or floating point number without a dot and with "f".
  360. # syn case ignore
  361. # syn match     cNumbers        display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal
  362. # " Same, but without octal error (for comments)
  363. # syn match     cNumbersCom     display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal
  364. # syn match     cNumber         display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
  365. # "hex number
  366. # syn match     cNumber         display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
  367. # " Flag the first zero of an octal number as something special
  368. # syn match     cOctal          display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
  369. # syn match     cOctalZero      display contained "\<0"
  370. # syn match     cFloat          display contained "\d\+f"
  371. # "floating point number, with dot, optional exponent
  372. # syn match     cFloat          display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
  373. # "floating point number, starting with a dot, optional exponent
  374. # syn match     cFloat          display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
  375. # "floating point number, without dot, with exponent
  376. # syn match     cFloat          display contained "\d\+e[-+]\=\d\+[fl]\=\>"
  377. # if !exists("c_no_c99")
  378. #   "hexadecimal floating point number, optional leading digits, with dot, with exponent
  379. #   syn match   cFloat          display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>"
  380. #   "hexadecimal floating point number, with leading digits, optional dot, with exponent
  381. #   syn match   cFloat          display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>"
  382. # endif
  383. #
  384. # " flag an octal number with wrong digits
  385. # syn match     cOctalError     display contained "0\o*[89]\d*"
  386. # syn case match
  387. #
  388. # if exists("c_comment_strings")
  389. #   " A comment can contain cString, cCharacter and cNumber.
  390. #   " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  391. #   " need to use a special type of cString: cCommentString, which also ends on
  392. #   " "*/", and sees a "*" at the start of the line as comment again.
  393. #   " Unfortunately this doesn't very well work for // type of comments :-(
  394. #   syn match   cCommentSkip    contained "^\s*\*\($\|\s\+\)"
  395. #   syn region cCommentString   contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  396. #   syn region cComment2String  contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  397. #   syn region  cCommentL       start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cComment2String,cCharacter,cNumbersCom,cSpaceError,@Spell
  398. #   if exists("c_no_comment_fold")
  399. #     " Use "extend" here to have preprocessor lines not terminate halfway a
  400. #     " comment.
  401. #     syn region cComment       matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell extend
  402. #   else
  403. #     syn region cComment       matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell fold extend
  404. #   endif
  405. # else
  406. #   syn region  cCommentL       start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cSpaceError,@Spell
  407. #   if exists("c_no_comment_fold")
  408. #     syn region        cComment        matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell extend
  409. #   else
  410. #     syn region        cComment        matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell fold extend
  411. #   endif
  412. # endif
  413. # " keep a // comment separately, it terminates a preproc. conditional
  414. # syn match     cCommentError   display "\*/"
  415. # syn match     cCommentStartError display "/\*"me=e-1 contained
  416. #
  417. # syn keyword   cOperator       sizeof
  418. # if exists("c_gnu")
  419. #   syn keyword cStatement      __asm__
  420. #   syn keyword cOperator       typeof __real__ __imag__
  421. # endif
  422. # syn keyword   cType           int long short char void
  423. # syn keyword   cType           signed unsigned float double
  424. # if !exists("c_no_ansi") || exists("c_ansi_typedefs")
  425. #   syn keyword   cType         size_t ssize_t off_t wchar_t ptrdiff_t sig_atomic_t fpos_t
  426. #   syn keyword   cType         clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t
  427. #   syn keyword   cType         mbstate_t wctrans_t wint_t wctype_t
  428. # endif
  429. # if !exists("c_no_c99") " ISO C99
  430. #   syn keyword cType           _Bool bool _Complex complex _Imaginary imaginary
  431. #   syn keyword cType           int8_t int16_t int32_t int64_t
  432. #   syn keyword cType           uint8_t uint16_t uint32_t uint64_t
  433. #   syn keyword cType           int_least8_t int_least16_t int_least32_t int_least64_t
  434. #   syn keyword cType           uint_least8_t uint_least16_t uint_least32_t uint_least64_t
  435. #   syn keyword cType           int_fast8_t int_fast16_t int_fast32_t int_fast64_t
  436. #   syn keyword cType           uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
  437. #   syn keyword cType           intptr_t uintptr_t
  438. #   syn keyword cType           intmax_t uintmax_t
  439. # endif
  440. # if exists("c_gnu")
  441. #   syn keyword cType           __label__ __complex__ __volatile__
  442. # endif
  443. #
  444. # syn keyword   cStructure      struct union enum typedef
  445. # syn keyword   cStorageClass   static register auto volatile extern const
  446. # if exists("c_gnu")
  447. #   syn keyword cStorageClass   inline __attribute__
  448. # endif
  449. # if !exists("c_no_c99")
  450. #   syn keyword cStorageClass   inline restrict
  451. # endif
  452. # if !exists("c_no_c11")
  453. #   syn keyword cStorageClass   _Alignas alignas
  454. #   syn keyword cOperator       _Alignof alignof
  455. #   syn keyword cStorageClass   _Atomic
  456. #   syn keyword cOperator       _Generic
  457. #   syn keyword cStorageClass   _Noreturn noreturn
  458. #   syn keyword cOperator       _Static_assert static_assert
  459. #   syn keyword cStorageClass   _Thread_local thread_local
  460. #   syn keyword   cType         char16_t char32_t
  461. # endif
  462. #
  463. # if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
  464. #   if exists("c_gnu")
  465. #     syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__
  466. #   endif
  467. #   syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__
  468. #   syn keyword cConstant __STDC_VERSION__
  469. #   syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
  470. #   syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
  471. #   syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN
  472. #   syn keyword cConstant CHAR_MAX INT_MAX LONG_MAX SHRT_MAX
  473. #   syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
  474. #   syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
  475. #   if !exists("c_no_c99")
  476. #     syn keyword cConstant __func__
  477. #     syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX
  478. #     syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN
  479. #     syn keyword cConstant INT8_MAX INT16_MAX INT32_MAX INT64_MAX
  480. #     syn keyword cConstant UINT8_MAX UINT16_MAX UINT32_MAX UINT64_MAX
  481. #     syn keyword cConstant INT_LEAST8_MIN INT_LEAST16_MIN INT_LEAST32_MIN INT_LEAST64_MIN
  482. #     syn keyword cConstant INT_LEAST8_MAX INT_LEAST16_MAX INT_LEAST32_MAX INT_LEAST64_MAX
  483. #     syn keyword cConstant UINT_LEAST8_MAX UINT_LEAST16_MAX UINT_LEAST32_MAX UINT_LEAST64_MAX
  484. #     syn keyword cConstant INT_FAST8_MIN INT_FAST16_MIN INT_FAST32_MIN INT_FAST64_MIN
  485. #     syn keyword cConstant INT_FAST8_MAX INT_FAST16_MAX INT_FAST32_MAX INT_FAST64_MAX
  486. #     syn keyword cConstant UINT_FAST8_MAX UINT_FAST16_MAX UINT_FAST32_MAX UINT_FAST64_MAX
  487. #     syn keyword cConstant INTPTR_MIN INTPTR_MAX UINTPTR_MAX
  488. #     syn keyword cConstant INTMAX_MIN INTMAX_MAX UINTMAX_MAX
  489. #     syn keyword cConstant PTRDIFF_MIN PTRDIFF_MAX SIG_ATOMIC_MIN SIG_ATOMIC_MAX
  490. #     syn keyword cConstant SIZE_MAX WCHAR_MIN WCHAR_MAX WINT_MIN WINT_MAX
  491. #   endif
  492. #   syn keyword cConstant FLT_RADIX FLT_ROUNDS
  493. #   syn keyword cConstant FLT_DIG FLT_MANT_DIG FLT_EPSILON
  494. #   syn keyword cConstant DBL_DIG DBL_MANT_DIG DBL_EPSILON
  495. #   syn keyword cConstant LDBL_DIG LDBL_MANT_DIG LDBL_EPSILON
  496. #   syn keyword cConstant FLT_MIN FLT_MAX FLT_MIN_EXP FLT_MAX_EXP
  497. #   syn keyword cConstant FLT_MIN_10_EXP FLT_MAX_10_EXP
  498. #   syn keyword cConstant DBL_MIN DBL_MAX DBL_MIN_EXP DBL_MAX_EXP
  499. #   syn keyword cConstant DBL_MIN_10_EXP DBL_MAX_10_EXP
  500. #   syn keyword cConstant LDBL_MIN LDBL_MAX LDBL_MIN_EXP LDBL_MAX_EXP
  501. #   syn keyword cConstant LDBL_MIN_10_EXP LDBL_MAX_10_EXP
  502. #   syn keyword cConstant HUGE_VAL CLOCKS_PER_SEC NULL
  503. #   syn keyword cConstant LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY
  504. #   syn keyword cConstant LC_NUMERIC LC_TIME
  505. #   syn keyword cConstant SIG_DFL SIG_ERR SIG_IGN
  506. #   syn keyword cConstant SIGABRT SIGFPE SIGILL SIGHUP SIGINT SIGSEGV SIGTERM
  507. #   " Add POSIX signals as well...
  508. #   syn keyword cConstant SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP
  509. #   syn keyword cConstant SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
  510. #   syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU
  511. #   syn keyword cConstant SIGUSR1 SIGUSR2
  512. #   syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF
  513. #   syn keyword cConstant FOPEN_MAX FILENAME_MAX L_tmpnam
  514. #   syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET
  515. #   syn keyword cConstant TMP_MAX stderr stdin stdout
  516. #   syn keyword cConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
  517. #   " Add POSIX errors as well
  518. #   syn keyword cConstant E2BIG EACCES EAGAIN EBADF EBADMSG EBUSY
  519. #   syn keyword cConstant ECANCELED ECHILD EDEADLK EDOM EEXIST EFAULT
  520. #   syn keyword cConstant EFBIG EILSEQ EINPROGRESS EINTR EINVAL EIO EISDIR
  521. #   syn keyword cConstant EMFILE EMLINK EMSGSIZE ENAMETOOLONG ENFILE ENODEV
  522. #   syn keyword cConstant ENOENT ENOEXEC ENOLCK ENOMEM ENOSPC ENOSYS
  523. #   syn keyword cConstant ENOTDIR ENOTEMPTY ENOTSUP ENOTTY ENXIO EPERM
  524. #   syn keyword cConstant EPIPE ERANGE EROFS ESPIPE ESRCH ETIMEDOUT EXDEV
  525. #   " math.h
  526. #   syn keyword cConstant M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_PI_2 M_PI_4
  527. #   syn keyword cConstant M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2
  528. # endif
  529. # if !exists("c_no_c99") " ISO C99
  530. #   syn keyword cConstant true false
  531. # endif
  532. #
  533. # " Accept %: for # (C99)
  534. # syn region    cPreCondit      start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
  535. # syn match     cPreConditMatch display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
  536. # if !exists("c_no_if0")
  537. #   syn cluster cCppOutInGroup  contains=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
  538. #   syn region  cCppOutWrapper  start="^\s*\(%:\|#\)\s*if\s\+0\+\s*\($\|//\|/\*\|&\)" end=".\@=\|$" contains=cCppOutIf,cCppOutElse,@NoSpell fold
  539. #   syn region  cCppOutIf       contained start="0\+" matchgroup=cCppOutWrapper end="^\s*\(%:\|#\)\s*endif\>" contains=cCppOutIf2,cCppOutElse
  540. #   if !exists("c_no_if0_fold")
  541. #     syn region        cCppOutIf2      contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0\+\s*\($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell fold
  542. #   else
  543. #     syn region        cCppOutIf2      contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0\+\s*\($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
  544. #   endif
  545. #   syn region  cCppOutElse     contained matchgroup=cCppOutWrapper start="^\s*\(%:\|#\)\s*\(else\|elif\)" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit
  546. #   syn region  cCppInWrapper   start="^\s*\(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\($\|//\|/\*\||\)" end=".\@=\|$" contains=cCppInIf,cCppInElse fold
  547. #   syn region  cCppInIf        contained matchgroup=cCppInWrapper start="\d\+" end="^\s*\(%:\|#\)\s*endif\>" contains=TOP,cPreCondit
  548. #   if !exists("c_no_if0_fold")
  549. #     syn region        cCppInElse      contained start="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold
  550. #   else
  551. #     syn region        cCppInElse      contained start="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2
  552. #   endif
  553. #   syn region  cCppInElse2     contained matchgroup=cCppInWrapper start="^\s*\(%:\|#\)\s*\(else\|elif\)\([^/]\|/[^/*]\)*" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
  554. #   syn region  cCppOutSkip     contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppOutSkip
  555. #   syn region  cCppInSkip      contained matchgroup=cCppInWrapper start="^\s*\(%:\|#\)\s*\(if\s\+\(\d\+\s*\($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" containedin=cCppOutElse,cCppInIf,cCppInSkip contains=TOP,cPreProc
  556. # endif
  557. # syn region    cIncluded       display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  558. # syn match     cIncluded       display contained "<[^>]*>"
  559. # syn match     cInclude        display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
  560. # "syn match cLineSkip  "\\$"
  561. # syn cluster   cPreProcGroup   contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti,cBadBlock
  562. # syn region    cDefine         start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  563. # syn region    cPreProc        start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  564. #
  565. # " Highlight User Labels
  566. # syn cluster   cMultiGroup     contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString
  567. # if s:ft ==# 'c' || exists("cpp_no_cpp11")
  568. #   syn region  cMulti          transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell
  569. # endif
  570. # " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  571. # syn cluster   cLabelGroup     contains=cUserLabel
  572. # syn match     cUserCont       display "^\s*\I\i*\s*:$" contains=@cLabelGroup
  573. # syn match     cUserCont       display ";\s*\I\i*\s*:$" contains=@cLabelGroup
  574. # syn match     cUserCont       display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  575. # syn match     cUserCont       display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  576. #
  577. # syn match     cUserLabel      display "\I\i*" contained
  578. #
  579. # " Avoid recognizing most bitfields as labels
  580. # syn match     cBitField       display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
  581. # syn match     cBitField       display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
  582. #
  583. # if exists("c_minlines")
  584. #   let b:c_minlines = c_minlines
  585. # else
  586. #   if !exists("c_no_if0")
  587. #     let b:c_minlines = 50     " #if 0 constructs can be long
  588. #   else
  589. #     let b:c_minlines = 15     " mostly for () constructs
  590. #   endif
  591. # endif
  592. # if exists("c_curly_error")
  593. #   syn sync fromstart
  594. # else
  595. #   exec "syn sync ccomment cComment minlines=" . b:c_minlines
  596. # endif
  597. #
  598. # " Define the default highlighting.
  599. # " Only used when an item doesn't have highlighting yet
  600. # hi def link cFormat           cSpecial
  601. # hi def link cCppString                cString
  602. # hi def link cCommentL         cComment
  603. # hi def link cCommentStart     cComment
  604. # hi def link cLabel            Label
  605. # hi def link cUserLabel                Label
  606. # hi def link cConditional      Conditional
  607. # hi def link cRepeat           Repeat
  608. # hi def link cCharacter                Character
  609. # hi def link cSpecialCharacter cSpecial
  610. # hi def link cNumber           Number
  611. # hi def link cOctal            Number
  612. # hi def link cOctalZero                PreProc  " link this to Error if you want
  613. # hi def link cFloat            Float
  614. # hi def link cOctalError               cError
  615. # hi def link cParenError               cError
  616. # hi def link cErrInParen               cError
  617. # hi def link cErrInBracket     cError
  618. # hi def link cCommentError     cError
  619. # hi def link cCommentStartError        cError
  620. # hi def link cSpaceError               cError
  621. # hi def link cSpecialError     cError
  622. # hi def link cCurlyError               cError
  623. # hi def link cOperator         Operator
  624. # hi def link cStructure                Structure
  625. # hi def link cStorageClass     StorageClass
  626. # hi def link cInclude          Include
  627. # hi def link cPreProc          PreProc
  628. # hi def link cDefine           Macro
  629. # hi def link cIncluded         cString
  630. # hi def link cError            Error
  631. # hi def link cStatement                Statement
  632. # hi def link cCppInWrapper     cCppOutWrapper
  633. # hi def link cCppOutWrapper    cPreCondit
  634. # hi def link cPreConditMatch   cPreCondit
  635. # hi def link cPreCondit                PreCondit
  636. # hi def link cType             Type
  637. # hi def link cConstant         Constant
  638. # hi def link cCommentString    cString
  639. # hi def link cComment2String   cString
  640. # hi def link cCommentSkip      cComment
  641. # hi def link cString           String
  642. # hi def link cComment          Comment
  643. # hi def link cSpecial          SpecialChar
  644. # hi def link cTodo             Todo
  645. # hi def link cBadContinuation  Error
  646. # hi def link cCppOutSkip               cCppOutIf2
  647. # hi def link cCppInElse2               cCppOutIf2
  648. # hi def link cCppOutIf2                cCppOut2  " Old syntax group for #if 0 body
  649. # hi def link cCppOut2          cCppOut  " Old syntax group for #if of #if 0
  650. # hi def link cCppOut           Comment
  651. #
  652. # endif
  653. #
  654. # let b:current_syn = 'man'
  655. # unlet s:ft
  656. #
  657. # let &cpo = s:cpo_save
  658. # unlet s:cpo_save
  659. # " vim: ts=8
  660. #
  661. #=end:vman.vim=
captcha