Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] Named Buffers - Problem Solved

Expand Messages
  • Veli-Pekka Tätilä
    ... Quite right. Actually I don t use the term too often myself, thinking that it is a bit needlessly techy, but used it this time to emphasize the Vi
    Message 1 of 1 , Jan 22, 2006
    • 0 Attachment
      rpdooling wrote:
      > Buffer is what emacs or xemacs calls (roughly) what we refer to as an
      > open file or open doc (saved or unsaved).
      Quite right. Actually I don't use the term too often myself, thinking that
      it is a bit needlessly techy, but used it this time to emphasize the Vi
      inspiration in my case.

      > wants a kind of permanent variable or the equivalent of a "key" in Perl or
      > Python.
      You hit the proverbial nail on the head.

      > VP, Since you are so conversant with Perl, I think you will be
      > happiest creating a Perl hash and running ^$GetDosOutput(Perl.exe
      > Script.pl argv)$
      I did just that and it does work. There are several advantages to ini files
      I think. FIrstly, no size limit on data and the buffer names can contain any
      characters including double quotes and spaces. Also Perl is pretty fast with
      text data, though as we are talking about relatively small text snippets
      here, say about 10 KB at max, that won't be a problem at any rate.

      Here's my Perl code:
      use strict; use warnings;
      use fatal qw|open close unlink|;
      use Data::Dump;
      my($file, $name, %buffer) = "$0.data";
      undef local $/;
      ($_, $name) = (shift, join(' ', @ARGV)); # Easy white-space handling.
      # Delete file.
      die "Usage: <command> [<buffer_name>]" unless defined $_ and (defined($name)
      or /c/);
      unlink($file), exit(0) if /c/;
      # Desrialize named buffers.
      if(-e $file)
      open FILE, $file; # Deserialize.
      %buffer = eval join('', <FILE>);
      close FILE;
      } # if
      # Read and write commands.
      die "No such buffer: $name\n" if /r/ and not exists $buffer{$name};
      if(/r/) { print $buffer{$name} }
      elsif(/w/) { $buffer{$name} = <STDIN>; chop $buffer{$name} }
      else { die "Unknown command: $_\n" }
      # Serializing on disk, again.
      open FILE, ">$file"; # Serialize.
      print FILE Data::Dump::dump(%buffer);
      End code.

      And the clips that interface with the script are as follows:

      ^$GetInputOutput("perl.exe namedbuf.plx c")$

      ^!Set %buffer%=^?{Buffer name}
      ^$GetInputOutput("perl.exe namedbuf.plx w ^%buffer%")$

      ^!Set %buffer%=^?{Buffer name}
      ^$GetInputOutput("perl.exe namedbuf.plx r ^%buffer%")$
      End code.

      Actually, I would have liked to simply keep the perl script running in the
      background at all times and merely read or write some hash keys. But that
      led to inter-process communication and sockets pretty quickly and so I gave
      up that route.

      Thanks to everyone contributing in this thread, though. There were some nice
      points made and I'm sure the ini approach might well have served over ninety
      percent of my needs, too.

      With kind regards Veli-Pekka Tätilä (vtatila@...)
      Accessibility, game music, synthesizers and programming:
    Your message has been successfully submitted and would be delivered to recipients shortly.