help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Spaces rather than tabs by a major mode hook


From: Yuri Khan
Subject: Re: Spaces rather than tabs by a major mode hook
Date: Thu, 9 Jun 2022 22:12:07 +0700

On Thu, 9 Jun 2022 at 21:39, goncholden via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> I want to use spaces rather than tabs, but need to do this setting by a major 
> mode hook?
>
> How can this be done exactly?

    (defun my-indent-with-spaces ()
      (setq-local indent-tabs-mode nil))
    (add-hook 'emacs-lisp-mode 'my-indent-with-spaces)
    (add-hook 'js-mode 'my-indent-with-spaces)


Alternatively, use spaces by default and only use tabs for specific modes:

    (setq-default indent-tabs-mode nil)
    (defun my-indent-with-tabs ()
      (setq-local indent-tabs-mode t))
    (add-hook 'c++-mode 'my-indent-with-tabs)
    (add-hook 'c-mode 'my-indent-with-tabs)


Or use spaces everywhere by default and only use tabs for specific
modes in specific projects where prescribed by coding convention:

    (setq-default indent-tabs-mode nil)

In your project’s root directory, put a .dir-locals.el:

    ((c++-mode
      (indent-tabs-mode . t)
     (c-mode
      (indent-tabs-mode . t)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]