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

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

[nongnu] elpa/go-mode 0a570b1 014/495: use `go env` to determine goroot


From: ELPA Syncer
Subject: [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
Date: Sat, 7 Aug 2021 09:04:34 -0400 (EDT)

branch: elpa/go-mode
commit 0a570b15f1ce8e3989c117ecb1d92dc5622f4c72
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>

    use `go env` to determine goroot and gopath, support multiple gopath 
entries and skip over ones with no pkg dir
---
 go-mode.el | 62 ++++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 36 insertions(+), 26 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 82dea67..ee7eabf 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -553,19 +553,19 @@ If no list exists yet, one will be created if possible."
         ('none (insert "\nimport (\n\t" line "\n)\n"))))))
 
 (defun go-directory-dirs (dir)
-  (unless (file-directory-p dir)
-    (error "Not a directory `%s'" dir))
-  (let ((dir (directory-file-name dir))
-        (dirs '())
-        (files (directory-files dir nil nil t)))
-    (dolist (file files)
-      (unless (member file '("." ".."))
-        (let ((file (concat dir "/" file)))
-          (when (file-directory-p file)
-            (setq dirs (append (cons file
-                                     (go-directory-dirs file))
-                               dirs))))))
-    dirs))
+  (if (file-directory-p dir)
+      (let ((dir (directory-file-name dir))
+            (dirs '())
+            (files (directory-files dir nil nil t)))
+        (dolist (file files)
+          (unless (member file '("." ".."))
+            (let ((file (concat dir "/" file)))
+              (when (file-directory-p file)
+                (setq dirs (append (cons file
+                                         (go-directory-dirs file))
+                                   dirs))))))
+        dirs)
+    '()))
 
 (defun go-flatten (lst)
   (if (atom lst)
@@ -587,20 +587,30 @@ If no list exists yet, one will be created if possible."
               (list item)
             nil))))))
 
+(defun go-root-and-paths ()
+  (let* ((output (process-lines "go" "env" "GOROOT" "GOPATH"))
+         (root (car output))
+         (paths (split-string (car (cdr output)) ":")))
+    (append (list root) paths)))
+
 (defun go-packages ()
-  (sort (delete-dups (go-flatten (mapcar (lambda (topdir)
-            (let ((pkgdir (concat topdir "/pkg/")))
-            (mapcar (lambda (dir)
-                                (mapcar (lambda (file)
-                                          (let ((sub (substring file (length 
pkgdir) -2)))
-                                            (unless (or (string-prefix-p 
"obj/" sub) (string-prefix-p "tool/" sub))
-                                              (mapconcat 'identity (cdr 
(split-string sub "/")) "/")
-                                            )
-                                          ))
-                                        (directory-files dir t "\\.a$")))
-                              (go-directory-dirs pkgdir))
-            ))
-          (list (getenv "GOROOT") (getenv "GOPATH"))))) 'string<))
+  (sort
+   (delete-dups
+    (go-flatten
+     (mapcar
+      (lambda (topdir)
+        (let ((pkgdir (concat topdir "/pkg/")))
+          (mapcar (lambda (dir)
+                    (mapcar (lambda (file)
+                              (let ((sub (substring file (length pkgdir) -2)))
+                                (unless (or (string-prefix-p "obj/" sub) 
(string-prefix-p "tool/" sub))
+                                  (mapconcat 'identity (cdr (split-string sub 
"/")) "/")
+                                  )
+                                ))
+                            (if (file-directory-p dir)
+                                (directory-files dir t "\\.a$"))))
+                  (go-directory-dirs pkgdir))))
+      (go-root-and-paths)))) 'string<))
 
 
 (provide 'go-mode)



reply via email to

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