Skip to content

Commit

Permalink
Only proceed to next line when not looking at the start of a block and
Browse files Browse the repository at this point in the history
the current indent is deeper than the target block's indent. Fixes
issue with selecting a nested block with trailing statements.

Adds test for marking a nested block with trailing statements in the
outer block.
  • Loading branch information
fgeller committed Jul 24, 2012
1 parent b400719 commit e643a26
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
31 changes: 31 additions & 0 deletions features/fgallina-python-el-expansions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,34 @@ Feature: fgallinas python.el expansions
else:
print('Booyah.')
"""

Scenario: Mark nested Python block with subsequent statements in outer block
Given I turn on python-mode
And there is no region selected
When I insert:
"""
def outer_foo():
def inner_foo():
return 23
return inner_foo()
"""
And I go to point "23"
And I press "C-@"
Then the region should be:
"""
def
"""
And I press "C-@"
Then the region should be:
"""
def inner_foo():
"""
And I press "C-@"
Then the region should be:
"""
def inner_foo():
return 23
"""
4 changes: 3 additions & 1 deletion python-el-fgallina-expansions.el
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ than NEXT-INDENT-LEVEL."
;; Looking at an empty line
(looking-at (rx line-start (* whitespace) line-end))
;; We're not looking at the start of a Python block
(not (looking-at er--python-block-start-regex))))
;; and the indent is deeper than the block's indent
(and (not (looking-at er--python-block-start-regex))
(> (current-indentation) block-indentation))))
(forward-line 1)
(back-to-indentation))
;; Find the end of the block by skipping comments backwards
Expand Down

0 comments on commit e643a26

Please sign in to comment.