From 0b830fb6ef16361667788adc4f8c61bbc72f74c8 Mon Sep 17 00:00:00 2001 From: Grigory Shipunov Date: Mon, 8 May 2023 12:44:06 +0200 Subject: [PATCH] llvm style for C/C++ by default --- init.el | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/init.el b/init.el index 58b67b6..07d7a7a 100644 --- a/init.el +++ b/init.el @@ -75,10 +75,44 @@ (setq-local fill-column 100)) (require 'cc-mode) + +;;; Copypasta of llvm/utils/emacs/emacs.el +;; LLVM coding style guidelines in emacs +;; Maintainer: LLVM Team, http://llvm.org/ +(defun llvm-lineup-statement (langelem) + (let ((in-assign (c-lineup-assignments langelem))) + (if (not in-assign) + '++ + (aset in-assign 0 + (+ (aref in-assign 0) + (* 2 c-basic-offset))) + in-assign))) + +;; Add a cc-mode style for editing LLVM C and C++ code +(c-add-style "llvm.org" + '("gnu" + (fill-column . 80) + (c++-indent-level . 2) + (c-basic-offset . 2) + (indent-tabs-mode . nil) + (c-offsets-alist . ((arglist-intro . ++) + (innamespace . 0) + (member-init-intro . ++) + (statement-cont . llvm-lineup-statement))))) + +;; Files with "llvm" in their names will automatically be set to the +;; llvm.org coding style. +(add-hook 'c-mode-common-hook + (function + (lambda nil + (if (string-match "llvm" buffer-file-name) + (progn + (c-set-style "llvm.org")))))) + (setq c-default-style '((java-mode . "java") (awk-mode . "awk") - (c-mode . "linux") - (c++-mode . "stroustrup") + (c-mode . "llvm.org") + (c++-mode . "llvm.org") (other . "stroustrup"))) ;; completion