static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, long amount_after, bool adjust_folds, bool end_temp) { int i; int fnum = curbuf->b_fnum; linenr_T *lp; static pos_T initpos = INIT_POS_T(1, 0, 0); if (line2 < line1 && amount_after == 0L) /* nothing to do */ return; if (!cmdmod.lockmarks) { /* named marks, lower case and upper case */ for (i = 0; i < NMARKS; i++) { one_adjust(&(curbuf->b_namedm[i].mark.lnum)); if (namedfm[i].fmark.fnum == fnum) one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } for (i = NMARKS; i < NGLOBALMARKS; i++) { if (namedfm[i].fmark.fnum == fnum) one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } /* last Insert position */ one_adjust(&(curbuf->b_last_insert.mark.lnum)); /* last change position */ one_adjust(&(curbuf->b_last_change.mark.lnum)); /* last cursor position, if it was set */ if (!equalpos(curbuf->b_last_cursor.mark, initpos)) one_adjust(&(curbuf->b_last_cursor.mark.lnum)); /* list of change positions */ for (i = 0; i < curbuf->b_changelistlen; ++i) one_adjust_nodel(&(curbuf->b_changelist[i].mark.lnum)); /* Visual area */ one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); // quickfix marks if (!qf_mark_adjust(NULL, line1, line2, amount, amount_after)) { curbuf->b_has_qf_entry &= ~BUF_HAS_QF_ENTRY; } // location lists bool found_one = false; FOR_ALL_TAB_WINDOWS(tab, win) { found_one |= qf_mark_adjust(win, line1, line2, amount, amount_after); } if (!found_one) { curbuf->b_has_qf_entry &= ~BUF_HAS_LL_ENTRY; } sign_mark_adjust(line1, line2, amount, amount_after); bufhl_mark_adjust(curbuf, line1, line2, amount, amount_after, end_temp); }
/* * To change context, call setpcmark(), then move the current position to * where ever, then call checkpcmark(). This ensures that the previous * context will only be changed if the cursor moved to a different line. * If pcmark was deleted (with "dG") the previous mark is restored. */ void checkpcmark(void) { if (curwin->w_prev_pcmark.lnum != 0 && (equalpos(curwin->w_pcmark, curwin->w_cursor) || curwin->w_pcmark.lnum == 0)) { curwin->w_pcmark = curwin->w_prev_pcmark; curwin->w_prev_pcmark.lnum = 0; /* Show it has been checked */ } }
/*ARGSUSED*/ int workshop_get_positions( void *clientData, /* unused */ char **filename, /* output data */ int *curLine, /* output data */ int *curCol, /* output data */ int *selStartLine, /* output data */ int *selStartCol, /* output data */ int *selEndLine, /* output data */ int *selEndCol, /* output data */ int *selLength, /* output data */ char **selection) /* output data */ { static char ffname[MAXPATHLEN]; #ifdef WSDEBUG_TRACE if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) wstrace("workshop_get_positions(%#x, \"%s\", ...)\n", clientData, (curbuf && curbuf->b_sfname != NULL) ? (char *)curbuf->b_sfname : "<None>"); #endif strcpy(ffname, (char *) curbuf->b_ffname); *filename = ffname; /* copy so nobody can change b_ffname */ *curLine = curwin->w_cursor.lnum; *curCol = curwin->w_cursor.col; if (curbuf->b_visual_mode == 'v' && equalpos(curwin->w_cursor, curbuf->b_visual_end)) { *selStartLine = curbuf->b_visual_start.lnum; *selStartCol = curbuf->b_visual_start.col; *selEndLine = curbuf->b_visual_end.lnum; *selEndCol = curbuf->b_visual_end.col; *selection = get_selection(curbuf); if (*selection) *selLength = strlen(*selection); else *selLength = 0; } else { *selStartLine = *selEndLine = -1; *selStartCol = *selEndCol = -1; *selLength = 0; *selection = ""; } return True; }
/* * Adjust marks between line1 and line2 (inclusive) to move 'amount' lines. * Must be called before changed_*(), appended_lines() or deleted_lines(). * May be called before or after changing the text. * When deleting lines line1 to line2, use an 'amount' of MAXLNUM: The marks * within this range are made invalid. * If 'amount_after' is non-zero adjust marks after line2. * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2); * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0); * or: mark_adjust(56, 55, MAXLNUM, 2); */ void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after) { int i; int fnum = curbuf->b_fnum; linenr_T *lp; static pos_T initpos = INIT_POS_T(1, 0, 0); if (line2 < line1 && amount_after == 0L) /* nothing to do */ return; if (!cmdmod.lockmarks) { /* named marks, lower case and upper case */ for (i = 0; i < NMARKS; i++) { one_adjust(&(curbuf->b_namedm[i].mark.lnum)); if (namedfm[i].fmark.fnum == fnum) one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } for (i = NMARKS; i < NGLOBALMARKS; i++) { if (namedfm[i].fmark.fnum == fnum) one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } /* last Insert position */ one_adjust(&(curbuf->b_last_insert.mark.lnum)); /* last change position */ one_adjust(&(curbuf->b_last_change.mark.lnum)); /* last cursor position, if it was set */ if (!equalpos(curbuf->b_last_cursor.mark, initpos)) one_adjust(&(curbuf->b_last_cursor.mark.lnum)); /* list of change positions */ for (i = 0; i < curbuf->b_changelistlen; ++i) one_adjust_nodel(&(curbuf->b_changelist[i].mark.lnum)); /* Visual area */ one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); /* quickfix marks */ qf_mark_adjust(NULL, line1, line2, amount, amount_after); /* location lists */ FOR_ALL_TAB_WINDOWS(tab, win) { qf_mark_adjust(win, line1, line2, amount, amount_after); } sign_mark_adjust(line1, line2, amount, amount_after); }
/* * Adjust marks between line1 and line2 (inclusive) to move 'amount' lines. * Must be called before changed_*(), appended_lines() or deleted_lines(). * May be called before or after changing the text. * When deleting lines line1 to line2, use an 'amount' of MAXLNUM: The marks * within this range are made invalid. * If 'amount_after' is non-zero adjust marks after line2. * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2); * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0); * or: mark_adjust(56, 55, MAXLNUM, 2); */ void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after) { int i; int fnum = curbuf->b_fnum; linenr_T *lp; win_T *win; tabpage_T *tab; static pos_T initpos = INIT_POS_T(1, 0, 0); if (line2 < line1 && amount_after == 0L) /* nothing to do */ return; if (!cmdmod.lockmarks) { /* named marks, lower case and upper case */ for (i = 0; i < NMARKS; i++) { one_adjust(&(curbuf->b_namedm[i].lnum)); if (namedfm[i].fmark.fnum == fnum) one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++) { if (namedfm[i].fmark.fnum == fnum) one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); } /* last Insert position */ one_adjust(&(curbuf->b_last_insert.lnum)); /* last change position */ one_adjust(&(curbuf->b_last_change.lnum)); /* last cursor position, if it was set */ if (!equalpos(curbuf->b_last_cursor, initpos)) one_adjust(&(curbuf->b_last_cursor.lnum)); /* list of change positions */ for (i = 0; i < curbuf->b_changelistlen; ++i) one_adjust_nodel(&(curbuf->b_changelist[i].lnum)); /* Visual area */ one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); /* quickfix marks */ qf_mark_adjust(NULL, line1, line2, amount, amount_after); /* location lists */ FOR_ALL_TAB_WINDOWS(tab, win) qf_mark_adjust(win, line1, line2, amount, amount_after); } /* previous context mark */ one_adjust(&(curwin->w_pcmark.lnum)); /* previous pcmark */ one_adjust(&(curwin->w_prev_pcmark.lnum)); /* saved cursor for formatting */ if (saved_cursor.lnum != 0) one_adjust_nodel(&(saved_cursor.lnum)); /* * Adjust items in all windows related to the current buffer. */ FOR_ALL_TAB_WINDOWS(tab, win) { if (!cmdmod.lockmarks) /* Marks in the jumplist. When deleting lines, this may create * duplicate marks in the jumplist, they will be removed later. */ for (i = 0; i < win->w_jumplistlen; ++i) if (win->w_jumplist[i].fmark.fnum == fnum) one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum)); if (win->w_buffer == curbuf) { if (!cmdmod.lockmarks) /* marks in the tag stack */ for (i = 0; i < win->w_tagstacklen; i++) if (win->w_tagstack[i].fmark.fnum == fnum) one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum)); /* the displayed Visual area */ if (win->w_old_cursor_lnum != 0) { one_adjust_nodel(&(win->w_old_cursor_lnum)); one_adjust_nodel(&(win->w_old_visual_lnum)); } /* topline and cursor position for windows with the same buffer * other than the current window */ if (win != curwin) { if (win->w_topline >= line1 && win->w_topline <= line2) { if (amount == MAXLNUM) { /* topline is deleted */ if (line1 <= 1) win->w_topline = 1; else win->w_topline = line1 - 1; } else /* keep topline on the same line */ win->w_topline += amount; win->w_topfill = 0; } else if (amount_after && win->w_topline > line2) { win->w_topline += amount_after; win->w_topfill = 0; } if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2) { if (amount == MAXLNUM) { /* line with cursor is deleted */ if (line1 <= 1) win->w_cursor.lnum = 1; else win->w_cursor.lnum = line1 - 1; win->w_cursor.col = 0; } else /* keep cursor on the same line */ win->w_cursor.lnum += amount; } else if (amount_after && win->w_cursor.lnum > line2) win->w_cursor.lnum += amount_after; } /* adjust folds */ foldMarkAdjust(win, line1, line2, amount, amount_after); } } /* adjust diffs */ diff_mark_adjust(line1, line2, amount, amount_after); }