packages feed

mcm-0.6.5.0: mcm.vim

" Language:    mcm
" Maintainer:  Anthony Doggett (MCM@interfaces.org.uk)
"
" MCM - Machine Configuration Manager; manages the contents of files and directories
" Copyright (c) 2013-2017 Anthony Doggett <mcm@interfaces.org.uk>
"
" Licence:
"     This program is free software: you can redistribute it and/or modify
"     it under the terms of the GNU General Public License as published by
"     the Free Software Foundation, either version 3 of the License, or
"     (at your option) any later version.
"
"     This program is distributed in the hope that it will be useful,
"     but WITHOUT ANY WARRANTY; without even the implied warranty of
"     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
"     GNU General Public License for more details.
"
"     You should have received a copy of the GNU General Public License
"     along with this program.  If not, see <http://www.gnu.org/licenses/>.
"
" Installation Instructions:
"
" 1) Place this file in $HOME/.vim/syntax/
"
" 2) Create the file $HOME/.vim/filetype.vim if it does not already exist.
"    Insert the following:
"
"    " My filetype file
"    if exists("did_load_filetypes")
"            finish
"    endif
"    augroup filetypedetect
"            au! BufRead,BufNewFile *.mcm         setfiletype mcm
"    augroup END


" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

" All patterns match one-line only
syn sync minlines=1 maxlines=1

syn match tagError "^\t*\zs[ ]\+"
syn match tagComment "^[ ]*#.*"
syn match tagDoubleAt "@@"
syn match tagDoubleAt "@@" contained
syn match tagCase "^\t\(case [a-z][A-Za-z0-9_]*\|when .\+\)$"
syn match tagDefine "^define "
syn match tagMCM "^MCM "
syn match tagImport "^import "
syn match tagBuiltin "^\t\(File\|Fragment\|Absent\|Symlink\|Dir\)\ze\($\| \)" contained
syn match tagLocalDef "^\t\.[a-z@][A-Za-z0-9_@]*\ze\($\| \)" contained
syn match tagImportedDef "^\t[A-Z][A-Za-z0-9_]*\.[a-z@][A-Za-z0-9_@]*\ze\($\| \)" contained
syn match tagContaVar "@[0-9a-zA-Z_]\+" contained
syn match tagContaVar "@([0-9a-zA-Z_]\+)" contained
syn match tagVariable "@[0-9a-zA-Z_]\+"
syn match tagVariable "@([0-9a-zA-Z_]\+)"
" The following line doesn't work right.  It's as though every line needs
" a space in it for a match to work.
syn match tagVariable "^\(\t\)\?let\( \|$\)"
syn match tagVariable "^\(\t\)\?let [0-9a-zA-Z_]\+ =\( \|$\)"
syn match tagVariable "^\(\t\)\?let [0-9a-zA-Z_]\+ =\ze\$.*" contains=tagCommandGroup
syn match tagVariable "^\t\t[0-9a-zA-Z_]\+ =\( \|$\)"
syn match tagVariable "^\t\t[0-9a-zA-Z_]\+ =\ze\$.*" contains=tagCommandGroup
syn match tagVariable "^\t\t\t[0-9a-zA-Z_]\+ =\( \|$\)"
syn match tagVariable "^\t\t\t[0-9a-zA-Z_]\+ =\ze\$.*" contains=tagCommandGroup
" See vim's help for "syn-define" :)
" And ":h pattern"
syn match tagInLine "^\t\t[a-z][a-z0-9A-Z_]*[:>]\([$ ].*\|$\)" contains=tagInlineArg,tagContaVar,tagDoubleAt
syn match tagInLine "^\t\t\t[+\\]\($\|[$ ].*\)" contains=tagContinuation,tagContaVar,tagDoubleAt
syn match tagContinuation "^\t\t\t[+\\]\($\| \).*" contained
syn match tagContinuation "^\t\t\t[+\\]\zs\$.*" contained contains=tagCommandGroup
syn match tagCommandGroup "\$\<\(fragments\|rawfile\|rawstring\|file\|string\)(.*)$" contained contains=tagCommand
syn match tagWordCommandGroup "\$\<\(fragments\|rawfile\|rawstring\|file\|string\)(\S*)" contained contains=tagCommand
syn match tagCommand "\$\<\(fragments\|rawfile\|rawstring\|file\|string\)(" contained
syn match tagCommand ")$" contained
syn match tagCommand "," contained
syn match tagContent "> \zs\S\+" contained
syn match tagContent ": \zs.*" contained
syn match tagContent ">\zs\$\S\+\ze" contained contains=tagWordCommandGroup
syn match tagContent ":\zs\$.*" contained contains=tagCommandGroup
syn match tagInlineArg "[\t ][a-z][0-9a-zA-Z_]*\(>[$ ]\S\+\|:\($\|[$ ].*\)\)" contained contains=tagContent
syn match tagCallingLine "^\t\S\+\( [a-z][a-zA-Z0-9_]*>[$ ]\S\+\)*\( [a-z][a-zA-Z0-9_]*:[$ ].*\)\?$" contains=tagInlineArg,tagBuiltin,tagLocalDef,tagImportedDef

syn region myFold start="^\(define\|\nimport\) " end="^$" transparent fold
set foldmethod=syntax

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_drchip_tags_inits")
  if version < 508
    let did_drchip_tags_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink tagBuiltin Identifier
  HiLink tagLocalDef Identifier
  HiLink tagImportedDef Identifier
  HiLink tagImport PreProc
  HiLink tagMCM Statement
  HiLink tagVariable Number
  HiLink tagContaVar Number
  HiLink tagCase Type
  HiLink tagDefine Type
  HiLink tagDoubleAt Todo
  HiLink tagInlineArg Comment
  HiLink tagComment Comment
  HiLink tagContinuation Special
  HiLink tagCommand Statement
  HiLink tagContent Special
  HiLink tagError Error

  delcommand HiLink
endif

if !exists("g:qualifiedtagjump")
 function MCM_QualifiedTagJump()
   let save_cursor = getcurpos()
   let cWord = expand("<cWORD>")
   let id = matchstr(cWord, "\\.\\zs\\S\\+\\ze")
   let prefix = matchstr(cWord, "^[^.]\\+")
   call cursor(1,1)
   let mcmline = search('^MCM ','n')
   let thispackage = matchstr(getline(mcmline), "^MCM \\zs\\S\\+\\ze")
   let importline = search('^import \S\+ as ' . prefix . '$', 'nW')
   let fullnameprefix = matchstr(getline(importline), "^import \\zs\\S\\+\\ze")
   if prefix == ""
     let fulltag = thispackage . "." . id
   elseif id == ""
     let fulltag = fullnameprefix
   else
     let fulltag = fullnameprefix . "." . id
   endif
   call setpos('.', save_cursor)
   execute 'tag' fnameescape(fulltag)
 endfunction
 let g:qualifiedtagjump = "mcm"
endif
map <C-]> :call MCM_QualifiedTagJump()<Return>

setlocal iskeyword=a-z,A-Z,_,48-57
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal tabstop=4
setlocal comments=b:+,b:#,b:\
setlocal formatoptions-=t formatoptions+=rojql

let b:current_syntax = "mcm"