* bug#56600: 29.0.50; Python navigation problem with an empty line in nested defun
@ 2022-07-16 13:28 kobarity
2022-07-16 13:37 ` kobarity
0 siblings, 1 reply; 3+ messages in thread
From: kobarity @ 2022-07-16 13:28 UTC (permalink / raw)
To: 56600
Hi,
The following steps will place the point at the beginning of the line
"def foo():", not the line "def bar():".
1. emacs -Q
2. Load the following Python file using M-x find-file
#+begin_src python
def foo():
def bar():
pass
def baz():
pass
#+end_src
3. M-: (forward-line 2)
4. M-: (python-nav-beginning-of-defun)
python-nav-end-of-defun has a similar problem.
Best Regards,
--
In GNU Emacs 29.0.50 (build 6, x86_64-pc-linux-gnu)
of 2022-07-16 built on ubuntu
Repository revision: ea9b442b82f1efd7e41094b455a00d73c16d0fc3
Repository branch: master
System Description: Ubuntu 22.04 LTS
Configured using:
'configure --without-x --with-gnutls=ifavailable'
Configured features:
ACL LIBXML2 MODULES NOTIFY INOTIFY PDUMPER SECCOMP SOUND SQLITE3 THREADS
XIM ZLIB
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
Major mode: Lisp Interaction
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
show-paren-mode: t
electric-indent-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
line-number-mode: t
indent-tabs-mode: t
transient-mark-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
Load-path shadows:
None found.
Features:
(shadow regexp-opt sort mail-extr emacsbug message mailcap yank-media
puny dired dnd dired-loaddefs rfc822 mml mml-sec password-cache epa
derived epg rfc6068 epg-config gnus-util text-property-search time-date
subr-x mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils term/screen term/xterm xterm
byte-opt gv bytecomp byte-compile cconv rmc iso-transl tooltip eldoc
paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select mouse
jit-lock font-lock syntax font-core term/tty-colors frame minibuffer
nadvice seq simple cl-generic indonesian philippine cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop
case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads inotify
multi-tty make-network-process emacs)
Memory information:
((conses 16 44274 5286)
(symbols 48 5634 1)
(strings 32 15464 1865)
(string-bytes 1 494915)
(vectors 16 8324)
(vector-slots 8 102199 7439)
(floats 8 25 355)
(intervals 56 202 14)
(buffers 992 11))
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#56600: 29.0.50; Python navigation problem with an empty line in nested defun
2022-07-16 13:28 bug#56600: 29.0.50; Python navigation problem with an empty line in nested defun kobarity
@ 2022-07-16 13:37 ` kobarity
2022-07-16 16:14 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: kobarity @ 2022-07-16 13:37 UTC (permalink / raw)
To: 56600
[-- Attachment #1: Type: text/plain, Size: 296 bytes --]
Hello,
I'm afraid this is a bug in my patch to fix #56105. It initialized
`min-indentation' using `current-indentation' of the current line.
However, it was not adequate for an empty line as
`current-indentation' of an empty line is zero.
Attached is a patch to fix this issue.
Best Regards,
[-- Attachment #2: fix-56600.patch --]
[-- Type: application/octet-stream, Size: 5460 bytes --]
commit 3b23ee92fab820497e90038b9eab5c030b989de4
Author: kobarity <kobarity@gmail.com>
Date: Sat Jul 16 22:30:31 2022 +0900
Fix python navigation problem with an empty line in nested defun
* lisp/progmodes/python.el (python-nav--beginning-of-defun): Fix
bug when point is on an empty line (bug#56600).
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 1c99937c4b..f31832fec9 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1454,21 +1454,24 @@ python-nav--beginning-of-defun
(line-beg-pos (line-beginning-position))
(line-content-start (+ line-beg-pos (current-indentation)))
(pos (point-marker))
- (min-indentation (+ (current-indentation)
- (if (python-info-looking-at-beginning-of-defun)
- python-indent-offset 0)))
+ (min-indentation (if (python-info-current-line-empty-p)
+ most-positive-fixnum
+ (current-indentation)))
(body-indentation
(and (> arg 0)
- (save-excursion
- (while (and
- (or (not (python-info-looking-at-beginning-of-defun))
- (>= (current-indentation) min-indentation))
- (setq min-indentation
- (min min-indentation (current-indentation)))
- (python-nav-backward-block)))
- (or (and (python-info-looking-at-beginning-of-defun)
- (+ (current-indentation) python-indent-offset))
- 0))))
+ (or (and (python-info-looking-at-beginning-of-defun)
+ (+ (current-indentation) python-indent-offset))
+ (save-excursion
+ (while
+ (and
+ (python-nav-backward-block)
+ (or (not (python-info-looking-at-beginning-of-defun))
+ (>= (current-indentation) min-indentation))
+ (setq min-indentation
+ (min min-indentation (current-indentation)))))
+ (or (and (python-info-looking-at-beginning-of-defun)
+ (+ (current-indentation) python-indent-offset))
+ 0)))))
(found
(progn
(when (and (python-info-looking-at-beginning-of-defun nil t)
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 92c20288c8..b2cccdd956 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1876,7 +1876,7 @@ python-nav-beginning-of-defun-2
(beginning-of-line)
(point))))
;; Nested defuns should be skipped.
- (python-tests-look-at "return a" -1)
+ (forward-line -1)
(should (= (save-excursion
(python-nav-beginning-of-defun)
(point))
@@ -1885,6 +1885,15 @@ python-nav-beginning-of-defun-2
(beginning-of-line)
(point))))
;; Defuns on same levels should be respected.
+ (python-tests-look-at "if True:" -1)
+ (forward-line -1)
+ (should (= (save-excursion
+ (python-nav-beginning-of-defun)
+ (point))
+ (save-excursion
+ (python-tests-look-at "def a():" -1)
+ (beginning-of-line)
+ (point))))
(python-tests-look-at "def a():" -1)
(should (= (save-excursion
(python-nav-beginning-of-defun)
@@ -1893,8 +1902,16 @@ python-nav-beginning-of-defun-2
(python-tests-look-at "def b():" -1)
(beginning-of-line)
(point))))
- ;; Jump to a top level defun.
+ ;; Jump to an upper level defun.
(python-tests-look-at "def b():" -1)
+ (should (= (save-excursion
+ (python-nav-beginning-of-defun)
+ (point))
+ (save-excursion
+ (python-tests-look-at "def m(self):" -1)
+ (beginning-of-line)
+ (point))))
+ (forward-line -1)
(should (= (save-excursion
(python-nav-beginning-of-defun)
(point))
@@ -2009,6 +2026,15 @@ python-nav-end-of-defun-1
(python-tests-look-at "def c(self):")
(forward-line -1)
(point))))
+ (should (= (save-excursion
+ (python-tests-look-at "def b():")
+ (forward-line -1)
+ (python-nav-end-of-defun)
+ (point))
+ (save-excursion
+ (python-tests-look-at "def c(self):")
+ (forward-line -1)
+ (point))))
(should (= (save-excursion
(python-tests-look-at "def b():")
(python-nav-end-of-defun)
@@ -2017,6 +2043,10 @@ python-nav-end-of-defun-1
(python-tests-look-at "def b():")
(forward-line 2)
(point))))
+ (should (not (save-excursion
+ (python-tests-look-at "def a():")
+ (forward-line -1)
+ (python-nav-end-of-defun))))
(should (= (save-excursion
(python-tests-look-at "def c(self):")
(python-nav-end-of-defun)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#56600: 29.0.50; Python navigation problem with an empty line in nested defun
2022-07-16 13:37 ` kobarity
@ 2022-07-16 16:14 ` Lars Ingebrigtsen
0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-16 16:14 UTC (permalink / raw)
To: kobarity; +Cc: 56600
kobarity <kobarity@gmail.com> writes:
> I'm afraid this is a bug in my patch to fix #56105. It initialized
> `min-indentation' using `current-indentation' of the current line.
> However, it was not adequate for an empty line as
> `current-indentation' of an empty line is zero.
>
> Attached is a patch to fix this issue.
Thanks; pushed to Emacs 29.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-16 16:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-16 13:28 bug#56600: 29.0.50; Python navigation problem with an empty line in nested defun kobarity
2022-07-16 13:37 ` kobarity
2022-07-16 16:14 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).