Skip to content

Instantly share code, notes, and snippets.

@qazwsxpawel
Forked from nicwest/python-label-thing.vim
Created April 23, 2014 09:33
Show Gist options
  • Save qazwsxpawel/11208705 to your computer and use it in GitHub Desktop.
Save qazwsxpawel/11208705 to your computer and use it in GitHub Desktop.
function! PythonGetLabel()
if foldlevel('.') != 0
norm! zo
endif
let originalline = getpos('.')
let lnlist = []
let lastlineindent = indent(line('.'))
let objregexp = "^\\s*\\(class\\|def\\)\\s\\+[^:]\\+\\s*:"
if match(getline('.'),objregexp) != -1
let lastlineindent = indent(line('.'))
norm! ^wye
call insert(lnlist, @0, 0)
endif
while line('.') > 1
if indent('.') < lastlineindent
if match(getline('.'),objregexp) != -1
let lastlineindent = indent(line('.'))
norm! ^wye
call insert(lnlist, @0, 0)
endif
endif
norm! k
endwhile
let pathlist = split(expand('%:r'), '/')
echo 'Python label: ' join(pathlist + lnlist, '.')
let @0 = join(pathlist + lnlist, '.')
let @+ = @0
call setpos('.', originalline)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment