Modified Vim with complete and proper highlighting on folds

View: New views
6 Messages — Rating Filter:   Alert me  

Modified Vim with complete and proper highlighting on folds

by Noel Henson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Everyone,

Here is my solution to the constant fold color. It allows a user script to
override the default folded-lines highlighting with whatever you want.  
I have added a new user function called foldhighlight (fdh, for short) that
contains a user script much like foldtext does.

But cooler than just allowing you to do something like:

setlocal foldhighlight=MyFoldHi(v:foldlevel)
" MyFoldHi(level) {{{2
" Determine the fold syntax of a fold.
function! MyFoldHi(level)
        return hlID("Folded".a:level)
endfunction

Which will set the highlight group to Folded0 to Foldedn. You will have to
update your colorscheme to include hl commands for these new highlight
groups.

Or... You can do something even cooler:

setlocal foldhighlight=MyFoldHi(v:foldstart)
" MyFoldHi(fold) {{{2
" Determine the fold syntax of a fold.
function! MyFoldHi(fold)
        return synID(a:fold,1,0)
endfunction

Which will have vim use the highlighting for the fold which is already
specified. In other words, body text will be green, folded or not. Tables
will be darkviolet, folded or not; etc. This way, no additional highlight
specifications are necessary for object we have already defined.

You can download a patched version of (g)vim for testing here:
www.vimoutliner.org/files/vim

For gvim, just ln -s vim gvim

You will also need the attached vo_base file to put into ~/.vim/ftplugin.

Let me know what you think.

Oh, and if you don't want to mess up your current vim. Just put the
downloaded vim somewhere else and call it with ./vim or ./gvim.

Happy VOing

Noel

--

------------------------------------------------------------------
  Noel Henson
  www.noels-lab.com Chips, firmware and embedded systems
  www.vimoutliner.org Work fast. Think well.


"#########################################################################
"# ftplugin/vo_base.vim: VimOutliner functions, commands and settings
"# version 0.3.0
"#   Copyright (C) 2001,2003 by Steve Litt (slitt@...)
"#   Copyright (C) 2004 by Noel Henson (noel@...)
"#
"#   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 2 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, write to the Free Software
"#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"#
"# Steve Litt, slitt@..., http://www.troubleshooters.com
"#########################################################################

" HISTORY {{{1
"#########################################################################
"#  V0.1.0 Pre-alpha
"#      Set of outliner friendly settings
"# Steve Litt, 5/28/2001
"# End of version 0.1.0
"#
"#  V0.1.1 Pre-alpha
"#      No change
"#
"# Steve Litt, 5/28/2001
"# End of version 0.1.1
"#
"#  V0.1.2 Pre-alpha
"# No Change
"# Steve Litt, 5/30/2001
"# End of version 0.1.2
"#  V0.1.3 Pre-alpha
"# No Change
"# Steve Litt, 5/30/2001
"# End of version 0.1.3
"#  V0.2.0
"# Noel Henson adds code for outliner-friendly expand and
"# collapse, comma comma commands, color coding, hooks for a
"# spellchecker, sorting, and date insertion.
"# Noel Henson, 11/24/2002
"# End of version 0.2.0
"#
"# All other history in the CHANGES file.
"# END OF HISTORY
"#
"#########################################################################


" Load the plugin {{{1
" Prevenet the plugin from being loaded twice
"if exists("b:did_ftplugin")
"  finish
"endif
"let b:did_ftplugin = 1
let b:current_syntax = "outliner"

" User Preferences {{{1

let maplocalleader = ",," " this is prepended to VO key mappings

setlocal ignorecase " searches ignore case
setlocal smartcase " searches use smart case

let use_space_colon=0

" End User Preferences

" VimOutliner Standard Settings {{{1
setlocal autoindent
setlocal backspace=2
setlocal wrapmargin=5
setlocal wrap!
setlocal tw=78
setlocal noexpandtab
setlocal nosmarttab
setlocal softtabstop=0
setlocal foldlevel=20
setlocal foldcolumn=1 " turns on "+" at the begining of close folds
setlocal tabstop=4 " tabstop and shiftwidth must match
setlocal shiftwidth=4 " values from 2 to 8 work well
setlocal foldmethod=expr
setlocal foldexpr=MyFoldLevel(v:lnum)
setlocal foldhighlight=MyFoldHi(v:foldstart)
setlocal indentexpr=
setlocal nocindent
setlocal iskeyword=@,39,45,48-57,_,129-255

" Vim Outliner Functions {{{1

if !exists("b:loaded_vimoutliner_functions")
let b:loaded_vimoutliner_functions=1

" Sorting {{{2
" IsParent(line) {{{3
" Return 1 if this line is a parent
function! IsParent(line)
        return (Ind(a:line)+1) == Ind(a:line+1)
endfunction
"}}}3
" FindParent(line) {{{3
" Return line if parent, parent line if not
function! FindParent(line)
        if IsParent(a:line)
                return a:line
        else
                let l:parentindent = Ind(a:line)-1
                let l:searchline = a:line
                while (Ind(l:searchline) != l:parentindent) && (l:searchline > 0)
                        let l:searchline = l:searchline-1
                endwhile
                return l:searchline
        endif
