[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode be9186c 417/495: Support remote files in `gofmt'
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode be9186c 417/495: Support remote files in `gofmt' |
Date: |
Sat, 7 Aug 2021 09:06:00 -0400 (EDT) |
branch: elpa/go-mode
commit be9186c658c33e2cfd09e8808e578d525dcbf2a2
Author: Philipp Stephani <phst@google.com>
Commit: Dominik Honnef <dominik@honnef.co>
Support remote files in `gofmt'
---
go-mode.el | 49 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 41 insertions(+), 8 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index cfcf42b..ed7ca11 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1069,7 +1069,7 @@ with goflymake \(see URL
`https://github.com/dougm/goflymake'), gocode
The tool used can be set via ‘gofmt-command` (default: gofmt) and additional
arguments can be set as a list via ‘gofmt-args`."
(interactive)
- (let ((tmpfile (make-temp-file "gofmt" nil ".go"))
+ (let ((tmpfile (go--make-nearby-temp-file "gofmt" nil ".go"))
(patchbuf (get-buffer-create "*Gofmt patch*"))
(errbuf (if gofmt-show-errors (get-buffer-create "*Gofmt Errors*")))
(coding-system-for-read 'utf-8)
@@ -1095,17 +1095,25 @@ arguments can be set as a list via ‘gofmt-args`."
;; accepting a full path, and some features
;; of goimports rely on knowing the full
;; name.
- (list "-srcdir" (file-truename buffer-file-name)))))
- (setq our-gofmt-args (append our-gofmt-args
- gofmt-args
- (list "-w" tmpfile)))
+ (list "-srcdir" (go--file-local-name
+ (file-truename
buffer-file-name))))))
+ (setq our-gofmt-args
+ (append our-gofmt-args gofmt-args
+ (list "-w" (go--file-local-name tmpfile))))
(message "Calling gofmt: %s %s" gofmt-command our-gofmt-args)
;; 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 (apply #'call-process gofmt-command nil errbuf nil
our-gofmt-args))
+ (if (zerop (apply #'process-file gofmt-command nil errbuf nil
our-gofmt-args))
(progn
- (if (zerop (call-process-region (point-min) (point-max) "diff"
nil patchbuf nil "-n" "-" tmpfile))
+ ;; There is no remote variant of ‘call-process-region’, but we
+ ;; can invoke diff locally, and the results should be the same.
+ (if (zerop (let ((local-copy (file-local-copy tmpfile)))
+ (unwind-protect
+ (call-process-region
+ (point-min) (point-max) "diff" nil patchbuf
+ nil "-n" "-" (or local-copy tmpfile))
+ (when local-copy (delete-file local-copy)))))
(message "Buffer is already gofmted")
(go--apply-rcs-patch patchbuf)
(message "Applied gofmt"))
@@ -1134,7 +1142,10 @@ arguments can be set as a list via ‘gofmt-args`."
(if (gofmt--is-goimports-p)
(concat (file-name-directory filename)
(file-name-nondirectory tmpfile))
tmpfile)))
- (while (search-forward-regexp (concat "^\\(" (regexp-quote truefile)
"\\):") nil t)
+ (while (search-forward-regexp
+ (concat "^\\(" (regexp-quote (go--file-local-name truefile))
+ "\\):")
+ nil t)
(replace-match (file-name-nondirectory filename) t t nil 1)))
(compilation-mode)
(display-buffer errbuf))))
@@ -2010,6 +2021,28 @@ If BUFFER, return the number of characters in that
buffer instead."
(1- (position-bytes (point-max)))))
+;; Polyfills for functions added in Emacs 26. Remove these once we don’t
+;; support Emacs 25 any more.
+(defalias 'go--file-local-name
+ (if (fboundp 'file-local-name) #'file-local-name
+ (lambda (file) (or (file-remote-p file 'localname) file))))
+
+(defalias 'go--make-nearby-temp-file
+ (if (fboundp 'make-nearby-temp-file) #'make-nearby-temp-file
+ (lambda (prefix &optional dir-flag suffix)
+ (let ((temporary-file-directory (go--temporary-file-directory)))
+ (make-temp-file prefix dir-flag suffix)))))
+
+(defalias 'go--temporary-file-directory
+ (if (fboundp 'temporary-file-directory) #'temporary-file-directory
+ (lambda ()
+ (let ((remote (file-remote-p default-directory)))
+ (if remote
+ ;; Assume that /tmp is a temporary directory on the remote host.
+ ;; This won’t work on Windows.
+ (concat remote "/tmp")
+ temporary-file-directory)))))
+
(provide 'go-mode)
;;; go-mode.el ends here
- [nongnu] elpa/go-mode bfc4f9b 385/495: tools/refactor/rename: add provide to rename.el, (continued)
- [nongnu] elpa/go-mode bfc4f9b 385/495: tools/refactor/rename: add provide to rename.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0604054 388/495: cmd/gorename: emacs: do not auto shrink error window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1b85887 389/495: refactor/rename: require cl-lib, use cl- namespace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8144ae8 392/495: Merge commit '12ef34c', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 269eb01 398/495: Remove support for Emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5056b85 403/495: Use xref functions if available, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3f02a16 406/495: Add go-guru-definition-other-window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7eb5b3d 409/495: Delete go-mode-autoloads.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2d1d33a 407/495: Fix off-by-one in point calculations, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7f87c32 416/495: Permit empty guru scope, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode be9186c 417/495: Support remote files in `gofmt',
ELPA Syncer <=
- [nongnu] elpa/go-mode 287595a 420/495: Don't traverse symlinks when recursing directories, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b990645 425/495: Fix call expr indenting after dangling operator., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode ac6dd8c 430/495: Fix go-remove-unused-imports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e8674fe 437/495: Expand electric indent config a bit, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6a64cbf 439/495: Fix indentation for composite literal keys., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fb1272c 441/495: indent: fix performance in giant comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c020e2c 456/495: Fontify type names in more places., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2a1584f 454/495: Readme: add note recommending goimports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 57becfb 460/495: Fontify type names in interface declarations, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode cf53daa 459/495: Fix indentation in naked blocks., ELPA Syncer, 2021/08/07