Tweak text and code of the "Go Programming" section
This commit is contained in:
parent
98948a3168
commit
b306e75fde
43
README.org
43
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 "*Gofmt*" "*Occur*" "*grep*" "*xref*"))
|
`(,(rx (or "*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.
|
||||||
@ -4503,14 +4503,20 @@ Links to learn [[https://go.dev/][Go]] are:
|
|||||||
1. [[https://www.golangprograms.com/go-language.html][Go programming language]] contains a tutorial and a reference.
|
1. [[https://www.golangprograms.com/go-language.html][Go programming language]] contains a tutorial and a reference.
|
||||||
2. [[https://gobyexample.com/][Go by example]] is a showcase of short examples with explanations.
|
2. [[https://gobyexample.com/][Go by example]] is a showcase of short examples with explanations.
|
||||||
3. [[https://interpreterbook.com/][Writing An Interpreter In Go]] is book showing how to write a real program.
|
3. [[https://interpreterbook.com/][Writing An Interpreter In Go]] is book showing how to write a real program.
|
||||||
|
Listing [[lst:setup-go]] defines:
|
||||||
|
- =gotsfmt= which is a cheap small replacement for =gofmt= in [[https://github.com/dominikh/go-mode.el][go-mode]]. Adding
|
||||||
|
=gofmt= to =before-save-hook= is safe, but adding =gotsfmt= to it is unsafe
|
||||||
|
because =gotsfmt= calls =save-buffer=.
|
||||||
|
- =gots8tabs= which sets tab stops to the default 8 spaces locally in the
|
||||||
|
current buffer if the major mode is =go-ts-mode=.
|
||||||
|
- =gots2tabs= which sets tab stops to 2 spaces locally in the current buffer if
|
||||||
|
the major mode is =go-ts-mode=.
|
||||||
|
|
||||||
#+caption[Setup Go programming]:
|
#+caption[Setup Go programming]:
|
||||||
#+caption: Setup Go programming.
|
#+caption: Setup Go programming.
|
||||||
#+name: lst:setup-go
|
#+name: lst:setup-go
|
||||||
#+begin_src emacs-lisp -n :results silent
|
#+begin_src emacs-lisp -n :results silent
|
||||||
(when (featurep 'treesit)
|
(when (featurep 'treesit)
|
||||||
(setopt go-ts-mode-indent-offset 8) ; for compatibility with Go tools.
|
|
||||||
|
|
||||||
(defun gots2tabs ()
|
(defun gots2tabs ()
|
||||||
"Set tab stops to 2 spaces in current `go-ts` buffer."
|
"Set tab stops to 2 spaces in current `go-ts` buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
@ -4523,32 +4529,37 @@ Links to learn [[https://go.dev/][Go]] are:
|
|||||||
(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 8)))
|
||||||
|
|
||||||
(defun gotsfmt ()
|
(defun gotsfmt ()
|
||||||
"Let `gofmt` format current `go-ts` buffer and file."
|
"Let `gofmt` format current `go-ts` buffer and file."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (eq major-mode 'go-ts-mode)
|
(when (eq major-mode 'go-ts-mode)
|
||||||
(save-buffer)
|
(let ((source (current-buffer))
|
||||||
(let ((cb (current-buffer))
|
(goal (get-buffer-create "*Gofmt Output*"))
|
||||||
(pb (get-buffer-create "*Gofmt*"))
|
(filename (buffer-file-name)))
|
||||||
(fn (buffer-file-name)))
|
(when (eq t (buffer-modified-p source)) ; autosaved is not OK.
|
||||||
(set-buffer pb)
|
(save-buffer))
|
||||||
|
(set-buffer goal)
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(if (zerop (call-process "gofmt" nil t nil "-d" fn))
|
;; Direct stdin and stderr to goal.
|
||||||
|
;; Get goal with filename in patch by calling "gofmt -d filename".
|
||||||
|
;; Provoke a gofmt error (delete package statement) to debug this.
|
||||||
|
(if (zerop (call-process "gofmt" nil t nil "-d" filename))
|
||||||
(if (> (point) (point-min))
|
(if (> (point) (point-min))
|
||||||
(progn
|
(progn
|
||||||
(display-buffer pb)
|
(diff-apply-buffer)
|
||||||
(switch-to-buffer pb)
|
(set-buffer source)
|
||||||
(diff-apply-hunk)
|
|
||||||
(set-buffer cb)
|
|
||||||
(save-buffer)
|
(save-buffer)
|
||||||
(message "Gofmt tabbed your code!"))
|
(message "Gofmt tabbed your code!"))
|
||||||
(message "Gofmt adores your code!"))
|
(message "Gofmt adores your code!"))
|
||||||
(display-buffer pb)
|
(display-buffer goal)
|
||||||
(switch-to-buffer pb)
|
|
||||||
(message "Your code chokes Gofmt!")))))
|
(message "Your code chokes Gofmt!")))))
|
||||||
|
|
||||||
|
(add-to-list 'display-buffer-alist `("*Gofmt Output*"
|
||||||
|
display-buffer-reuse-window
|
||||||
|
(inhibit-same-window . nil)))
|
||||||
|
|
||||||
(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