endfunction
"}}}3
" FindLastChild(line) {{{3
" Return the line number of the last decendent of parent line
function! FindLastChild(line)
        let l:parentindent = Ind(a:line)
        let l:searchline = a:line+1
        while Ind(l:searchline) > l:parentindent
                let l:searchline = l:searchline+1
        endwhile
        return l:searchline-1
endfunction
"}}}3
" MoveDown() {{{3
" Move a heading down by one
" Used for sorts and reordering of headings
function! MoveDown()
        call cursor(line("."),0)
        del x
        put x
endfunction
"}}}3
" DelHead() {{{3
" Delete a heading
" Used for sorts and reordering of headings
function! DelHead(line)
        let l:fstart = foldclosed(a:line)
        if l:fstart == -1
                let l:execstr = a:line . "del x"
        else
                let l:fend = foldclosedend(a:line)
                let l:execstr = l:fstart . "," . l:fend . "del x"
        endif
        exec l:execstr
endfunction
" PutHead() {{{3
" Put a heading
" Used for sorts and reordering of headings
function! PutHead(line)
        let l:fstart = foldclosed(a:line)
        if l:fstart == -1
                let l:execstr = a:line . "put x"
                exec l:execstr
        else
                let l:fend = foldclosedend(a:line)
                let l:execstr = l:fend . "put x"
                exec l:execstr
        endif
endfunction
"}}}3
" NextHead(line) {{{3
" Return line of next heanding
" Used for sorts and reordering of headings
function! NextHead(line)
        let l:fend = foldclosedend(a:line)
        if l:fend == -1
                return a:line+1
        else
                return l:fend+1
        endif
endfunction
"}}}3
" CompHead(line) {{{3
" Compare this heading and the next
" Return 1: next is greater, 0 next is same, -1 next is less
function! CompHead(line)
        let l:thisline=getline(a:line)
        let l:nextline=getline(NextHead(a:line))
        if l:thisline <# l:nextline
                return 1
        elseif l:thisline ># l:nextline
                return -1
        else
                return 0
        endif
endfunction
"}}}3
" Sort1Line(line) {{{3
" Compare this heading and the next and swap if out of order
" Dir is 0 for forward, 1 for reverse
" Return a 1 if a change was made
function! Sort1Line(line,dir)
        if (CompHead(a:line) == -1) && (a:dir == 0)
                call DelHead(a:line)
                call PutHead(a:line)
                return 1
        elseif (CompHead(a:line) == 1) && (a:dir == 1)
                call DelHead(a:line)
                call PutHead(a:line)
                return 1
        else
                return 0
        endif
endfunction
"}}}3
" Sort1Pass(start,end,dir) {{{3
" Compare this heading and the next and swap if out of order
" Dir is 0 for forward, 1 for reverse
" Return a 0 if no change was made, other wise return the change count
function! Sort1Pass(fstart,fend,dir)
        let l:i = a:fstart
        let l:changed = 0
        while l:i < a:fend
                let l:changed = l:changed + Sort1Line(l:i,a:dir)
                let l:i = NextHead(l:i)
        endwhile
        return l:changed
endfunction
"}}}3
" Sort(start,end,dir) {{{3
" Sort this range of headings
" dir: 0 = ascending, 1 = decending
function! SortRange(fstart,fend,dir)
        let l:changed = 1
        while l:changed != 0
                let l:changed = Sort1Pass(a:fstart,a:fend,a:dir)
        endwhile
endfunction
"}}}3
" SortChildren(dir) {{{3
" Sort the children of a parent
" dir: 0 = ascending, 1 = decending
function! SortChildren(dir)
        let l:oldcursor = line(".")
        let l:fstart = FindParent(line("."))
        let l:fend = FindLastChild(l:fstart)
        let l:fstart = l:fstart
        if l:fend <= l:fstart + 1
                return
        endif
        call append(line("$"),"Temporary last line for sorting")
        mkview
        let l:execstr = "set foldlevel=" . foldlevel(l:fstart)
        exec l:execstr
        call SortRange(l:fstart + 1,l:fend,a:dir)
        call cursor(line("$"),0)
        del x
        loadview
        call cursor(l:oldcursor,0)
endfunction
"}}}3
"}}}2
" MakeChars() {{{2
" Make a string of characters
" Used for strings of repeated characters
function! MakeChars(count,char)
        let i = 0
        let l:chars=""
        while i < a:count
                let l:chars = l:chars . a:char
                let i = i + 1
        endwhile
        return l:chars
endfunction
"}}}2
" MakeSpaces() {{{2
" Make a string of spaces
function! MakeSpaces(count)
        return MakeChars(a:count," ")
endfunction
"}}}2
" MakeDashes() {{{2
" Make a string of dashes
function! MakeDashes(count)
        return MakeChars(a:count,"-")
