~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))
|
(setq indent-tabs-mode t))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
** C/C++
|
** 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
|
#+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)
|
(setq-default c-basic-offset 2)
|
||||||
#+END_SRC
|
(setq c-default-style '((java-mode . "java")
|
||||||
*** Clang format
|
(awk-mode . "awk")
|
||||||
use-package clang-format for ease of use formatting, binding to "C-c '" for both C and C++ mode maps.
|
(other . "user")))
|
||||||
#+BEGIN_SRC emacs-lisp
|
|
||||||
(use-package clang-format
|
|
||||||
:after cc-mode
|
|
||||||
:config
|
: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
|
(c-add-style
|
||||||
"user"
|
"user"
|
||||||
'((c-basic-offset . 2)
|
'((c-basic-offset . 2)
|
||||||
@@ -599,17 +591,14 @@
|
|||||||
(substatement-label . 0)
|
(substatement-label . 0)
|
||||||
(access-label . 0)
|
(access-label . 0)
|
||||||
(label . 0)
|
(label . 0)
|
||||||
(statement-cont . +))))
|
(statement-cont . +)))))
|
||||||
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
*** Clang format
|
||||||
*** Set default styles
|
use-package clang-format for ease of use formatting, binding to "C-c '" for both C and C++ mode maps.
|
||||||
Set the default style for modes
|
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(setq c-default-style '((java-mode . "java")
|
(use-package clang-format
|
||||||
(awk-mode . "awk")
|
:after cc-mode
|
||||||
(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
|
#+END_SRC
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user