Skip to content
Browse files

Include check for end of buffer in `er/mark-python-block'.

 - Add a test for marking a buffer with a nested one.

 - Be more clear about position of point while looping.
  • Loading branch information...
1 parent 1c3d599 commit b400719f9a6d781f5ec272364e33afd2c68468f9 @fgeller fgeller committed Jul 21, 2012
Showing with 34 additions and 5 deletions.
  1. +21 −0 features/fgallina-python-el-expansions.feature
  2. +13 −5 python-el-fgallina-expansions.el
View
21 features/fgallina-python-el-expansions.feature
@@ -135,6 +135,27 @@ Feature: fgallinas python.el expansions
print('To be, or not to be...')
"""
+ Scenario: Mark another Python block with a nested block
+ Given I turn on python-mode
+ And there is no region selected
+ When I insert:
+ """
+ def moo(data):
+ for foo in data.items():
+ print(foo)
+
+ """
+ And I go to point "1"
+ And I press "C-@"
+ And I press "C-@"
+ And I press "C-@"
+ Then the region should be:
+ """
+ def moo(data):
+ for foo in data.items():
+ print(foo)
+ """
+
Scenario: Mark an outer Python block
Given I turn on python-mode
And there is no region selected
View
18 python-el-fgallina-expansions.el
@@ -113,12 +113,20 @@ than NEXT-INDENT-LEVEL."
;; Save indentation and look for the end of this block
(let ((block-indentation (current-indentation)))
(forward-line 1)
- (while (and (or (> (current-indentation) block-indentation)
- (looking-at (rx line-start (* whitespace) line-end)))
- (not (looking-at er--python-block-start-regex)))
- (forward-line 1))
+ (while (and
+ ;; No need to go beyond the end of the buffer. Can't use
+ ;; eobp as the loop places the point at the beginning of
+ ;; line, but eob might be at the end of the line.
+ (not (= (point-max) (point-at-eol)))
+ ;; Proceed if: indentation is too deep
+ (or (> (current-indentation) block-indentation)
+ ;; 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))))
+ (forward-line 1)
+ (back-to-indentation))
;; Find the end of the block by skipping comments backwards
- (beginning-of-line)
(python-util-forward-comment -1)
(exchange-point-and-mark))))

0 comments on commit b400719

Please sign in to comment.
Something went wrong with that request. Please try again.