1

This is more or less a question of putting the answer from Make web-mode always indent with spaces into the use-package declaration.

I want to set tab indent to 2 spaces, and use the spaces throughout the lines, even when reaching 8 spaces etc.

This is my effort so far, I've tried both setq and setq-default, and I've tried to put the init code in either :config or :init, but it's not working. When I "describe variable", tab-width is always 8 in the .go file that I'm opening.

(use-package go-mode
  :mode "\\.go\\'"
  :config
  (progn
    (setq-default tab-width 2)
    (setq-default indent-tabs-mode nil)
    ;; tab-width & indent-tabs-mode are both buffer-local so need setq-default
    )

  :init
  (progn
    (setq-default tab-width 2)
    (setq-default indent-tabs-mode nil)
    )

  )

1 Answer 1

2

The most go specific way to do it is using a go-mode-hook.

In your :config add something like (add-hook 'go-mode-hook (lambda () (setq tab-width 2))) That way you set it for every go buffer you open.

3
  • Why would you recommend changing this var at all? tab-width never affects the width of indentation inside Emacs.
    – Dmitry
    Commented May 6, 2020 at 12:58
  • Because it does exactly what the xpt is asking for. Commented May 6, 2020 at 14:52
  • Doesn't seem to be what they need, though.
    – Dmitry
    Commented May 6, 2020 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.