From ccec10683e5c52dd2d57fa270a65cbd497571a7f Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 1 Jan 2021 00:00:34 +0000 Subject: [PATCH] Enable smart tabs for C and C++ --- config.org | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/config.org b/config.org index 7a71040..019fbbd 100644 --- a/config.org +++ b/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