From 24994206971abbbb3753d134941156da121a86c5 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Wed, 12 Apr 2017 17:40:38 +0100 Subject: [PATCH] Bunch of C formatting rules for emacs --- emacs/.emacs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/emacs/.emacs b/emacs/.emacs index 857b765..040b49d 100644 --- a/emacs/.emacs +++ b/emacs/.emacs @@ -68,6 +68,7 @@ (use-package org-evil :ensure t) + (use-package flycheck :ensure t :init (global-flycheck-mode)) @@ -157,3 +158,41 @@ (eval-after-load 'company '(add-to-list 'company-backends 'company-jedi)) + +(eval-after-load 'autoinsert + '(define-auto-insert '("\\.org\\'" . "Org header") + '( + "Hides all but one star and uncollapses everything." + "#+STARTUP: hidestars showall\n\n" + _))) + +(add-hook 'find-file-hook 'auto-insert) + +; Sane C formatting + +(defun c-lineup-arglist-tabs-only (ignored) + "Line up argument lists by tabs, not spaces." + (let* ((anchor (c-langelem-pos c-syntactic-element)) + (column (c-langelem-2nd-pos c-syntactic-element)) + (offset (- (1+ column) anchor)) + (steps (floor offset c-basic-offset))) + (* (max steps 1) + c-basic-offset))) + +(add-hook 'c-mode-common-hook + (lambda () + ;; Add kernel style + (c-add-style + "linux-tabs-only" + '("linux" (c-offsets-alist + (arglist-cont-nonempty + c-lineup-gcc-asm-reg + c-lineup-arglist-tabs-only)))))) + +(add-hook 'c-mode-hook + (lambda () + (let ((filename (buffer-file-name))) + ;; Enable kernel mode for the appropriate files + (setq indent-tabs-mode t) + (setq show-trailing-whitespace t) + (c-set-style "linux-tabs-only"))))) -- 2.45.2