Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: davidshepherd7/electric-operator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3cfca10eac804ba22dd149befe1caaad697dee8a
Choose a base ref
..
head repository: davidshepherd7/electric-operator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9aa3340da4f50e4bbfc0d43e6e57af2a8950a70b
Choose a head ref
Showing with 35 additions and 15 deletions.
  1. +3 −2 .github/workflows/main.yml
  2. +17 −13 electric-operator.el
  3. +15 −0 features/python-mode.feature
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -23,9 +23,10 @@ jobs:
strategy:
matrix:
emacs_version:
- 25.3
- 26.3
- 27.1
- 27.2
- 28.2
- 29.1
fail-fast: false

steps:
30 changes: 17 additions & 13 deletions electric-operator.el
Original file line number Diff line number Diff line change
@@ -39,10 +39,10 @@
(defcustom electric-operator-c-pointer-type-style 'variable
"Defines how C/C++ mode pointer and reference types are spaced.
If set to 'variable' then the operator is touching the variable
If set to \\='variable then the operator is touching the variable
name, as in `int *x'.
If set to 'type' then the operator is touching the type name , as
If set to \\='type then the operator is touching the type name, as
in `int* x'."
:group 'electricity
:type 'symbol
@@ -52,7 +52,7 @@ in `int* x'."
"Defines whether = in R named function arguments should be
spaced.
Setting the value to 'spaced' results in f(foo = 1), 'unspaced'
Setting the value to \\='spaced results in f(foo = 1), \\='unspaced
results in f(foo=1)."
:group 'electricity
:type 'symbol
@@ -190,7 +190,7 @@ from point) as the key."
(defun electric-operator-rule-regex-with-whitespace (op)
"Construct regex matching operator and any whitespace before/inside/after.
For example for the operator '+=' we allow '+=', ' +=', '+ ='. etc.
For example for the operator `+=' we allow `+=', ` +=', `+ ='. etc.
Whitespace before the operator is captured for possible use later.
"
@@ -236,8 +236,8 @@ Returns a modified copy of the rule list."
(defun electric-operator-add-rules-for-mode (major-mode-symbol &rest new-rules)
"Replace or add spacing rules for major mode
Destructively modifies `electric-operator--mode-rules-table' to use the new rules for
the given major mode."
Destructively modifies `electric-operator--mode-rules-table' to use the new
rules for the given major mode."
(puthash major-mode-symbol
(electric-operator--add-rule-list (or (electric-operator-get-rules-trie-for-mode major-mode-symbol)
(make-electric-operator--trie))
@@ -630,7 +630,7 @@ Any better ideas would be welcomed."
"_t"
"Regex used in looking-back-locally to check for C types
For now we just assume that anything ending in '_t' is a type.
For now we just assume that anything ending in \"_t\" is a type.
I'm not sure if we can do any better by default.
You could add your own type names to this if needed. Send pull
@@ -816,7 +816,7 @@ Also handles C++ lambda capture by reference."

(defun electric-operator-c-mode-** ()
"C pointer to pointer or multiplication by pointer dereference.
e.g. `res = a * *b;`'"
e.g. `res = a * *b;'"
(if (or (electric-operator-c-after-type?) (electric-operator-c-is-function-or-class-definition?))
(electric-operator-c-space-pointer-type "**")
" * *"))
@@ -886,14 +886,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\\s-[^:]*"))

(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
@@ -1529,8 +1531,9 @@ Also handles C++ lambda capture by reference."
(t " * ")))

(defun electric-operator-f90-mode-/()
"Handle (/ /) style implicit array declaration."
"Currently fails for fractions in implict declaration."
"Handle (/ /) style implicit array declaration.
Currently fails for fractions in implict declaration."
(cond
;; We do this instead of having separate (/ and /) operators so that it works
;; with electric pairs. TODO: find a way to make this work more generally.
@@ -1539,7 +1542,8 @@ Also handles C++ lambda capture by reference."
(t " / ")))

(defun electric-operator-character-after-paren()
"Return the character immediately after the opening brace of the current paren group."
"Return the character immediately after the opening brace of
the current paren group."
(let ((ppss (syntax-ppss)))
(when (nth 1 ppss) (char-after (+ (nth 1 ppss) 1)))))

15 changes: 15 additions & 0 deletions features/python-mode.feature
Original file line number Diff line number Diff line change
@@ -160,6 +160,21 @@ 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 at the start of another word doesn't affect spacing
When I type "lambdabar=1"
Then I should see "lambdabar = 1"

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

Scenario: Zero argument lambda
When I type "lambda: x, y=1"
Then I should see "lambda: x, y = 1"

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