-
-
Save qazwsxpawel/11208705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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