Permalink
Browse files

Fixes for er/mark-*-python-string.

 - `forward-sexp' is now jumps block-wise

 - Use a (brittle) search for the delimiters at the beginning of the
   string.

 - Factor out common functionality
  • Loading branch information...
1 parent f432267 commit 3fdcb44a1de5254c9ff8e468864795fa1352c290 @fgeller fgeller committed Jul 17, 2012
Showing with 17 additions and 13 deletions.
  1. +17 −13 python-el-fgallina-expansions.el
@@ -32,25 +32,29 @@
(defvar er--python-string-delimiter "'\"")
-(defun er/mark-inside-python-string ()
- (interactive)
+(defun er/match-python-string-delimiter ()
+ "Returns the Python string delimiter at point, if there is one."
+ (looking-at "\\(\"\"\"\\|\"\\|'''\\|'\\)")
+ (match-string 1))
+
+(defun er/mark-python-string (mark-inside)
(let ((beginning-of-string (python-info-ppss-context 'string (syntax-ppss))))
(when beginning-of-string
(goto-char beginning-of-string)
- (forward-sexp)
- (skip-chars-backward er--python-string-delimiter)
- (set-mark (point))
- (goto-char beginning-of-string)
- (skip-chars-forward er--python-string-delimiter))))
+ (let ((string-delimiter (er/match-python-string-delimiter)))
+ (search-forward string-delimiter nil nil 2)
+ (when mark-inside (skip-chars-backward er--python-string-delimiter))
+ (set-mark (point))
+ (goto-char beginning-of-string)
+ (when mark-inside (skip-chars-forward er--python-string-delimiter))))))
+
+(defun er/mark-inside-python-string ()
+ (interactive)
+ (er/mark-python-string t))
(defun er/mark-outside-python-string ()
(interactive)
- (let ((beginning-of-string (python-info-ppss-context 'string (syntax-ppss))))
- (when beginning-of-string
- (goto-char beginning-of-string)
- (set-mark (point))
- (forward-sexp)
- (exchange-point-and-mark))))
+ (er/mark-python-string nil))
(defun er/mark-python-statement ()
(interactive)

0 comments on commit 3fdcb44

Please sign in to comment.