endfunction
"}}}2
" MyFoldText() {{{2
function! MyFoldText()
        let l:MySpaces = MakeSpaces(&sw)
        let l:line = getline(v:foldstart)
        let l:bodyTextFlag=0
        if l:line =~ "^\t* \\S" || l:line =~ "^\t*\:"
                let l:bodyTextFlag=1
                let l:MySpaces = MakeSpaces(&sw * (v:foldlevel-1))
                let l:line = l:MySpaces."[TEXT]"
        elseif l:line =~ "^\t*\;"
                let l:bodyTextFlag=1
                let l:MySpaces = MakeSpaces(&sw * (v:foldlevel-1))
                let l:line = l:MySpaces."[TEXT BLOCK]"
        elseif l:line =~ "^\t*\> "
                let l:bodyTextFlag=1
                let l:MySpaces = MakeSpaces(&sw * (v:foldlevel-1))
                let l:line = l:MySpaces."[USER]"
        elseif l:line =~ "^\t*\>"
                let l:ls = stridx(l:line,">")
                let l:le = stridx(l:line," ")
                if l:le == -1
                        let l:l = strpart(l:line, l:ls+1)
                else
                        let l:l = strpart(l:line, l:ls+1, l:le-l:ls-1)
                endif
                let l:bodyTextFlag=1
                let l:MySpaces = MakeSpaces(&sw * (v:foldlevel-1))
                let l:line = l:MySpaces."[USER ".l:l."]"
        elseif l:line =~ "^\t*\< "
                let l:bodyTextFlag=1
                let l:MySpaces = MakeSpaces(&sw * (v:foldlevel-1))
                let l:line = l:MySpaces."[USER BLOCK]"
        elseif l:line =~ "^\t*\<"
                let l:ls = stridx(l:line,"<")
                let l:le = stridx(l:line," ")
                if l:le == -1
                        let l:l = strpart(l:line, l:ls+1)
                else
                        let l:l = strpart(l:line, l:ls+1, l:le-l:ls-1)
                endif
                let l:bodyTextFlag=1
                let l:MySpaces = MakeSpaces(&sw * (v:foldlevel-1))
                let l:line = l:MySpaces."[USER BLOCK ".l:l."]"
        elseif l:line =~ "^\t*\|"
                let l:bodyTextFlag=1
                let l:MySpaces = MakeSpaces(&sw * (v:foldlevel-1))
                let l:line = l:MySpaces."[TABLE]"
        endif
        let l:sub = substitute(l:line,'\t',l:MySpaces,'g')
        let l:len = strlen(l:sub)
        let l:sub = l:sub . " " . MakeDashes(58 - l:len)
        let l:sub = l:sub . " (" . ((v:foldend + l:bodyTextFlag)- v:foldstart)
        if ((v:foldend + l:bodyTextFlag)- v:foldstart) == 1
                let l:sub = l:sub . " line)"
        else
                let l:sub = l:sub . " lines)"
        endif
        return l:sub
endfunction
"}}}2
" InsertDate() {{{2
" Insert today's date.
function! InsertDate(ba)
        let @x = strftime("%Y-%m-%d")
        if a:ba == "0"
                normal! "xp
        else
                normal! "xP
        endif
endfunction
"}}}2
" InsertSpaceDate() {{{2
" Insert a space, then today's date.
function! InsertSpaceDate()
        let @x = " "
        let @x = @x . strftime("%Y-%m-%d")
        normal! "xp
endfunction
"}}}2
" InsertTime() {{{2
" Insert the time.
function! InsertTime(ba)
        let @x = strftime("%T")
        if a:ba == "0"
                normal! "xp
        else
                normal! "xP
        endif
endfunction
"}}}2
" InsertSpaceTime() {{{2
" Insert a space, then the time.
function! InsertSpaceTime()
        let @x = " "
        let @x = @x . strftime("%T")
        normal! "xp
endfunction
"}}}2
" Ind(line) {{{2
" Determine the indent level of a line.
" Courtesy of Gabriel Horner
function! Ind(line)
        return indent(a:line)/&tabstop
endfunction
"}}}2
" BodyText(line) {{{2
" Determine the indent level of a line.
function! BodyText(line)
        return (match(getline(a:line),"^\t*:") == 0)
endfunction
"}}}2
" PreformattedBodyText(line) {{{2
" Determine the indent level of a line.
function! PreformattedBodyText(line)
        return (match(getline(a:line),"^\t*;") == 0)
endfunction
"}}}2
" PreformattedUserText(line) {{{2
" Determine the indent level of a line.
function! PreformattedUserText(line)
        return (match(getline(a:line),"^\t*<") == 0)
endfunction
"}}}2
" PreformattedUserTextLabeled(line) {{{2
" Determine the indent level of a line.
function! PreformattedUserTextLabeled(line)
        return (match(getline(a:line),"^\t*<\S") == 0)
endfunction
"}}}2
" PreformattedUserTextSpace(line) {{{2
" Determine the indent level of a line.
function! PreformattedUserTextSpace(line)
        return (match(getline(a:line),"^\t*< ") == 0)
