[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 37181ae 021/495: add feature for removing unused i
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 37181ae 021/495: add feature for removing unused imports |
Date: |
Sat, 7 Aug 2021 09:04:36 -0400 (EDT) |
branch: elpa/go-mode
commit 37181ae561593f8c9aa9c590ec440db96b20362c
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
add feature for removing unused imports
---
go-mode.el | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/go-mode.el b/go-mode.el
index 6592b5e..63676ea 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -612,5 +612,26 @@ If no list exists yet, one will be created if possible."
(go--directory-dirs pkgdir))))
(go-root-and-paths)))) 'string<))
+(defun go-unused-imports-lines ()
+ ;; TODO handle *_test.gi files
+ (reverse (remove nil
+ (mapcar
+ (lambda (line)
+ (if (string-match "^\\(.+\\):\\([[:digit:]]+\\):
imported and not used: \".+\"$" line)
+ (if (string= (file-truename (match-string 1 line))
buffer-file-truename)
+ (string-to-number (match-string 2 line)))))
+ (split-string (shell-command-to-string "go build -o
/dev/null") "\n")))))
+
+(defun go-remove-unused-imports (arg)
+ (interactive "P")
+ (save-excursion
+ (let ((lines (go-unused-imports-lines)))
+ (dolist (import lines)
+ (goto-line import)
+ (beginning-of-line)
+ (if arg
+ (comment-region (line-beginning-position) (line-end-position))
+ (kill-line)))
+ (message "Removed %d imports" (length lines)))))
(provide 'go-mode)
- [nongnu] elpa/go-mode 5c8a47c 030/495: use (forward-line -1) instead of (previous-line), (continued)
- [nongnu] elpa/go-mode 5c8a47c 030/495: use (forward-line -1) instead of (previous-line), ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4c5493b 036/495: also load diff-mode during compilation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode faafd90 038/495: add autoload cookies, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c97dacc 044/495: do not change the indentation of multiline comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5fbf6bd 048/495: remove unnecessary progns, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8065408 051/495: formatting, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c14eb13 061/495: more test cases, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5dc94e8 069/495: Remove enclosing quotes in go-import-add, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 426d2df 050/495: Improve indentation speed by not trying to indent unnested lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d10c4bc 020/495: use /= instead of (not (=)), ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 37181ae 021/495: add feature for removing unused imports,
ELPA Syncer <=
- [nongnu] elpa/go-mode cf557a3 024/495: Merge branch 'fix/gh-2', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4372f5d 026/495: teach go-import-add how to uncomment imports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 22427ec 028/495: update documentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode cf14ed3 033/495: comment unused function go--common-prefix, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8e413db 035/495: require diff-mode during compilation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 572c754 042/495: For continuation lines, do not assume the indentation of a multiline raw string, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 087f58f 043/495: don't expect a line end after labels or cases, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 54a102e 046/495: do not move cursor to beginning of line after indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1128e71 052/495: do not try to turn off flymake if flymake isn't loaded, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 903768b 053/495: tweak godoc to behave more like help in emacs, ELPA Syncer, 2021/08/07