Skip to content

Instantly share code, notes, and snippets.

@belden
Last active August 29, 2015 14:21
Show Gist options
  • Save belden/e3600a3d73e798ce516b to your computer and use it in GitHub Desktop.
Save belden/e3600a3d73e798ce516b to your computer and use it in GitHub Desktop.
Golang stuff for Logan
;; this could use some improvement
;;
;; - it doesn't clean up the temp file
;; - it doesn't ensure there's a selected region
;; - etc.
;;
(defun logan/run-selected-golang-code ()
"run the selected code as though it is golang code"
(interactive)
(let ((tempfile (format "%s.go" (make-temp-file "logan-golang"))))
(write-region (region-beginning) (region-end) tempfile)
(compile (format "go run %s" tempfile))))
;; if you add the above function and this following line into your
;; ~/.emacs (which is a lousy way of doing things) then you can
;; highlight some code, then run "C-x g r" to "go-run this region"
(global-set-key (kbd "C-x g r") 'logan/run-selected-golang-code))
@belden
Copy link
Author

belden commented May 20, 2015

Load that code up, then in an emacs buffer, paste in this:

here is a random buffer with some crap in it

Oh hang on, let's type some  go code
package main

import "fmt"

func main() {
fmt.Println("Hello, 世界")
}

adf
adf
asdf
a

Highlight the golang code, then run M-x logan/run-selected-golang-code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment