All Projects → grafov → go-playground

grafov / go-playground

Licence: GPL-3.0 License
GNU/Emacs mode that setup local Go playground for code snippets like play.golang.org or even better :)

Programming Languages

emacs lisp
2029 projects

Projects that are alternatives of or similar to go-playground

emacs-mips-mode
An Emacs major mode for MIPS assembly code
Stars: ✭ 22 (-65.62%)
Mutual labels:  melpa, emacs-mode
Inim
Interactive Nim Shell / REPL / Playground
Stars: ✭ 407 (+535.94%)
Mutual labels:  playground, repl
Graphql Mode
An Emacs mode for GraphQL
Stars: ✭ 120 (+87.5%)
Mutual labels:  melpa, emacs-mode
psysh.el
PsySH on Emacs, PHP interactive shell (REPL)
Stars: ✭ 27 (-57.81%)
Mutual labels:  repl, melpa
vue-code-view
A Vue 2 component like Vue SFC REPL `@vue/repl` : u can edit, run and preview the code effect display in real time on the web page.
Stars: ✭ 67 (+4.69%)
Mutual labels:  playground, repl
goplay
The Go Playground (https://play.golang.org/) client
Stars: ✭ 75 (+17.19%)
Mutual labels:  playground, go-playground
Gistlyn
Run Roslyn Gists
Stars: ✭ 75 (+17.19%)
Mutual labels:  playground, repl
aik
Frontend Playground
Stars: ✭ 43 (-32.81%)
Mutual labels:  playground, repl
emacs-pug-mode
Pug support for Emacs, based on slim-mode.
Stars: ✭ 39 (-39.06%)
Mutual labels:  melpa, emacs-mode
solid-playground
Quickly discover what the solid compiler will generate from your JSX template
Stars: ✭ 45 (-29.69%)
Mutual labels:  repl
mode-line-stats
A bunch of easy to set up stats for the Emacs mode-line.
Stars: ✭ 27 (-57.81%)
Mutual labels:  emacs-mode
emacs-auto-deployment
Copy file on save, automatic deployment it. aka auto-deployment.
Stars: ✭ 18 (-71.87%)
Mutual labels:  melpa
tsquery-playground
Playground for TSQuery
Stars: ✭ 30 (-53.12%)
Mutual labels:  playground
typescript-playground
TypeScript Playground
Stars: ✭ 52 (-18.75%)
Mutual labels:  playground
coin-ticker-mode
Emacs minor mode for showing the price of Bitcoin, Ethereum, and other cryptocurrencies.
Stars: ✭ 21 (-67.19%)
Mutual labels:  melpa
tutorial
Tutorials for GoPlus (The Go+ Language)
Stars: ✭ 27 (-57.81%)
Mutual labels:  playground
re-mote
Re-mote operations using SSH and Re-gent
Stars: ✭ 61 (-4.69%)
Mutual labels:  repl
ts-comint
ts-comint will send the code from Emacs into a Typescript REPL.
Stars: ✭ 28 (-56.25%)
Mutual labels:  repl
UsingPlayground
👶 Demo how to use Playground
Stars: ✭ 25 (-60.94%)
Mutual labels:  playground
KittyTerminalImages.jl
A package that allows Julia to display images in the kitty terminal editor
Stars: ✭ 57 (-10.94%)
Mutual labels:  repl

Local Golang playground MELPA Stable MELPA

The simple mode for GNU/Emacs for setting up local Go language playground with features similar (and with help of go-mode even outperform!) service at play.golang.org. You may treat it like the simple REPL for Go. This is not a wrapper for working with play.golang.org from Emacs (it is already did by original go-mode), this is complete alternative for setting local playground inside Emacs without using browser for experiments with code snippets.

Web playground at play.golang.org is a nice idea. It has not require setup and it executes your code in a restricted environment where you can't damage you system. But it brings many restrictions too especially when you want use additional helpers for working with your code: formatters, code completers etc. Emacs offers many such tools for Go development so it is the most comfortable play with snippets inside Emacs instead of rude webeditor. Of course local playground requres you to setup Go environment but if you developing in Go (or you want to do it) you are anyway would need to setup go-mode and helper tools for working with code in a comfortable way.

Features

  • works under go-mode with all your plugins (like lsp, linters and so on)
  • keeps the library of snippets under a customized root path
  • allows split the code into arbitrary number of files
  • allows add new subdirs with subpackages
  • import any external packages
  • compatible with Go modules but could be customized for old GOPATH way

Install

First install go-mode and gotest — these are mandatory. Setup any additional tools you want for Golang (see Emacs Wiki for guides or google for "emacs+golang"). Minimal way is install goimports that automatically add import clauses to your snippets. For a fully functional Go IDE look at lsp and supplementary packages.

Install go-playground from MELPA:

M-x package-install RET go-playground

Or:

(use-package go-playground)

If you want to share snippets use go-play-buffer from go-mode. Install gist-buffer from MELPA if you want publish gists on github.com.

The mirror repository of the project: https://notabug.org/grafov/go-playground. I really not think that this small project need the mirror but I just would like advertise a nice git hosting for FOSS. Try notabug.org for your projects! :)

Usage

Quick start

  1. From any mode run M-x go-playground for start a new playground buffer filled with basic template for main package (see the picture below).
  2. Add your code then press Ctl-Return (it bound to go-playground-exec command). It will save, compile and exec the snippet code.
  3. When you played enough with this snippet just run M-x go-playground-rm. It will remove the current snippet with its directory and all files.

Mode not offers default bindings except Ctl-Return. It just lefts the space for you.

For easy running the template declares main package with defined main() function. Each snippet saved to its own directory (named by timestamp by default). Remember go-playground runs the compiler as go run *.go so any sources from the snippet directory will be included.

List of interactive functions

Function name Description
go-playground Create a new playground buffer with basic template for the main package.
go-playground-download Download the snippet from the URL at play.golang.org.
go-playground-exec Save, compile and run the code of the snippet.
go-playground-cmd Save the code then prompts for the command (compile-mode used).
go-playground-upload Upload the buffer to play.golang.org and return the short URL.
go-playground-rm Remove the snippet with its directory with all files.

List of customizable variables

Function name Description
go-playground-ask-filename Ask for the snippet filename on a new playground creation. By default it got name snippet.go.
go-playground-basedir Default directory where snippets dirs will placed. Each new snippet got a new dir under this. It has sense place the default directory under GOPATH. Var introduced in the release 1.1.
go-playground-confirm-deletion Ask for confirmation before snippet deletion. It may be annoying so you can switch confirmations off. Var introduced in the release 1.2.
go-playground-go-command Set a custom path to go command, possibly with environment (example: "CGO_ENABLED=0 /opt/bin/go").
go-playground-init-command Setup shell command that will be run once when a new snippet just created.
go-playground-compiler-args That arguments should be passed for the compiler.

Example screen after creation of a new snippet:

screenshot

Using with go modules

By default the playground runs go-command as it defined in settings of go-mode. You could use special customized compiler path with go-playground-go-command. For using with modules it could be used such way:

  1. Set go-playground-go-command to "GO111MODULE=on".
  2. Set go-playground-init-command to "go mod init".

Snippet with multiple files and subpackages

Explained here #19.

Similar projects

  • Try go-scratch it even simplier than go-playground. But it prevents you from using many of tools because it not keeps code in files.
  • gorepl-mode is REPL for Go, helpful for interactive research of code.

Licence

Under terms of GPL v3. See LICENSE file.

Future plans and accepting contributions

I don't want to make this package much complex. Most of go-playground functions depends on other packages around go-mode. And it is good way. But one thing I want to add is snippet list buffer where you can easily find and edit/delete snippets of your library. Bugfixes and small features accepted as well.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].