My Emacs config, and other editor settings
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

;; C indentation settings
;; bsd AKA Allman
(setq-default c-default-style "bsd"
c-basic-offset 4
tab-width 4
indent-tabs-mode t)
;; Doesn't quite work
;; (defun infer-indentation-style ()
;; ;; if our source file uses tabs, we use tabs, if spaces spaces, and if
;; ;; neither, we use the current indent-tabs-mode
;; (let ((space-count (how-many "^ " (point-min) (point-max)))
;; (tab-count (how-many "^\t" (point-min) (point-max))))
;; (if (> space-count tab-count)
;; ;; ((message "Indent using space")
;; (setq indent-tabs-mode nil))
;; (if (> tab-count space-count)
;; ;; ((message "Indent using tab")
;; (setq indent-tabs-mode t))))
;; (add-hook 'c-mode-common-hook
;; (lambda () (setq indent-tabs-mode nil)
;; (infer-indentation-style)))
;; (add-hook 'lisp-mode-hook
;; (lambda () (setq indent-tabs-mode nil)
;; (infer-indentation-style)))
;; Clang format
;; Looks for .clang-format in project dir
(when (require 'clang-format)
(defun macoy-clang-format-region-or-buffer ()
"Format the region if one is selected, otherwise format the buffer"
(if (use-region-p)
(call-interactively 'clang-format-region)
(call-interactively 'clang-format-buffer))))
(defun macoy-clang-format-paragraph ()
"Format the block/paragraph"
(unless (use-region-p)
(when (use-region-p)
(call-interactively 'clang-format-region)))
(defun macoy-clang-format-function ()
"Format the function"
(unless (use-region-p)
(when (use-region-p)
(call-interactively 'clang-format-region))))
(global-set-key (kbd "C-M-a") 'macoy-clang-format-region-or-buffer)
(global-set-key (kbd "C-.") 'macoy-clang-format-paragraph)
(global-set-key (kbd "C->") 'macoy-clang-format-function)
;; Not sure if this actually does anything
;; (fset 'c-indent-region 'clang-format-region)