Add the Golang cube

This commit is contained in:
Sameer Rahmani 2021-05-04 10:16:39 +01:00
parent 2f7855ce1b
commit 1f71ce0f0a
8 changed files with 130 additions and 19 deletions

View File

@ -1,16 +0,0 @@
## Summary
<Describe your changes here including your rational, the problem, your solution vice versa>
### QA
<Describe the steps necessary to test your changes>
### Checklist
[ ] Is the linter happy?
[ ] Is the byte compiler happy (no warning) ?
[ ] Is it backward compatible
[ ] Did you document your changes ?
[ ] Did you update the CHANGELOG ?
[ ] Did you actually test your changes ?

View File

@ -1,4 +1,4 @@
;;; EditorCubes --- The common cubes for FG42 -*- lexical-binding: t; -*-
;;; AutocompletionCubes --- The completion related cubes for FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors
;;
@ -32,11 +32,13 @@
:init
(global-flycheck-mode)))
(defcube fg42/yaml-cube
(:docs "cubes/fg42/prog-cubes.org"
:no-flag t)
(fpkg/use yaml-mode))
(defcube fg42/lsp-cube
(:docs "cubes/fg42/lsp-cube.org"
:flag lsp)

View File

@ -28,6 +28,15 @@
"Enable the support for font icones in FG42.")
(defcube fg42/exec-path-cube
(:docs "cubes/fg42/exec-path-cube.org"
:flag exec-path-from-shell)
(fpkg/use exec-path-from-shell
:init
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))))
(defcube fg42/cursor-cube
(:docs "cubes/fg42/cursor-cube.org"
:flag cursor-type)

50
core/cubes/golang.el Normal file
View File

@ -0,0 +1,50 @@
;;; GolangCubes --- The Golang cubes for FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://gitlab.com/FG42/FG42
;; Version: 3.0.0
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;; Code:
(require 'fpkg)
(require 'fg42/cube)
(require 'fg42/utils)
(autoload-cube 'fg42/initialize-golang "golang/core.el" "Initalize the go mode.")
(defcube fg42/golang-cube
(:docs "cubes/fg42/golang-cube.org"
:flag golang)
(fpkg/use go-mode
:defer t
:mode "\\.go\\'"
:config
(progn
(add-hook 'go-mode-hook 'fg42/initialize-golang)
(when-flag lsp
(add-hook 'go-mode-hook
(lambda ()
(when (not (boundp 'lsp))
(require 'lsp)
(lsp-deferred))))))))
(provide 'cubes/golang)
;;; golang.el ends here

64
core/cubes/golang/core.el Normal file
View File

@ -0,0 +1,64 @@
;;; GolangCubes --- The Golang cubes for FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://gitlab.com/FG42/FG42
;; Version: 3.0.0
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;; Code:
(require 'fg42/flags)
(defun fg42/go-path-from-env ()
"Gets gopath from OS env."
(exec-path-from-shell-copy-env "GOPATH"))
(defun fg42/go-path-binary (gopath)
"Gets Go binaries path with respect to the given GOPATH."
;; TODO: Use `expand-file-name' here
(concat gopath "/bin"))
(defun fg42/initialize-golang ()
"Setup Emacs hooks and turn necessary modes on."
(when-flag lsp
(lsp-register-custom-settings
'(("gopls.completeUnimported" t t)
("gopls.staticcheck" t t)))
(add-hook 'before-save-hook
(lambda ()
(when (eq major-mode 'go-mode)
(lsp-format-buffer t)
(lsp-organize-imports t)))))
(when-flag company
(setq-local company-backends
'(company-capf
company-dabbrev
company-dabbrev-code)))
(let ((go-path (or (plist-get fg42/golang-cube-params :go-path)
(fg42/go-path-from-env))))
(add-to-list 'exec-path (fg42/go-path-binary go-path)))
(local-set-key (kbd "M-.") #'godef-jump)
(local-set-key (kbd "M-*") 'pop-tag-mark))
(provide 'cubes/golang/core)
;;; core.el ends here

View File

@ -21,9 +21,10 @@
;;
;;; Commentary:
;;; Code:
(require 'fg42/flags)
(defun wm-randr ()
"RandR support for WM"
"RandR support for wm."
(when-wm
(require 'exwm-randr)
(setq exwm-randr-workspace-output-plist '(0 "HDMI-1"

View File

@ -99,7 +99,7 @@ For example, `(fg42/merge-flags (list f1 f2 f3) f4 -f2)' will return `(f1 f3 f4)
(member flag cube-local-flags))
`,@body
`(if (member ',flag fg42/flags)
,body
,@body
nil)))

View File

@ -48,6 +48,7 @@ On the first level, I should feel comfortable with it.
(package-install 'exec-path-from-shell)
(exec-path-from-shell-initialize)
#+END_SRC
** TODO Turn on yasnippet mode for Go mode
* Things that didn't work out
- rbenv
- helm