-
-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy path__init__.py
More file actions
64 lines (47 loc) · 1.91 KB
/
__init__.py
File metadata and controls
64 lines (47 loc) · 1.91 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
60
61
62
63
64
"""Pymode support functions."""
import sys
from importlib.machinery import PathFinder as _PathFinder
import vim # noqa
if not hasattr(vim, 'find_module'):
try:
vim.find_module = _PathFinder.find_module # deprecated
except AttributeError:
def _find_module(package_name):
spec = _PathFinder.find_spec(package_name)
return spec.loader if spec else None
vim.find_module = _find_module
def auto():
"""Fix PEP8 errors in current buffer using ruff format.
pymode: uses it in command PymodeLintAuto with pymode#lint#auto()
"""
from .ruff_integration import run_ruff_format, check_ruff_available
if not check_ruff_available():
vim.command('echoerr "Ruff is not available. Please install ruff: pip install ruff"')
return
current_buffer = vim.current.buffer
file_path = current_buffer.name
if not file_path:
vim.command('echoerr "Cannot format unsaved buffer"')
return
# Get current buffer content
content = '\n'.join(current_buffer) + '\n'
# Run ruff format
formatted_content = run_ruff_format(file_path, content)
if formatted_content is not None and formatted_content != content:
# Update buffer with formatted content
lines = formatted_content.rstrip('\n').splitlines()
if not lines:
lines = ['']
current_buffer[:] = lines
# Mark buffer as modified so Vim knows it can be written
vim.command('setlocal modified')
vim.command('echom "Ruff format completed"')
else:
vim.command('echom "No formatting changes needed"')
def get_documentation():
"""Search documentation and append to current buffer."""
from io import StringIO
sys.stdout, _ = StringIO(), sys.stdout
help(vim.eval('a:word'))
sys.stdout, out = _, sys.stdout.getvalue()
vim.current.buffer.append(str(out).splitlines(), 0)