Skip to content

Commit

Permalink
Incorporating @edmccard's recommendations.
Browse files Browse the repository at this point in the history
 - Adding py-mark-def and py-mark-clause to python-mode expansions

 - Removing er/mark-inside-quotes and er/mark-outside-quotes

 - Incorporating marking inside and outside of a Python string separately

(cf. #29)
  • Loading branch information
fgeller committed Apr 13, 2012
1 parent 376f54f commit 0cabb17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 25 additions & 7 deletions python-el-expansions.el
Expand Up @@ -32,27 +32,45 @@

(require 'expand-region-core)

(defvar er--python-string-delimiter "'\"")

(defun er/mark-python-statement ()
"Marks one Python statement, eg. x = 3"
(interactive)
(python-end-of-statement)
(set-mark (point))
(python-beginning-of-statement))

(defun er/mark-python-string ()
"Marks one (possibly multi-line) Python string"
(defun er/mark-outside-python-string ()
"Marks region outside a (possibly multi-line) Python string"
(interactive)
(python-beginning-of-string)
(set-mark (point))
(forward-sexp)
(exchange-point-and-mark))

(defun er/mark-inside-python-string ()
"Marks region inside a (possibly multi-line) Python string"
(interactive)
(when (eq 'string (syntax-ppss-context (syntax-ppss)))
(python-beginning-of-string)
(let ((string-beginning (point)))
(forward-sexp)
(skip-chars-backward er--python-string-delimiter)
(set-mark (point))
(goto-char string-beginning)
(skip-chars-forward er--python-string-delimiter))))

(defun er/add-python-mode-expansions ()
"Adds Python-specific expansions for buffers in python-mode"
(set (make-local-variable 'er/try-expand-list) (append
er/try-expand-list
'(er/mark-python-statement
er/mark-python-string
python-mark-block))))
(let ((try-expand-list-additions '(er/mark-python-statement
er/mark-inside-python-string
er/mark-outside-python-string
python-mark-block)))
(set (make-local-variable 'er/try-expand-list)
(remove 'er/mark-inside-quotes
(remove 'er/mark-outside-quotes
(append er/try-expand-list try-expand-list-additions))))))

(add-hook 'python-mode-hook 'er/add-python-mode-expansions)

Expand Down
2 changes: 2 additions & 0 deletions python-mode-expansions.el
Expand Up @@ -119,6 +119,8 @@ line and selecting the surrounding block."
py-mark-expression
py-mark-statement
py-mark-block
py-mark-def
py-mark-clause
er/mark-x-python-compound-statement
er/mark-outer-python-block
py-mark-class
Expand Down

0 comments on commit 0cabb17

Please sign in to comment.