Add golint for emacs.
Fixes #19.
Fixes #23.
Signed-off-by: David Symonds <dsymonds@golang.org>
diff --git a/README b/README
index 9d4e572..c763bdd 100644
--- a/README
+++ b/README
@@ -45,3 +45,15 @@
Optionally, add this to your ~/.vimrc to automatically run golint on :w
autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
+
+
+Emacs
+-----
+Add this to your .emacs file:
+ (add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/golang/lint/misc/emacs"))
+ (require 'golint)
+If you have multiple entries in your GOPATH, replace $GOPATH with the right value.
+
+Running M-x golint will run golint on the current file.
+For more usage, see Compilation-Mode:
+ http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation-Mode.html
diff --git a/misc/emacs/golint.el b/misc/emacs/golint.el
new file mode 100644
index 0000000..4d6c2cd
--- /dev/null
+++ b/misc/emacs/golint.el
@@ -0,0 +1,46 @@
+;;; golint.el --- lint for the Go source code
+;;; https://github.com/golang/lint
+
+;; Copyright 2013 The Go Authors. All rights reserved.
+;; Use of this source code is governed by a BSD-style
+;; license that can be found in the LICENSE file.
+
+;;; Commentary:
+
+;; To install golint, add the following lines to your .emacs file:
+;; (add-to-list 'load-path "PATH CONTAINING golint.el" t)
+;; (require 'golint)
+;;
+;; After this, type M-x golint on Go source code.
+;;
+;; Usage:
+;; C-x `
+;; Jump directly to the line in your code which caused the first message.
+;;
+;; For more usage, see Compilation-Mode:
+;; http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation-Mode.html
+
+(require 'compile)
+
+(defun go-lint-buffer-name (mode)
+ "*Golint*")
+
+(defun golint-process-setup ()
+ "Setup compilation variables and buffer for `golint'."
+ (run-hooks 'golint-setup-hook))
+
+(define-compilation-mode golint-mode "golint"
+ "Golint is a linter for Go source code."
+ (set (make-local-variable 'compilation-scroll-output) nil)
+ (set (make-local-variable 'compilation-disable-input) t)
+ (set (make-local-variable 'compilation-process-setup-function)
+ 'golint-process-setup)
+)
+
+(defun golint ()
+ "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."
+ (interactive)
+ (compilation-start (concat "golint " buffer-file-name)
+ 'golint-mode))
+
+(provide 'golint)