endfunction
"}}}2
" UserText(line) {{{2
" Determine the indent level of a line.
function! UserText(line)
        return (match(getline(a:line),"^\t*>") == 0)
endfunction
"}}}2
" UserTextSpace(line) {{{2
" Determine the indent level of a line.
function! UserTextSpace(line)
        return (match(getline(a:line),"^\t*> ") == 0)
endfunction
"}}}2
" UserTextLabeled(line) {{{2
" Determine the indent level of a line.
function! UserTextLabeled(line)
        return (match(getline(a:line),"^\t*>\S") == 0)
endfunction
"}}}2
" PreformattedTable(line) {{{2
" Determine the indent level of a line.
function! PreformattedTable(line)
        return (match(getline(a:line),"^\t*|") == 0)
endfunction
"}}}2
" MyFoldHi(Line) {{{2
" Determine the fold syntax of a fold.
function! MyFoldHi(fold)
" return hlID("Folded".a:level)
        return synID(a:fold,1,0)
endfunction

" MyFoldLevel(Line) {{{2
" Determine the fold level of a line.
function! MyFoldLevel(line)
        let l:myindent = Ind(a:line)
        let l:nextindent = Ind(a:line+1)

        if BodyText(a:line)
                if (BodyText(a:line-1) == 0)
                        return '>'.(l:myindent+1)
                endif
                if (BodyText(a:line+1) == 0)
                        return '<'.(l:myindent+1)
                endif
                return (l:myindent+1)
        elseif PreformattedBodyText(a:line)
                if (PreformattedBodyText(a:line-1) == 0)
                        return '>'.(l:myindent+1)
                endif
                if (PreformattedBodyText(a:line+1) == 0)
                        return '<'.(l:myindent+1)
                endif
                return (l:myindent+1)
        elseif PreformattedTable(a:line)
                if (PreformattedTable(a:line-1) == 0)
                        return '>'.(l:myindent+1)
                endif
                if (PreformattedTable(a:line+1) == 0)
                        return '<'.(l:myindent+1)
                endif
                return (l:myindent+1)
        elseif PreformattedUserText(a:line)
                if (PreformattedUserText(a:line-1) == 0)
                        return '>'.(l:myindent+1)
                endif
                if (PreformattedUserTextSpace(a:line+1) == 0)
                        return '<'.(l:myindent+1)
                endif
                return (l:myindent+1)
        elseif PreformattedUserTextLabeled(a:line)
                if (PreformattedUserTextLabeled(a:line-1) == 0)
                        return '>'.(l:myindent+1)
                endif
                if (PreformattedUserText(a:line+1) == 0)
                        return '<'.(l:myindent+1)
                endif
                return (l:myindent+1)
        elseif UserText(a:line)
                if (UserText(a:line-1) == 0)
                        return '>'.(l:myindent+1)
                endif
                if (UserTextSpace(a:line+1) == 0)
                        return '<'.(l:myindent+1)
                endif
                return (l:myindent+1)
        elseif UserTextLabeled(a:line)
                if (UserTextLabeled(a:line-1) == 0)
                        return '>'.(l:myindent+1)
                endif
                if (UserText(a:line+1) == 0)
                        return '<'.(l:myindent+1)
                endif
                return (l:myindent+1)
        else
                if l:myindent < l:nextindent
                        return '>'.(l:myindent+1)
                endif
                if l:myindent > l:nextindent
                        return (l:myindent)
                endif
                return l:myindent
        endif
endfunction
"}}}2
" Spawn(line) {{{2
" Execute an executable line
" Courtesy of Steve Litt
if !exists("loaded_steveoutliner_functions")
        let loaded_steveoutliner_functions=1
function! Spawn()
                let theline=getline(line("."))
                let idx=matchend(theline, "_exe_\\s*")
                if idx == -1
                        echo "Not an executable line"
                else
                        let command=strpart(theline, idx)
                        let command="!".command
                        exec command
                endif
endfunction
endif
"}}}2
" This should be a setlocal but that doesn't work when switching to a new .otl file
" within the same buffer. Using :e has demonstrates this.
set foldtext=MyFoldText()

setlocal fillchars=|,

endif " if !exists("loaded_vimoutliner_functions")
" End Vim Outliner Functions

" Vim Outliner Key Mappings {{{1
" insert the date
nmap <buffer> <localleader>d $:call InsertSpaceDate()<cr>
imap <buffer> <localleader>d ~<esc>x:call InsertDate(0)<cr>a
nmap <buffer> <localleader>D ^:call InsertDate(1)<cr>a <esc>


" insert the time
nmap <buffer> <localleader>t $:call InsertSpaceTime()<cr>
imap <buffer> <localleader>t ~<esc>x:call InsertTime(0)<cr>a
nmap <buffer> <localleader>T ^:call InsertTime(1)<cr>a <esc>

" sort a list naturally
map <buffer> <localleader>s :call SortChildren(0)<cr>
" sort a list, but you supply the options
map <buffer> <localleader>S :call SortChildren(1)<cr>

" invoke the file explorer
map <buffer> <localleader>f :e .<cr>
imap <buffer> <localleader>f :e .<cr>

