Skip to content

Commit 2591a49

Browse files
committed
fix: go-playground-upload not working in playground snippet buffers
This fixes the condition in the go-playground-upload function, so it runs go-play-buffer within go-playground snippet file buffers only. Previously it would run it in any buffer, except snippet buffers. I also removed the cursor movement and insertion of the result from go-play-upload, as default behavior of go-play-buffer and go-play-region is to place the URL on the killring, and can be customized setting the go-play-browse-function variable.
1 parent 9ee7dcc commit 2591a49

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

go-playground.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ Tries to look for a URL at point."
214214
(defun go-playground-upload ()
215215
"Upload the current buffer to play.golang.org and return the short URL of the playground."
216216
(interactive)
217-
(if (go-playground-inside)
218-
(goto-char (point-min))
219-
(forward-line)
220-
(insert (go-play-buffer))))
217+
(if (not (go-playground-inside))
218+
(message "Not in a Go Playground buffer!")
219+
(go-play-buffer)))
221220

222221
(defun go-playground-snippet-unique-dir (prefix)
223222
"Get unique directory under GOPATH/`go-playground-basedir`."
@@ -229,8 +228,10 @@ Tries to look for a URL at point."
229228

230229
(defun go-playground-inside ()
231230
"Is the current buffer is valid go-playground buffer."
232-
(if (string-match-p (file-truename go-playground-basedir) (file-truename (buffer-file-name)))
233-
(bound-and-true-p go-playground-mode)))
231+
(and (bound-and-true-p go-playground-mode)
232+
buffer-file-name
233+
(string-prefix-p (file-truename go-playground-basedir)
234+
(file-truename buffer-file-name))))
234235

235236
(provide 'go-playground)
236237
;;; go-playground.el ends here

0 commit comments

Comments
 (0)