help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Elegance in elisp, need advices


From: Stefan Monnier <address@hidden>
Subject: Re: Elegance in elisp, need advices
Date: 29 Jan 2003 14:04:59 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

[ 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.

> Also, to decode/encode int8 int16 and int32 into mldonkey format, I
> use this kind of infamous functions :

I remember someone posting some generic code to do packing/unpacking of
binary data (maybe it was called struct.el or something like that).

>>> (defun int32-to-proto (n) (string (mod n 256) (mod (/ n 256) 256) (mod (/ n 
>>> 65536) 256) (mod (/ n 16777216) 256)))

BTW, on 32bit machines, Emacs' integers only use 28bits (i.e. from -2^17
to 2^17-1).


        Stefan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]