I am unable to set gofmt arguments to consume the following arguments

-tabs=false -tabwidth=2 -w=true

When I set the variable gofmt-args, I get the following error Invalid read syntax: "Trailing garbage following expression".

If I give just one argument such as -tabwidth=2, I get the error Value ‘-tabwidth=2’ does not match type repeat of gofmt-args

Any suggestions on how to fix this?

  • Can you share the code snippet where you tried to set gofmt-args? – psanford Apr 2 at 1:32
  • I just used M-x set-variable – hmehra Apr 2 at 4:59

Based on the error, it looks like you tried passing an unquoted string to set gofmt-args. gofmt-args's type is a list of strings, so that is what you need to give it. You can set it like this:

(setq gofmt-args '("-tabs=false" "-tabwidth=2" "-w=true"))

If you are setting it interactively, its probably easiest to use M-x customize-variable RET gofmt-args RET. That will give you an interactive UI for adding and removing elements from the list and you don't need to worry about quoting.

  • Thanks @psanford. That indeed works. customize-variable is much much better than set-variable. – hmehra Apr 2 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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