emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/go-mode 0f9b5c5 291/495: Add go-packages-function and go-p


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 0f9b5c5 291/495: Add go-packages-function and go-packages-go-list
Date: Sat, 7 Aug 2021 09:05:34 -0400 (EDT)

branch: elpa/go-mode
commit 0f9b5c5f92ab5ac27ad22663ddd2e423c632795b
Author: Dominik Honnef <dominik@honnef.co>
Commit: Dominik Honnef <dominik@honnef.co>

    Add go-packages-function and go-packages-go-list
    
    Allow choosing between different ways of finding installed packages.
    go-packages will call go-packages-function.
    
    The old implementation of go-packages, which looks for .a files, now
    lives in go-packages-native and is the default value for
    go-packages-function.
    
    A new implementation based on calling 'go list all' was added as
    go-packages-go-list. This function produces better results, but can be
    significantly slower.
    
    Closes gh-120
---
 NEWS       |  5 +++++
 go-mode.el | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/NEWS b/NEWS
index dc9a362..4983edd 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,11 @@ go-mode-1.4.0 (???)
     - go-goto-return-values
     - go-goto-method-receiver
 
+ * Add new variable go-packages-function, which allows choosing
+   between different ways of finding installed packages. Currently,
+   go-packages-native (the default) and go-packages-go-list are
+   provided.
+
 go-mode-1.3.1 (2015-07-03)
 
  * The 1.3.0 release forgot to update the version in the package
diff --git a/go-mode.el b/go-mode.el
index da87c00..3b2747e 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -220,6 +220,20 @@ a `before-save-hook'."
   :type '(repeat (list regexp (choice (repeat string) function)))
   :group 'go)
 
+(defcustom go-packages-function 'go-packages-native
+  "Function called by `go-packages' to determine the list of
+available packages. This is used in e.g. tab completion in
+`go-import-add'.
+
+This package provides two functions: `go-packages-native' uses
+elisp to find all .a files in all /pkg/ directories.
+`go-packages-go-list' uses 'go list all' to determine all Go
+packages. `go-packages-go-list' generally produces more accurate
+results, but can be slower than `go-packages-native'."
+  :type 'function
+  :package-version '(go-mode . 1.4.0)
+  :group 'go)
+
 (defun go--kill-new-message (url)
   "Make URL the latest kill and print a message."
   (kill-new url)
@@ -1305,6 +1319,11 @@ If IGNORE-CASE is non-nil, the comparison is 
case-insensitive."
 
 
 (defun go-packages ()
+  (funcall go-packages-function))
+
+(defun go-packages-native ()
+  "Return a list of all installed Go packages. It looks for
+archive files in /pkg/"
   (sort
    (delete-dups
     (mapcan
@@ -1322,6 +1341,12 @@ If IGNORE-CASE is non-nil, the comparison is 
case-insensitive."
      (go-root-and-paths)))
    #'string<))
 
+(defun go-packages-go-list ()
+  "Return a list of all Go packages, using `go list'"
+  (with-temp-buffer
+    (call-process go-command nil (current-buffer) nil "list" "-e" "all")
+    (split-string (buffer-string) "\n" t)))
+
 (defun go-unused-imports-lines ()
   ;; FIXME Technically, -o /dev/null fails in quite some cases (on
   ;; Windows, when compiling from within GOPATH). Practically,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]