Enable smart tabs for C and C++
This commit is contained in:
parent
f2531b8d84
commit
ccec10683e
48
config.org
48
config.org
@ -323,7 +323,8 @@
|
||||
(setq-default basic-offset 4)
|
||||
#+end_src
|
||||
|
||||
And generally indenting with spaces is more common, so make that the default:
|
||||
And generally indenting with spaces is more common, so make that
|
||||
the default:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(setq-default indent-tabs-mode nil)
|
||||
@ -356,20 +357,49 @@
|
||||
(require 'lsp-ido)
|
||||
#+end_src
|
||||
|
||||
** C
|
||||
For C there is =clangd= implementing LSP. Assuming that's installed
|
||||
and on the =PATH=, we can just hook =lsp-mode= into the default
|
||||
mode and there will be much rejoicing.
|
||||
*** Smart Tabs
|
||||
Indent with tabs and align with spaces. Installing the package
|
||||
here but it's enabled on a per-language basis in the languages'
|
||||
individual config sections.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(add-hook 'c-mode-hook #'lsp-deferred)
|
||||
#+end_src
|
||||
#+begin_src emacs-lisp
|
||||
(use-package smart-tabs-mode)
|
||||
#+end_src
|
||||
|
||||
[[help:smart-tabs-insinuate][smart-tabs-insinuate]] enables smart tabs for a particular language,
|
||||
but also it will only be used when [[help:indent-tabs-mode][indent-tabs-mode]] is
|
||||
non-nil. The following function wraps up setting
|
||||
~indent-tabs-mode~ and enabling smart tabs for the language into
|
||||
one thing:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun enable-smart-tabs (lang hook)
|
||||
"Enable smart tabs for lang (even if indent-tabs-mode is nil by default)"
|
||||
(smart-tabs-insinuate lang)
|
||||
(add-hook hook (lambda () (setq indent-tabs-mode nil))))
|
||||
#+end_src
|
||||
|
||||
** C
|
||||
For C there is =clangd= implementing LSP. Assuming that's
|
||||
installed and on the =PATH=, we can just hook =lsp-mode= into the
|
||||
default mode and there will be much rejoicing.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(add-hook 'c-mode-hook #'lsp-deferred)
|
||||
#+end_src
|
||||
|
||||
And we want to enable smart tabs:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(enable-smart-tabs 'c 'c-mode-hook)
|
||||
#+end_src
|
||||
|
||||
** C++
|
||||
Essentially the same story as for C
|
||||
Essentially the same story as for C.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(add-hook 'c++-mode-hook #'lsp-deferred)
|
||||
(enable-smart-tabs 'c++ 'c++-mode-hook)
|
||||
#+end_src
|
||||
|
||||
** Haskell
|
||||
|
Loading…
x
Reference in New Issue
Block a user