Created
August 20, 2013 07:28
-
-
Save jcinnamond/6278135 to your computer and use it in GitHub Desktop.
Local Go playground in emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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