nroff.vim 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. " VIM syntax file
  2. " Language: nroff/groff
  3. " Maintainer: John Marshall <jmarshall@hey.com>
  4. " Previous Maintainer: Pedro Alejandro López-Valencia <palopezv@gmail.com>
  5. " Previous Maintainer: Jérôme Plût <Jerome.Plut@ens.fr>
  6. " Last Change: 2021 Mar 28
  7. "
  8. " {{{1 Todo
  9. "
  10. " TODO:
  11. "
  12. " * Write syntax highlighting files for the preprocessors,
  13. " and integrate with nroff.vim.
  14. "
  15. "
  16. " {{{1 Start syntax highlighting.
  17. "
  18. " quit when a syntax file was already loaded
  19. "
  20. if exists("b:current_syntax")
  21. finish
  22. endif
  23. let s:cpo_save = &cpo
  24. set cpo&vim
  25. if exists("nroff_is_groff")
  26. let b:nroff_is_groff = 1
  27. endif
  28. syn spell toplevel
  29. syn case match
  30. "
  31. " {{{1 plugin settings...
  32. "
  33. " {{{2 enable spacing error highlighting
  34. "
  35. if exists("nroff_space_errors")
  36. syn match nroffError /\s\+$/
  37. syn match nroffSpaceError /[.,:;!?]\s\{2,}/
  38. endif
  39. "
  40. "
  41. " {{{1 Special file settings
  42. "
  43. " {{{2 ms exdented paragraphs are not in the default paragraphs list.
  44. "
  45. setlocal paragraphs+=XP
  46. "
  47. " {{{2 Activate navigation to preprocessor sections.
  48. "
  49. if exists("b:preprocs_as_sections")
  50. setlocal sections=EQTSPS[\ G1GS
  51. endif
  52. " {{{1 Escape sequences
  53. " ------------------------------------------------------------
  54. syn match nroffEscChar /\\[CN]/ nextgroup=nroffEscCharArg
  55. syn match nroffEscape /\\[*fgmnYV]/ nextgroup=nroffEscRegPar,nroffEscRegArg
  56. syn match nroffEscape /\\s[+-]\=/ nextgroup=nroffSize
  57. syn match nroffEscape /\\[$AbDhlLRvxXZ]/ nextgroup=nroffEscPar,nroffEscArg
  58. syn match nroffEscRegArg /./ contained
  59. syn match nroffEscRegArg2 /../ contained
  60. syn match nroffEscRegPar /(/ contained nextgroup=nroffEscRegArg2
  61. syn match nroffEscArg /./ contained
  62. syn match nroffEscArg2 /../ contained
  63. syn match nroffEscPar /(/ contained nextgroup=nroffEscArg2
  64. syn match nroffSize /\((\d\)\=\d/ contained
  65. syn region nroffEscCharArg start=/'/ end=/'/ contained
  66. syn region nroffEscArg start=/'/ end=/'/ contained contains=nroffEscape,@nroffSpecial
  67. if exists("b:nroff_is_groff")
  68. syn region nroffEscRegArg matchgroup=nroffEscape start=/\[/ end=/\]/ contained oneline
  69. syn region nroffSize matchgroup=nroffEscape start=/\[/ end=/\]/ contained
  70. endif
  71. syn match nroffEscape /\\[adprtu{}]/
  72. syn match nroffEscape /\\$/
  73. syn match nroffEscape /\\\$[@*]/
  74. " {{{1 Strings and special characters
  75. " ------------------------------------------------------------
  76. syn match nroffSpecialChar /\\[\\eE?!-]/
  77. syn match nroffSpace "\\[&%~|^0)/,]"
  78. syn match nroffSpecialChar /\\(../
  79. if exists("b:nroff_is_groff")
  80. syn match nroffSpecialChar /\\\[[^]]*]/
  81. syn region nroffPreserve matchgroup=nroffSpecialChar start=/\\?/ end=/\\?/ oneline
  82. endif
  83. syn region nroffPreserve matchgroup=nroffSpecialChar start=/\\!/ end=/$/ oneline
  84. syn cluster nroffSpecial contains=nroffSpecialChar,nroffSpace
  85. syn region nroffString start=/"/ end=/"/ skip=/\\$/ contains=nroffEscape,@nroffSpecial contained
  86. syn region nroffString start=/'/ end=/'/ skip=/\\$/ contains=nroffEscape,@nroffSpecial contained
  87. " {{{1 Numbers and units
  88. " ------------------------------------------------------------
  89. syn match nroffNumBlock /[0-9.]\a\=/ contained contains=nroffNumber
  90. syn match nroffNumber /\d\+\(\.\d*\)\=/ contained nextgroup=nroffUnit,nroffBadChar
  91. syn match nroffNumber /\.\d\+)/ contained nextgroup=nroffUnit,nroffBadChar
  92. syn match nroffBadChar /./ contained
  93. syn match nroffUnit /[icpPszmnvMu]/ contained
  94. " {{{1 Requests
  95. " ------------------------------------------------------------
  96. " Requests begin with . or ' at the beginning of a line, or
  97. " after .if or .ie.
  98. syn match nroffReqLeader /^[.']/ nextgroup=nroffReqName skipwhite
  99. syn match nroffReqLeader /[.']/ contained nextgroup=nroffReqName skipwhite
  100. if exists("b:nroff_is_groff")
  101. "
  102. " GNU troff allows long request names
  103. "
  104. syn match nroffReqName /[^\t \\\[?]\+/ contained nextgroup=nroffReqArg
  105. else
  106. syn match nroffReqName /[^\t \\\[?]\{1,2}/ contained nextgroup=nroffReqArg
  107. endif
  108. syn region nroffReqArg start=/\S/ skip=/\\$/ end=/$/ contained contains=nroffEscape,@nroffSpecial,nroffString,nroffError,nroffSpaceError,nroffNumBlock,nroffComment
  109. " {{{2 Conditional: .if .ie .el
  110. syn match nroffReqName /\(if\|ie\)/ contained nextgroup=nroffCond skipwhite
  111. syn match nroffReqName /el/ contained nextgroup=nroffReqLeader skipwhite
  112. syn match nroffCond /\S\+/ contained nextgroup=nroffReqLeader skipwhite
  113. " {{{2 String definition: .ds .as
  114. syn match nroffReqname /[da]s/ contained nextgroup=nroffDefIdent skipwhite
  115. syn match nroffDefIdent /\S\+/ contained nextgroup=nroffDefinition skipwhite
  116. syn region nroffDefinition matchgroup=nroffSpecialChar start=/"/ matchgroup=NONE end=/\\"/me=e-2 skip=/\\$/ start=/\S/ end=/$/ contained contains=nroffDefSpecial
  117. syn match nroffDefSpecial /\\$/ contained
  118. syn match nroffDefSpecial /\\\((.\)\=./ contained
  119. if exists("b:nroff_is_groff")
  120. syn match nroffDefSpecial /\\\[[^]]*]/ contained
  121. endif
  122. " {{{2 Macro definition: .de .am, also diversion: .di
  123. syn match nroffReqName /\(d[ei]\|am\)/ contained nextgroup=nroffIdent skipwhite
  124. syn match nroffIdent /[^[?( \t]\+/ contained
  125. if exists("b:nroff_is_groff")
  126. syn match nroffReqName /als/ contained nextgroup=nroffIdent skipwhite
  127. endif
  128. " {{{2 Register definition: .rn .rr
  129. syn match nroffReqName /[rn]r/ contained nextgroup=nroffIdent skipwhite
  130. if exists("b:nroff_is_groff")
  131. syn match nroffReqName /\(rnn\|aln\)/ contained nextgroup=nroffIdent skipwhite
  132. endif
  133. " {{{1 eqn/tbl/pic
  134. " ------------------------------------------------------------
  135. " <jp>
  136. " XXX: write proper syntax highlight for eqn / tbl / pic ?
  137. " <jp />
  138. syn region nroffEquation start=/^\.\s*EQ\>/ end=/^\.\s*EN\>/
  139. syn region nroffTable start=/^\.\s*TS\>/ end=/^\.\s*TE\>/ contains=@Spell
  140. syn region nroffPicture start=/^\.\s*PS\>/ end=/^\.\s*PE\>/
  141. syn region nroffRefer start=/^\.\s*\[\>/ end=/^\.\s*\]\>/ contains=@Spell
  142. syn region nroffGrap start=/^\.\s*G1\>/ end=/^\.\s*G2\>/
  143. syn region nroffGremlin start=/^\.\s*GS\>/ end=/^\.\s*GE|GF\>/
  144. " {{{1 Comments
  145. " ------------------------------------------------------------
  146. syn region nroffIgnore start=/^[.']\s*ig/ end=/^['.]\s*\./
  147. syn match nroffComment /\(^[.']\s*\)\=\\".*/ contains=nroffTodo,@Spell
  148. syn match nroffComment /^'''.*/ contains=nroffTodo,@Spell
  149. if exists("b:nroff_is_groff")
  150. syn match nroffComment "\\#.*$" contains=nroffTodo,@Spell
  151. endif
  152. syn keyword nroffTodo TODO XXX FIXME contained
  153. " {{{1 Hilighting
  154. " ------------------------------------------------------------
  155. "
  156. "
  157. " Define the default highlighting.
  158. " Only when an item doesn't have highlighting yet
  159. "
  160. hi def link nroffEscChar nroffSpecialChar
  161. hi def link nroffEscCharArg nroffSpecialChar
  162. hi def link nroffSpecialChar SpecialChar
  163. hi def link nroffSpace Delimiter
  164. hi def link nroffEscRegArg2 nroffEscRegArg
  165. hi def link nroffEscRegArg nroffIdent
  166. hi def link nroffEscArg2 nroffEscArg
  167. hi def link nroffEscPar nroffEscape
  168. hi def link nroffEscRegPar nroffEscape
  169. hi def link nroffEscArg nroffEscape
  170. hi def link nroffSize nroffEscape
  171. hi def link nroffEscape PreProc
  172. hi def link nroffIgnore Comment
  173. hi def link nroffComment Comment
  174. hi def link nroffTodo Todo
  175. hi def link nroffReqLeader nroffRequest
  176. hi def link nroffReqName nroffRequest
  177. hi def link nroffRequest Statement
  178. hi def link nroffCond PreCondit
  179. hi def link nroffDefIdent nroffIdent
  180. hi def link nroffIdent Identifier
  181. hi def link nroffEquation PreProc
  182. hi def link nroffTable PreProc
  183. hi def link nroffPicture PreProc
  184. hi def link nroffRefer PreProc
  185. hi def link nroffGrap PreProc
  186. hi def link nroffGremlin PreProc
  187. hi def link nroffNumber Number
  188. hi def link nroffBadChar nroffError
  189. hi def link nroffSpaceError nroffError
  190. hi def link nroffError Error
  191. hi def link nroffPreserve String
  192. hi def link nroffString String
  193. hi def link nroffDefinition String
  194. hi def link nroffDefSpecial Special
  195. let b:current_syntax = "nroff"
  196. let &cpo = s:cpo_save
  197. unlet s:cpo_save
  198. " vim600: set fdm=marker fdl=2: