Created
March 20, 2015 23:05
-
-
Save yudai/8ac50af71dccd3fd390c to your computer and use it in GitHub Desktop.
To fix go-remove-unused-imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my-go-unused-imports-lines () | |
;; FIXME Technically, -o /dev/null fails in quite some cases (on | |
;; Windows, when compiling from within GOPATH). Practically, | |
;; however, it has the same end result: There won't be a | |
;; compiled binary/archive, and we'll get our import errors when | |
;; there are any. | |
(reverse (remove nil | |
(mapcar | |
(lambda (line) | |
(when (string-match "^\\(.+\\):\\([[:digit:]]+\\): imported and not used: \".+\".*$" line) | |
(let ((error-file-name (match-string 1 line)) | |
(error-line-num (match-string 2 line))) | |
(if (string= (file-truename error-file-name) (file-truename buffer-file-name)) | |
(string-to-number error-line-num))))) | |
(split-string (shell-command-to-string | |
(concat go-command | |
(if (string-match "_test\.go$" buffer-file-truename) | |
" test -c" | |
" build -o /dev/null"))) "\n"))))) | |
(advice-add 'go-unused-imports-lines :override #'my-go-unused-imports-lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment