From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?utf-8?Q?Etienne_Prud=E2=80=99homme?= Newsgroups: gmane.emacs.devel Subject: Emacs Lisp container Date: Mon, 26 Jun 2017 23:03:25 -0400 Message-ID: <87podqdtdu.fsf@x230.lts> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1498532624 31383 195.159.176.226 (27 Jun 2017 03:03:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 27 Jun 2017 03:03:44 +0000 (UTC) User-Agent: Emacs/25.2 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 27 05:03:36 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPgms-0007fK-FF for ged-emacs-devel@m.gmane.org; Tue, 27 Jun 2017 05:03:34 +0200 Original-Received: from localhost ([::1]:50118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPgmx-0007y6-QT for ged-emacs-devel@m.gmane.org; Mon, 26 Jun 2017 23:03:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPgmr-0007xm-39 for emacs-devel@gnu.org; Mon, 26 Jun 2017 23:03:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPgmo-0005Nq-0p for emacs-devel@gnu.org; Mon, 26 Jun 2017 23:03:33 -0400 Original-Received: from mail-qt0-x231.google.com ([2607:f8b0:400d:c0d::231]:34360) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPgmn-0005N4-SA for emacs-devel@gnu.org; Mon, 26 Jun 2017 23:03:29 -0400 Original-Received: by mail-qt0-x231.google.com with SMTP id 32so15549951qtv.1 for ; Mon, 26 Jun 2017 20:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:user-agent:mime-version :content-transfer-encoding; bh=L9BVurl3AuC3tPloKHVVUSgKCJkfd7rfzlQMpHjbngY=; b=uYnMItB44gOgYlTwCPjgZZ1sosc9gThkciRHEktMgSzWN8WzurIxCaiSejvoITGVS2 wrxta29NRDZcItdVbxpvYG7sR+fM+9h+kVNflx7WGR5rioSI9mRs/AAHzVH6Kgx07fcf 6wOYptISmejGH93+TiVDNGR4i5NezojaW6SrbxamobJJqgeIPnT+HTnWM7UQTdNCCsZL fdkkigTJ/hyLxZQ6Pj5LSJ3e7/ktn4UbWk/QxS7nFkzNbZ9T+LCC7DZChnB5hXLRjykp HcQ29mi37k8QfmorSPMbxkXTnvSp6I3riuKNB/6RIeSBZpwZSNvBT2BEj6sFsXe23bx5 Eydg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version:content-transfer-encoding; bh=L9BVurl3AuC3tPloKHVVUSgKCJkfd7rfzlQMpHjbngY=; b=ZNK1FJR9lmoz131/Pet3MiKUXtdNxQ/KksRts6gowkEDEsqmel4IcYKvC/7U5Ko43D Lwm2kdD38Q4HyccNWAi8yDdtPA7AGPnAz/dNxK0DUWaVEJ4wxnTrJyEVq9/sN90xRLN8 MMX2S8Nypi+S1J0lnzIiAbsSnyYCsvhB9OunIKs7zGj5jXasARfvI3aUCWBIl6i6Wdd7 D9VXxGb4jylip37UPg10Zs/NZO1AAavTAbmA78S2XHRCCk0l56Q+xvCtspU3iCbaCHeY AQ0UQkfba1TpmgFBEhnRtCu8VhGW5HV5l9M4+fWUYocnWS2pNGCriiINsme9+cryNCbN fNLQ== X-Gm-Message-State: AKS2vOz0BVitudmQeknwj3/Ax7mjdhaGuIuvJvLc0fidAwNUByqYiLeD fYIcp6rQv7R2g1smMU4= X-Received: by 10.237.53.12 with SMTP id a12mr3860736qte.207.1498532607189; Mon, 26 Jun 2017 20:03:27 -0700 (PDT) Original-Received: from localhost (modemcable232.49-20-96.mc.videotron.ca. [96.20.49.232]) by smtp.gmail.com with ESMTPSA id k23sm1454568qke.41.2017.06.26.20.03.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Jun 2017 20:03:26 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:216020 Archived-At: Hi, I=E2=80=99ve tried to find a library or some tool to execute Elisp in a run= ning 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=E2=80=99m fully aware that starting a new session seem to do the same thi= ng, 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=E2=80=99s more of a pro= of 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)) ; =3D> "0.0.0" > emacs-version ; =3D> 26.0.50 The above snippet doesn=E2=80=99t (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. =20 * 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=E2= =80=99m 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=E2=80=99t make much sense to me. I=E2=80=99m probably not = used enough with evalutation. I can=E2=80=99t figure out why: > (funcall #'setq test 1) works while: > (funcall #'setq 'test 1) doesn=E2=80=99t 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