" Insert a fence for segemented lists.
" I also use this divider to create a <hr> when converting to html
map <buffer> <localleader>- o----------------------------------------0
imap <buffer> <localleader>- ----------------------------------------<cr>

" switch document between the two types of bodytext styles
if use_space_colon == 1
  "   First, convert document to the marker style
  map <localleader>b :%s/\(^\t*\) :/\1/e<cr>:%s/\(^\t*\) /\1 : /e<cr>:let @/=""<cr>
  "   Now, convert document to the space style
  map <localleader>B :%s/\(^\t*\) :/\1/e<cr>:let @/=""<cr>
else
  "   First, convert document to the marker style
  map <localleader>b :%s/\(^\t*\):/\1/e<cr>:%s/\(^\t*\) /\1: /e<cr>:let @/=""<cr>
  "   Now, convert document to the space style
  map <localleader>B :%s/\(^\t*\):/\1/e<cr>:let @/=""<cr>
endif

" Steve's additional mappings start here
map <buffer>   <C-K>         <C-]>
map <buffer>   <C-N>         <C-T>
map <buffer>   <localleader>0           :set foldlevel=99999<CR>
map <buffer>   <localleader>9           :set foldlevel=8<CR>
map <buffer>   <localleader>8           :set foldlevel=7<CR>
map <buffer>   <localleader>7           :set foldlevel=6<CR>
map <buffer>   <localleader>6           :set foldlevel=5<CR>
map <buffer>   <localleader>5           :set foldlevel=4<CR>
map <buffer>   <localleader>4           :set foldlevel=3<CR>
map <buffer>   <localleader>3           :set foldlevel=2<CR>
map <buffer>   <localleader>2           :set foldlevel=1<CR>
map <buffer>   <localleader>1           :set foldlevel=0<CR>
map <buffer>   <localleader>,,          :source $HOME/.vimoutliner/outliner.vim<CR>
map! <buffer>  <localleader>w           <Esc>:w<CR>a
nmap <buffer>   <localleader>e :call Spawn()<cr>
" Steve's additional mappings end here

" Placeholders for already assigned but non-functional commands
map <buffer> <localleader>h :echo "VimOutliner reserved command: ,,h"<cr>
imap <buffer> <localleader>h :echo "VimOutliner reserved command: ,,h"<cr>
map <buffer> <localleader>H :echo "VimOutliner reserved command: ,,H"<cr>
imap <buffer> <localleader>H :echo "VimOutliner reserved command: ,,H"<cr>

" End of Vim Outliner Key Mappings }}}1
" Menu Entries {{{1
" VO menu
amenu &VO.Expand\ Level\ &1 :set foldlevel=0<cr>
amenu &VO.Expand\ Level\ &2 :set foldlevel=1<cr>
amenu &VO.Expand\ Level\ &3 :set foldlevel=2<cr>
amenu &VO.Expand\ Level\ &4 :set foldlevel=3<cr>
amenu &VO.Expand\ Level\ &5 :set foldlevel=4<cr>
amenu &VO.Expand\ Level\ &6 :set foldlevel=5<cr>
amenu &VO.Expand\ Level\ &7 :set foldlevel=6<cr>
amenu &VO.Expand\ Level\ &8 :set foldlevel=7<cr>
amenu &VO.Expand\ Level\ &9 :set foldlevel=8<cr>
amenu &VO.Expand\ Level\ &All :set foldlevel=99999<cr>
amenu &VO.-Sep1- :
amenu &VO.&Tools.&otl2thml\.py\ (otl2html\.py\ thisfile\ -S\ nnnnnn\.css\ >\ thisfile\.html) :!otl2html.py -S nnnnnn.css % > %.html<cr>
amenu &VO.&Tools.&myotl2thml\.sh\ (myotl2html\.sh\ thisfile) :!myotl2html.sh %<cr>
amenu &VO.-Sep2- :
amenu &VO.&Color\ Scheme :popup Edit.Color\ Scheme<cr>
amenu &VO.-Sep3- :
amenu &VO.&Help.&Index :he vo<cr>
amenu &VO.&Help.&,,\ Commands :he vo-command<cr>
amenu &VO.&Help.&Checkboxes :he vo-checkbox<cr>
amenu &VO.&Help.&Hoisting :he vo-hoisting<cr>
amenu &Help.-Sep1- :
" Help menu additions
amenu &Help.&Vim\ Outliner.&Index :he vo<cr>
amenu &Help.&Vim\ Outliner.&,,\ Commands :he vo-command<cr>
amenu &Help.&Vim\ Outliner.&Checkboxes :he vo-checkbox<cr>
amenu &Help.&Vim\ Outliner.&Hoisting :he vo-hoisting<cr>
"}}}1
" Auto-commands {{{1
if !exists("autocommand_vo_loaded")
        let autocommand_vo_loaded = 1
        au BufNewFile,BufRead *.otl                     setf vo_base
" au CursorHold *.otl                             syn sync fromstart
        set updatetime=500
endif
"}}}1

