Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.1 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. ;;; prelude-go.el --- Emacs Prelude: Go programming support.
  2. ;;
  3. ;; Author: Doug MacEachern
  4. ;; URL: https://github.com/bbatsov/prelude
  5. ;; This file is not part of GNU Emacs.
  6. ;;; Commentary:
  7. ;; Prelude configuration for Go
  8. ;;; License:
  9. ;; This program is free software; you can redistribute it and/or
  10. ;; modify it under the terms of the GNU General Public License
  11. ;; as published by the Free Software Foundation; either version 3
  12. ;; of the License, or (at your option) any later version.
  13. ;;
  14. ;; This program is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;;
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  21. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. ;; Boston, MA 02110-1301, USA.
  23. ;;; Code:
  24. (require 'prelude-programming)
  25. (require 'prelude-lsp)
  26. (prelude-require-packages '(go-mode
  27. go-projectile
  28. lsp-mode
  29. lsp-ui
  30. company
  31. gotest))
  32. (require 'go-projectile)
  33. ;; Ignore go test -c output files
  34. (add-to-list 'completion-ignored-extensions ".test")
  35. (define-key 'help-command (kbd "G") 'godoc)
  36. ;; Fix: super-save will cause go files to be saved when lsp-mode does
  37. ;; certain things, triggering lsp-format-buffer. This causes, inter alia,
  38. ;; commas to disappear when typing go function invocations
  39. (add-to-list 'super-save-predicates
  40. (lambda () (not (eq major-mode 'go-mode))))
  41. (with-eval-after-load 'go-mode
  42. (defun prelude-go-mode-defaults ()
  43. ;; Add to default go-mode key bindings
  44. (let ((map go-mode-map))
  45. (define-key map (kbd "C-c a") 'go-test-current-project) ;; current package, really
  46. (define-key map (kbd "C-c m") 'go-test-current-file)
  47. (define-key map (kbd "C-c .") 'go-test-current-test)
  48. (define-key map (kbd "C-c b") 'go-run)
  49. (define-key map (kbd "C-h f") 'godoc-at-point))
  50. ;; Prefer goimports to gofmt if installed
  51. (let ((goimports (executable-find "goimports")))
  52. (when goimports
  53. (setq gofmt-command goimports)))
  54. ;; stop whitespace being highlighted
  55. (whitespace-toggle-options '(tabs))
  56. ;; CamelCase aware editing operations
  57. (subword-mode +1))
  58. ;; if yas is present, this enables yas-global-mode
  59. ;; which provides completion via company
  60. (if (fboundp 'yas-global-mode)
  61. (yas-global-mode))
  62. ;; configure lsp for go
  63. (defun lsp-go-install-save-hooks ()
  64. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  65. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  66. (add-hook 'go-mode-hook #'lsp-go-install-save-hooks)
  67. (add-hook 'go-mode-hook #'lsp-deferred)
  68. (setq prelude-go-mode-hook 'prelude-go-mode-defaults)
  69. (add-hook 'go-mode-hook (lambda ()
  70. (run-hooks 'prelude-go-mode-hook))))
  71. (provide 'prelude-go)
  72. ;;; prelude-go.el ends here