blob: f373161c7c8cc07361bf493e78a648b4f410078d [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax support file
2" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +02003" Last Change: 2020 Apr 13
Bram Moolenaar071d4272004-06-13 20:20:40 +00004
5" This file sets up for syntax highlighting.
6" It is loaded from "syntax.vim" and "manual.vim".
7" 1. Set the default highlight groups.
8" 2. Install Syntax autocommands for all the available syntax files.
9
10if !has("syntax")
11 finish
12endif
13
14" let others know that syntax has been switched on
15let syntax_on = 1
16
17" Set the default highlighting colors. Use a color scheme if specified.
18if exists("colors_name")
19 exe "colors " . colors_name
20else
21 runtime! syntax/syncolor.vim
22endif
23
24" Line continuation is used here, remove 'C' from 'cpoptions'
25let s:cpo_save = &cpo
26set cpo&vim
27
28" First remove all old syntax autocommands.
29au! Syntax
30
31au Syntax * call s:SynSet()
32
33fun! s:SynSet()
34 " clear syntax for :set syntax=OFF and any syntax name that doesn't exist
35 syn clear
36 if exists("b:current_syntax")
37 unlet b:current_syntax
38 endif
39
40 let s = expand("<amatch>")
41 if s == "ON"
42 " :set syntax=ON
43 if &filetype == ""
44 echohl ErrorMsg
45 echo "filetype unknown"
46 echohl None
47 endif
48 let s = &filetype
Bram Moolenaar97cc2382012-10-03 21:46:54 +020049 elseif s == "OFF"
50 let s = ""
Bram Moolenaar071d4272004-06-13 20:20:40 +000051 endif
52
53 if s != ""
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000054 " Load the syntax file(s). When there are several, separated by dots,
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020055 " load each in sequence. Skip empty entries.
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000056 for name in split(s, '\.')
Bram Moolenaar2c7f8c52020-04-20 19:52:53 +020057 if !empty(name)
58 exe "runtime! syntax/" . name . ".vim syntax/" . name . "/*.vim"
59 endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000060 endfor
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 endif
62endfun
63
64
Bram Moolenaarfc39ecf2015-08-11 20:34:49 +020065" Handle adding doxygen to other languages (C, C++, C#, IDL, java, php, DataScript)
66au Syntax c,cpp,cs,idl,java,php,datascript
Bram Moolenaard4755bb2004-09-02 19:12:26 +000067 \ if (exists('b:load_doxygen_syntax') && b:load_doxygen_syntax)
68 \ || (exists('g:load_doxygen_syntax') && g:load_doxygen_syntax)
Bram Moolenaarc9b4b052006-04-30 18:54:39 +000069 \ | runtime! syntax/doxygen.vim
Bram Moolenaard4755bb2004-09-02 19:12:26 +000070 \ | endif
71
Bram Moolenaard4755bb2004-09-02 19:12:26 +000072
Bram Moolenaar071d4272004-06-13 20:20:40 +000073" Source the user-specified syntax highlighting file
Bram Moolenaar25de4c22016-11-06 14:48:06 +010074if exists("mysyntaxfile")
75 let s:fname = expand(mysyntaxfile)
76 if filereadable(s:fname)
77 execute "source " . fnameescape(s:fname)
78 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000079endif
80
81" Restore 'cpoptions'
82let &cpo = s:cpo_save
83unlet s:cpo_save