|
|
@ -2,9 +2,9 @@ |
|
|
|
;; C indentation settings |
|
|
|
;; bsd AKA Allman https://www.emacswiki.org/emacs/IndentingC |
|
|
|
(setq-default c-default-style "bsd" |
|
|
|
c-basic-offset 4 |
|
|
|
tab-width 4 |
|
|
|
indent-tabs-mode t) |
|
|
|
c-basic-offset 4 |
|
|
|
tab-width 4 |
|
|
|
indent-tabs-mode t) |
|
|
|
|
|
|
|
;; Doesn't quite work |
|
|
|
;; (defun infer-indentation-style () |
|
|
@ -13,11 +13,11 @@ |
|
|
|
;; (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)) |
|
|
|
;; ;; ((message "Indent using space") |
|
|
|
;; (setq indent-tabs-mode nil)) |
|
|
|
;; (if (> tab-count space-count) |
|
|
|
;; ;; ((message "Indent using tab") |
|
|
|
;; (setq indent-tabs-mode t)))) |
|
|
|
;; ;; ((message "Indent using tab") |
|
|
|
;; (setq indent-tabs-mode t)))) |
|
|
|
|
|
|
|
;; (add-hook 'c-mode-common-hook |
|
|
|
;; (lambda () (setq indent-tabs-mode nil) |
|
|
@ -25,48 +25,37 @@ |
|
|
|
|
|
|
|
;; (add-hook 'lisp-mode-hook |
|
|
|
;; (lambda () (setq indent-tabs-mode nil) |
|
|
|
;; (infer-indentation-style))) |
|
|
|
;; (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" |
|
|
|
(interactive) |
|
|
|
(save-excursion |
|
|
|
(if (use-region-p) |
|
|
|
(call-interactively 'clang-format-region) |
|
|
|
(call-interactively 'clang-format-buffer) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
"Format the region if one is selected, otherwise format the buffer" |
|
|
|
(interactive) |
|
|
|
(save-excursion |
|
|
|
(if (use-region-p) |
|
|
|
(call-interactively 'clang-format-region) |
|
|
|
(call-interactively 'clang-format-buffer)))) |
|
|
|
|
|
|
|
(defun macoy-clang-format-paragraph () |
|
|
|
"Format the block/paragraph" |
|
|
|
(interactive) |
|
|
|
(save-excursion |
|
|
|
(unless (use-region-p) |
|
|
|
(mark-paragraph) |
|
|
|
) |
|
|
|
(when (use-region-p) |
|
|
|
(call-interactively 'clang-format-region) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
"Format the block/paragraph" |
|
|
|
(interactive) |
|
|
|
(save-excursion |
|
|
|
(unless (use-region-p) |
|
|
|
(mark-paragraph)) |
|
|
|
(when (use-region-p) |
|
|
|
(call-interactively 'clang-format-region)))) |
|
|
|
|
|
|
|
(defun macoy-clang-format-function () |
|
|
|
"Format the function" |
|
|
|
(interactive) |
|
|
|
(save-excursion |
|
|
|
(unless (use-region-p) |
|
|
|
(mark-defun) |
|
|
|
) |
|
|
|
(when (use-region-p) |
|
|
|
(call-interactively 'clang-format-region) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
"Format the function" |
|
|
|
(interactive) |
|
|
|
(save-excursion |
|
|
|
(unless (use-region-p) |
|
|
|
(mark-defun)) |
|
|
|
(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) |
|
|
|