aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el48
1 files changed, 26 insertions, 22 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 1d7cf02ca5a..53aff94ae0e 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1192,28 +1192,32 @@ Returns nil if point is not in a def or class."
1192 ;; Ensure point moves forward. 1192 ;; Ensure point moves forward.
1193 (and (> beg-pos (point)) (goto-char beg-pos))))) 1193 (and (> beg-pos (point)) (goto-char beg-pos)))))
1194 1194
1195(defun python-nav--syntactically (fn poscompfn &optional pos) 1195(defun python-nav--syntactically (fn poscompfn &optional contextfn)
1196 "Move to point using FN ignoring non-code or paren context. 1196 "Move point using FN avoiding places with specific context.
1197FN must take no arguments and could be used to set match-data. 1197FN must take no arguments. POSCOMPFN is a two arguments function
1198POSCOMPFN is a two arguments function used to compare current and 1198used to compare current and previous point after it is moved
1199previous point after it is moved using FN, this is normally a 1199using FN, this is normally a less-than or greater-than
1200less-than or greater-than comparison. Optional argument POS is 1200comparison. Optional argument CONTEXTFN defaults to
1201internally used in recursive calls and should not be explicitly 1201`python-syntax-context-type' and is used for checking current
1202passed." 1202point context, it must return a non-nil value if this point must
1203 (let* ((newpos 1203be skipped."
1204 (and (funcall fn) 1204 (let ((contextfn (or contextfn 'python-syntax-context-type))
1205 (save-match-data 1205 (start-pos (point-marker))
1206 (and 1206 (prev-pos))
1207 (not (python-syntax-context-type)) 1207 (catch 'found
1208 (point-marker))))) 1208 (while t
1209 (current-match-data (match-data))) 1209 (let* ((newpos
1210 (cond ((or (and (not pos) newpos) 1210 (and (funcall fn) (point-marker)))
1211 (and pos newpos (funcall poscompfn newpos pos))) 1211 (context (funcall contextfn)))
1212 (set-match-data current-match-data) 1212 (cond ((and (not context) newpos
1213 (point-marker)) 1213 (or (and (not prev-pos) newpos)
1214 ((and (not pos) (not newpos)) nil) 1214 (and prev-pos newpos
1215 (t (python-nav--syntactically 1215 (funcall poscompfn newpos prev-pos))))
1216 fn poscompfn (point-marker)))))) 1216 (throw 'found (point-marker)))
1217 ((and newpos context)
1218 (setq prev-pos (point)))
1219 (t (when (not newpos) (goto-char start-pos))
1220 (throw 'found nil))))))))
1217 1221
1218(defun python-nav--forward-defun (arg) 1222(defun python-nav--forward-defun (arg)
1219 "Internal implementation of python-nav-{backward,forward}-defun. 1223 "Internal implementation of python-nav-{backward,forward}-defun.