I installed the newest doom emacs on macOS. Also configed language packages as

$ emacs ~/.doom.d/init.el
(go +lsp)

$ ~/.emacs.d/bin/doom sync

When I open a .go file, the code became highlight. But after save the file, the code can't been formated automatically. I have installed gofmt and goimports. How to set emacs to use them?

I read this document: lang/go module. It seems it can do it: Auto-formatting on save (gofmt). Maybe because of environment path? So how to call system path from emacs? My GOPATH is ~/go, it set in ~/.zshrc. When I open shell via M+x, something is different from terminal. How to import .zshrc configuration completely?


In your doom init.el file you need to enable format +onsave in the :editor section. See the snippet below or look at the example init.el (with format +onsave disabled) on the doom emacs git repo

   (evil +everywhere); come to the dark side, we have cookies
   file-templates    ; auto-snippets for empty files
   fold              ; (nigh) universal code folding
   (format +onsave)  ; automated prettiness
   ;;god               ; run Emacs commands without modifier keys
   ;;lispy             ; vim for lisp, for people who don't like vim
   ;;multiple-cursors  ; editing in many places at once
   ;;objed             ; text object editing for the innocent
   ;;parinfer          ; turn lisp into python, sort of
   ;;rotate-text       ; cycle region at point between text candidates
   snippets          ; my elves. They type so I don't have to
   ;;word-wrap         ; soft wrapping with language-aware indent

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.