]> git.friedersdorff.com Git - max/dotfiles.git/commitdiff
Bunch of C formatting rules for emacs
authorMaximilian Friedersdorff <max@friedersdorff.com>
Wed, 12 Apr 2017 16:40:38 +0000 (17:40 +0100)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Wed, 12 Apr 2017 16:40:38 +0000 (17:40 +0100)
emacs/.emacs

index 857b765ac124dda401eb3b26b3901df7dd6dfe82..040b49d97e0e2497d5626318721274f74dc11982 100644 (file)
@@ -68,6 +68,7 @@
 (use-package org-evil
   :ensure t)
 
+
 (use-package flycheck
   :ensure t
   :init (global-flycheck-mode))
 
 (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")))))