CodingStyle

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Wed Mar 5 16:52:05 PST 2014


On Thu, 6 Mar 2014, Dirk Hohndel wrote:
>
> This is not a goal onto itself. It's something to help us overall be
> more productive. So let's not turn this into more than it is.

I totally agree.

We're somewhat limited to a set of (imperfect) tools, like clang +
perl, vim, emacs, etc, also listed in CodingStyle.  The more they can
be convinced to do a deterministic job, the better.  I tried to find
ways to make emacs match your clang-format + perl stuff.  Tuff :)
What I found most troublesome are the '#define' macros.  Syntax is
ununiform/inconsistent.  I asked:

> Still, can we agree that each open bracket followed by a '\'
> introduces a new level of indentation?

The other thing was the code commented out which gets indentation
damaged.  Some parts of the code need mending.

Let's see if people come with better ideas.
Until then, attaching an improved version of the elisp-script.


Cheers,

-- 
Cristian
-------------- next part --------------
(c-add-style "linux-tabs-only"
	     '("linux"
	       (c-basic-offset . 8)		; Guessed value
	       ;; the _backslash_ stuff exposes some grotesque things, IMO
	       ;; remove comments and check out the result
	       (c-backslash-column . 8)	; down from default 48
	       (c-backslash-max-column . 8)	; down from default 72
	       (c-offsets-alist
		(access-label . -)
		(annotation-top-cont . 0)
		(annotation-var-cont . +)
		(arglist-close . c-lineup-close-paren)
		(arglist-cont c-lineup-gcc-asm-reg 0)
		(arglist-cont-nonempty . c-lineup-arglist)
		(arglist-intro . +)
		(block-close . 0)		; Guessed value
		(block-open . 0)
		(brace-entry-open . 0)
		(brace-list-close . 0)		; Guessed value
		(brace-list-open . 0)
		(brace-list-entry . 0)		; Guessed value
		(brace-list-intro . +)		; Guessed value
		(c . c-lineup-C-comments)
		(case-label . 0)		; Guessed value
		(catch-clause . 0)
		(class-close . 0)		; Guessed value
		(class-open . 0)		; Guessed value
		(comment-intro . c-lineup-comment)
		(composition-close . 0)
		(composition-open . 0)

		;; this controls if the first line after a #define
		;; is indented or not; each open bracket causes an extra
		;; level of indentation
		;;(cpp-define-intro . +)		; Guessed value
		(cpp-define-intro . (c-lineup-cpp-define 0))	; cii

		(cpp-macro . -1000)

		;; this controls if the first line after a #define ... \
		;; (continuation) is indented or not
		(cpp-macro-cont . +)

		(defun-block-intro . +)		; Guessed value
		(defun-close . 0)		; Guessed value
		(defun-open . 0)		; Guessed value
		(do-while-closure . 0)
		(else-clause . 0)		; Guessed value
		(extern-lang-open . 0)
		(extern-lang-close . 0)		; Guessed value
		(friend . 0)
		(func-decl-cont . +)
		(inclass . +)			; Guessed value
		(incomposition . +)
		(inexpr-class . +)
		(inexpr-statement . +)
		(inextern-lang . 0)		; Guessed value
		(inher-cont . c-lineup-multi-inher)
		(inher-intro . +)
		(inlambda . c-lineup-inexpr-block)
		(inline-close . 0)
		(inline-open . +)
		(inmodule . +)
		(innamespace . +)
		(knr-argdecl . 0)
		(knr-argdecl-intro . 0)
		(label . 0)			; Guessed value
		(lambda-intro-cont . +)
		(member-init-cont . c-lineup-multi-inher)
		(member-init-intro . +)
		(module-close . 0)
		(module-open . 0)
		(namespace-close . 0)
		(namespace-open . 0)
		(objc-method-args-cont . c-lineup-ObjC-method-args)
		(objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call +)
		(objc-method-intro .
				   [0])
		(statement . 0)			; Guessed value
		(statement-block-intro . +)	; Guessed value
		(statement-case-open . 0)
		(statement-case-intro . +)	; Guessed value

		;; this should insert one TAB on the line(s) that
		;; continue an assignment
		;;(statement-cont . +)		; Guessed value

		;; this takes notice of an assignment character '=' and
		;; aligns code at the right of the '='
		(statement-cont . (c-lineup-assignments +))	; cii

		(stream-op . c-lineup-streamop)
		(string . -1000)
		(substatement . +)		; Guessed value
		(substatement-label . 0)
		(substatement-open . 0)
		(template-args-cont c-lineup-template-args +)
		(topmost-intro . 0)		; Guessed value
		(topmost-intro-cont . c-lineup-topmost-intro-cont))))

;; subsurface c-style hook
(defun subsurface-file-hook ()
  "Subsurface style (automaticaly activated only for .[ch] files)"
  (if (and (string-match "/subsurface/" (buffer-file-name))
	   (string-match "\.[ch]$" (buffer-file-name)))
      (progn
	(c-set-style "linux-tabs-only")
	(setq c-file-style "linux-tabs-only"
	      comment-style 'extra-line)
	)))
(add-hook 'c-mode-hook 'subsurface-file-hook)

(defun subsurface-indent-buffer ()
  "Indent entire buffer; just `M-x subsurface-indent-buffer'"
  (interactive)
  (indent-region (point-min) (point-max) nil))


More information about the subsurface mailing list