[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 22cbf11 321/495: Support unsaved buffers with goge
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 22cbf11 321/495: Support unsaved buffers with gogetdoc |
Date: |
Sat, 7 Aug 2021 09:05:40 -0400 (EDT) |
branch: elpa/go-mode
commit 22cbf114c20ea6f4972809c4736d5d1f737b3d94
Author: Dominik Honnef <dominik@honnef.co>
Commit: Dominik Honnef <dominik@honnef.co>
Support unsaved buffers with gogetdoc
---
go-mode.el | 49 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 37 insertions(+), 12 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index ae78e8d..f1b6a8a 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -315,19 +315,22 @@ Consider using godoc-gogetdoc instead for more accurate
results."
You can install gogetdoc with 'go get github.com/rogpeppe/godef'."
(if (not (buffer-file-name (go--coverage-origin-buffer)))
- ;; TODO: once gogetdoc supports unsaved files, we can remove
- ;; this by using a fake name
+ ;; TODO: gogetdoc supports unsaved files, but not introducing
+ ;; new artifical files, so this limitation will stay for now.
(error "Cannot use gogetdoc on a buffer without a file name"))
- (if (buffer-modified-p)
- ;; TODO: once gogetdoc supports unsaved files, we can remove
- ;; this check
- (error "Please save the buffer before invoking gogetdoc"))
- (set-process-sentinel
- (start-process "gogetdoc" (godoc--get-buffer "<at point>") "gogetdoc"
- (format "-pos=%s:#%d"
- (shell-quote-argument (file-truename
buffer-file-name))
- (1- (go--position-bytes (point)))))
- 'godoc--buffer-sentinel))
+ (let ((posn (format "%s:#%d" (shell-quote-argument (file-truename
buffer-file-name)) (1- (go--position-bytes point))))
+ (out (godoc--get-buffer "<at point>")))
+ (with-current-buffer (get-buffer-create "*go-gogetdoc-input*")
+ (setq buffer-read-only nil)
+ (erase-buffer)
+ (go--insert-modified-files)
+ (call-process-region (point-min) (point-max) "gogetdoc" nil out nil
+ "-modified"
+ (format "-pos=%s" posn)))
+ (with-current-buffer out
+ (goto-char (point-min))
+ (godoc-mode)
+ (display-buffer (current-buffer) t))))
(defun go--kill-new-message (url)
"Make URL the latest kill and print a message."
@@ -2025,6 +2028,28 @@ switching projects."
"Return the original value of GOPATH from when Emacs was started."
(let ((process-environment initial-environment)) (getenv "GOPATH")))
+(defun go--insert-modified-files ()
+ "Insert the contents of each modified Go buffer into the
+current buffer in the format specified by guru's -modified flag."
+ (mapc #'(lambda (b)
+ (and (buffer-modified-p b)
+ (buffer-file-name b)
+ (string= (file-name-extension (buffer-file-name b)) "go")
+ (go--insert-modified-file (buffer-file-name b) b)))
+ (buffer-list)))
+
+(defun go--insert-modified-file (name buffer)
+ (insert (format "%s\n%d\n" name (go--buffer-size-bytes buffer)))
+ (insert-buffer-substring buffer))
+
+(defun go--buffer-size-bytes (&optional buffer)
+ (message "buffer; %s" buffer)
+ "Return the number of bytes in the current buffer.
+If BUFFER, return the number of characters in that buffer instead."
+ (with-current-buffer (or buffer (current-buffer))
+ (1- (position-bytes (point-max)))))
+
+
(provide 'go-mode)
;;; go-mode.el ends here
- [nongnu] elpa/go-mode 400d2ae 289/495: Add a changelog, (continued)
- [nongnu] elpa/go-mode 400d2ae 289/495: Add a changelog, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0f9b5c5 291/495: Add go-packages-function and go-packages-go-list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8c884f3 292/495: Support goimports' new -srcdir flag, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c65dd39 297/495: Complain about outdated goimports, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0b5b29d 316/495: Reformat code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a6717a1 318/495: Fix filename replacement in gofmt error buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 50bceae 326/495: Use HTTPS with go-play-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 49521d5 310/495: Add go-reset-gopath, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b767500 325/495: Set compilation-error-screen-columns to nil, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 15ea9a4 320/495: No longer provide a default in M-x godoc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 22cbf11 321/495: Support unsaved buffers with gogetdoc,
ELPA Syncer <=
- [nongnu] elpa/go-mode 0b25cb5 327/495: Generate HTTPS URL for playground entry, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f63d982 323/495: Make godoc interactive again, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 218d8c5 346/495: cmd/oracle: emacs: look for oracle on $PATH and nowhere else, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode aa733d8 339/495: go.tools/oracle: turn emacs integration into minor-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode cbf7274 343/495: x/tools/oracle: add whicherrs query mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 01dff21 358/495: cmd/guru: emacs: package.el compatibility changes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode dc424ef 361/495: cmd/guru: emacs: add default key binding for whicherrs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6bfbd41 371/495: cmd/guru: emacs: report most specific element in expand-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9753f6a 342/495: go.tools: use golang.org/x/... import paths, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode aa9a40c 351/495: cmd/guru: in Emacs, change 'definition' to jump directly, ELPA Syncer, 2021/08/07