" this command needs to be run every time so Vim doesn't forget where to look
setlocal tags^=$HOME/.vimoutliner/vo_tags.tag

" Added an indication of current syntax as per Dillon Jones' request
let b:current_syntax = "outliner"
 
" Personal configuration options files as per Matej Cepl
setlocal runtimepath+=$HOME/.vimoutliner,$HOME
ru! .vimoutlinerrc vimoutlinerrc
" More sophisticated version of the modules loading; thanks to Preben 'Peppe'
" Guldberg for telling me how to split string and make semi-lists with vim.
" - Matej Cepl
let s:tmp = g:vo_modules_load . ':'
let s:idx = stridx(s:tmp, ':')

while (s:idx != -1)
    let s:part = strpart(s:tmp, 0, s:idx)
    let s:tmp = strpart(s:tmp, s:idx + 1)
    let s:idx = stridx(s:tmp, ':')
    "exec 'ru! ftplugin/vo_' . part . '.vim'
    exec "runtime! plugins/vo_" . s:part . ".vim"
endwhile

" The End
" vim600: set foldmethod=marker foldlevel=0:

_______________________________________________
VimOutliner mailing list
VimOutliner@...
http://www.lists.vimoutliner.org/mailman/listinfo

Re: Modified Vim with complete and proper highlighting on folds

by Noel Henson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Modified patch. There was a bug in foldhidef(); one too many levels of
indirection. It now just returns the HLF_FL constant.

Noel

--

------------------------------------------------------------------
  Noel Henson
  www.noels-lab.com Chips, firmware and embedded systems
  www.vimoutliner.org Work fast. Think well.


[foldhi.patch]

diff -rpuN original/eval.c new/eval.c
--- original/eval.c 2009-09-13 03:36:29.000000000 -0700
+++ new/eval.c 2009-09-13 11:40:07.000000000 -0700
@@ -537,6 +537,7 @@ static void f_foldclosedend __ARGS((typv
 static void f_foldlevel __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_foldtext __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_foldtextresult __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_foldhidef __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_foreground __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_function __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_garbagecollect __ARGS((typval_T *argvars, typval_T *rettv));
@@ -1725,6 +1726,56 @@ eval_foldexpr(arg, cp)
 
     return retval;
 }
+
+/*
+ * Evaluate 'foldhighlight'.  Returns the fold hlID
+ */
+    int
+/* eval_foldhighlight(arg)*/
+eval_foldhighlight(fdt, lnum, lnume, foldinfo)
+    char_u *fdt;
+    linenr_T lnum, lnume;
+    foldinfo_T *foldinfo;
+
+{
+    typval_T tv;
+    int retval;
+    int         level;
+    int use_sandbox = was_set_insecurely((char_u *)"foldhighlight",
+   OPT_LOCAL);
+
+    /* Set "v:foldstart" and "v:foldend". */
+    set_vim_var_nr(VV_FOLDSTART, lnum);
+    set_vim_var_nr(VV_FOLDEND, lnume);
+
+    /* Set "v:foldlevel" to "level". */
+    level = foldinfo->fi_level;
+    if (level > 50)
+        level = 50;
+    set_vim_var_nr(VV_FOLDLEVEL, (long)level);
+
+    ++emsg_off;
+    if (use_sandbox)
+ ++sandbox;
+    ++textlock;
+    if (eval0(fdt, &tv, NULL, TRUE) == FAIL)
+ retval = syn_get_foldhidef();
+    else
+    {
+ /* If the result is a number, just return the number. */
+ if (tv.v_type == VAR_NUMBER)
+    retval = tv.vval.v_number;
+ else
+    retval = syn_get_foldhidef();
+ clear_tv(&tv);
+    }
+    --emsg_off;
+    if (use_sandbox)
+ --sandbox;
+    --textlock;
+
+    return retval;
+}
 #endif
 
 /*
@@ -7496,6 +7547,7 @@ static struct fst
     {"foldlevel", 1, 1, f_foldlevel},
     {"foldtext", 0, 0, f_foldtext},
     {"foldtextresult", 1, 1, f_foldtextresult},
+    {"foldhidef", 0, 0, f_foldhidef},
     {"foreground", 0, 0, f_foreground},
     {"function", 1, 1, f_function},
     {"garbagecollect", 0, 1, f_garbagecollect},
@@ -10162,6 +10214,17 @@ f_foldlevel(argvars, rettv)
 }
 
 /*
+ * "foldhidef()" function
+ */
+    static void
+f_foldhidef(argvars, rettv)
+    typval_T *argvars;
+    typval_T *rettv;
+{
+ rettv->vval.v_number = HLF_FL;
+}
+
+/*
  * "foldtext()" function
  */
 /*ARGSUSED*/
diff -rpuN original/option.c new/option.c
--- original/option.c 2009-09-13 03:36:29.000000000 -0700
+++ new/option.c 2009-09-13 03:36:44.000000000 -0700
@@ -200,6 +200,7 @@
 # ifdef FEAT_EVAL
 #  define PV_FDE OPT_WIN(WV_FDE)
 #  define PV_FDT OPT_WIN(WV_FDT)
+#  define PV_FDH OPT_WIN(WV_FDH)
 # endif
 # define PV_FMR OPT_WIN(WV_FMR)
 #endif
@@ -1125,6 +1126,15 @@ static struct vimoption
     {(char_u *)NULL, (char_u *)0L}
 # endif
     },
