diff options
| author | Eli Zaretskii | 2013-04-18 19:20:48 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2013-04-18 19:20:48 +0300 |
| commit | 4f0e6095fc0bcc8b9e8bcf6bf907b957b15cf699 (patch) | |
| tree | abab34f8645852eaef34782428fbc422f8098332 /lisp/progmodes/python.el | |
| parent | 224e1caae160cccd6447db6228cc617765f7ad31 (diff) | |
| parent | cdca825560c4f97fba5ccd6ba87df5c881d1ffce (diff) | |
| download | emacs-4f0e6095fc0bcc8b9e8bcf6bf907b957b15cf699.tar.gz emacs-4f0e6095fc0bcc8b9e8bcf6bf907b957b15cf699.zip | |
Merge from trunk.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 48 |
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. |
| 1197 | FN must take no arguments and could be used to set match-data. | 1197 | FN must take no arguments. POSCOMPFN is a two arguments function |
| 1198 | POSCOMPFN is a two arguments function used to compare current and | 1198 | used to compare current and previous point after it is moved |
| 1199 | previous point after it is moved using FN, this is normally a | 1199 | using FN, this is normally a less-than or greater-than |
| 1200 | less-than or greater-than comparison. Optional argument POS is | 1200 | comparison. Optional argument CONTEXTFN defaults to |
| 1201 | internally used in recursive calls and should not be explicitly | 1201 | `python-syntax-context-type' and is used for checking current |
| 1202 | passed." | 1202 | point context, it must return a non-nil value if this point must |
| 1203 | (let* ((newpos | 1203 | be 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. |