Split listing in "Go Programming" section and edit the text
This commit is contained in:
parent
f78bc1f5f5
commit
f5e56af4e7
70
README.org
70
README.org
@ -367,8 +367,7 @@ version.
|
|||||||
Mickey Peterson's post [[https://www.masteringemacs.org/article/how-to-get-started-tree-sitter?utm_source=newsletter&utm_medium=rss][How To Get Started with Tree-Sitter]] explains how to use
|
Mickey Peterson's post [[https://www.masteringemacs.org/article/how-to-get-started-tree-sitter?utm_source=newsletter&utm_medium=rss][How To Get Started with Tree-Sitter]] explains how to use
|
||||||
=tree-sitter= in Emacs-29.1. Listing [[lst:setup-treesit-sources][Setup =treesit= grammar sources]] configures
|
=tree-sitter= in Emacs-29.1. Listing [[lst:setup-treesit-sources][Setup =treesit= grammar sources]] configures
|
||||||
for different =tree-sitter= grammar sources and maps =python-mode= to
|
for different =tree-sitter= grammar sources and maps =python-mode= to
|
||||||
=python-ts-mode=. Listing [[lst:setup-go][Setup Go programming]] shows how to configure
|
=python-ts-mode=.
|
||||||
~tab-width~ for ~go-ts-mod~ and ~go-mode-ts-mode~.
|
|
||||||
|
|
||||||
#+caption[Setup =treesit= grammar sources]:
|
#+caption[Setup =treesit= grammar sources]:
|
||||||
#+caption: Setup =treesit= grammar sources.
|
#+caption: Setup =treesit= grammar sources.
|
||||||
@ -4411,7 +4410,6 @@ changes the semantics of calling `beginning-of-defun'."
|
|||||||
:CUSTOM_ID: sec:go-programming
|
:CUSTOM_ID: sec:go-programming
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
|
|
||||||
[[https://jorge.olano.dev/blog/getting-started-with-go-and-emacs/][Getting started with Go and Emacs]] looks interesting but this setup uses ~eglot~
|
[[https://jorge.olano.dev/blog/getting-started-with-go-and-emacs/][Getting started with Go and Emacs]] looks interesting but this setup uses ~eglot~
|
||||||
~go-ts-mode~ (instead of ~go-mode~) and my hardware is too old to use [[https://brew.sh/][HomeBrew]].
|
~go-ts-mode~ (instead of ~go-mode~) and my hardware is too old to use [[https://brew.sh/][HomeBrew]].
|
||||||
This setup uses the following links to install [[https://go.dev/][Go]] and [[https://pkg.go.dev/golang.org/x/tools/gopls][gopls]] on [[https://en.wikipedia.org/wiki/Darwin_(operating_system)][Darwin]]:
|
This setup uses the following links to install [[https://go.dev/][Go]] and [[https://pkg.go.dev/golang.org/x/tools/gopls][gopls]] on [[https://en.wikipedia.org/wiki/Darwin_(operating_system)][Darwin]]:
|
||||||
@ -4422,34 +4420,19 @@ 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]:
|
Listing [[lst:setup-go-1]] defines =gotsfmt= which is a cheap small replacement for
|
||||||
#+caption: Setup Go programming.
|
=gofmt= in [[https://github.com/dominikh/go-mode.el][go-mode]]. Adding =gofmt= to =before-save-hook= is safe, but adding
|
||||||
#+name: lst:setup-go
|
=gotsfmt= is unsafe because =gotsfmt= calls =save-buffer=. Listing
|
||||||
#+begin_src emacs-lisp -n :results silent
|
[[lst:setup-go-2]] defines =gots8tabs=, =gots4tabs=, and =gots2tabs= which set tab
|
||||||
|
stops to respectively 8, 4, and 2 spaces locally in the current buffer if the
|
||||||
|
major mode is =go-ts-mode=.
|
||||||
|
|
||||||
|
#+caption[Setup tab stops handling]:
|
||||||
|
#+caption: Setup tab stops handling.
|
||||||
|
#+name: lst:setup-go-1
|
||||||
|
#+begin_src emacs-lisp
|
||||||
(when (featurep 'treesit)
|
(when (featurep 'treesit)
|
||||||
(defun gots2tabs ()
|
|
||||||
"Set tab stops to 2 spaces in current `go-ts` buffer."
|
|
||||||
(interactive)
|
|
||||||
(when (eq major-mode 'go-ts-mode)
|
|
||||||
(setq-local go-ts-mode-indent-offset 2)
|
|
||||||
(setq-local tab-width 2)))
|
|
||||||
|
|
||||||
(defun gots8tabs ()
|
|
||||||
"Set tab stops to 8 spaces in current `go-ts` buffer."
|
|
||||||
(interactive)
|
|
||||||
(when (eq major-mode 'go-ts-mode)
|
|
||||||
(setq-local go-ts-mode-indent-offset 8)
|
|
||||||
(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)
|
||||||
@ -4474,7 +4457,34 @@ Listing [[lst:setup-go]] defines:
|
|||||||
(message "Gofmt adores your code!"))
|
(message "Gofmt adores your code!"))
|
||||||
(display-buffer output '(display-buffer-below-selected
|
(display-buffer output '(display-buffer-below-selected
|
||||||
(inhibit-same-window . t)))
|
(inhibit-same-window . t)))
|
||||||
(message "Your code chokes Gofmt!")))))
|
(message "Your code chokes Gofmt!"))))))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+caption[Setup tab stops handling]:
|
||||||
|
#+caption: Setup tab stops handling.
|
||||||
|
#+name: lst:setup-go-2
|
||||||
|
#+begin_src emacs-lisp -n :results silent
|
||||||
|
(when (featurep 'treesit)
|
||||||
|
(defun gots2tabs ()
|
||||||
|
"Set tab stops to 2 spaces in current `go-ts` buffer."
|
||||||
|
(interactive)
|
||||||
|
(when (eq major-mode 'go-ts-mode)
|
||||||
|
(setq-local go-ts-mode-indent-offset 2)
|
||||||
|
(setq-local tab-width 2)))
|
||||||
|
|
||||||
|
(defun gots4tabs ()
|
||||||
|
"Set tab stops to 4 spaces in current `go-ts` buffer."
|
||||||
|
(interactive)
|
||||||
|
(when (eq major-mode 'go-ts-mode)
|
||||||
|
(setq-local go-ts-mode-indent-offset 4)
|
||||||
|
(setq-local tab-width 4)))
|
||||||
|
|
||||||
|
(defun gots8tabs ()
|
||||||
|
"Set tab stops to 8 spaces in current `go-ts` buffer."
|
||||||
|
(interactive)
|
||||||
|
(when (eq major-mode 'go-ts-mode)
|
||||||
|
(setq-local go-ts-mode-indent-offset 8)
|
||||||
|
(setq-local tab-width 8)))
|
||||||
|
|
||||||
(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