Skip to content

Instantly share code, notes, and snippets.

@jcinnamond
Created August 20, 2013 07:28
Show Gist options
  • Save jcinnamond/6278135 to your computer and use it in GitHub Desktop.
Save jcinnamond/6278135 to your computer and use it in GitHub Desktop.
Local Go playground in emacs
(defun go-create-playground ()
"Creates a new temporary file with a skeletal Go application"
(interactive)
(let ((filename (make-temp-file "go-play-" nil ".go")))
(find-file filename)
(rename-buffer (generate-new-buffer-name "Go Playground"))
(insert (concat "package main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(\"This file is located in " filename "\")\n}"))
(save-buffer)
(previous-line)
(end-of-line)
(insert "\n\t")
(go-mode)))
(defun go-switch-to-playground ()
"Switch to Go Playground buffer, creating if necessary"
(interactive)
(let ((playground (get-buffer "Go Playground")))
(if playground
(switch-to-buffer playground)
(go-create-playground))))
(global-set-key (kbd "C-c C-g p") 'go-switch-to-playground)
(global-set-key (kbd "C-c C-g n") 'go-create-playground)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment