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

Re: Buffer bug?



>    ? 
>    Buffer #<BUFFER-MARK 0/119> has 119 chars, which are: 
                         ^^^
>    'This )) is (people person 1) bad too.
>    ;This (( is a ) bad ( string, no?
>    ;This is a nice string (people person 1), yes?
>    '.
>    ((IS A) (PEOPLE PERSON 1))          ;correct result
>    ? 
>|#
>
>
>;;;
>;;; Test2: Evaluate following form:
>;;;
>#|
>(let ((buffer (make-buffer)))
>  (buffer-insert buffer "This )) is (people person 1) bad too.
>;This (( is a ) bad ( string, no?
>;This is a nice string (people person 1), yes?
>")
>  (l-lists-in-buffer buffer))
>|#
>;;;
>;;; The result this time was different and *wrong* IMHO:
>;;;
>#|
>? 
>    Buffer #<BUFFER-MARK 119/119> has 119 chars, which are: 
                          ^^^
>    'This )) is (people person 1) bad too.
>    ;This (( is a ) bad ( string, no?
>    ;This is a nice string (people person 1), yes?
>    '.
>    NIL                                 ;*wrong* result!
>    ? 
>|#

buffer-insert apparently destructively modifies its buffer argument to be
at the end of the insert.  [Note the difference in the print-string of the
buffer mark in the two tests.]  While you explicitly use the number 0 and
the buffer size to get all the text in your call to buffer-substring, you
do not do so in your call to buffer-current-sexp.

If you make a new buffer mark at 0 and use *that* in your iteration, you
will almost certainly get the desired results.

Whether buffer-insert *should* or should not modify its buffer argument is
something you will have to take up with the MCL team.  IMHO, it could be
quite useful information to have returned in the modified buffer-mark.

Disclaimer:  I'm making this answer up based just on output and looking at
your code and have little actual experience with buffers and buffer-insert.
"TANSTAAFL" Rich lynch@ils.nwu.edu