Skip to content

Commit 62f2107

Browse files
Mbed TLS indentation style for C
Signed-off-by: Gilles Peskine <[email protected]>
1 parent ad65828 commit 62f2107

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tools/emacs/mbedtls-autoloads.el

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,54 @@
1515
;; .function files are C code
1616
(add-to-list 'auto-mode-alist '("/suites/[^/]+\\.function\\'" . c-mode))
1717

18+
;; Mbed TLS indentation style
19+
20+
(defun cc-style-lineup-if-with-else (context)
21+
"When there is a newline in else/if, indent if like else.
22+
That is, indent like this:
23+
if (...)
24+
...
25+
else
26+
if (...)
27+
...
28+
instead of this:
29+
if (...)
30+
...
31+
else
32+
if (...)
33+
...
34+
To achieve this, add `(substatement cc-style-lineup-if-with-else +)'
35+
to `c-offsets-alist'."
36+
;; https://emacs.stackexchange.com/questions/31038/stop-reindenting-if-after-else/31041#31041
37+
(pcase context
38+
(`(substatement . ,anchor)
39+
(save-excursion
40+
(back-to-indentation)
41+
(when (looking-at-p "if\\_>")
42+
(goto-char anchor)
43+
(when (looking-at-p "\\(else\\|switch\\)\\_>")
44+
0))))))
45+
46+
(defun cc-style-make-mbedtls ()
47+
(let ((entry (assoc "mbedtls" c-style-alist)))
48+
(unless entry
49+
(setq entry (cons "mbedtls" nil))
50+
(setq c-style-alist (cons entry c-style-alist)))
51+
(setcdr entry '((c-basic-offset . 4)
52+
(c-hanging-braces-alist
53+
(arglist-cont before after)
54+
(arglist-cont-nonempty before after)
55+
(substatement-open before after))
56+
(c-offsets-alist
57+
(case-label . +)
58+
(inextern-lang . 0)
59+
(label . 0)
60+
(substatement cc-style-lineup-if-with-else +)
61+
(substatement-open . 0)
62+
(substatement-label . 0)
63+
)))))
64+
(eval-after-load "cc-styles" '(cc-style-make-mbedtls))
65+
1866
(provide 'mbedtls-autoloads)
1967

2068
;;; That's all.

0 commit comments

Comments
 (0)