Skip to content

Commit

Permalink
Fix things like foolambda being parsed as a lambda declaration
Browse files Browse the repository at this point in the history
Closes #109
  • Loading branch information
davidshepherd7 committed Aug 27, 2023
1 parent 281abda commit c005f8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions electric-operator.el
Original file line number Diff line number Diff line change
Expand Up @@ -862,14 +862,16 @@ Also handles C++ lambda capture by reference."

(defun electric-operator-python-mode-in-lambda-args? ()
"Are we inside the arguments statement of a lambda?"
(electric-operator-looking-back-locally "lambda[^:]*"))
;; \\(\\s-\\|^\\) instead of just \\b because otherwise foo_lambda matches
(electric-operator-looking-back-locally "\\(\\s-\\|^\\)lambda[^:]*"))

(defun electric-operator-python-mode-: ()
"Handle python dict assignment"
(cond
((electric-operator-python-mode-in-lambda-args?) ": ")

;; A keyword statement (we can't use \\b here because it matches _)
;; A keyword statement (we need \\(\\s-\\|^\\) instead of \\b here not not
;; match _)
((electric-operator-looking-back-locally "\\(\\s-\\|^\\)\\(if\\|elif\\|else\\|for\\|while\\|class\\|def\\|try\\|except\\|with\\)") ":")

;; type definition inside a function
Expand Down
7 changes: 7 additions & 0 deletions features/python-mode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ Feature: Python mode basics
When I type "lambda x=y[1:5]:print x"
Then I should see "lambda x=y[1:5]: print x"

Scenario: Lambda inside another word doesn't affect spacing
When I type "foolambdabar=1"
Then I should see "foolambdabar = 1"

Scenario: Lambda inside another word with _ doesn't affect spacing
When I type "foo_lambdabar=1"
Then I should see "foo_lambdabar = 1"

# Slice operator
Scenario: Don't space : inside slices
Expand Down

0 comments on commit c005f8c

Please sign in to comment.