unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Luke Gorrie <luke@bluetail.com>
Subject: Re: Elegance in elisp, need advices
Date: 03 Feb 2003 01:30:40 +0100	[thread overview]
Message-ID: <lhptqa9pe7.fsf@dodo.bluetail.com> (raw)
In-Reply-To: 5ly9537p5w.fsf@rum.cs.yale.edu

"Stefan Monnier <foo@acm.com>" <monnier+gnu.emacs.sources/news/@flint.cs.yale.edu> writes:

> [ redirecting follow-ups to gnu.emacs.help ]
> 
> > For instance, the connection is set up with open-network-stream and
> > set-process-filter. I keep a buffer-like string (buffer as in C not as
> > in emacs), to which I concatenate every received string. When I am
> [...]
> > What would be the 'good' way to do that ?
> 
> Other than details of the layout of your code (more than 80 cols, docstring
> on the same line as the `defun', ...) it looks OK.  I don't know of any way
> to make it much better.  You could of course use a real Emacs buffer rather
> than a string, so you can use `insert / delete-region' rather than
> `concat / substring', but fundamentally, it can't be very different.
> 
> Admittedly, many process filters do such things, so it might be worth it
> to provide a generic way to solve it, but I don't know of anybody who's
> done that yet.

I have something like this, it's a simple library for writing
network-attached state machines. It basically gives your process
buffer a "state", which is the name of a function to call when
something happens (initialization, data arrives, disconnection.) Like
a sentinel+filter, but I also accumulate data in the buffer itself
(optionally.)

The state machine also has a function to call if it terminates
successfully and one to call if it fails (explicitly or via lisp
error.) This is nice if you want to deliver the final result of your
connection to some other code.

When data arrives, the state function will typically check the buffer
to see if a whole message is there, and if not just return (to be
reinvoked when more data arrives), otherwise consume the message and
possibly change states.

It also has some debugging support, via an *fsm-debug* buffer that
logs events and state changes.

It's not properly documented, but the code is here (net-fsm.el):

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/distel/distel/elisp/net-fsm.el?rev=1.6&content-type=text/vnd.viewcvs-markup

It was mostly written to support an implementation of the Distributed
Erlang state machine (derl.el):

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/distel/distel/elisp/derl.el?rev=1.16&content-type=text/vnd.viewcvs-markup

A simpler machine talks to the Erlang Port Mapper Daemon (epmd.el):

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/distel/distel/elisp/epmd.el?rev=1.1&content-type=text/vnd.viewcvs-markup

If this sounds interesting but the code is too opaque, let me know and
I'll document it when I have a chance.

BTW, Emacs buffers (rather than strings) make exquisite network
buffers I reckon, since you can interactively switch into them and
call your data-reading functions via M-: or the debugger, and see the
point advance through the input, etc. I love it a lot for debugging.

Cheers,
Luke

      parent reply	other threads:[~2003-02-03  0:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <874r7r7v1d.fsf@noos.fr>
2003-01-29 19:04 ` Elegance in elisp, need advices Stefan Monnier <foo@acm.com>
2003-01-30  1:36   ` Kim F. Storm
2003-02-03  0:30   ` Luke Gorrie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=lhptqa9pe7.fsf@dodo.bluetail.com \
    --to=luke@bluetail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).