Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax support file |
| 2 | " Maintainer: Bram Moolenaar <Bram@vim.org> |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 3 | " Last Change: 2005 Feb 08 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4 | |
| 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 | |
| 10 | if !has("syntax") |
| 11 | finish |
| 12 | endif |
| 13 | |
| 14 | " let others know that syntax has been switched on |
| 15 | let syntax_on = 1 |
| 16 | |
| 17 | " Set the default highlighting colors. Use a color scheme if specified. |
| 18 | if exists("colors_name") |
| 19 | exe "colors " . colors_name |
| 20 | else |
| 21 | runtime! syntax/syncolor.vim |
| 22 | endif |
| 23 | |
| 24 | " Line continuation is used here, remove 'C' from 'cpoptions' |
| 25 | let s:cpo_save = &cpo |
| 26 | set cpo&vim |
| 27 | |
| 28 | " First remove all old syntax autocommands. |
| 29 | au! Syntax |
| 30 | |
| 31 | au Syntax * call s:SynSet() |
| 32 | |
| 33 | fun! 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 |
| 49 | endif |
| 50 | |
| 51 | if s != "" |
| 52 | " Load the syntax file(s) |
Bram Moolenaar | 4399ef4 | 2005-02-12 14:29:27 +0000 | [diff] [blame] | 53 | exe "runtime! syntax/" . s . ".vim syntax/" . s . "/*.vim" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 54 | endif |
| 55 | endfun |
| 56 | |
| 57 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 58 | " Handle adding doxygen to other languages (C, C++, IDL) |
| 59 | au Syntax cpp,c,idl |
| 60 | \ if (exists('b:load_doxygen_syntax') && b:load_doxygen_syntax) |
| 61 | \ || (exists('g:load_doxygen_syntax') && g:load_doxygen_syntax) |
| 62 | \ | runtime syntax/doxygen.vim |
| 63 | \ | endif |
| 64 | |
| 65 | au Syntax *doxygen |
| 66 | \ if exists("b:current_syntax") | finish | endif |
| 67 | \ | let syn = substitute(expand("<amatch>"), 'doxygen$', '', '') |
| 68 | \ | if syn != '' | exe 'runtime syntax/'.syn.'.vim' | endif |
| 69 | \ | if b:current_syntax !~ 'doxygen' | runtime syntax/doxygen.vim | endif |
| 70 | |
| 71 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 72 | " Source the user-specified syntax highlighting file |
| 73 | if exists("mysyntaxfile") && filereadable(expand(mysyntaxfile)) |
| 74 | execute "source " . mysyntaxfile |
| 75 | endif |
| 76 | |
| 77 | " Restore 'cpoptions' |
| 78 | let &cpo = s:cpo_save |
| 79 | unlet s:cpo_save |