Add golint for emacs.
Fixes #19.
Fixes #23.
Signed-off-by: David Symonds <dsymonds@golang.org>
Ato ARAKI authored 10 years ago
David Symonds committed 10 years ago
44 | 44 |
|
45 | 45 |
Optionally, add this to your ~/.vimrc to automatically run golint on :w
|
46 | 46 |
autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
|
|
47 |
|
|
48 |
|
|
49 |
Emacs
|
|
50 |
-----
|
|
51 |
Add this to your .emacs file:
|
|
52 |
(add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/golang/lint/misc/emacs"))
|
|
53 |
(require 'golint)
|
|
54 |
If you have multiple entries in your GOPATH, replace $GOPATH with the right value.
|
|
55 |
|
|
56 |
Running M-x golint will run golint on the current file.
|
|
57 |
For more usage, see Compilation-Mode:
|
|
58 |
http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation-Mode.html
|
|
0 |
;;; golint.el --- lint for the Go source code
|
|
1 |
;;; https://github.com/golang/lint
|
|
2 |
|
|
3 |
;; Copyright 2013 The Go Authors. All rights reserved.
|
|
4 |
;; Use of this source code is governed by a BSD-style
|
|
5 |
;; license that can be found in the LICENSE file.
|
|
6 |
|
|
7 |
;;; Commentary:
|
|
8 |
|
|
9 |
;; To install golint, add the following lines to your .emacs file:
|
|
10 |
;; (add-to-list 'load-path "PATH CONTAINING golint.el" t)
|
|
11 |
;; (require 'golint)
|
|
12 |
;;
|
|
13 |
;; After this, type M-x golint on Go source code.
|
|
14 |
;;
|
|
15 |
;; Usage:
|
|
16 |
;; C-x `
|
|
17 |
;; Jump directly to the line in your code which caused the first message.
|
|
18 |
;;
|
|
19 |
;; For more usage, see Compilation-Mode:
|
|
20 |
;; http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation-Mode.html
|
|
21 |
|
|
22 |
(require 'compile)
|
|
23 |
|
|
24 |
(defun go-lint-buffer-name (mode)
|
|
25 |
"*Golint*")
|
|
26 |
|
|
27 |
(defun golint-process-setup ()
|
|
28 |
"Setup compilation variables and buffer for `golint'."
|
|
29 |
(run-hooks 'golint-setup-hook))
|
|
30 |
|
|
31 |
(define-compilation-mode golint-mode "golint"
|
|
32 |
"Golint is a linter for Go source code."
|
|
33 |
(set (make-local-variable 'compilation-scroll-output) nil)
|
|
34 |
(set (make-local-variable 'compilation-disable-input) t)
|
|
35 |
(set (make-local-variable 'compilation-process-setup-function)
|
|
36 |
'golint-process-setup)
|
|
37 |
)
|
|
38 |
|
|
39 |
(defun golint ()
|
|
40 |
"Run golint on the current file and populate the fix list. Pressing C-x ` will jump directly to the line in your code which caused the first message."
|
|
41 |
(interactive)
|
|
42 |
(compilation-start (concat "golint " buffer-file-name)
|
|
43 |
'golint-mode))
|
|
44 |
|
|
45 |
(provide 'golint)
|