Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 22, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpython.vim
More file actions
Latest commit
59 lines (53 loc) · 1.53 KB
/
Copy pathpython.vim
File metadata and controls
59 lines (53 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
" Vim folding file
" Language: Python (docstring)
" Author: Eric Chiang, Milly (module)
" Last Change: 20 Jan 2018
" Version: 1.1
ifexists('g:loaded_python_docstring')
finish
endif
letg:loaded_python_docstring=1
if!has('pythonx')
echomsg"Error: Docstring requires vim compiled with +python or +python3"
finish
endif
function!PyDocHide()
setlocalfoldmethod=manual
pythonx << EOF
importvim
import ast
importre
try:
lines=list(vim.current.buffer)
root = ast.parse("\n".join(lines))
for node in ast.walk(root):
if not isinstance(node, (ast.Module, ast.FunctionDef, ast.ClassDef)):
continue
if ast.get_docstring(node) is None:
continue
first_child = node.body[0]
if not isinstance(first_child, ast.Expr):
continue
end= first_child.lineno
if'"""'inlines[end-1]:
bracket ='"""'
elif "'''"inlines[end-1]:
bracket ="'''"
else:
continue
ifre.search(bracket +'.*'+ bracket, lines[end-1]):
start=end
else:
start= node.lineno ifhasattr(node, 'lineno') else1
fori, lineinenumerate(lines[end-2 : start-1 : -1]):
if bracket inline:
start=end-i-1
break
else:
continue
vim.command("%d,%dfold"% (start, end))
except Exceptionase:
print("Error: %s"% (e,))
EOF
endfunction
command! PyDocHide callPyDocHide()