1
1
; ;; go-playground.el --- Local Golang playground for short snippets.
2
2
3
- ; ; Copyright (C) 2015-2018 Alexander I.Grafov (axel)
3
+ ; ; Copyright (C) 2015-2019 Alexander I.Grafov
4
4
5
- ; ; Author: Alexander I.Grafov (axel) <[email protected] >
5
+ ; ; Author: Alexander I.Grafov <[email protected] >
6
6
; ; URL: https://github.com/grafov/go-playground
7
7
; ; Keywords: tools, golang
8
- ; ; Version: 1.4
8
+ ; ; Version: 1.5
9
9
; ; Package-Requires: ((emacs "24") (go-mode "1.4.0") (gotest "0.13.0"))
10
10
11
11
; ; This program is free software; you can redistribute it and/or modify
@@ -80,10 +80,10 @@ By default confirmation required."
80
80
81
81
(defun go-playground-snippet-file-name (&optional snippet-name )
82
82
(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" )))
87
87
88
88
;
89
89
(defun go-playground-save-and-run ()
@@ -100,12 +100,22 @@ By default confirmation required."
100
100
(make-local-variable 'compile-command )
101
101
(compile (concat go-command " " go-playground-go-command-args)))))
102
102
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
+
103
113
;;;### autoload
104
114
(defun go-playground ()
105
115
" Run playground for Go language in a new buffer."
106
116
(interactive )
107
117
(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))
109
119
(go-playground-insert-template-head " snippet of code" )
110
120
(insert " package main
111
121
@@ -117,10 +127,10 @@ func main() {
117
127
fmt.Println(\" Results:\" )
118
128
}
119
129
" )
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 )))
124
134
125
135
(defun go-playground-insert-template-head (description )
126
136
(insert " // -*- mode:go;mode:go-playground -*-
@@ -136,7 +146,7 @@ func main() {
136
146
" Remove files of the current snippet together with directory of this snippet."
137
147
(interactive )
138
148
(if (go-playground-inside)
139
- (if (or (not go-playground-confirm-deletion)
149
+ (if (or (not go-playground-confirm-deletion)
140
150
(y-or-n-p (format " Do you want delete whole snippet dir %s ? "
141
151
(file-name-directory (buffer-file-name )))))
142
152
(progn
@@ -148,7 +158,7 @@ func main() {
148
158
149
159
;;;### autoload
150
160
(defun go-playground-remove-current-snippet ()
151
- " Obsoleted by `go-playground-rm' ."
161
+ " Obsoleted by `go-playground-rm' ."
152
162
(interactive )
153
163
(go-playground-rm))
154
164
@@ -158,20 +168,20 @@ func main() {
158
168
Tries to look for a URL at point."
159
169
(interactive (list (read-from-minibuffer " Playground URL: " (ffap-url-p (ffap-string-at-point 'url )))))
160
170
(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
169
179
(goto-char (point-min ))
170
180
(go-playground-insert-template-head (concat url " imported" ))
171
181
(go-mode )
172
182
(go-playground-mode)
173
183
(set-visited-file-name snippet-file-name t )
174
- (switch-to-buffer buffer)))))
184
+ (switch-to-buffer buffer)))))
175
185
176
186
(defun go-playground-upload ()
177
187
" 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."
184
194
(defun go-playground-snippet-unique-dir (prefix )
185
195
" Get unique directory under GOPATH/`go-playground-basedir`."
186
196
(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))
191
201
192
202
(defun go-playground-inside ()
193
203
" Is the current buffer is valid go-playground buffer."
0 commit comments