[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multiple parallel environments
From: |
Ludovic Courtès |
Subject: |
Re: Multiple parallel environments |
Date: |
Thu, 30 Jul 2009 16:45:16 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
Hello!
Peter Brett <address@hidden> writes:
> address@hidden (Ludovic Courtès) writes:
[...]
>> What do you mean by "environment"? All the global variables associated
>> with a given file in the editor?
>
> Sort of. The whole of Guile's top level bindings at that point. (The
> per-directory config is literally loaded as a Scheme script, so it
> could define and redefine functions and variables at will).
Then you are looking for Guile's nifty first-class modules. The module
API is unfortunately lightly documented (info "(guile) Module System
Reflection").
>> What do you mean by "save"? Serialize to a file the "environment"
>> associated with a file (or the difference compared to the initial
>> environment)?
>
> It doesn't need to be serialised -- I don't even need to be able to
> get a C pointer to it! -- it just needs to be "stashed" somewhere so
> that I can "rewind" Guile's toplevel bindings to that point at a later
> time.
>
> Essentially, I want each directory/"project" to be able to define its
> own functions, include its own modules etc. without stomping over
> another project that happens to be loaded into the application at the
> same time.
Easy! :-)
What you would do is create one module for each file/project/directory:
(define (make-per-file-module name)
(let ((m (make-module)))
(set-module-name! m name) ;; give the module an optional name
(beautify-user-module! m) ;; populate the module with the
;; default bindings
m))
Then you create one such module for each file/directory/etc. and somehow
associate it with said file/directory/etc. (with an alist, a hash table,
or something similar). When entering a file associated with that
module, you just have to make it current:
(define (enter-file-buffer file)
(set-current-module! (lookup-per-file-module file)))
And voilà! :-)
Hope this helps,
Ludo'.