On Fri, 13 Aug 2010, Jeri Raye wrote:

> I can imagine something like this:
> 
> sy match vhdlFoo "\<foo\>"
> sy match vhdlBar "\<bar\>"
> 
> sy region vhdlFooBarFold
>       \ start=""
>       \ end=""
>       \ fold transparent
>       \ keepend
> 
> What to fill in for the start and end parameter of the region, to get
> the folding as:
> +--  x lines: foo ------------------------------------------------------
> 
> 

The attached file seems to do what you want, w.r.t. both the multiple 
block keywords, and not modifying the original 
$VIMRUNTIME/syntax/vhdl.vim.  To use it, put it in your 
~/.vim/after/syntax/ directory (create if needed) as 'vhdl.vim'.

For some insight into how it works, do:
:echo orig_syntax
:syn list vhdlStatement

Essentially, the file gets the original vhdlStatement list of keywords, 
and recreates it, filtering out the keywords you want to use as folding 
block indicators.  (The attached file uses the list: 'if', 'else', 
'entity', and 'zab'.  You should be able to modify block_keywords to 
whatever you want.)

Then it does two things: one is to fill in the answer to your question 
above.  Instead of creating the individual matches/regions 'vhdlFoo', 
'vhdlBar', and 'vhdlFooBarFold', it just adds them as matches in 
vhdlStatement, and adds the single region 'vhdlBlockFold':

syn region vhdlFooBarFold
       \ start="\z(\<foo\|bar\>\)"
       \ end="\<end\s\+\z1"
       ...etc...

-- 
Best,
Ben

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
redir => original_syntax
silent syn list vhdlStatement
redir END

syn clear vhdlStatement
hi def link vhdlStatement Statement

let block_keywords = [ 'if', 'else', 'entity', 'zab' ]
for line in split(original_syntax, "\n")
   let skippable = 0
   for pat in ['^---','^\s*$','^\s\+match\>','^\s\+links to']
      if match(line, pat) >= 0
         let skippable += 1
      endif
   endfor
   if !skippable
      let line=substitute(line, '^vhdlStatement\s\+xxx', '', '')
      let line=substitute(line, '^\s\+', '', '')
      for kword in filter(split(line, '\s\+'), "index(block_keywords, v:val) < 
0")
         exe ":syn keyword vhdlStatement ".kword
      endfor
   endif
endfor

let match_block_keywords = '\<'.join(block_keywords,'\|').'\>'
exe ':syn match vhdlStatement /'.match_block_keywords.'/'
exe ':syn region vhdlBlockFold start=/\z('.match_block_keywords.'\)/ 
end=/\<end\s\+\z1/ fold transparent keepend'

Reply via email to