Fix smart tabs

This commit is contained in:
Camden Dixie O'Brien 2021-01-01 00:00:35 +00:00
parent 1f7121db14
commit ae1f32c997

View File

@ -366,17 +366,16 @@
(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:
The package has this really annoying behaviour that it turns
itself off if [[help:indent-tabs-mode][indent-tabs-mode]] is nil, even when you just
explicitly turned it on. The solution on the Emacs wiki is to set
indent-tabs-mode to t in a =c-mode-common= hook, which is a bit of
a hack, but I tried my own approach and it didn't work for no
apparent reason so I'm just going to do as I'm told.
#+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))))
(add-hook 'c-mode-common-hook
(lambda () (setq indent-tabs-mode t)))
#+end_src
** C
@ -391,7 +390,7 @@
And we want to enable smart tabs:
#+begin_src emacs-lisp
(enable-smart-tabs 'c 'c-mode-hook)
(smart-tabs-insinuate 'c)
#+end_src
** C++
@ -399,7 +398,7 @@
#+begin_src emacs-lisp
(add-hook 'c++-mode-hook #'lsp-deferred)
(enable-smart-tabs 'c++ 'c++-mode-hook)
(smart-tabs-insinuate 'c++)
#+end_src
** Haskell