Skip to content

Commit 34aa3a1

Browse files
committed
Add new command go-playground-cmd
It allows apply custom arguments to the compile mode.
1 parent b107196 commit 34aa3a1

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ compiler as `go run *.go` so any sources from the snippet directory will be incl
6868
| `go-playground` | Create a new playground buffer with basic template for the `main` package. |
6969
| `go-playground-download` | Download the snippet from the URL at play.golang.org. |
7070
| `go-playground-exec` | Save, compile and run the code of the snippet. |
71+
| `go-playground-cmd` | Save the code then prompts for the command (compile-mode used). |
7172
| `go-playground-upload` | Upload the buffer to play.golang.org and return the short URL. |
7273
| `go-playground-rm` | Remove the snippet with its directory with all files. |
7374
-->
@@ -77,6 +78,7 @@ compiler as `go run *.go` so any sources from the snippet directory will be incl
7778
| `go-playground` | Create a new playground buffer with basic template for the `main` package. |
7879
| `go-playground-download` | Download the snippet from the URL at play.golang.org. |
7980
| `go-playground-exec` | Save, compile and run the code of the snippet. |
81+
| `go-playground-cmd` | Save the code then prompts for the command (compile-mode used). |
8082
| `go-playground-upload` | Upload the buffer to play.golang.org and return the short URL. |
8183
| `go-playground-rm` | Remove the snippet with its directory with all files. |
8284
<!--- END RECEIVE ORGTBL keys -->

go-playground.el

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
;;; go-playground.el --- Local Golang playground for short snippets.
22

3-
;; Copyright (C) 2015-2018 Alexander I.Grafov (axel)
3+
;; Copyright (C) 2015-2019 Alexander I.Grafov
44

5-
;; Author: Alexander I.Grafov (axel) <[email protected]>
5+
;; Author: Alexander I.Grafov <[email protected]>
66
;; URL: https://github.com/grafov/go-playground
77
;; Keywords: tools, golang
8-
;; Version: 1.4
8+
;; Version: 1.5
99
;; Package-Requires: ((emacs "24") (go-mode "1.4.0") (gotest "0.13.0"))
1010

1111
;; This program is free software; you can redistribute it and/or modify
@@ -80,10 +80,10 @@ By default confirmation required."
8080

8181
(defun go-playground-snippet-file-name(&optional snippet-name)
8282
(let ((file-name (cond (snippet-name)
83-
(go-playground-ask-file-name
84-
(read-string "Go Playground filename: "))
85-
("snippet"))))
86-
(concat (go-playground-snippet-unique-dir file-name) "/" file-name ".go")))
83+
(go-playground-ask-file-name
84+
(read-string "Go Playground filename: "))
85+
("snippet"))))
86+
(concat (go-playground-snippet-unique-dir file-name) "/" file-name ".go")))
8787

8888
;
8989
(defun go-playground-save-and-run ()
@@ -100,12 +100,22 @@ By default confirmation required."
100100
(make-local-variable 'compile-command)
101101
(compile (concat go-command " " go-playground-go-command-args)))))
102102

103+
(defun go-playground-cmd (cmd)
104+
"Save the buffer then apply custom compile command from
105+
minibuffer to the files or buffer."
106+
(interactive "scompile command: ")
107+
(if (go-playground-inside)
108+
(progn
109+
(save-buffer t)
110+
(make-local-variable 'compile-command)
111+
(compile cmd))))
112+
103113
;;;###autoload
104114
(defun go-playground ()
105115
"Run playground for Go language in a new buffer."
106116
(interactive)
107117
(let ((snippet-file-name (go-playground-snippet-file-name)))
108-
(switch-to-buffer (create-file-buffer snippet-file-name))
118+
(switch-to-buffer (create-file-buffer snippet-file-name))
109119
(go-playground-insert-template-head "snippet of code")
110120
(insert "package main
111121
@@ -117,10 +127,10 @@ func main() {
117127
fmt.Println(\"Results:\")
118128
}
119129
")
120-
(backward-char 3)
121-
(go-mode)
122-
(go-playground-mode)
123-
(set-visited-file-name snippet-file-name t)))
130+
(backward-char 3)
131+
(go-mode)
132+
(go-playground-mode)
133+
(set-visited-file-name snippet-file-name t)))
124134

125135
(defun go-playground-insert-template-head (description)
126136
(insert "// -*- mode:go;mode:go-playground -*-
@@ -136,7 +146,7 @@ func main() {
136146
"Remove files of the current snippet together with directory of this snippet."
137147
(interactive)
138148
(if (go-playground-inside)
139-
(if (or (not go-playground-confirm-deletion)
149+
(if (or (not go-playground-confirm-deletion)
140150
(y-or-n-p (format "Do you want delete whole snippet dir %s? "
141151
(file-name-directory (buffer-file-name)))))
142152
(progn
@@ -148,7 +158,7 @@ func main() {
148158

149159
;;;###autoload
150160
(defun go-playground-remove-current-snippet ()
151-
"Obsoleted by `go-playground-rm'."
161+
"Obsoleted by `go-playground-rm'."
152162
(interactive)
153163
(go-playground-rm))
154164

@@ -158,20 +168,20 @@ func main() {
158168
Tries to look for a URL at point."
159169
(interactive (list (read-from-minibuffer "Playground URL: " (ffap-url-p (ffap-string-at-point 'url)))))
160170
(with-current-buffer
161-
(let ((url-request-method "GET") url-request-data url-request-extra-headers)
162-
(url-retrieve-synchronously (concat url ".go")))
163-
(let* ((snippet-file-name (go-playground-snippet-file-name)) (buffer (create-file-buffer snippet-file-name)))
164-
(goto-char (point-min))
165-
(re-search-forward "\n\n")
166-
(copy-to-buffer buffer (point) (point-max))
167-
(kill-buffer)
168-
(with-current-buffer buffer
171+
(let ((url-request-method "GET") url-request-data url-request-extra-headers)
172+
(url-retrieve-synchronously (concat url ".go")))
173+
(let* ((snippet-file-name (go-playground-snippet-file-name)) (buffer (create-file-buffer snippet-file-name)))
174+
(goto-char (point-min))
175+
(re-search-forward "\n\n")
176+
(copy-to-buffer buffer (point) (point-max))
177+
(kill-buffer)
178+
(with-current-buffer buffer
169179
(goto-char (point-min))
170180
(go-playground-insert-template-head (concat url " imported"))
171181
(go-mode)
172182
(go-playground-mode)
173183
(set-visited-file-name snippet-file-name t)
174-
(switch-to-buffer buffer)))))
184+
(switch-to-buffer buffer)))))
175185

176186
(defun go-playground-upload ()
177187
"Upload the current buffer to play.golang.org and return the short URL of the playground."
@@ -184,10 +194,10 @@ Tries to look for a URL at point."
184194
(defun go-playground-snippet-unique-dir (prefix)
185195
"Get unique directory under GOPATH/`go-playground-basedir`."
186196
(let ((dir-name (concat go-playground-basedir "/"
187-
(if (and prefix go-playground-ask-file-name) (concat prefix "-"))
188-
(time-stamp-string "at-%:y-%02m-%02d-%02H%02M%02S"))))
189-
(make-directory dir-name t)
190-
dir-name))
197+
(if (and prefix go-playground-ask-file-name) (concat prefix "-"))
198+
(time-stamp-string "at-%:y-%02m-%02d-%02H%02M%02S"))))
199+
(make-directory dir-name t)
200+
dir-name))
191201

192202
(defun go-playground-inside ()
193203
"Is the current buffer is valid go-playground buffer."

0 commit comments

Comments
 (0)