Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " VIM syntax file |
| 2 | " Language: nroff/groff |
Bram Moolenaar | b8ff1fb | 2012-02-04 21:59:01 +0100 | [diff] [blame] | 3 | " Maintainer: Pedro Alejandro López-Valencia <palopezv@gmail.com> |
| 4 | " URL: http://vorbote.wordpress.com/ |
| 5 | " Last Change: 2012 Feb 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6 | " |
| 7 | " {{{1 Acknowledgements |
| 8 | " |
| 9 | " ACKNOWLEDGEMENTS: |
| 10 | " |
| 11 | " My thanks to Jérôme Plût <Jerome.Plut@ens.fr>, who was the |
| 12 | " creator and maintainer of this syntax file for several years. |
| 13 | " May I be as good at it as he has been. |
| 14 | " |
| 15 | " {{{1 Todo |
| 16 | " |
| 17 | " TODO: |
| 18 | " |
| 19 | " * Write syntax highlighting files for the preprocessors, |
| 20 | " and integrate with nroff.vim. |
| 21 | " |
| 22 | " |
| 23 | " {{{1 Start syntax highlighting. |
| 24 | " |
| 25 | " For version 5.x: Clear all syntax items |
| 26 | " For version 6.x: Quit when a syntax file was already loaded |
| 27 | " |
| 28 | if version < 600 |
| 29 | syntax clear |
| 30 | elseif exists("b:current_syntax") |
| 31 | finish |
| 32 | endif |
| 33 | |
Bram Moolenaar | b8ff1fb | 2012-02-04 21:59:01 +0100 | [diff] [blame] | 34 | let s:cpo_save = &cpo |
| 35 | set cpo&vim |
| 36 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 37 | " |
| 38 | " {{{1 plugin settings... |
| 39 | " |
| 40 | " {{{2 enable spacing error highlighting |
| 41 | " |
| 42 | if exists("nroff_space_errors") |
| 43 | syn match nroffError /\s\+$/ |
| 44 | syn match nroffSpaceError /[.,:;!?]\s\{2,}/ |
| 45 | endif |
| 46 | " |
| 47 | " |
| 48 | " {{{1 Special file settings |
| 49 | " |
| 50 | " {{{2 ms exdented paragraphs are not in the default paragraphs list. |
| 51 | " |
| 52 | setlocal paragraphs+=XP |
| 53 | " |
| 54 | " {{{2 Activate navigation to preporcessor sections. |
| 55 | " |
| 56 | if exists("b:preprocs_as_sections") |
| 57 | setlocal sections=EQTSPS[\ G1GS |
| 58 | endif |
| 59 | |
| 60 | " {{{1 Escape sequences |
| 61 | " ------------------------------------------------------------ |
| 62 | |
| 63 | syn match nroffEscChar /\\[CN]/ nextgroup=nroffEscCharArg |
| 64 | syn match nroffEscape /\\[*fgmnYV]/ nextgroup=nroffEscRegPar,nroffEscRegArg |
| 65 | syn match nroffEscape /\\s[+-]\=/ nextgroup=nroffSize |
| 66 | syn match nroffEscape /\\[$AbDhlLRvxXZ]/ nextgroup=nroffEscPar,nroffEscArg |
| 67 | |
| 68 | syn match nroffEscRegArg /./ contained |
| 69 | syn match nroffEscRegArg2 /../ contained |
| 70 | syn match nroffEscRegPar /(/ contained nextgroup=nroffEscRegArg2 |
| 71 | syn match nroffEscArg /./ contained |
| 72 | syn match nroffEscArg2 /../ contained |
| 73 | syn match nroffEscPar /(/ contained nextgroup=nroffEscArg2 |
| 74 | syn match nroffSize /\((\d\)\=\d/ contained |
| 75 | |
| 76 | syn region nroffEscCharArg start=/'/ end=/'/ contained |
| 77 | syn region nroffEscArg start=/'/ end=/'/ contained contains=nroffEscape,@nroffSpecial |
| 78 | |
| 79 | if exists("b:nroff_is_groff") |
| 80 | syn region nroffEscRegArg matchgroup=nroffEscape start=/\[/ end=/\]/ contained oneline |
| 81 | syn region nroffSize matchgroup=nroffEscape start=/\[/ end=/\]/ contained |
| 82 | endif |
| 83 | |
| 84 | syn match nroffEscape /\\[adprtu{}]/ |
| 85 | syn match nroffEscape /\\$/ |
| 86 | syn match nroffEscape /\\\$[@*]/ |
| 87 | |
| 88 | " {{{1 Strings and special characters |
| 89 | " ------------------------------------------------------------ |
| 90 | |
| 91 | syn match nroffSpecialChar /\\[\\eE?!-]/ |
| 92 | syn match nroffSpace "\\[&%~|^0)/,]" |
| 93 | syn match nroffSpecialChar /\\(../ |
| 94 | |
| 95 | if exists("b:nroff_is_groff") |
| 96 | syn match nroffSpecialChar /\\\[[^]]*]/ |
| 97 | syn region nroffPreserve matchgroup=nroffSpecialChar start=/\\?/ end=/\\?/ oneline |
| 98 | endif |
| 99 | |
| 100 | syn region nroffPreserve matchgroup=nroffSpecialChar start=/\\!/ end=/$/ oneline |
| 101 | |
| 102 | syn cluster nroffSpecial contains=nroffSpecialChar,nroffSpace |
| 103 | |
| 104 | |
| 105 | syn region nroffString start=/"/ end=/"/ skip=/\\$/ contains=nroffEscape,@nroffSpecial contained |
| 106 | syn region nroffString start=/'/ end=/'/ skip=/\\$/ contains=nroffEscape,@nroffSpecial contained |
| 107 | |
| 108 | |
| 109 | " {{{1 Numbers and units |
| 110 | " ------------------------------------------------------------ |
| 111 | syn match nroffNumBlock /[0-9.]\a\=/ contained contains=nroffNumber |
| 112 | syn match nroffNumber /\d\+\(\.\d*\)\=/ contained nextgroup=nroffUnit,nroffBadChar |
| 113 | syn match nroffNumber /\.\d\+)/ contained nextgroup=nroffUnit,nroffBadChar |
| 114 | syn match nroffBadChar /./ contained |
| 115 | syn match nroffUnit /[icpPszmnvMu]/ contained |
| 116 | |
| 117 | |
| 118 | " {{{1 Requests |
| 119 | " ------------------------------------------------------------ |
| 120 | |
| 121 | " Requests begin with . or ' at the beginning of a line, or |
| 122 | " after .if or .ie. |
| 123 | |
| 124 | syn match nroffReqLeader /^[.']/ nextgroup=nroffReqName skipwhite |
| 125 | syn match nroffReqLeader /[.']/ contained nextgroup=nroffReqName skipwhite |
| 126 | |
| 127 | if exists("b:nroff_is_groff") |
| 128 | " |
| 129 | " GNU troff allows long request names |
| 130 | " |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 131 | syn match nroffReqName /[^\t \\\[?]\+/ contained nextgroup=nroffReqArg |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 132 | else |
| 133 | syn match nroffReqName /[^\t \\\[?]\{1,2}/ contained nextgroup=nroffReqArg |
| 134 | endif |
| 135 | |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 136 | syn region nroffReqArg start=/\S/ skip=/\\$/ end=/$/ contained contains=nroffEscape,@nroffSpecial,nroffString,nroffError,nroffSpaceError,nroffNumBlock,nroffComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 137 | |
| 138 | " {{{2 Conditional: .if .ie .el |
| 139 | syn match nroffReqName /\(if\|ie\)/ contained nextgroup=nroffCond skipwhite |
| 140 | syn match nroffReqName /el/ contained nextgroup=nroffReqLeader skipwhite |
| 141 | syn match nroffCond /\S\+/ contained nextgroup=nroffReqLeader skipwhite |
| 142 | |
| 143 | " {{{2 String definition: .ds .as |
| 144 | syn match nroffReqname /[da]s/ contained nextgroup=nroffDefIdent skipwhite |
| 145 | syn match nroffDefIdent /\S\+/ contained nextgroup=nroffDefinition skipwhite |
| 146 | syn region nroffDefinition matchgroup=nroffSpecialChar start=/"/ matchgroup=NONE end=/\\"/me=e-2 skip=/\\$/ start=/\S/ end=/$/ contained contains=nroffDefSpecial |
| 147 | syn match nroffDefSpecial /\\$/ contained |
| 148 | syn match nroffDefSpecial /\\\((.\)\=./ contained |
| 149 | |
| 150 | if exists("b:nroff_is_groff") |
| 151 | syn match nroffDefSpecial /\\\[[^]]*]/ contained |
| 152 | endif |
| 153 | |
| 154 | " {{{2 Macro definition: .de .am, also diversion: .di |
| 155 | syn match nroffReqName /\(d[ei]\|am\)/ contained nextgroup=nroffIdent skipwhite |
| 156 | syn match nroffIdent /[^[?( \t]\+/ contained |
| 157 | if exists("b:nroff_is_groff") |
| 158 | syn match nroffReqName /als/ contained nextgroup=nroffIdent skipwhite |
| 159 | endif |
| 160 | |
| 161 | " {{{2 Register definition: .rn .rr |
| 162 | syn match nroffReqName /[rn]r/ contained nextgroup=nroffIdent skipwhite |
| 163 | if exists("b:nroff_is_groff") |
| 164 | syn match nroffReqName /\(rnn\|aln\)/ contained nextgroup=nroffIdent skipwhite |
| 165 | endif |
| 166 | |
| 167 | |
| 168 | " {{{1 eqn/tbl/pic |
| 169 | " ------------------------------------------------------------ |
| 170 | " <jp> |
| 171 | " XXX: write proper syntax highlight for eqn / tbl / pic ? |
| 172 | " <jp /> |
| 173 | |
| 174 | syn region nroffEquation start=/^\.\s*EQ\>/ end=/^\.\s*EN\>/ |
| 175 | syn region nroffTable start=/^\.\s*TS\>/ end=/^\.\s*TE\>/ |
| 176 | syn region nroffPicture start=/^\.\s*PS\>/ end=/^\.\s*PE\>/ |
| 177 | syn region nroffRefer start=/^\.\s*\[\>/ end=/^\.\s*\]\>/ |
| 178 | syn region nroffGrap start=/^\.\s*G1\>/ end=/^\.\s*G2\>/ |
| 179 | syn region nroffGremlin start=/^\.\s*GS\>/ end=/^\.\s*GE|GF\>/ |
| 180 | |
| 181 | " {{{1 Comments |
| 182 | " ------------------------------------------------------------ |
| 183 | |
| 184 | syn region nroffIgnore start=/^[.']\s*ig/ end=/^['.]\s*\./ |
| 185 | syn match nroffComment /\(^[.']\s*\)\=\\".*/ contains=nroffTodo |
| 186 | syn match nroffComment /^'''.*/ contains=nroffTodo |
| 187 | |
| 188 | if exists("b:nroff_is_groff") |
| 189 | syn match nroffComment "\\#.*$" contains=nroffTodo |
| 190 | endif |
| 191 | |
| 192 | syn keyword nroffTodo TODO XXX FIXME contained |
| 193 | |
| 194 | " {{{1 Hilighting |
| 195 | " ------------------------------------------------------------ |
| 196 | " |
| 197 | |
| 198 | " |
| 199 | " Define the default highlighting. |
| 200 | " For version 5.7 and earlier: only when not done already |
| 201 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 202 | " |
| 203 | if version >= 508 || !exists("did_nroff_syn_inits") |
| 204 | |
| 205 | if version < 508 |
| 206 | let did_nroff_syn_inits = 1 |
| 207 | command -nargs=+ HiLink hi link <args> |
| 208 | else |
| 209 | command -nargs=+ HiLink hi def link <args> |
| 210 | endif |
| 211 | |
| 212 | HiLink nroffEscChar nroffSpecialChar |
| 213 | HiLink nroffEscCharAr nroffSpecialChar |
| 214 | HiLink nroffSpecialChar SpecialChar |
| 215 | HiLink nroffSpace Delimiter |
| 216 | |
| 217 | HiLink nroffEscRegArg2 nroffEscRegArg |
| 218 | HiLink nroffEscRegArg nroffIdent |
| 219 | |
| 220 | HiLink nroffEscArg2 nroffEscArg |
| 221 | HiLink nroffEscPar nroffEscape |
| 222 | |
| 223 | HiLink nroffEscRegPar nroffEscape |
| 224 | HiLink nroffEscArg nroffEscape |
| 225 | HiLink nroffSize nroffEscape |
| 226 | HiLink nroffEscape Preproc |
| 227 | |
| 228 | HiLink nroffIgnore Comment |
| 229 | HiLink nroffComment Comment |
| 230 | HiLink nroffTodo Todo |
| 231 | |
| 232 | HiLink nroffReqLeader nroffRequest |
| 233 | HiLink nroffReqName nroffRequest |
| 234 | HiLink nroffRequest Statement |
| 235 | HiLink nroffCond PreCondit |
| 236 | HiLink nroffDefIdent nroffIdent |
| 237 | HiLink nroffIdent Identifier |
| 238 | |
| 239 | HiLink nroffEquation PreProc |
| 240 | HiLink nroffTable PreProc |
| 241 | HiLink nroffPicture PreProc |
| 242 | HiLink nroffRefer PreProc |
| 243 | HiLink nroffGrap PreProc |
| 244 | HiLink nroffGremlin PreProc |
| 245 | |
| 246 | HiLink nroffNumber Number |
| 247 | HiLink nroffBadChar nroffError |
| 248 | HiLink nroffSpaceError nroffError |
| 249 | HiLink nroffError Error |
| 250 | |
| 251 | HiLink nroffPreserve String |
| 252 | HiLink nroffString String |
| 253 | HiLink nroffDefinition String |
| 254 | HiLink nroffDefSpecial Special |
| 255 | |
| 256 | delcommand HiLink |
| 257 | |
| 258 | endif |
| 259 | |
| 260 | let b:current_syntax = "nroff" |
| 261 | |
Bram Moolenaar | b8ff1fb | 2012-02-04 21:59:01 +0100 | [diff] [blame] | 262 | let &cpo = s:cpo_save |
| 263 | unlet s:cpo_save |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 264 | " vim600: set fdm=marker fdl=2: |