Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: kill-region hook



On Fri, 30 Jan 2009 01:07:32 +0100
Michal Maruska <michal@xxxxxxxx> wrote:
> Then I found zlelineasstring, but I don't understand what metafy is about
> (it's called in zlelineasstring to modify the C string somehow).

There are two representations of strings: ZLE_STRING_T is in terms of wide
characters and is used for editing functions, a "metafied" character string
is used elswhere in the shell.  The latter is basically an ordinary
null-terminated string, but with the special Meta character embedded in it
that indicates that the following character is not special and should be
xor'd with 32 to get the normal character (hence Meta followed by space
represents and embedded null character that does not terminate the
string).  zlelineasstring() and stringaszleline() convert between the two
representations.  We only use ordinary ("unmetafied") C strings for
interacting with the outside world (a particular example is for filenames
passed to system functions).

The other thing you need to be aware of is memory allocation: it's not
always clear in the shell whether things should be allocated permanently
using zalloc() and relatives or on the heap for freeing at the end of the
current command execution using zhalloc().  You can work it out by looking
at enough code, but possibly not just from the immediate context.
So if you're converting a string for permanent storage you'd use the
former, if you converting it for temporarily working on it and then
converting it back you'd probably use the heap (though you can of course
allocate it and free it, which is slower but does mean memory doesn't build
up if the operation is repeated).  There's some description of this in
Src/mem.c.

One upshot of that is that zlelineasstring() is probably the right thing to
call, but I think you're temporary function argument list for the hook is
coming from heap memory (newlinklist() is off the heap, unlike
znewlinklist(), and you're not freeing it), so you need the final argument 1 to
zlelineasstring().  Your size is now uninitialised, but I don't think
you'll need it.

Otherwise it looks roughly OK, but I'd have to look a bit more than I have
time for at the moment to see if it's in the most logical place to catch
operations on the cut buffer and kill ring, and if you're extracting the
right bits of the cut buffer.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author