Hi Pablo!

On Di, 06 Jul 2010, Pablo Giménez wrote:

> I am trying to make more clear my indent levels when programming python.
> In many editors you can set to visualize indentation level in your
> text, at every level a character, usually a point is shown, so you
> onlu need to count the number of preceding points to know your indent
> level.
> I am already using cream-showinvisibles plugin:
> http://vim.sourceforge.net/scripts/script.php?script_id=363
> But this one don't show indentation levels visually.

I am not sure I understand correctly. I think you could use the signs 
feature to display the numerical indent level by calculating the 
indentlevel by using indent()/&sts for each line.

<a little bit later…>

Here is a sample plugin. This is a very rough version, that was ripped 
off of one of my plugins (changesPlugin: 
http://www.vim.org/scripts/script.php?script_id=3052)

regards,
Christian
-- 
Urlaub ohne Unterlaß wäre ein gutes Training für den Aufenthalt in
der Hölle.
                -- George Bernard Shaw

-- 
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
" IndentSigns.vim - Using Signs for indenting level
" ---------------------------------------------------------------
" Version:      0.1
" Authors:      Christian Brabandt <[email protected]>
" Last Change: Tue, 19 July 2010 21:16:28 +0200

" Script:  
" License: VIM License
" Documentation: N/A
" GetLatestVimScripts: 

" Documentation: N/A

" Init Folkore "{{{1
if &cp || exists("g:loaded_changes")
 finish
endif
let g:loaded_indentSigns   = 1
let s:keepcpo              = &cpo
set cpo&vim

" Check preconditions"{{{1
fu! s:Check()
        " Check for the existence of unsilent
        if exists(":unsilent")
                let s:echo_cmd='unsilent echomsg'
        else
                let s:echo_cmd='echomsg'
        endif

        if !has("signs")
                call add(s:msg, "Sign Support support not available in your Vim 
version.")
                call add(s:msg, "IndentSigns plugin will not be working!")
                call s:WarningMsg()
                throw 'indentSigns:abort'
        endif

        let s:sign_prefix = 99
        let s:id_hl               = "DiffAdd"
endfu

fu! s:WarningMsg()"{{{1
        redraw!
        if !empty(s:msg)
                let msg=["IndentSigns.vim: " . s:msg[0]] + s:msg[1:]
                echohl WarningMsg
                for mess in msg
                        exe s:echo_cmd "mess"
                endfor

                echohl Normal
                let v:errmsg=msg[0]
        endif
endfu

fu! s:Init()"{{{1
        " Message queue, that will be displayed.
        let s:msg  = []
        " Only check the first time this file is loaded
        " It should not be neccessary to check every time
        if !exists("s:precheck")
                call s:Check()
                let s:precheck=1
        endif

        " This variable is a prefix for all placed signs.
        " This is needed, to not mess with signs placed by the user
        let s:signs={}

        " Delete previously placed signs
        call s:UnPlaceSigns()
        call s:DefineSigns()
        call s:AuCmd(1)
endfu

fu! s:AuCmd(arg)"{{{1
        if a:arg
        augroup IndentSigns
                autocmd!
                let s:verbose=0
                au InsertLeave,CursorHold * :call s:UpdateView()
        augroup END
        else
        augroup IndentSigns
                autocmd!
        augroup END
        endif
endfu

fu! s:UnPlaceSigns()"{{{1
        redir => a
        silent sign place
        redir end
        let b=split(a,"\n")
        let b=filter(b, 'v:val =~ "id=".s:sign_prefix')
        let b=map(b, 'matchstr(v:val, ''id=\zs\d\+'')')
        for id in b
        exe "sign unplace" id
        endfor
endfu


fu! s:PlaceSigns()"{{{1
        for item in range(1,line('$'))
        let indent=indent(item)
        if indent > 0
                exe "sign place " s:sign_prefix . item . " line=" . item . " 
name=" . (indent/&l:sts) . " buffer=" . bufnr('')
        endif
        endfor
endfu


fu! s:DefineSigns()"{{{1
        for item in range(1,99)
                exe "silent! sign undefine " item
                exe "sign define" item  "text=".item . " texthl=" . s:id_hl
        endfor
endfu

fu! s:UpdateView()"{{{1
        if !exists("b:changes_chg_tick")
                let b:changes_chg_tick = 0
        endif
        " Only update, if there have been changes to the buffer
        if b:changes_chg_tick != b:changedtick
                call indentSigns#Run()
        endif
endfu

fu! indentSigns#Run()"{{{1
        try
                call s:Init()
    catch /^indentSigns:/
                call s:WarningMsg()
                return
    endtry
        call s:PlaceSigns()
endfu

fu! s:CleanUp()"{{{1
        " only delete signs, that have been set by this plugin
        call s:UnPlaceSigns()
        for item in range(1,99)
                exe "sign undefine " item
        endfor
        call s:AuCmd(0)
endfu

" Define Commands "{{{1
:com! IndentSigns :call indentSigns#Run()
:com! DisableIndentSigns :call s:CleanUp()

" Restore Vim Settings "{{{1
let &cpo= s:keepcpo
unlet s:keepcpo
" Modeline "{{{1
" vi:fdm=marker fdl=0

Reply via email to