/* * Delete signs in group 'group' in buffer "buf". If 'group' is '*', then * delete all the signs. */ void buf_delete_signs(buf_T *buf, char_u *group) { signlist_T *sign; signlist_T **lastp; // pointer to pointer to current sign signlist_T *next; // When deleting the last sign need to redraw the windows to remove the // sign column. Not when curwin is NULL (this means we're exiting). if (buf->b_signlist != NULL && curwin != NULL) { redraw_buf_later(buf, NOT_VALID); changed_cline_bef_curs(); } lastp = &buf->b_signlist; for (sign = buf->b_signlist; sign != NULL; sign = next) { next = sign->next; if (sign_in_group(sign, group)) { *lastp = next; if (next != NULL) next->prev = sign->prev; if (sign->group != NULL) sign_group_unref(sign->group->sg_name); vim_free(sign); } else lastp = &sign->next; } }
/* * When curwin->w_leftcol has changed, adjust the cursor position. * Return true if the cursor was moved. */ bool leftcol_changed(void) { // TODO(hinidu): I think it should be colnr_T or int, but p_siso is long. // Perhaps we can change p_siso to int. int64_t lastcol; colnr_T s, e; bool retval = false; changed_cline_bef_curs(); lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1; validate_virtcol(); /* * If the cursor is right or left of the screen, move it to last or first * character. */ if (curwin->w_virtcol > (colnr_T)(lastcol - p_siso)) { retval = true; coladvance((colnr_T)(lastcol - p_siso)); } else if (curwin->w_virtcol < curwin->w_leftcol + p_siso) { retval = true; coladvance((colnr_T)(curwin->w_leftcol + p_siso)); } /* * If the start of the character under the cursor is not on the screen, * advance the cursor one more char. If this fails (last char of the * line) adjust the scrolling. */ getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e); if (e > (colnr_T)lastcol) { retval = true; coladvance(s - 1); } else if (s < curwin->w_leftcol) { retval = true; if (coladvance(e + 1) == FAIL) { /* there isn't another character */ curwin->w_leftcol = s; /* adjust w_leftcol instead */ changed_cline_bef_curs(); } } if (retval) curwin->w_set_curswant = true; redraw_later(NOT_VALID); return retval; }
/* * Insert a new sign into the signlist for buffer 'buf' between the 'prev' and * 'next' signs. */ static void insert_sign( buf_T *buf, // buffer to store sign in signlist_T *prev, // previous sign entry signlist_T *next, // next sign entry int id, // sign ID char_u *group, // sign group; NULL for global group int prio, // sign priority linenr_T lnum, // line number which gets the mark int typenr) // typenr of sign we are adding { signlist_T *newsign; newsign = (signlist_T *)lalloc_id((long_u)sizeof(signlist_T), FALSE, aid_insert_sign); if (newsign != NULL) { newsign->id = id; newsign->lnum = lnum; newsign->typenr = typenr; if (group != NULL) { newsign->group = sign_group_ref(group); if (newsign->group == NULL) { vim_free(newsign); return; } } else newsign->group = NULL; newsign->priority = prio; newsign->next = next; newsign->prev = prev; if (next != NULL) next->prev = newsign; if (prev == NULL) { // When adding first sign need to redraw the windows to create the // column for signs. if (buf->b_signlist == NULL) { redraw_buf_later(buf, NOT_VALID); changed_cline_bef_curs(); } // first sign in signlist buf->b_signlist = newsign; #ifdef FEAT_NETBEANS_INTG if (netbeans_active()) buf->b_has_sign_column = TRUE; #endif } else prev->next = newsign; } }
/* * Delete sign 'id' in group 'group' from buffer 'buf'. * If 'id' is zero, then delete all the signs in group 'group'. Otherwise * delete only the specified sign. * If 'group' is '*', then delete the sign in all the groups. If 'group' is * NULL, then delete the sign in the global group. Otherwise delete the sign in * the specified group. * Returns the line number of the deleted sign. If multiple signs are deleted, * then returns the line number of the last sign deleted. */ linenr_T buf_delsign( buf_T *buf, // buffer sign is stored in linenr_T atlnum, // sign at this line, 0 - at any line int id, // sign id char_u *group) // sign group { signlist_T **lastp; // pointer to pointer to current sign signlist_T *sign; // a sign in a b_signlist signlist_T *next; // the next sign in a b_signlist linenr_T lnum; // line number whose sign was deleted lastp = &buf->b_signlist; lnum = 0; for (sign = buf->b_signlist; sign != NULL; sign = next) { next = sign->next; if ((id == 0 || sign->id == id) && (atlnum == 0 || sign->lnum == atlnum) && sign_in_group(sign, group)) { *lastp = next; if (next != NULL) next->prev = sign->prev; lnum = sign->lnum; if (sign->group != NULL) sign_group_unref(sign->group->sg_name); vim_free(sign); redraw_buf_line_later(buf, lnum); // Check whether only one sign needs to be deleted // If deleting a sign with a specific identifier in a particular // group or deleting any sign at a particular line number, delete // only one sign. if (group == NULL || (*group != '*' && id != 0) || (*group == '*' && atlnum != 0)) break; } else lastp = &sign->next; } // When deleting the last sign the cursor position may change, because the // sign columns no longer shows. And the 'signcolumn' may be hidden. if (buf->b_signlist == NULL) { redraw_buf_later(buf, NOT_VALID); changed_cline_bef_curs(); } return lnum; }
static int luaV_buffer_newindex(lua_State *L) { buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1); linenr_T n = (linenr_T) luaL_checkinteger(L, 2); #ifdef HAVE_SANDBOX luaV_checksandbox(L); #endif if (n < 1 || n > b->b_ml.ml_line_count) luaL_error(L, "invalid line number"); if (lua_isnil(L, 3)) /* delete line */ { buf_T *buf = curbuf; curbuf = b; if (u_savedel(n, 1L) == FAIL) { curbuf = buf; luaL_error(L, "cannot save undo information"); } else if (ml_delete(n, FALSE) == FAIL) { curbuf = buf; luaL_error(L, "cannot delete line"); } else { deleted_lines_mark(n, 1L); if (b == curwin->w_buffer) /* fix cursor in current window? */ { if (curwin->w_cursor.lnum >= n) { if (curwin->w_cursor.lnum > n) { curwin->w_cursor.lnum -= 1; check_cursor_col(); } else check_cursor(); changed_cline_bef_curs(); } invalidate_botline(); } } curbuf = buf; } else if (lua_isstring(L, 3)) /* update line */ { buf_T *buf = curbuf; curbuf = b; if (u_savesub(n) == FAIL) { curbuf = buf; luaL_error(L, "cannot save undo information"); } else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL) { curbuf = buf; luaL_error(L, "cannot replace line"); } else changed_bytes(n, 0); curbuf = buf; if (b == curwin->w_buffer) check_cursor_col(); } else luaL_error(L, "wrong argument to change line"); return 0; }