+    {"foldhighlight",     "fdh",  P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
+# ifdef FEAT_EVAL
+    (char_u *)VAR_WIN, PV_FDH,
+    {(char_u *)"foldhidef()", (char_u *)NULL}
+# else
+    (char_u *)NULL, PV_NONE,
+    {(char_u *)NULL, (char_u *)0L}
+# endif
+    },
 #endif
     {"formatexpr", "fex",   P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
 #ifdef FEAT_EVAL
@@ -5249,6 +5259,7 @@ insecure_flag(opt_idx, opt_flags)
 # ifdef FEAT_FOLDING
     case PV_FDE: return &curwin->w_p_fde_flags;
     case PV_FDT: return &curwin->w_p_fdt_flags;
+    case PV_FDH: return &curwin->w_p_fdh_flags;
 # endif
 # ifdef FEAT_BEVAL
     case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
@@ -9024,6 +9035,7 @@ get_varp(p)
 # ifdef FEAT_EVAL
  case PV_FDE: return (char_u *)&(curwin->w_p_fde);
  case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
+ case PV_FDH: return (char_u *)&(curwin->w_p_fdh);
 # endif
  case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
 #endif
diff -rpuN original/option.h new/option.h
--- original/option.h 2009-09-13 03:36:33.000000000 -0700
+++ new/option.h 2009-09-13 03:36:49.000000000 -0700
@@ -1032,6 +1032,7 @@ enum
 # ifdef FEAT_EVAL
     , WV_FDE
     , WV_FDT
+    , WV_FDH
 # endif
     , WV_FMR
 #endif
diff -rpuN original/screen.c new/screen.c
--- original/screen.c 2009-09-13 03:36:29.000000000 -0700
+++ new/screen.c 2009-09-13 03:36:44.000000000 -0700
@@ -2171,7 +2171,11 @@ fold_line(wp, fold_count, foldinfo, lnum
 #endif
 
     /* Set all attributes of the 'number' column and the text */
-    RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col);
+    /* RL_MEMSET(col, syn_get_foldhi(eval_foldhighlight(wp->w_p_fdh)), W_WIDTH(wp) - col);*/
+    RL_MEMSET(col, syn_get_foldhi(eval_foldhighlight(wp->w_p_fdh, lnum, lnume,foldinfo)),
+                                                     W_WIDTH(wp) - col);
+   /* RL_MEMSET(col, eval_foldhighlight(wp->w_p_fdh), W_WIDTH(wp) - col);
+    */
 
 #ifdef FEAT_SIGNS
     /* If signs are being displayed, add two spaces. */
@@ -2186,10 +2190,10 @@ fold_line(wp, fold_count, foldinfo, lnum
     if (wp->w_p_rl)
  /* the line number isn't reversed */
  copy_text_attr(off + W_WIDTH(wp) - len - col,
- (char_u *)"  ", len, hl_attr(HLF_FL));
+ (char_u *)"  ", len, syn_get_foldhidef());
     else
 # endif
- copy_text_attr(off + col, (char_u *)"  ", len, hl_attr(HLF_FL));
+ copy_text_attr(off + col, (char_u *)"  ", len, syn_get_foldhidef());
     col += len;
  }
     }
@@ -2212,10 +2216,10 @@ fold_line(wp, fold_count, foldinfo, lnum
     if (wp->w_p_rl)
  /* the line number isn't reversed */
  copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len,
-     hl_attr(HLF_FL));
+     syn_get_foldhidef());
     else
 #endif
- copy_text_attr(off + col, buf, len, hl_attr(HLF_FL));
+ copy_text_attr(off + col, buf, len, syn_get_foldhidef());
     col += len;
  }
     }
diff -rpuN original/structs.h new/structs.h
--- original/structs.h 2009-09-13 03:36:33.000000000 -0700
+++ new/structs.h 2009-09-13 03:36:49.000000000 -0700
@@ -157,6 +157,8 @@ typedef struct
 # define w_p_fde w_onebuf_opt.wo_fde /* 'foldexpr' */
     char_u *wo_fdt;
 #  define w_p_fdt w_onebuf_opt.wo_fdt /* 'foldtext' */
+    char_u *wo_fdh;
+#  define w_p_fdh w_onebuf_opt.wo_fdh /* 'foldhighlight' */
 # endif
     char_u *wo_fmr;
 # define w_p_fmr w_onebuf_opt.wo_fmr /* 'foldmarker' */
@@ -1946,6 +1948,7 @@ struct window_S
 #ifdef FEAT_EVAL
     long_u w_p_fde_flags;    /* flags for 'foldexpr' */
     long_u w_p_fdt_flags;    /* flags for 'foldtext' */
