Permalink
Browse files

some reorg + tweaks to string motion funcs

  • Loading branch information...
1 parent c608005 commit 693a84672b1a89eb92c12bfe1a64d23b3fd7c2fb @tavisrudd committed Jun 25, 2010
Showing with 47 additions and 34 deletions.
  1. +45 −0 dss-codenav-helpers.el
  2. +2 −34 dss-python.el
View
@@ -24,12 +24,22 @@
Do nothing if not in string."
;; from loveshack's python-beginning-of-string
(interactive)
+ (if (and (not (dss/in-string-p))
+ (save-excursion
+ (backward-char)
+ (dss/in-string-p)))
+ (backward-char))
(let ((state (syntax-ppss)))
(when (eq 'string (syntax-ppss-context state))
(goto-char (nth 8 state)))))
(defun dss/end-of-string ()
(interactive)
+ (if (and (not (dss/in-string-p))
+ (save-excursion
+ (forward-char)
+ (dss/in-string-p)))
+ (forward-char))
(if (dss/in-string-p)
(progn
(dss/beginning-of-string)
@@ -61,6 +71,41 @@ Do nothing if not in string."
;@@TR: I should add some similar functions for working with comments etc.
+(defun dss/out-sexp (&optional level forward syntax)
+ "Skip out of any nested brackets.
+ Skip forward if FORWARD is non-nil, else backward.
+ If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point.
+ Return non-nil if and only if skipping was done."
+ (interactive)
+ (if (dss/in-string-p)
+ (dss/beginning-of-string))
+ (progn
+ (let* ((depth (syntax-ppss-depth (or syntax (syntax-ppss))))
+ (level (or level depth))
+ (forward (if forward -1 1)))
+ (unless (zerop depth)
+ (if (> depth 0)
+ ;; Skip forward out of nested brackets.
+ (condition-case () ; beware invalid syntax
+ (progn (backward-up-list (* forward level)) t)
+ (error nil))
+ ;; Invalid syntax (too many closed brackets).
+ ;; Skip out of as many as possible.
+ (let (done)
+ (while (condition-case ()
+ (progn (backward-up-list forward)
+ (setq done t))
+ (error nil)))
+ done))))))
+
+(defun dss/out-one-sexp (&optional forward)
+ (interactive)
+ (dss/out-sexp 1 forward))
+
+(defun dss/out-one-sexp-forward ()
+ (interactive)
+ (dss/out-sexp 1 1))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dss/electric-pair ()
"If at end of line, insert character pair without surrounding spaces.
View
@@ -1,4 +1,6 @@
;; python-mode
+(require 'dss-codenav-helpers)
+
(add-to-list 'load-path "/usr/share/emacs/site-lisp/python-mode")
(autoload 'python-mode "python-mode" "PY" t)
@@ -38,40 +40,6 @@
(insert "pylint: disable-msg="))
(insert msgid)))
-(defun dss/out-sexp (&optional level forward syntax)
- "Skip out of any nested brackets.
- Skip forward if FORWARD is non-nil, else backward.
- If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point.
- Return non-nil if and only if skipping was done."
- (interactive)
- (if (dss/in-string-p)
- (dss/beginning-of-string))
- (progn
- (let* ((depth (syntax-ppss-depth (or syntax (syntax-ppss))))
- (level (or level depth))
- (forward (if forward -1 1)))
- (unless (zerop depth)
- (if (> depth 0)
- ;; Skip forward out of nested brackets.
- (condition-case () ; beware invalid syntax
- (progn (backward-up-list (* forward level)) t)
- (error nil))
- ;; Invalid syntax (too many closed brackets).
- ;; Skip out of as many as possible.
- (let (done)
- (while (condition-case ()
- (progn (backward-up-list forward)
- (setq done t))
- (error nil)))
- done))))))
-
-(defun dss/out-one-sexp (&optional forward)
- (interactive)
- (dss/out-sexp 1 forward))
-
-(defun dss/out-one-sexp-forward ()
- (interactive)
- (dss/out-sexp 1 1))
(defun dss/py-insert-docstring ()
(interactive)

0 comments on commit 693a846

Please sign in to comment.