2 " Language: nroff / groff
3 " Maintainer: Jérôme Plût <Jerome.Plut@ens.fr>
4 " URL: http://www.eleves.ens.fr:8080/home/plut/nroff.vim
5 " Last Change: 2001 May 10
8 " groff (GNU troff) behaves slightly differently from groff; it allows
9 " long names being specified between brackets: for instance, \[hy] is
11 " This file handle both syntaxes, depending on the value of 'filetype'.
13 " For version 5.x: Clear all syntax items
14 " For version 6.x: Quit when a syntax file was already loaded
17 elseif exists("b:current_syntax")
22 if exists("nroff_space_errors")
23 syn match nroffError /\s\+$/
26 " {{{1 Escape sequences
27 " ------------------------------------------------------------
29 syn match nroffEscChar /\\[CN]/ nextgroup=nroffEscCharArg
30 syn match nroffEscape /\\[*gnYV]/ nextgroup=nroffEscRegPar,nroffEscRegArg
31 syn match nroffEscape /\\s[+-]\=/ nextgroup=nroffSize
32 syn match nroffEscape /\\[$AbDfhlLRvxXZ]/ nextgroup=nroffEscPar,nroffEscArg
34 syn match nroffEscRegArg /./ contained
35 syn match nroffEscRegArg2 /../ contained
36 syn match nroffEscRegPar /(/ contained nextgroup=nroffEscRegArg2
37 syn match nroffEscArg /./ contained
38 syn match nroffEscArg2 /../ contained
39 syn match nroffEscPar /(/ contained nextgroup=nroffEscArg2
40 syn match nroffSize /\((\d\)\=\d/ contained
42 syn region nroffEscCharArg start=/'/ end=/'/ contained
43 syn region nroffEscArg start=/'/ end=/'/ contained contains=nroffEscape,@nroffSpecial
45 if exists("b:nroff_is_groff")
46 syn region nroffEscRegArg matchgroup=nroffEscape start=/\[/ end=/\]/ contained oneline
47 syn region nroffSize matchgroup=nroffEscape start=/\[/ end=/\]/ contained
50 syn match nroffEscape /\\[adprtu{}]/
51 syn match nroffEscape /\\$/
52 syn match nroffEscape /\\\$[@*]/
54 " {{{1 Strings and special characters
55 " ------------------------------------------------------------
57 syn match nroffSpecialChar /\\[\\eE?!-]/
58 syn match nroffSpace "\\[&%~|^0)/,]"
59 syn match nroffSpecialChar /\\(../
60 if exists("b:nroff_is_groff")
61 syn match nroffSpecialChar /\\\[[^]]*]/
62 syn region nroffPreserve matchgroup=nroffSpecialChar start=/\\?/ end=/\\?/ oneline
64 syn region nroffPreserve matchgroup=nroffSpecialChar start=/\\!/ end=/$/ oneline
66 syn cluster nroffSpecial contains=nroffSpecialChar,nroffSpace
69 syn region nroffString start=/"/ end=/"/ skip=/\\$/ contains=nroffEscape,@nroffSpecial contained
70 syn region nroffString start=/'/ end=/'/ skip=/\\$/ contains=nroffEscape,@nroffSpecial contained
73 " {{{1 Numbers and units
74 " ------------------------------------------------------------
75 syn match nroffNumBlock /[0-9.]\a\=/ contained contains=nroffNumber
76 syn match nroffNumber /\d\+\(\.\d*\)\=/ contained nextgroup=nroffUnit,nroffBadChar
77 syn match nroffNumber /\.\d\+)/ contained nextgroup=nroffUnit,nroffBadChar
78 syn match nroffBadChar /./ contained
79 syn match nroffUnit /[icpPszmnvMu]/ contained
83 " ------------------------------------------------------------
85 " Requests begin with . or ' at the beginning of a line, or after .if or
88 syn match nroffReqLeader /^[.']/ nextgroup=nroffReqName skipwhite
89 syn match nroffReqLeader /[.']/ contained nextgroup=nroffReqName skipwhite
90 if exists("b:nroff_is_groff")
91 " GNU troff allows long request names
92 syn match nroffReqName /[^\t \\\[?]\+/ contained nextgroup=nroffReqArg
94 syn match nroffReqName /[^\t \\\[?]\{1,2}/ contained nextgroup=nroffReqArg
96 syn region roffReqArg start=/\S/ skip=/\\$/ end=/$/ contained contains=nroffEscape,@nroffSpecial,nroffString,nroffError,nroffNumBlock,nroffComment
98 " {{{2 Conditional: .if .ie .el
99 syn match nroffReqName /\(if\|ie\)/ contained nextgroup=nroffCond skipwhite
100 syn match nroffReqName /el/ contained nextgroup=nroffReqLeader skipwhite
101 syn match nroffCond /\S\+/ contained nextgroup=nroffReqLeader skipwhite
103 " {{{2 String definition: .ds .as
104 syn match nroffReqname /[da]s/ contained nextgroup=nroffDefIdent skipwhite
105 syn match nroffDefIdent /\S\+/ contained nextgroup=nroffDefinition skipwhite
106 syn region nroffDefinition matchgroup=nroffSpecialChar start=/"/ matchgroup=NONE end=/\\"/me=e-2 skip=/\\$/ start=/\S/ end=/$/ contained contains=nroffDefSpecial
107 syn match nroffDefSpecial /\\$/ contained
108 syn match nroffDefSpecial /\\\((.\)\=./ contained
110 if exists("b:nroff_is_groff")
111 syn match nroffDefSpecial /\\\[[^]]*]/ contained
114 " {{{2 Macro definition: .de .am, also diversion: .di
115 syn match nroffReqName /\(d[ei]\|am\)/ contained nextgroup=nroffIdent skipwhite
116 syn match nroffIdent /[^[?( \t]\+/ contained
117 if exists("b:nroff_is_groff")
118 syn match nroffReqName /als/ contained nextgroup=nroffIdent skipwhite
121 " {{{2 Register definition: .rn .rr
122 syn match nroffReqName /[rn]r/ contained nextgroup=nroffIdent skipwhite
123 if exists("b:nroff_is_groff")
124 syn match nroffReqName /\(rnn\|aln\)/ contained nextgroup=nroffIdent skipwhite
129 " ------------------------------------------------------------
130 " XXX: write proper syntax highlight for eqn / tbl / pic ?
132 syn region nroffEquation start=/^\.\s*EQ/ end=/^\.\s*EN/
133 syn region nroffTable start=/^\.\s*TB/ end=/^\.\s*TE/
134 syn region nroffPicture start=/^\.\s*PB/ end=/^\.\s*PE/
137 " ------------------------------------------------------------
139 syn region nroffIgnore start=/^[.']\s*ig/ end=/^['.]\s*\./
140 syn match nroffComment /\(^[.']\s*\)\=\\".*/ contains=nroffTodo
141 syn match nroffComment /^'''.*/ contains=nroffTodo
142 if exists("b:nroff_is_groff")
143 syn match nroffComment "\\#.*$" contains=nroffTodo
145 syn keyword nroffTodo TODO XXX FIXME contained
148 " ------------------------------------------------------------
150 " Define the default highlighting.
151 " For version 5.7 and earlier: only when not done already
152 " For version 5.8 and later: only when an item doesn't have highlighting yet
153 if version >= 508 || !exists("did_nroff_syn_inits")
155 let did_nroff_syn_inits = 1
156 command -nargs=+ HiLink hi link <args>
158 command -nargs=+ HiLink hi def link <args>
161 HiLink nroffEscChar nroffSpecialChar
162 HiLink nroffEscCharAr nroffSpecialChar
163 HiLink nroffSpecialChar SpecialChar
164 HiLink nroffSpace Delimiter
166 HiLink nroffEscRegArg2 nroffEscRegArg
167 HiLink nroffEscRegArg nroffIdent
169 HiLink nroffEscArg2 nroffEscArg
170 HiLink nroffEscPar nroffEscape
172 HiLink nroffEscRegPar nroffEscape
173 HiLink nroffEscArg nroffEscape
174 HiLink nroffSize nroffEscape
175 HiLink nroffEscape Preproc
177 HiLink nroffIgnore Comment
178 HiLink nroffComment Comment
179 HiLink nroffTodo Todo
181 HiLink nroffReqLeader nroffRequest
182 HiLink nroffReqName nroffRequest
183 HiLink nroffRequest Statement
184 HiLink nroffCond PreCondit
185 HiLink nroffDefIdent nroffIdent
186 HiLink nroffIdent Identifier
188 HiLink nroffEquation PreProc
189 HiLink nroffTable PreProc
190 HiLink nroffPicture PreProc
192 HiLink nroffNumber Number
193 HiLink nroffBadChar nroffError
194 HiLink nroffError Error
196 HiLink nroffPreserve String
197 HiLink nroffString String
198 HiLink nroffDefinition String
199 HiLink nroffDefSpecial Special
204 " I recommend using for nroffDefinition an highlight that shows spaces,
205 " since nroff includes them in the string, for instance:
206 " hi def nroffDefinition term=italic cterm=italic gui=reverse
207 " hi def nroffDefSpecial term=italic,bold cterm=italic,bold gui=reverse,bold
209 let b:current_syntax = "nroff"
212 " vim: set ts=8 sw=2:
213 " vim600: set fdm=marker fdl=2: