all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs Lisp container
@ 2017-06-27  3:03 Etienne Prud’homme
  2017-06-27  4:37 ` Marcin Borkowski
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Etienne Prud’homme @ 2017-06-27  3:03 UTC (permalink / raw)
  To: emacs-devel

Hi,

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
environment*.


I finally came up with a small library I named _container_[1].  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.

e.g.

> (let ((container-ignore-error t)
>   (container
>     (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
  configuration after.

* 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)

works while:

> (funcall #'setq 'test 1)

doesn’t work.

Of course, I may be totally wrong in my approach and would appreciate
being corrected.  Help and comments are welcomed!

[1] https://github.com/notetiene/emacs-lisp-container
--
Etienne



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs Lisp container
  2017-06-27  3:03 Emacs Lisp container Etienne Prud’homme
@ 2017-06-27  4:37 ` Marcin Borkowski
  2017-07-02 18:06   ` Wilfred Hughes
  2017-06-27  7:22 ` Phillip Lord
  2017-06-28 19:07 ` Stefan Monnier
  2 siblings, 1 reply; 5+ messages in thread
From: Marcin Borkowski @ 2017-06-27  4:37 UTC (permalink / raw)
  To: Etienne Prud’homme; +Cc: emacs-devel


On 2017-06-27, at 05:03, Etienne Prud’homme <e.e.f.prudhomme@gmail.com> wrote:

> I finally came up with a small library I named _container_[1].  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.

Interesting.

Another approach could be to write a metacircular Elisp interpreter.

> * (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)
>
> works while:
>
>> (funcall #'setq 'test 1)
>
> doesn’t work.

Is it because setq is not a function?

Best,

-- 
Marcin Borkowski



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs Lisp container
  2017-06-27  3:03 Emacs Lisp container Etienne Prud’homme
  2017-06-27  4:37 ` Marcin Borkowski
@ 2017-06-27  7:22 ` Phillip Lord
  2017-06-28 19:07 ` Stefan Monnier
  2 siblings, 0 replies; 5+ messages in thread
From: Phillip Lord @ 2017-06-27  7:22 UTC (permalink / raw)
  To: "Etienne Prud’homme"; +Cc: emacs-devel

On Tue, June 27, 2017 3:03 am, Etienne Prud’homme wrote:
> Hi,
>
>
> 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
> environment*.
>
>
> I finally came up with a small library I named _container_[1].  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.
>
> e.g.
>
>> (let ((container-ignore-error t)
>> (container
>> (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
> configuration after.
>
> * 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)
>>
>
> works while:
>
>> (funcall #'setq 'test 1)
>>
>
> doesn’t work.
>
> Of course, I may be totally wrong in my approach and would appreciate
> being corrected.  Help and comments are welcomed!


It's a nice idea, but I think that C-level calls to setq will just ignore
your changes. Likewise for all your other alterations.

So, this will get you some of the way there, but not all of the way.
Besides which you still allow buffer changes which is, of course, a major
issue with statelessness.

Phil




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs Lisp container
  2017-06-27  3:03 Emacs Lisp container Etienne Prud’homme
  2017-06-27  4:37 ` Marcin Borkowski
  2017-06-27  7:22 ` Phillip Lord
@ 2017-06-28 19:07 ` Stefan Monnier
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2017-06-28 19:07 UTC (permalink / raw)
  To: emacs-devel

> 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.

Can you give us some background, like what concrete code you'd like to
run in such a sandbox?


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs Lisp container
  2017-06-27  4:37 ` Marcin Borkowski
@ 2017-07-02 18:06   ` Wilfred Hughes
  0 siblings, 0 replies; 5+ messages in thread
From: Wilfred Hughes @ 2017-07-02 18:06 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Etienne Prud’homme, emacs-devel

On 27 June 2017 at 05:37, Marcin Borkowski <mbork@mbork.pl> wrote:
>
>
> Another approach could be to write a metacircular Elisp interpreter.

I've actually been writing a metacircular elisp interpreter as part of
writing an abstract interpreter: https://github.com/wilfred/peval. It
is not finished yet, however.

Alternatively, fsbot on the #emacs IRC channel on freenode has an
elisp sandbox. The sandbox code is available as a standalone library
here: https://github.com/joelmccracken/elisp-sandbox

Wilfred



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-07-02 18:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-27  3:03 Emacs Lisp container Etienne Prud’homme
2017-06-27  4:37 ` Marcin Borkowski
2017-07-02 18:06   ` Wilfred Hughes
2017-06-27  7:22 ` Phillip Lord
2017-06-28 19:07 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.