[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 4372f5d 026/495: teach go-import-add how to uncomm
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 4372f5d 026/495: teach go-import-add how to uncomment imports |
Date: |
Sat, 7 Aug 2021 09:04:37 -0400 (EDT) |
branch: elpa/go-mode
commit 4372f5d3f9159244ceee1f7570d3ec74a214b391
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
teach go-import-add how to uncomment imports
---
go-mode.el | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 506c093..08a75b5 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -534,23 +534,40 @@ link in the kill ring."
When called with a prefix argument asks for an alternative name
to import the package as.
-If no list exists yet, one will be created if possible."
+If no list exists yet, one will be created if possible.
+
+If an identical import has been commented, it will be
+uncommented, otherwise a new import will be added."
+
+ ;; - If there's a matching `// import "foo"`, uncomment it
+ ;; - If we're in an import() block and there's a matching `"foo"`, uncomment
it
+ ;; - Otherwise add a new import, with the appropriate syntax
(interactive
(list
current-prefix-arg
(completing-read "Package: " (go-packages))))
(save-excursion
- (let (as line)
+ (let (as line import-start)
(if arg
(setq as (read-from-minibuffer "Import as: ")))
(if as
(setq line (format "%s \"%s\"" as import))
(setq line (format "\"%s\"" import)))
- (case (go-goto-imports)
- ('fail (message "Could not find a place to add import."))
- ('block (insert "\n\t" line))
- ('single (insert "import " line "\n"))
- ('none (insert "\nimport (\n\t" line "\n)\n"))))))
+
+ (beginning-of-buffer)
+ (if (re-search-forward (concat "^// import " line "$") nil t)
+ (uncomment-region (line-beginning-position) (line-end-position))
+ (case (go-goto-imports)
+ ('fail (message "Could not find a place to add import."))
+ ('block
+ (save-excursion
+ (re-search-backward "^import (")
+ (setq import-start (point)))
+ (if (re-search-backward (concat "^[[:space:]]+// " line "$")
import-start t)
+ (uncomment-region (line-beginning-position)
(line-end-position))
+ (insert "\n\t" line)))
+ ('single (insert "import " line "\n"))
+ ('none (insert "\nimport (\n\t" line "\n)\n")))))))
(defun go--directory-dirs (dir)
(if (file-directory-p dir)
- [nongnu] elpa/go-mode faafd90 038/495: add autoload cookies, (continued)
- [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, 2021/08/07
- [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 <=
- [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
- [nongnu] elpa/go-mode e78baea 054/495: do not leave point at beginning of line when (not) indenting a comment, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a5164ac 055/495: Fix indentation for code after multi-line function signature, ELPA Syncer, 2021/08/07