diff options
author | Tomas Nordin <tomasn@posteo.net> | 2020-12-14 16:58:07 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2020-12-14 16:58:07 +0100 |
commit | 8b3de06347dfcb4afab93f17f32297fe721b363b (patch) | |
tree | f7b827eff170ee18f886368d2dbdd01924ef295a /lisp | |
parent | 252366866b5691965c8c752aa103ab157a6f3aaa (diff) | |
download | emacs-8b3de06347dfcb4afab93f17f32297fe721b363b.tar.gz emacs-8b3de06347dfcb4afab93f17f32297fe721b363b.tar.bz2 emacs-8b3de06347dfcb4afab93f17f32297fe721b363b.zip |
Fix narrow-to-defun in python-mode
* lisp/progmodes/python.el (python-nav--beginning-of-defun): Make
narrow-to-defun work better in classes (bug#40563).
Copyright-paperwork-exempt: yes
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/progmodes/python.el | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d75944a702f..d58b32f3c3c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1404,7 +1404,7 @@ With positive ARG search backwards, else search forwards." (line-beg-pos (line-beginning-position)) (line-content-start (+ line-beg-pos (current-indentation))) (pos (point-marker)) - (beg-indentation + (body-indentation (and (> arg 0) (save-excursion (while (and @@ -1415,9 +1415,16 @@ With positive ARG search backwards, else search forwards." 0)))) (found (progn - (when (and (< arg 0) - (python-info-looking-at-beginning-of-defun)) + (when (and (python-info-looking-at-beginning-of-defun) + (or (< arg 0) + ;; If looking at beginning of defun, and if + ;; pos is > line-content-start, ensure a + ;; backward re search match this defun by + ;; going to end of line before calling + ;; re-search-fn bug#40563 + (and (> arg 0) (> pos line-content-start)))) (end-of-line 1)) + (while (and (funcall re-search-fn python-nav-beginning-of-defun-regexp nil t) (or (python-syntax-context-type) @@ -1425,7 +1432,7 @@ With positive ARG search backwards, else search forwards." ;; backwards by checking indentation. (and (> arg 0) (not (= (current-indentation) 0)) - (>= (current-indentation) beg-indentation))))) + (>= (current-indentation) body-indentation))))) (and (python-info-looking-at-beginning-of-defun) (or (not (= (line-number-at-pos pos) (line-number-at-pos))) |