chiark / gitweb /
el/dot-emacs.el: Add an approximate simulacrum of work C style.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 28 Apr 2016 12:22:22 +0000 (13:22 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 28 Apr 2016 12:22:22 +0000 (13:22 +0100)
This will get refined later.  The most awful thing is having to hack on
indentation after `arglist-cont-nonempty'.  I'm not sure how this will
work in some cases, but it seems to match, more or less, what I find in
the existing files.

el/dot-emacs.el

index 8b24c35d4d137847c5d1f766a0857a1375eefb96..a2989fea4eb737f2093801e09fca2c14ba6b0802 100644 (file)
@@ -1450,6 +1450,22 @@ (defun mdw-c-indent-extern-mumble (langelem)
        c-basic-offset
       nil)))
 
+(defun mdw-c-indent-arglist-nested (langelem)
+  "Indent continued argument lists.
+If we've nested more than one argument list, then only introduce a single
+indentation anyway."
+  (let ((context c-syntactic-context)
+       (pos (c-langelem-2nd-pos c-syntactic-element))
+       (should-indent-p t))
+    (while (and context
+               (eq (caar context) 'arglist-cont-nonempty))
+      (when (and (= (caddr (pop context)) pos)
+                context
+                (memq (caar context) '(arglist-intro
+                                       arglist-cont-nonempty)))
+       (setq should-indent-p nil)))
+    (if should-indent-p '+ 0)))
+
 (defvar mdw-define-c-styles-hook nil
   "Hook run when `cc-mode' starts up to define styles.")
 
@@ -1470,6 +1486,32 @@        (defun ,func () (c-add-style ,name-string ',assocs))
 (eval-after-load "cc-mode"
   '(run-hooks 'mdw-define-c-styles-hook))
 
+(mdw-define-c-style mdw-trustonic-c
+  (c-basic-offset . 4)
+  (comment-column . 0)
+  (c-indent-comment-alist (anchored-comment . (column . 0))
+                         (end-block . (space . 1))
+                         (cpp-end-block . (space . 1))
+                         (other . (space . 1)))
+  (c-class-key . "class")
+  (c-backslash-column . 0)
+  (c-auto-align-backslashes . nil)
+  (c-label-minimum-indentation . 0)
+  (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
+                  (defun-open . (add 0 c-indent-one-line-block))
+                  (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
+                  (topmost-intro . mdw-c-indent-extern-mumble)
+                  (cpp-define-intro . 0)
+                  (knr-argdecl . 0)
+                  (inextern-lang . [0])
+                  (label . 0)
+                  (case-label . +)
+                  (access-label . -)
+                  (inclass . +)
+                  (inline-open . ++)
+                  (statement-cont . +)
+                  (statement-case-intro . +)))
+
 (mdw-define-c-style mdw-c
   (c-basic-offset . 2)
   (comment-column . 40)