From 18e555a5cdfd7264c179f810d7fd4c71a80b715a Mon Sep 17 00:00:00 2001 From: David Shepherd Date: Sat, 14 Oct 2023 11:07:58 +0000 Subject: [PATCH] python: Fix lambdas after certain characters not working correctly --- electric-operator.el | 5 +++-- features/python-mode.feature | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/electric-operator.el b/electric-operator.el index fc95e36..8ced36c 100644 --- a/electric-operator.el +++ b/electric-operator.el @@ -862,8 +862,9 @@ Also handles C++ lambda capture by reference." (defun electric-operator-python-mode-in-lambda-args? () "Are we inside the arguments statement of a lambda?" - ;; \\(\\s-\\|^\\) instead of just \\b because otherwise foo_lambda matches - (electric-operator-looking-back-locally "\\(\\s-\\|^\\)lambda\\s-[^:]*")) + ;; We can't just \\b because otherwise foo_lambda matches, so we need a whole + ;; explicit list of things that could be before a lambda. + (electric-operator-looking-back-locally "\\([(,:[{=\\s-]\\|^\\)lambda\\s-[^:]*")) (defun electric-operator-python-mode-: () "Handle python dict assignment" diff --git a/features/python-mode.feature b/features/python-mode.feature index 1b2e7ab..7bd52e2 100644 --- a/features/python-mode.feature +++ b/features/python-mode.feature @@ -176,6 +176,11 @@ Feature: Python mode basics When I type "lambda: x, y=1" Then I should see "lambda: x, y = 1" + Scenario: Space after lambda arguments even inside a function + When I type "foo(lambda x:x" + Then I should see "foo(lambda x: x" + + # Slice operator Scenario: Don't space : inside slices When I type "a[1:2]"