Brad Beveridge wrote: > 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?
The screen updating code doesn't want to redraw everything all the time. Thus you must somehow specify what text got changed/inserted/deleted. If you don't do that you might indeed see redraw problems that go away when using CTRL-L. You are doing low level stuff here, thus you must take care of all these things yourself. > 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}; > 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; > } Do you save text for undo somewhere? That should be done for every change that is being made, otherwise undo won't work. -- hundred-and-one symptoms of being an internet addict: 250. You've given up the search for the "perfect woman" and instead, sit in front of the PC until you're just too tired to care. /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ download, build and distribute -- http://www.A-A-P.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///