Brad Beveridge wrote:
On 26/08/06, Brad Beveridge <[EMAIL PROTECTED]> wrote:
<SNIP>
Cheers
Brad
Hi, sorry for all the trouble :) I'm having redraw issues, where
running this code to append chars is causing strange problems.
The scenario is this (always using the code below for char output):
1) Write a char to a buffer (line1)
2) Write a newline (line 2)
3) Move the cursor to the bottom of the buffer (line2 empty)
4) Write another Char (appears in line2)
5) Press Ctrl-L
6) Notice that line1 has vanished.
moving the cursor to the new blank line at the bottom of the line is
critical here. I'm sure that I'm doing something wrong, but I really
can't figure it out.
As a side note, it feels very clumsy to have to manually call "changed
line" functions when calling ml_* funcs - is there some notes I can
read about why this is?
Anyhow, here is the code I'm using to put chars in a buffer - I really
appreciate any thoughts, this feels so close to working, but I've
spend several hours trying to get it right. Very frustrating :)
Cheers
Brad
static void vim_append_char (buf_T target_buf, char c)
{
static char string[2] = {0};
Should not you have "= {0, 0}" here? Second element never get
initialized but it could be accessed by ml_append_string.
buf_T *savebuf = curbuf;
curbuf = target_buf;
int start_line = curbuf->b_ml.ml_line_count;
int lines_changed = 0;
string[0] = c;
if (string[0] == '\n')
{
ml_append (start_line, "", 0, FALSE);
lines_changed = 0;
}
else
ml_append_string (start_line, string, -1);
changed_lines (start_line, 0, start_line, lines_changed);
/* restore and return */
curbuf = savebuf;
}