Giter Club home page Giter Club logo

emacs-playground's Introduction

Playground for Emacs

Build Status MELPA

Playground lets you try out .emacs.d configuration repositories.

The basic idea behind Playground is to create an isolated directory called a sandbox and make it $HOME of Emacs. Playground allows you to easily experiment with various Emacs configuration repositories available on GitHub, while keeping your current configuration untouched (almost, except for stuffs related to Playground). It can also simplify your workflow in Emacs by hiding irrelevant files and directories existing in your home directory.

For details on the mechanism of Playground, see how it works section.

Features

  • Two ways to checkout a sandbox: declarative configuration and interactively specifying a Git repository
  • Configured with some popular and/or notable Emacs configuration repositories
  • Support producing symbolic links for selectively mapping a directory structure between sandboxes and the home directory
  • Support producing a wrapper script to replace Emacs for regular use of a sandbox

Prerequisites

  • Emacs (>= 25.1)
  • Git
  • UNIX-like operating system with a graphical environment (not on terminal)
    • On Windows, Playground cannot generate a convenient shell script, but it still allows you to try a configuration

Installation

Playground is available on MELPA as playground package.

An alternative way is to clone this repository to somewhere and start Emacs using this command:

emacs -Q -l playground.el

Quick start

M-x playground-checkout

Then select a configuration in the minibuffer.

Alternatively, there is also playground-checkout-with-options command, which allows you to interactively specify detailed options such as a different name of the sandbox or a branch.

Configuration

These settings are mostly for users who might want to use a sandbox regularly. If you just want to try Emacs configurations for a short period of time, you can skip this section and proceed to Usage.

Configuration repositories

To add configuration repositories suggested in playground-checkout, set playground-dotemacs-list variable.

Each entry in the variable is a plist. The following keys are supported:

  • :repo: A Git repository URL to be used as ~/.emacs.d. Required.
  • :branch: A branch of the repository to check out. Optional, and the default is HEAD.
  • :name: A name of the sandbox. This can be any directory name, Optional, and the default is produced from the user name of the repository.
  • :recursive: Recursively check out submodules in the repository. The default is true, and you can set this to nil.
  • :depth: Limit the number of commits to fetch. The default is 1 (only the latest commit), but you can set this to nil to get all commits.

Location of wrapper scripts

By default, Playground installs wrapper scripts to ~/.local/bin when you run playground-persist. If this directory is not included in your $PATH, you can change the destination by setting playground-script-directory:

(setq playground-script-directory (expand-file-name "~/bin")) ; Install scripts to ~/bin

Symbolic links

By default, Playground creates a symbolic link in sandboxes only for ~/.gnupg. You can produce more symbolic links by setting playground-inherited-contents:

