1

I set the tab-width for Golang to 2 using the following:

(add-hook 'go-mode-hook
          (lambda ()
            (setq-default indent-tabs-mode 1)
            (setq-default tab-width 2)))

And when I check the tab-width variable, it shows:

   tab-width is a variable defined in ‘C source code’.
    Its value is 8
    Local in buffer plugin.go; global value is 2

      Automatically becomes buffer-local when set.
      This variable is safe as a file local variable if its value
      satisfies the predicate ‘integerp’.

But when I open any .go file, the tab width is still 8. Why?

2 Answers 2

3

The docs tell you to configure the go-tab-width spacemacs layer variable.

In .spacemacs, inside dotspacemacs/layers is a variable called dotspacemacs-configuration-layers. Add the go layer variables like so:

(defun dotspacemacs/layers ()
  (setq-default
   dotspacemacs-configuration-layers
   '(
     (go :variables go-tab-width 2)
   )))
2

setq-default sets the global value, whereas you want to set the value in your particular go-mode buffer. Basically, using setq-default within a mode-hook is never right. Try:

(add-hook 'go-mode-hook
          (lambda ()
            (setq indent-tabs-mode 1)
            (setq tab-width 2)))

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.