]> git.eshelyaron.com Git - emacs.git/commitdiff
Performance optimization of 'python-info-statement-ends-block-p'
authorkobarity <kobarity@gmail.com>
Sun, 20 Apr 2025 12:14:46 +0000 (21:14 +0900)
committerEshel Yaron <me@eshelyaron.com>
Sat, 26 Apr 2025 17:31:06 +0000 (19:31 +0200)
* lisp/progmodes/python.el (python-info-statement-ends-block-p):
Add a comparison of the indentation of the next statement with
the indentation of the current statement.  (Bug#77620)

(cherry picked from commit d753c884948499c0c557d01fefe5914f7d57573c)

lisp/progmodes/python.el

index 95a74ccd52bac94f3b0ad9319d5089b900f905e2..256a9e2838a20d2b31dce51baec38347588ec0f2 100644 (file)
@@ -6104,14 +6104,25 @@ parent defun name."
 
 (defun python-info-statement-ends-block-p ()
   "Return non-nil if point is at end of block."
-  (let ((end-of-block-pos (save-excursion
-                            (python-nav-end-of-block)))
-        (end-of-statement-pos (save-excursion
-                                (python-nav-end-of-statement)
-                                (python-util-forward-comment -1)
-                                (point))))
-    (and end-of-block-pos end-of-statement-pos
-         (= end-of-block-pos end-of-statement-pos))))
+  (let* (current-statement
+         (current-indentation (save-excursion
+                                (setq current-statement
+                                      (python-nav-beginning-of-statement))
+                                (current-indentation)))
+         next-statement
+         (next-indentation (save-excursion
+                             (python-nav-forward-statement)
+                             (setq next-statement (point))
+                             (current-indentation))))
+    (unless (and (< current-statement next-statement)
+                 (<= current-indentation next-indentation))
+      (and-let* ((end-of-statement-pos (save-excursion
+                                         (python-nav-end-of-statement)
+                                         (python-util-forward-comment -1)
+                                         (point)))
+                 (end-of-block-pos (save-excursion
+                                     (python-nav-end-of-block))))
+        (= end-of-block-pos end-of-statement-pos)))))
 
 (defun python-info-beginning-of-statement-p ()
   "Return non-nil if point is at beginning of statement."