Insert spaces before parentheses only after C keywords.

Pascal J. Bourguignon [2018-03-30 08:35]
Insert spaces before parentheses only after C keywords.
Filename
freerdp-c-style.el
diff --git a/freerdp-c-style.el b/freerdp-c-style.el
index 8e00ab9..8befdd0 100644
--- a/freerdp-c-style.el
+++ b/freerdp-c-style.el
@@ -506,12 +506,24 @@
               (indent-region start (point)))))
        (self-insert-command repeat)))

+(defun freerdp-c-keyword-p (string-designator)
+   (intern-soft (etypecase string-designator
+                    (symbol    (symbol-name (symbol-at-point)))
+                    (string    string-designator)
+                    (character (string string-designator)))
+                c-keywords-obarray))
+
 (defun freerdp-electric-paren-open (repeat)
   (interactive "p")
   (if (= 1 repeat)
       (progn
         (freerdp-remove-previous-spaces)
-        (insert " ()")
+        (let ((current (point)))
+          (backward-sexp)
+          (if (prog1 (freerdp-c-keyword-p (symbol-at-point))
+                (forward-sexp))
+              (insert " ()")
+              (insert "()")))
         (backward-char))
       (self-insert-command repeat)))
ViewGit