* bug#59009: python mode indentation behavior fix
@ 2022-11-03 15:41 Randomneo
2022-11-06 8:18 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Randomneo @ 2022-11-03 15:41 UTC (permalink / raw)
To: 59009
[-- Attachment #1.1: Type: text/plain, Size: 267 bytes --]
This patch will fix this bug #42513
<https://debbugs.gnu.org/cgi/bugreport.cgi?bug=42513>.
Also problems with same behaviour with pair of statements when one of them
is multiline with prantaces like https://pastebin.com/Z1yFbMtp.
with best regards Misiura Rostislav
[-- Attachment #1.2: Type: text/html, Size: 356 bytes --]
[-- Attachment #2: 0001-python.el-Opening-block-search-fix.patch --]
[-- Type: text/x-patch, Size: 1916 bytes --]
From 91b310d1412366340b6deeff65519e248d87a10f Mon Sep 17 00:00:00 2001
From: Rostyslav Misiura <rostislav9999@gmail.com>
Date: Thu, 3 Nov 2022 18:27:38 +0300
Subject: [PATCH] python.el: Opening block search fix
---
lisp/progmodes/python.el | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index cec0d54a44..3ca8e49f2b 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5373,16 +5373,16 @@ likely an invalid python file."
(apply #'min collected-indentations)))
;; There must be no line with indentation
;; smaller than `indentation' (except for
- ;; blank lines) between the found opening
- ;; block and the current line, otherwise it
- ;; is not an opening block.
+ ;; blank lines and comments) between the found
+ ;; opening block and the current line,
+ ;; otherwise it is not an opening block.
(save-excursion
(forward-line)
(let ((no-back-indent t))
(save-match-data
(while (and (< (point) cur-line)
(setq no-back-indent
- (or (> (current-indentation) indentation)
+ (or (>= (current-indentation) indentation)
(python-info-current-line-empty-p)
(python-info-current-line-comment-p))))
(forward-line)))
--
2.38.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#59009: python mode indentation behavior fix
2022-11-03 15:41 bug#59009: python mode indentation behavior fix Randomneo
@ 2022-11-06 8:18 ` Eli Zaretskii
2022-11-07 13:57 ` kobarity
0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2022-11-06 8:18 UTC (permalink / raw)
To: Randomneo, kobarity; +Cc: 59009
> From: Randomneo <rostislav9999@gmail.com>
> Date: Thu, 3 Nov 2022 18:41:42 +0300
>
> This patch will fix this bug #42513.
> Also problems with same behaviour with pair of statements when one of them is multiline with prantaces like
> https://pastebin.com/Z1yFbMtp.
>
> with best regards Misiura Rostislav
>
> From 91b310d1412366340b6deeff65519e248d87a10f Mon Sep 17 00:00:00 2001
> From: Rostyslav Misiura <rostislav9999@gmail.com>
> Date: Thu, 3 Nov 2022 18:27:38 +0300
> Subject: [PATCH] python.el: Opening block search fix
>
> ---
> lisp/progmodes/python.el | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
> index cec0d54a44..3ca8e49f2b 100644
> --- a/lisp/progmodes/python.el
> +++ b/lisp/progmodes/python.el
> @@ -5373,16 +5373,16 @@ likely an invalid python file."
> (apply #'min collected-indentations)))
> ;; There must be no line with indentation
> ;; smaller than `indentation' (except for
> - ;; blank lines) between the found opening
> - ;; block and the current line, otherwise it
> - ;; is not an opening block.
> + ;; blank lines and comments) between the found
> + ;; opening block and the current line,
> + ;; otherwise it is not an opening block.
> (save-excursion
> (forward-line)
> (let ((no-back-indent t))
> (save-match-data
> (while (and (< (point) cur-line)
> (setq no-back-indent
> - (or (> (current-indentation) indentation)
> + (or (>= (current-indentation) indentation)
> (python-info-current-line-empty-p)
> (python-info-current-line-comment-p))))
> (forward-line)))
> --
> 2.38.1
kobarity, any comments on this patch?
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#59009: python mode indentation behavior fix
2022-11-06 8:18 ` Eli Zaretskii
@ 2022-11-07 13:57 ` kobarity
2022-11-10 10:26 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: kobarity @ 2022-11-07 13:57 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 59009, Randomneo
[-- Attachment #1: Type: text/plain, Size: 596 bytes --]
Eli Zaretskii wrote:
> > From: Randomneo <rostislav9999@gmail.com>
> >
> > This patch will fix this bug #42513.
>
> kobarity, any comments on this patch?
Hello,
Unfortunately, the presented patch breaks the ERT
python-indent-electric-colon-4.
I think the problem lies in the forward-line after block-start
detection. The while loop is used to detect indentation inside the
block, so if block-start spans multiple lines, it should start at the
next line. To address this issue, I propose to add
python-nav-end-of-statement before forward-line. Attached is the
patch with an ERT.
Regards,
[-- Attachment #2: 0001-Fix-indentation-for-multi-line-block-start-in-Python.patch --]
[-- Type: application/octet-stream, Size: 2157 bytes --]
From 20c81eb76f8e9251610f40e7cb6c110ddabbb8c6 Mon Sep 17 00:00:00 2001
From: kobarity <kobarity@gmail.com>
Date: Mon, 7 Nov 2022 22:24:44 +0900
Subject: [PATCH] Fix indentation for multi-line block start in Python mode
* lisp/progmodes/python.el
(python-info-dedenter-opening-block-positions): Fix for multi-line
block start.
* test/lisp/progmodes/python-tests.el
(python-info-dedenter-opening-block-positions-6): New test. (Bug#59009)
---
lisp/progmodes/python.el | 1 +
test/lisp/progmodes/python-tests.el | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index cec0d54a44..a734e06149 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5377,6 +5377,7 @@ python-info-dedenter-opening-block-positions
;; block and the current line, otherwise it
;; is not an opening block.
(save-excursion
+ (python-nav-end-of-statement)
(forward-line)
(let ((no-back-indent t))
(save-match-data
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 8330525394..f871b7bc7d 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -5592,6 +5592,23 @@ python-info-dedenter-opening-block-positions-5
(equal (list (python-tests-look-at "else:" -1 t))
(python-info-dedenter-opening-block-positions)))))
+(ert-deftest python-info-dedenter-opening-block-positions-6 ()
+ "Test multiline block start."
+ (python-tests-with-temp-buffer
+ "
+def func():
+ if (
+ cond1 or
+ cond2
+ ):
+ something()
+ else
+"
+ (python-tests-look-at "else\n")
+ (should
+ (equal (list (python-tests-look-at "if (" -1 t))
+ (python-info-dedenter-opening-block-positions)))))
+
(ert-deftest python-info-dedenter-opening-block-message-1 ()
"Test dedenters inside strings are ignored."
(python-tests-with-temp-buffer
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#59009: python mode indentation behavior fix
2022-11-07 13:57 ` kobarity
@ 2022-11-10 10:26 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2022-11-10 10:26 UTC (permalink / raw)
To: kobarity; +Cc: 59009-done, rostislav9999
> Date: Mon, 07 Nov 2022 22:57:48 +0900
> From: kobarity <kobarity@gmail.com>
> Cc: Randomneo <rostislav9999@gmail.com>,
> 59009@debbugs.gnu.org
> Unfortunately, the presented patch breaks the ERT
> python-indent-electric-colon-4.
>
> I think the problem lies in the forward-line after block-start
> detection. The while loop is used to detect indentation inside the
> block, so if block-start spans multiple lines, it should start at the
> next line. To address this issue, I propose to add
> python-nav-end-of-statement before forward-line. Attached is the
> patch with an ERT.
Thanks, installed.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-10 10:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-03 15:41 bug#59009: python mode indentation behavior fix Randomneo
2022-11-06 8:18 ` Eli Zaretskii
2022-11-07 13:57 ` kobarity
2022-11-10 10:26 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.