Hmm, where to begin...

First of all, the executive summary: I think it'll be doable one way or another.

As Elian pointed out, if you want other people to understand what you're wanting, you might have to couch it in non-editor terms. (That being said, I used to hack around with Gosling's Emacs, so I know what you're saying.) Stated more generically, what you're asking for is a way to parameterize the lookup of variable names such that a particular generic variable name can refer to different specific variables at different times.

Perl has several mechanisms built in that get you most of the way there. As jdporter points out, package variables are thread local by default, so each thread gets its own copies of unshared variable. However, I don't think you necessarily want to tie a buffer to a thread.

As dakkar points out, you can get parameterized variables by using objects, where the attributes of the object can define themselves however they want. Perl 6 is trying to make object attributes work as much as possible like ordinary variables, so it might be acceptable to you to write $b.variable.

We've already said that you can curry classes into modules by assuming an invocant, so you could have a chunk of code that can even assume the $b. on the front. But then you don't get the sigils.

There's a mechanism built into regexes that variables of the form $?foo are kept in the current $0 object. That probably works outside of regexes as well.

Ordinary package variables don't support what you want, but if there were a way to declare a package using a global variable, then it'd be possible to compile variables in that scope to use that global variable as part of the variable's lookup strategy.

So there really are lots of ways to get the semantics you want. Which really means that you are asking for syntactic warpage after all. What you're asking for is that variables within a particular scope have a different lookup strategy than ordinary Perl names. So it'd be pretty easy to install a rule in the parser's grammar that lets you declare a variable using a new declarator that specifies a different "lifetime" for the variable. We currently have "my", "our", and "state" variables. You could set up a new declarator that declares buffer variables, and then binds the name however you jolly well please, using any of the parameterization methods we mentioned earlier to do the semantic warpage underneath.

If you want to discuss building a particular syntax in as standard, that should probably be discussed on the perl6-language mailing list.


In reply to Re: Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables? by TimToady
in thread Implementing (elisp-like) buffers in Perl 6: how to do buffer-localisation of arbitrary package variables? by jonadab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.