+    long_u w_p_fdh_flags;    /* flags for 'foldhilight' */
 #endif
 
     /* transform a pointer to a "onebuf" option into a "allbuf" option */
diff -rpuN original/syntax.c new/syntax.c
--- original/syntax.c 2009-09-13 03:36:29.000000000 -0700
+++ new/syntax.c 2009-09-13 11:40:14.000000000 -0700
@@ -6187,6 +6187,27 @@ syn_get_foldlevel(wp, lnum)
     }
     return level;
 }
+
+/*
+ * Function called to get the default highlight ID for folded lines
+ */
+    int
+syn_get_foldhidef()
+{
+    return hl_attr(HLF_FL);
+}
+
+/*
+ * Function called to get the user-defined highlight ID for folded lines
+ */
+    int
+syn_get_foldhi(hlid)
+{
+    if (hlid<HLF_COUNT)
+ return hl_attr(hlid);
+    else
+ return syn_id2attr(hlid);
+}
 #endif
 
 #endif /* FEAT_SYN_HL */


_______________________________________________
VimOutliner mailing list
VimOutliner@...
http://www.lists.vimoutliner.org/mailman/listinfo

Re: Modified Vim with complete and proper highlighting on folds

by Herbert Sitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Noel Henson wrote:
Modified patch. There was a bug in foldhidef(); one too many levels of
indirection. It now just returns the HLF_FL constant.

Noel
Noel  -- Thanks, that looks like a nifty solution.  At one point I had looked into trying to create custom function in eval.c but didn't have the c knowledge to easily grok what was going on.  Still don't, but I'll learn something from trying to figure out how you did it.  I'll look forward to trying this out.  Hopefully it's something they'll accept into vim core.  -- Herb

Re: Modified Vim with complete and proper highlighting on folds

by Noel Henson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 15 September 2009, hsitz wrote:

> Noel Henson wrote:
> > Modified patch. There was a bug in foldhidef(); one too many levels of
> > indirection. It now just returns the HLF_FL constant.
> >
> > Noel
>
> Noel  -- Thanks, that looks like a nifty solution.  At one point I had
> looked into trying to create custom function in eval.c but didn't have
> the c knowledge to easily grok what was going on.  Still don't, but I'll
> learn something from trying to figure out how you did it.  I'll look
> forward to trying this out.  Hopefully it's something they'll accept
> into vim core.  -- Herb

Herb,

Let me know when you get ready to try it. I'm going to compile against
newer sources. The 7.2 version has the maximum number of folds set in two
different places and to two different values. Also, I have a bug in the vim
I uploaded. I added a visible function to a function list in
a non-alphabetic way. If you like, I'll even compile a special version of
vim for you.

As far as being accepted into the vim core. I doubt that will happen.  
Nobody on the vim-dev list is interested. I couldn't get any suggestions on
the best way to implement the change and the completed patch has been
completely ignored. I have a feeling that this patch will go the way of
Vince Negri's conceal patch; a great new feature but not enough need.

I'll probably just offer the patch on the VO site for those interested;
apparently just a very few of us VO users.

Hopefully the new way of hoisting will be of more interest.

Noel

--

------------------------------------------------------------------
  Noel Henson
  www.noels-lab.com Chips, firmware and embedded systems
  www.vimoutliner.org Work fast. Think well.

_______________________________________________
VimOutliner mailing list
VimOutliner@...
http://www.lists.vimoutliner.org/mailman/listinfo

RE: Modified Vim with complete and proper highlighting on folds

by Zdenek Sekera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Noel,

> The 7.2 version has the maximum number of folds set in
> two
> different places and to two different values

What??? That shouldn't be. Did you tell Bram (or vim-dev)?
If not, please do.

Cheers and smiles,


---Zdenek

-----------------------------------------------------
Zdenek Sekera              | zdenek.sekera@...
LHC Computing Grid Project | +41 76 487 4971 (mobile)
CERN, IT Department        | +41 22 767 1068 (office)
CH-1211, Geneva 23, Switzerland


_______________________________________________
VimOutliner mailing list
VimOutliner@...
http://www.lists.vimoutliner.org/mailman/listinfo

Re: Modified Vim with complete and proper highlighting on folds

by Noel Henson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 15 September 2009, Zdenek Sekera wrote:

> Noel,
>
> > The 7.2 version has the maximum number of folds set in
> > two
> > different places and to two different values
>
> What??? That shouldn't be. Did you tell Bram (or vim-dev)?
> If not, please do.
>
> Cheers and smiles,
>
>
> ---Zdenek
>

I haven't mentioned it yet. I has probably been fixed in the newer sources.  
I built against 7.2.000. I'm heading out of town on business but when I get
back I want to build against the newest sources. I'll check to see if the
bug is still there.

Noel

--

------------------------------------------------------------------
  Noel Henson
  www.noels-lab.com Chips, firmware and embedded systems
  www.vimoutliner.org Work fast. Think well.

_______________________________________________
VimOutliner mailing list
VimOutliner@...
http://www.lists.vimoutliner.org/mailman/listinfo