lang/cc: rewrite & polish style settings

Doom used to have its own cc-mode style, which was difficult to
customize without first undoing all its changes.

A doom entry has been added to c-style-alist, which represents
a marriage of various styles (mostly linux), plus some context-sensitive
indentation functions which I think are reasonable.

More importantly, it can be disabled by changing c-default-style.

Also, removed a few hacks that have been merged into v5.33+ of cc-mode.
25.1 users beware! You may not have these changes.
This commit is contained in:
Henrik Lissner 2018-02-23 04:44:02 -05:00
parent 55c6244e9f
commit 5fc4ed3f81
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 51 additions and 37 deletions

View file

@ -19,19 +19,6 @@
(when (and (featurep 'irony) irony-mode)
(+cc|irony-init-compile-options)))
;;;###autoload
(defun +cc*align-lambda-arglist (orig-fun &rest args)
"Improve indentation of continued C++11 lambda function opened as argument."
(if (and (eq major-mode 'c++-mode)
(ignore-errors
(save-excursion
(goto-char (c-langelem-pos langelem))
;; Detect "[...](" or "[...]{". preceded by "," or "(",
;; and with unclosed brace.
(looking-at-p ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
0 ; no additional indent
(apply orig-fun args)))
;;;###autoload
(defun +cc-sp-point-is-template-p (id action context)
"Return t if point is in the right place for C++ angle-brackets."
@ -50,17 +37,26 @@
(looking-at-p "[ ]*#include[^<]+"))))
;;;###autoload
(defun +cc-c-lineup-inclass (_langelem)
"Indent privacy keywords at same level as class properties."
(if (memq major-mode '(c-mode c++-mode))
(let ((inclass (assq 'inclass c-syntactic-context)))
(save-excursion
(goto-char (c-langelem-pos inclass))
(if (or (looking-at "struct")
(looking-at "typedef struct"))
'+
'++)))
'+))
(defun +cc-c++-lineup-inclass (langelem)
"Indent inclass lines one level further than access modifier keywords."
(when (and (eq major-mode 'c++-mode)
(or (assoc 'access-label c-syntactic-context)
(save-excursion
(save-match-data
(re-search-backward
"\\(?:p\\(?:ublic\\|r\\(?:otected\\|ivate\\)\\)\\)"
(c-langelem-pos langelem) t)))))
'++))
;;;###autoload
(defun +cc-lineup-arglist-close (langlem)
"Line up the closing brace in an arglist with the opening brace IF cursor is
preceded by the opening brace or a comma (disregarding whitespace in between)."
(when (save-excursion
(save-match-data
(skip-chars-backward " \t\n" (c-langelem-pos langelem))
(memq (char-before) (list ?, ?\( ?\;))))
(c-lineup-arglist langlem)))
;;