Skip to content

Commit

Permalink
python: Fix lambdas after certain characters not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
davidshepherd7 committed Oct 14, 2023
1 parent cb21b85 commit 18e555a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions electric-operator.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions features/python-mode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down

0 comments on commit 18e555a

Please sign in to comment.