[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r112319: * lisp/progmodes/python.el (
From: |
Fabián Ezequiel Gallina |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r112319: * lisp/progmodes/python.el (python-nav--syntactically): Fix cornercases |
Date: |
Wed, 17 Apr 2013 19:23:13 -0300 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 112319
committer: Fabián Ezequiel Gallina <address@hidden>
branch nick: trunk
timestamp: Wed 2013-04-17 19:23:13 -0300
message:
* lisp/progmodes/python.el (python-nav--syntactically): Fix cornercases
and do not care about match data.
* test/automated/python-tests.el (python-nav-backward-defun-2)
(python-nav-backward-defun-3, python-nav-forward-defun-2)
(python-nav-forward-defun-3): New tests.
modified:
lisp/ChangeLog
lisp/progmodes/python.el
test/ChangeLog
test/automated/python-tests.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2013-04-17 20:52:02 +0000
+++ b/lisp/ChangeLog 2013-04-17 22:23:13 +0000
@@ -1,3 +1,8 @@
+2013-04-17 Fabián Ezequiel Gallina <address@hidden>
+
+ * progmodes/python.el (python-nav--syntactically): Fix cornercases
+ and do not care about match data.
+
2013-04-17 Stefan Monnier <address@hidden>
* emacs-lisp/lisp.el (lisp-completion-at-point): Provide specialized
=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el 2013-04-17 05:08:20 +0000
+++ b/lisp/progmodes/python.el 2013-04-17 22:23:13 +0000
@@ -1192,28 +1192,32 @@
;; Ensure point moves forward.
(and (> beg-pos (point)) (goto-char beg-pos)))))
-(defun python-nav--syntactically (fn poscompfn &optional pos)
- "Move to point using FN ignoring non-code or paren context.
-FN must take no arguments and could be used to set match-data.
-POSCOMPFN is a two arguments function used to compare current and
-previous point after it is moved using FN, this is normally a
-less-than or greater-than comparison. Optional argument POS is
-internally used in recursive calls and should not be explicitly
-passed."
- (let* ((newpos
- (and (funcall fn)
- (save-match-data
- (and
- (not (python-syntax-context-type))
- (point-marker)))))
- (current-match-data (match-data)))
- (cond ((or (and (not pos) newpos)
- (and pos newpos (funcall poscompfn newpos pos)))
- (set-match-data current-match-data)
- (point-marker))
- ((and (not pos) (not newpos)) nil)
- (t (python-nav--syntactically
- fn poscompfn (point-marker))))))
+(defun python-nav--syntactically (fn poscompfn &optional contextfn)
+ "Move point using FN avoiding places with specific context.
+FN must take no arguments. POSCOMPFN is a two arguments function
+used to compare current and previous point after it is moved
+using FN, this is normally a less-than or greater-than
+comparison. Optional argument CONTEXTFN defaults to
+`python-syntax-context-type' and is used for checking current
+point context, it must return a non-nil value if this point must
+be skipped."
+ (let ((contextfn (or contextfn 'python-syntax-context-type))
+ (start-pos (point-marker))
+ (prev-pos))
+ (catch 'found
+ (while t
+ (let* ((newpos
+ (and (funcall fn) (point-marker)))
+ (context (funcall contextfn)))
+ (cond ((and (not context) newpos
+ (or (and (not prev-pos) newpos)
+ (and prev-pos newpos
+ (funcall poscompfn newpos prev-pos))))
+ (throw 'found (point-marker)))
+ ((and newpos context)
+ (setq prev-pos (point)))
+ (t (when (not newpos) (goto-char start-pos))
+ (throw 'found nil))))))))
(defun python-nav--forward-defun (arg)
"Internal implementation of python-nav-{backward,forward}-defun.
=== modified file 'test/ChangeLog'
--- a/test/ChangeLog 2013-04-17 05:08:20 +0000
+++ b/test/ChangeLog 2013-04-17 22:23:13 +0000
@@ -1,5 +1,11 @@
2013-04-17 Fabián Ezequiel Gallina <address@hidden>
+ * automated/python-tests.el (python-nav-backward-defun-2)
+ (python-nav-backward-defun-3, python-nav-forward-defun-2)
+ (python-nav-forward-defun-3): New tests.
+
+2013-04-17 Fabián Ezequiel Gallina <address@hidden>
+
* automated/python-tests.el (python-nav-backward-defun-1)
(python-nav-forward-defun-1): New tests.
=== modified file 'test/automated/python-tests.el'
--- a/test/automated/python-tests.el 2013-04-17 05:08:20 +0000
+++ b/test/automated/python-tests.el 2013-04-17 22:23:13 +0000
@@ -718,6 +718,60 @@
(python-tests-look-at "class A(object): # A" -1)))
(should (not (python-nav-backward-defun)))))
+(ert-deftest python-nav-backward-defun-2 ()
+ (python-tests-with-temp-buffer
+ "
+def decoratorFunctionWithArguments(arg1, arg2, arg3):
+ '''print decorated function call data to stdout.
+
+ Usage:
+
+ @decoratorFunctionWithArguments('arg1', 'arg2')
+ def func(a, b, c=True):
+ pass
+ '''
+
+ def wwrap(f):
+ print 'Inside wwrap()'
+ def wrapped_f(*args):
+ print 'Inside wrapped_f()'
+ print 'Decorator arguments:', arg1, arg2, arg3
+ f(*args)
+ print 'After f(*args)'
+ return wrapped_f
+ return wwrap
+"
+ (goto-char (point-max))
+ (should (= (save-excursion (python-nav-backward-defun))
+ (python-tests-look-at " def wrapped_f(*args):" -1)))
+ (should (= (save-excursion (python-nav-backward-defun))
+ (python-tests-look-at " def wwrap(f):" -1)))
+ (should (= (save-excursion (python-nav-backward-defun))
+ (python-tests-look-at "def decoratorFunctionWithArguments(arg1,
arg2, arg3):" -1)))
+ (should (not (python-nav-backward-defun)))))
+
+(ert-deftest python-nav-backward-defun-3 ()
+ (python-tests-with-temp-buffer
+ "
+'''
+ def u(self):
+ pass
+
+ def v(self):
+ pass
+
+ def w(self):
+ pass
+'''
+
+class A(object):
+ pass
+"
+ (goto-char (point-min))
+ (let ((point (python-tests-look-at "class A(object):")))
+ (should (not (python-nav-backward-defun)))
+ (should (= point (point))))))
+
(ert-deftest python-nav-forward-defun-1 ()
(python-tests-with-temp-buffer
"
@@ -762,6 +816,60 @@
(python-tests-look-at "(self): # c")))
(should (not (python-nav-forward-defun)))))
+(ert-deftest python-nav-forward-defun-2 ()
+ (python-tests-with-temp-buffer
+ "
+def decoratorFunctionWithArguments(arg1, arg2, arg3):
+ '''print decorated function call data to stdout.
+
+ Usage:
+
+ @decoratorFunctionWithArguments('arg1', 'arg2')
+ def func(a, b, c=True):
+ pass
+ '''
+
+ def wwrap(f):
+ print 'Inside wwrap()'
+ def wrapped_f(*args):
+ print 'Inside wrapped_f()'
+ print 'Decorator arguments:', arg1, arg2, arg3
+ f(*args)
+ print 'After f(*args)'
+ return wrapped_f
+ return wwrap
+"
+ (goto-char (point-min))
+ (should (= (save-excursion (python-nav-forward-defun))
+ (python-tests-look-at "(arg1, arg2, arg3):")))
+ (should (= (save-excursion (python-nav-forward-defun))
+ (python-tests-look-at "(f):")))
+ (should (= (save-excursion (python-nav-forward-defun))
+ (python-tests-look-at "(*args):")))
+ (should (not (python-nav-forward-defun)))))
+
+(ert-deftest python-nav-forward-defun-3 ()
+ (python-tests-with-temp-buffer
+ "
+class A(object):
+ pass
+
+'''
+ def u(self):
+ pass
+
+ def v(self):
+ pass
+
+ def w(self):
+ pass
+'''
+"
+ (goto-char (point-min))
+ (let ((point (python-tests-look-at "(object):")))
+ (should (not (python-nav-forward-defun)))
+ (should (= point (point))))))
+
(ert-deftest python-nav-beginning-of-statement-1 ()
(python-tests-with-temp-buffer
"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r112319: * lisp/progmodes/python.el (python-nav--syntactically): Fix cornercases,
Fabián Ezequiel Gallina <=