Let gotsfmt replace gofmt in go-mode
This commit is contained in:
parent
0557f6e24a
commit
98948a3168
30
README.org
30
README.org
@ -668,7 +668,7 @@ for technical information.
|
|||||||
display-buffer-pop-up-window
|
display-buffer-pop-up-window
|
||||||
(inhibit-same-window . t)))
|
(inhibit-same-window . t)))
|
||||||
(add-to-list 'display-buffer-alist
|
(add-to-list 'display-buffer-alist
|
||||||
`(,(rx (or "*Occur*" "*grep*" "*xref*"))
|
`(,(rx (or "*Gofmt*" "*Occur*" "*grep*" "*xref*"))
|
||||||
display-buffer-reuse-window
|
display-buffer-reuse-window
|
||||||
(inhibit-same-window . nil)))
|
(inhibit-same-window . nil)))
|
||||||
;; BUG#70773: Eli tells `(setq delayed-warnings-hook nil)' is better.
|
;; BUG#70773: Eli tells `(setq delayed-warnings-hook nil)' is better.
|
||||||
@ -4512,19 +4512,43 @@ Links to learn [[https://go.dev/][Go]] are:
|
|||||||
(setopt go-ts-mode-indent-offset 8) ; for compatibility with Go tools.
|
(setopt go-ts-mode-indent-offset 8) ; for compatibility with Go tools.
|
||||||
|
|
||||||
(defun gots2tabs ()
|
(defun gots2tabs ()
|
||||||
"Set tab stops to 2 spaces locally in current go-ts buffer."
|
"Set tab stops to 2 spaces in current `go-ts` buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (eq major-mode 'go-ts-mode)
|
(when (eq major-mode 'go-ts-mode)
|
||||||
(setq-local go-ts-mode-indent-offset 2)
|
(setq-local go-ts-mode-indent-offset 2)
|
||||||
(setq-local tab-width 2)))
|
(setq-local tab-width 2)))
|
||||||
|
|
||||||
(defun gots8tabs ()
|
(defun gots8tabs ()
|
||||||
"Set tab stops to 8 spaces locally in current go-ts buffer."
|
"Set tab stops to 8 spaces in current `go-ts` buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (eq major-mode 'go-ts-mode)
|
(when (eq major-mode 'go-ts-mode)
|
||||||
(setq-local go-ts-mode-indent-offset 8)
|
(setq-local go-ts-mode-indent-offset 8)
|
||||||
(setq-local tab-width 9)))
|
(setq-local tab-width 9)))
|
||||||
|
|
||||||
|
(defun gotsfmt ()
|
||||||
|
"Let `gofmt` format current `go-ts` buffer and file."
|
||||||
|
(interactive)
|
||||||
|
(when (eq major-mode 'go-ts-mode)
|
||||||
|
(save-buffer)
|
||||||
|
(let ((cb (current-buffer))
|
||||||
|
(pb (get-buffer-create "*Gofmt*"))
|
||||||
|
(fn (buffer-file-name)))
|
||||||
|
(set-buffer pb)
|
||||||
|
(erase-buffer)
|
||||||
|
(if (zerop (call-process "gofmt" nil t nil "-d" fn))
|
||||||
|
(if (> (point) (point-min))
|
||||||
|
(progn
|
||||||
|
(display-buffer pb)
|
||||||
|
(switch-to-buffer pb)
|
||||||
|
(diff-apply-hunk)
|
||||||
|
(set-buffer cb)
|
||||||
|
(save-buffer)
|
||||||
|
(message "Gofmt tabbed your code!"))
|
||||||
|
(message "Gofmt adores your code!"))
|
||||||
|
(display-buffer pb)
|
||||||
|
(switch-to-buffer pb)
|
||||||
|
(message "Your code chokes Gofmt!")))))
|
||||||
|
|
||||||
(add-to-list 'auto-mode-alist `(,(rx ".go" eos) . go-ts-mode)))
|
(add-to-list 'auto-mode-alist `(,(rx ".go" eos) . go-ts-mode)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user