[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Emacs Lisp container
Emacs Lisp container
Mon, 26 Jun 2017 23:03:25 -0400
I’ve tried to find a library or some tool to execute Elisp in a running
session while keeping the same environment, but found none. Some call
it a container or sandbox or even jail.
What I mean by that, is that I would like to execute a body of code and
get the result without actually modifying the variables, functions,
loaded features, etc. of the current session.
I’m fully aware that starting a new session seem to do the same thing,
but I want to execute the piece of code in the *current running
I finally came up with a small library I named _container_. There
are many ways to escape the container (like using `funcall` & `apply`
and also using `eval` on a quoted `eval` form). It’s more of a proof a
concept than a working library right now.
> (let ((container-ignore-error t)
> (add-to-list 'load-path "~/Documents/")
> (require 'foo)
> (setq emacs-version "0.0.0")
> emacs-version)) ; => "0.0.0"
> emacs-version ; => 26.0.50
The above snippet doesn’t (seem to) have side-effects.
What it does is the following:
* Saves the window configuration and opens a new buffer.
* Overrides the `require` & `load` functions to unload after the
container finished executing.
* Overrides the `load-theme` function to restore the original theme
* Overrides the `set`, `setq` & `set-default` functions to make the
variable buffer local.
* Overrides the `eval` function to apply the above. This one is
particularly tricky since we could escape it using a quoted form. I’m
considering disabling it altogheter and signal an error.
* (Work in Progress) Overrides the `funcall` & `apply` functions to
apply the rules above. This is also tricky since the evaluation
process doesn’t make much sense to me. I’m probably not used enough
with evalutation. I can’t figure out why:
> (funcall #'setq test 1)
> (funcall #'setq 'test 1)
Of course, I may be totally wrong in my approach and would appreciate
being corrected. Help and comments are welcomed!
- Emacs Lisp container,
Etienne Prud’homme <=