8000 Implement select logical line · python-mode/python-mode@f78ff46 · GitHub
[go: up one dir, main page]

Skip to content

Commit f78ff46

Browse files
committed
Implement select logical line
1 parent 4bc4581 commit f78ff46

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

after/ftplugin/python.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ if g:pymode_motion
4242
vnoremap <buffer> aM :<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@', '^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
4343
vnoremap <buffer> iM :<C-U>call pymode#motion#select('^<Bslash>s*<Bslash&g 10000 t;(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@', '^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 1)<CR>
4444
45+
onoremap <buffer> V :<C-U>call pymode#rope#select_logical_line()<CR>
46+
4547
endif
4648

4749
if g:pymode_rope && g:pymode_rope_completion

autoload/pymode/rope.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,7 @@ fun! pymode#rope#generate_package() "{{{
194194
endif
195195
PymodePython rope.GenerateElementRefactoring('package').run()
196196
endfunction "}}}
197+
198+
fun! pymode#rope#select_logical_line() "{{{
199+
PymodePython rope.select_logical_line()
200+
endfunction "}}}

pymode/environment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,8 @@ def goto_buffer(bufnr):
242242
if str(bufnr) != '-1':
243243
vim.command('buffer %s' % bufnr)
244244

245+
def select_line(self, start, end):
246+
vim.command('normal %sggV%sgg' % (start, end))
247+
245248

246249
env = VimPymodeEnviroment()

pymode/rope.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import site
66
import sys
77

8-
from rope.base import project, libutils, exceptions, change, worder, pycore
8+
from rope.base import project, libutils, exceptions, change, worder, pycore, codeanalyze
99
from rope.base.fscommands import FileSystemCommands # noqa
1010
from rope.base.taskhandle import TaskHandle # noqa
1111
from rope.contrib import autoimport as rope_autoimport, codeassist, findit, generate # noqa
@@ -921,6 +921,18 @@ def _insert_import(name, module, ctx):
921921
reload_changes(changes)
922922

923923

924+
@env.catch_exceptions
925+
def select_logical_line():
926+
source, offset = env.get_offset_params()
927+
928+
lines = codeanalyze.SourceLinesAdapter(source)
929+
lineno = lines.get_line_number(offset)
930+
line_finder = codeanalyze.LogicalLineFinder(lines)
931+
start, end = line_finder.logical_line_in(lineno)
932+
933+
env.select_line(start, end)
934+
935+
924936
# Monkey patch Rope
925937
def find_source_folders(self, folder):
926938
"""Look only python files an packages."""

0 commit comments

Comments
 (0)
0