[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 9536e6b 010/495: go-import-add
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 9536e6b 010/495: go-import-add |
Date: |
Sat, 7 Aug 2021 09:04:33 -0400 (EDT) |
branch: elpa/go-mode
commit 9536e6b9664e47f878f61107298a450914eae130
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
go-import-add
---
go-mode.el | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/go-mode.el b/go-mode.el
index 503031e..95d8410 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -16,6 +16,7 @@
;; - Support for C-M-h (mark-defun
;; - go-goto-imports
;; - go-play-buffer and go-play-region
+;; - go-import-add (bound to C-c C-a)
;;
;; Minor changes:
;; - use view-mode for the godoc buffer
@@ -108,6 +109,7 @@ built-ins, functions, and some types.")
(define-key m "," 'go-mode-insert-and-indent)
(define-key m ":" 'go-mode-insert-and-indent)
(define-key m "=" 'go-mode-insert-and-indent)
+ (define-key m (kbd "C-c C-a") 'go-import-add)
m)
"Keymap used by Go mode to implement electric keys.")
@@ -547,7 +549,26 @@ link in the kill ring."
(if diff-pos (subseq s1 0 diff-pos) s1))))
(reduce #'common-prefix sequences)))
+(defun go-import-add (arg import)
+ "Add a new import to the list of imports.
+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."
+ (interactive "P\nMPackage: ")
+ (save-excursion
+ (let (as line)
+ (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"))))))
(provide 'go-mode)
- [nongnu] branch elpa/go-mode created (now 3497434), ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1db78fd 001/495: initial commit, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9af89df 006/495: add docstrings to go-goto-imports, go-play-region and go-play-buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 366ada1 011/495: add tab completion for go-import-add, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9536e6b 010/495: go-import-add,
ELPA Syncer <=
- [nongnu] elpa/go-mode fd0c117 012/495: move list of improvements to readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode ca48fc5 009/495: add return values to go-goto-imports that tell which kind of import has been jumped to, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode db41787 015/495: if line has been indented with spaces, replace them with tabs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d942d4f 013/495: add links to further extensions for editting go in emacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5af4f4d 019/495: mention imenu in readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4f3befb 003/495: add go-play-buffer and go-play-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 61467ee 004/495: add readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2835258 007/495: support `import foo "bar"` syntax in go-goto-imports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0a570b1 014/495: use `go env` to determine goroot and gopath, support multiple gopath entries and skip over ones with no pkg dir, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6ccd9b9 017/495: Revert "if line has been indented with spaces, replace them with tabs", ELPA Syncer, 2021/08/07