Improve tab stop handling and electric operators for Go
This commit is contained in:
parent
f4053d8246
commit
5881f5fc53
41
README.org
41
README.org
@ -4509,7 +4509,22 @@ Links to learn [[https://go.dev/][Go]] are:
|
||||
#+name: lst:setup-go
|
||||
#+begin_src emacs-lisp -n :results silent
|
||||
(when (featurep 'treesit)
|
||||
(setopt go-ts-mode-indent-offset 2)
|
||||
(setopt go-ts-mode-indent-offset 8) ; for compatibility with Go tools.
|
||||
|
||||
(defun gots2tabs ()
|
||||
"Set tab stops to 2 spaces locally 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 locally 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 9)))
|
||||
|
||||
(add-to-list 'auto-mode-alist `(,(rx ".go" eos) . go-ts-mode)))
|
||||
#+end_src
|
||||
|
||||
@ -5264,8 +5279,30 @@ add spaces around operators for [[https://go.dev/][Go]] and [[https://www.python
|
||||
#+begin_src emacs-lisp -n :results silent
|
||||
(when (ensure-package-installation 'electric-operator)
|
||||
;; electric-operator-mode does not handle all operators in Go correctly.
|
||||
;; (add-hook 'go-ts-mode-hook #'electric-operator-mode)
|
||||
(add-hook 'go-ts-mode-hook #'electric-operator-mode)
|
||||
(add-hook 'python-mode-hook #'electric-operator-mode))
|
||||
|
||||
(with-eval-after-load 'electric-operator
|
||||
;; https://go.dev/ref/spec#Operators
|
||||
(apply #'electric-operator-add-rules-for-mode 'go-mode
|
||||
(electric-operator-get-rules-for-mode 'prog-mode))
|
||||
(electric-operator-add-rules-for-mode 'go-mode
|
||||
(cons "*" #'electric-operator-c-mode-*)
|
||||
(cons "&" #'electric-operator-c-mode-&)
|
||||
(cons "++" #'electric-operator-c-mode-++)
|
||||
(cons "--" #'electric-operator-c-mode---)
|
||||
(cons "!=" " != ")
|
||||
(cons "&&" " && ")
|
||||
(cons "&^" " &^" )
|
||||
(cons "//" " // ")
|
||||
(cons ":=" " := ")
|
||||
(cons "<-" " <- ")
|
||||
(cons "<<" " << ")
|
||||
(cons "<=" " <= ")
|
||||
(cons "==" " == ")
|
||||
(cons ">=" " >= ")
|
||||
(cons ">>" " >> ")
|
||||
(cons "||" " || ")))
|
||||
#+end_src
|
||||
|
||||
** [[https://joaotavora.github.io/yasnippet/][Smart snippets]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user