|
15 | 15 | ;; .function files are C code |
16 | 16 | (add-to-list 'auto-mode-alist '("/suites/[^/]+\\.function\\'" . c-mode)) |
17 | 17 |
|
| 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 | + |
18 | 66 | (provide 'mbedtls-autoloads) |
19 | 67 |
|
20 | 68 | ;;; That's all. |
0 commit comments