Skip to content

Commit

Permalink
Merge pull request #18 from pksadiq/wip/sadiq
Browse files Browse the repository at this point in the history
cc-mode: Fix operator spacing after ',', '(', '=' etc.
  • Loading branch information
xwl authored Nov 13, 2016
2 parents 78e4ccb + 1dedd39 commit 7231d6e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions electric-spacing.el
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ so let's not get too insert-happy."
"\\)\\ *")
(line-beginning-position)))
(derived-mode-p 'sgml-mode))
(if (and c-buffer-is-cc-mode
(looking-back "^#\\(include\\|import\\) *"))
(electric-spacing-insert " " 'middle))
(insert "<>")
(backward-char))
(t
Expand Down Expand Up @@ -249,11 +252,17 @@ so let's not get too insert-happy."
;; | char *a = &b;
;; | int c = a & b;
;; | a && b;
;; | scanf ("%d", &i);
;; | func(&i)
;; `----
(cond ((looking-back (concat (electric-spacing-c-types) " *" ))
(electric-spacing-insert "&" 'after))
((looking-back "= *")
(electric-spacing-insert "&" 'before))
((looking-back "( *")
(electric-spacing-insert "&" 'middle))
((looking-back ", *")
(electric-spacing-insert "&" 'before))
(t
(electric-spacing-insert "&"))))
(t
Expand All @@ -269,6 +278,8 @@ so let's not get too insert-happy."
;; | (*a)->func();
;; | *p++;
;; | *a = *b;
;; | printf("%d", *ip);
;; | func(*p);
;; `----
(cond ((looking-back (concat (electric-spacing-c-types) " *" ))
(electric-spacing-insert "*" 'before))
Expand All @@ -277,6 +288,10 @@ so let's not get too insert-happy."
((looking-back "^[ (]*")
(electric-spacing-insert "*" 'middle)
(indent-according-to-mode))
((looking-back "( *")
(electric-spacing-insert "*" 'middle))
((looking-back ", *")
(electric-spacing-insert "*" 'before))
((looking-back "= *")
(electric-spacing-insert "*" 'before))
(t
Expand Down Expand Up @@ -311,6 +326,15 @@ so let's not get too insert-happy."
(delete-horizontal-space)))
(electric-spacing-insert "+" 'middle)
(indent-according-to-mode))

;; func(++i);
((looking-back "( *")
(electric-spacing-insert "+" 'middle))

;; j = ++i;
((looking-back "= *")
(electric-spacing-insert "+" 'before))

(t
(electric-spacing-insert "+"))))

Expand All @@ -333,6 +357,10 @@ so let's not get too insert-happy."
(not (looking-back "- *")))
(electric-spacing-insert "-" 'before))

;; func(--i)
((looking-back "( *")
(electric-spacing-insert "-" 'middle))

(t
(electric-spacing-insert "-"))))

Expand Down

0 comments on commit 7231d6e

Please sign in to comment.