From: Maximilian Friedersdorff Date: Wed, 12 Apr 2017 16:40:38 +0000 (+0100) Subject: Bunch of C formatting rules for emacs X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=24994206971abbbb3753d134941156da121a86c5;p=max%2Fdotfiles.git Bunch of C formatting rules for emacs --- 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")))))