(setq playground-inherited-contents '("Dropbox" ".gpg" "git"))

Each item in the list should be a relative path from the home directory. In the above example, the following three symbolic links are created (~/ is the sandbox context):

  • ~/Dropbox to ~USER/Dropbox
  • ~/.gpg to ~USER/.gpg
  • ~/git to ~USER/git

These symbolic links are produced when a new sandbox is created. To update the mappings in previously created sandboxes, run playground-update-symlinks command. This command creates missing symbolic links in existing sandboxes.

Usage

The main entry point to using Playground is playground-checkout command. It allows you to check out a sandbox from the following sources:

  • Existing sandboxes that you have checked out on the machine (via selection)
  • A predefined list of sandbox configurations (via selection)
  • Any Git repository that should be used as ~/.emacs.d in the new sandbox context (by typing a URL in the mini buffer)

If you enter a URL, Playground asks you a name for the created sandbox. It can be any file name.

After you specify an existing sandbox or a sandbox configuration in playground-checkout, Playground initializes the sandbox if it is not created yet and starts Emacs with the sandbox as its home. You can try it. You can also restart the last selected sandbox by playground-start-last command.

Replacing your Emacs

If you come to like a particular configuration and want to use it regularly, you can make it the default by running playground-persist command in the parent Emacs session. It creates a wrapper script that effectively replaces your current Emacs configuration. The following is how it works: The script will have the same name as Emacs (normally emacs), and it starts Emacs in the sandbox environment. Granted that this script is installed into a directory that have a higher precedence in $PATH, emacs command will always run Emacs on the sandbox.

In case you occasionally run Emacs in your original environment, Playground also creates emacs-noplay wrapper script. It starts Emacs on the original directory.

If you don't like the configuration you have set as the default, you can roll back this change by running playground-return command. The wrapper scripts will be deleted, and Emacs will run on the original home directory in all of its succeeding sessions.

How it works

The fundamental idea for Playground is to start Emacs with $HOME environment variable set to a different location:

HOME=/foo/bar emacs

This command line starts Emacs with /foo/bar as its home directory (~). Emacs started in this way loads an initialization file from /foo/bar/.emacs.d/init.el (or /foo/bar/.emacs[.el], etc.) rather than from ~USER/.emacs.d (~USER means the home directory of USER, which is usually /home/USER). You can use this technique to try a configuration repository created by other people.

This technique causes another effect of 'hiding' a bunch of files and directories located in the original home directory. If you use Emacs alongside other desktop applications, your home directory is likely to contain files that will never be edited or browsed in Emacs. This can be a mess when you use Emacs. However, in an Emacs session in the modified home environment variable, ~ points to /foo/bar. This applies to every situation inside the modified Emacs session, including caching downloaded packages, locating recent files and backup files, and interactive interfaces like find-file. The modified home environment virtually serves as a sandbox for Emacs.

Meanwhile, you can still visit files and directories in the original home directory . In find-file, you can browse files in your original home directory by typing ~USER/ (USER should be your login name) even on the modified environment. The same applies to other commands. You can save typing efforts for specific directories by creating symbolic links from inside the sandbox to corresponding locations in the original home directory, e.g. ~/path in the sandbox to ~USER/path.

Playground helps you manage sandboxes of this kind. It creates a sandbox in the following steps:

  1. Create a new directory inside a fixed location (~USER/.emacs-play by default). This will become your sandbox, a virtual ~ for Emacs.
  2. Clone a given Git repository to ~/.emacs.d in the sandbox context. You can specify any Git repository as your Emacs configuration for the sandbox.
  3. Create symbolic links from inside the sandbox to directories in the original home directory. This configuration is done globally, so you can enforce the same structure in all of your sandboxes.

Thanks

License

GPL v3

emacs-playground's People

Contributors

akirak avatar purcell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

emacs-playground's Issues

Travis error on Emacs 26

4.47s$ cask install
Importing package-keyring.gpg...
Importing package-keyring.gpg...done
Contacting host: melpa.org:443
Opening TLS connection to ‘melpa.org’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 melpa.org’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 melpa.org’...failed
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 melpa.org --protocols ssl3’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 melpa.org --protocols ssl3’...failed
Opening TLS connection to ‘melpa.org’...failed
Failed to download ‘melpa’ archive.
Contacting host: elpa.gnu.org:443
Opening TLS connection to ‘elpa.gnu.org’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 elpa.gnu.org’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 elpa.gnu.org’...failed
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 elpa.gnu.org --protocols ssl3’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 elpa.gnu.org --protocols ssl3’...failed
Opening TLS connection to ‘elpa.gnu.org’...failed
Package refresh done
Failed to download ‘gnu’ archive.
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
Package ‘s-’ is unavailable

Setting an entry point

steckemacs does not contain init.el but requires a symbolic link to steckemacs.el. This configuration can be supported by accepting an optional property :entry-point:

(... :entry-point "steckemacs.el")

That is, a symbolic link from ~/.emacs to steckemacs.el is produced when the sandbox is initialized.

Support Doom

I've tried to run doom-emacs on playground, but it turns out that the following commands needs to be run beforehand in order to use it:

cd ~/.emacs.d
cp init.example.el init.el
make install

To support a configuration like this, playground needs an enhancement to allow specification of an optional build command.

Generating shell scripts in Windows

As pointed out in this thread, Playground seems to require a tweak in order to make it run on Windows. I don't have a Windows machine, and I didn't consider support for Windows in the beginning, but the adaptation itself doesn't look difficult.

To investigate how Emacs runs on Windows, I tried to install cygwin onto Wine, but somehow it failed to install. Nor did I understand how to install the GNU version of Windows onto Wine. I am currently downloading a Windows VM image for testing. I will work on this issue later.

Travis errors

After adding package-lint to the Travis configuration, it raises the following errors in all Emacs versions:

2.13s$ cask emacs -Q --batch -l run-package-lint.el playground.el
Importing package-keyring.gpg...
Importing package-keyring.gpg...done
Contacting host: melpa.org:80
In `playground.el':
  at 64:50: warning: Use variable `user-emacs-directory' or function `locate-user-emacs-file' instead of a literal path to the Emacs user directory or files.
  at 282:62: warning: Use variable `user-emacs-directory' or function `locate-user-emacs-file' instead of a literal path to the Emacs user directory or files.
  at 323:62: warning: Use variable `user-emacs-directory' or function `locate-user-emacs-file' instead of a literal path to the Emacs user directory or files.
The command "cask emacs -Q --batch -l run-package-lint.el playground.el" exited with 1.
0.74s$ cask emacs -Q --batch --eval '(setq byte-compile-error-on-warn t)' -f batch-byte-compile playground.el
In toplevel form:
playground.el:397:1:Error: the following functions are not known to be defined: helm, helm-build-sync-source, helm-build-dummy-source
The command "cask emacs -Q --batch --eval '(setq byte-compile-error-on-warn t)' -f batch-byte-compile playground.el" exited with 1.

warning: Use variable user-emacs-directory' or function locate-user-emacs-file' instead of a literal path to the Emacs user directory or files.

This is because ".emacs.d" literal is used in those function to build a sandboxed emacs.d path. I want to suppress this warning, but I don't know how to fix that.

playground.el:397:1:Error: the following functions are not known to be defined: helm, helm-build-sync-source, helm-build-dummy-source

This is because helm is imported inside a function rather than at the top-level. I don't want to make this package depend on Helm, so I have no idea fix it.

An alternative way to try play.el (using Cask)

play.el bundles with init.el which can be used as ~/.emacs, but there is another way to try play.el:

cask install
cask exec emacs -Q --load play.el

However, when I run play-checkout loaded in this way, the following error is raised:

Setting current directory: No such file or directory, ~/github/play.el

Apparently, a workaround is needed to enable this flow.

Renaming this project

I've sent a request to add this package to MELPA, but I've received a response which suggests renaming this project to playground or sandbox, as play is an ambiguous name.

I am thinking of renaming it to playground. It will be a little inconvenient for current users, as the current package configuration will be broken for some time. If this change is needed, the sooner the better.

Do you have any opinions about this topic?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.