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

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

[nongnu] elpa/go-mode 8c884f3 292/495: Support goimports' new -srcdir fl


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 8c884f3 292/495: Support goimports' new -srcdir flag
Date: Sat, 7 Aug 2021 09:05:34 -0400 (EDT)

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

    Support goimports' new -srcdir flag
    
    goimports, in order to support vendoring, needs to know where the source
    file resides. Since we write the buffer's contents to a temporary file,
    we need to tell goimports where the file came from.
    
    We add a new customizable variable called gofmt-is-goimports. WHen it is
    set to true, we use goimports' -srcdir flag.
---
 NEWS       |  8 ++++++++
 go-mode.el | 16 ++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 4983edd..39320b3 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,14 @@ go-mode-1.4.0 (???)
    go-packages-native (the default) and go-packages-go-list are
    provided.
 
+ * Add new variable gofmt-is-goimports. If gofmt-command is set to a
+   value that invokes goimports instead of gofmt, this variable needs
+   to be set to t. Otherwise, goimports will not be able to add
+   imports for vendored packages.
+
+   Setting it to t while not using goimports will break gofmt, as
+   gofmt doesn't support goimports' -srcdir flag.
+
 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 3b2747e..ba9cc96 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -195,6 +195,12 @@ from https://github.com/bradfitz/goimports.";
   :type 'string
   :group 'go)
 
+(defcustom gofmt-is-goimports nil
+  "Set to t if you use goimports. This is required to enable
+support for vendored packages."
+  :type 'boolean
+  :group 'go)
+
 (defcustom gofmt-show-errors 'buffer
   "Where to display gofmt error output.
 It can either be displayed in its own buffer, in the echo area, or not at all.
@@ -1010,7 +1016,8 @@ with goflymake \(see URL 
`https://github.com/dougm/goflymake'), gocode
         (patchbuf (get-buffer-create "*Gofmt patch*"))
         (errbuf (if gofmt-show-errors (get-buffer-create "*Gofmt Errors*")))
         (coding-system-for-read 'utf-8)
-        (coding-system-for-write 'utf-8))
+        (coding-system-for-write 'utf-8)
+        our-gofmt-args)
 
     (unwind-protect
         (save-restriction
@@ -1024,10 +1031,15 @@ with goflymake \(see URL 
`https://github.com/dougm/goflymake'), gocode
 
           (write-region nil nil tmpfile)
 
+          (when (and gofmt-is-goimports buffer-file-name)
+            (setq our-gofmt-args
+                  (append our-gofmt-args
+                          (list "-srcdir" (file-name-directory (file-truename 
buffer-file-name))))))
+          (setq our-gofmt-args (append our-gofmt-args (list "-w" tmpfile)))
           ;; We're using errbuf for the mixed stdout and stderr output. This
           ;; is not an issue because gofmt -w does not produce any stdout
           ;; output in case of success.
-          (if (zerop (call-process gofmt-command nil errbuf nil "-w" tmpfile))
+          (if (zerop (apply #'call-process gofmt-command nil errbuf nil 
our-gofmt-args))
               (progn
                 (if (zerop (call-process-region (point-min) (point-max) "diff" 
nil patchbuf nil "-n" "-" tmpfile))
                     (message "Buffer is already gofmted")



reply via email to

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