~minimised C/C++ configuration to use-package cc-mode
use-package allows for lazy loading C features, which means load time is slightly smaller.
This commit is contained in:
@@ -560,28 +560,20 @@
|
||||
(setq indent-tabs-mode t))
|
||||
#+END_SRC
|
||||
** C/C++
|
||||
*** C Offset
|
||||
Setup for C and C++ modes via the cc-mode package.
|
||||
Firstly hook the C and C++ modes to activate tabs.
|
||||
Then set the offset to 2, and the general style to user.
|
||||
Finally, add a user style that mimics the Microsoft guidelines for C# (open braces everywhere).
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package cc-mode
|
||||
:hook (c-mode . +dx:activate-tabs)
|
||||
:hook (c++-mode . +dx:activate-tabs)
|
||||
:init
|
||||
(setq-default c-basic-offset 2)
|
||||
#+END_SRC
|
||||
*** Clang format
|
||||
use-package clang-format for ease of use formatting, binding to "C-c '" for both C and C++ mode maps.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package clang-format
|
||||
:after cc-mode
|
||||
(setq c-default-style '((java-mode . "java")
|
||||
(awk-mode . "awk")
|
||||
(other . "user")))
|
||||
:config
|
||||
(bind-key "C-c '" #'clang-format-region c-mode-map)
|
||||
(bind-key "C-c '" #'clang-format-region c++-mode-map))
|
||||
#+END_SRC
|
||||
*** Tabs mode for C and C++
|
||||
Add tabs to both C and C++ modes via =activate-tabs= function.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(add-hook 'c-mode-hook #'dx:activate-tabs)
|
||||
(add-hook 'c++-mode-hook #'dx:activate-tabs)
|
||||
#+END_SRC
|
||||
*** Custom user style
|
||||
Add a custom style which follows something like a 'Microsoft Style' in that it opens braces everywhere (for ease of reading).
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(c-add-style
|
||||
"user"
|
||||
'((c-basic-offset . 2)
|
||||
@@ -599,17 +591,14 @@
|
||||
(substatement-label . 0)
|
||||
(access-label . 0)
|
||||
(label . 0)
|
||||
(statement-cont . +))))
|
||||
|
||||
(statement-cont . +)))))
|
||||
#+END_SRC
|
||||
|
||||
*** Set default styles
|
||||
Set the default style for modes
|
||||
*** Clang format
|
||||
use-package clang-format for ease of use formatting, binding to "C-c '" for both C and C++ mode maps.
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq c-default-style '((java-mode . "java")
|
||||
(awk-mode . "awk")
|
||||
(other . "user")))
|
||||
(use-package clang-format
|
||||
:after cc-mode
|
||||
:config
|
||||
(bind-key "C-c '" #'clang-format-region c-mode-map)
|
||||
(bind-key "C-c '" #'clang-format-region c++-mode-map))
|
||||
#+END_SRC
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user