refactor/mark.c (#20596)

This commit is contained in:
Lewis Russell 2022-10-11 16:15:44 +01:00 committed by GitHub
parent cba05c541d
commit 6e11db2301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -645,20 +645,17 @@ fmark_T *getnextmark(pos_T *startpos, int dir, int begin_line)
// until the mark is used to avoid a long startup delay. // until the mark is used to avoid a long startup delay.
static void fname2fnum(xfmark_T *fm) static void fname2fnum(xfmark_T *fm)
{ {
char_u *p;
if (fm->fname != NULL) { if (fm->fname != NULL) {
// First expand "~/" in the file name to the home directory. // First expand "~/" in the file name to the home directory.
// Don't expand the whole name, it may contain other '~' chars. // Don't expand the whole name, it may contain other '~' chars.
if (fm->fname[0] == '~' && (fm->fname[1] == '/'
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
|| fm->fname[1] == '\\' if (fm->fname[0] == '~' && (fm->fname[1] == '/' || fm->fname[1] == '\\')) {
#else
if (fm->fname[0] == '~' && (fm->fname[1] == '/')) {
#endif #endif
)) {
int len;
expand_env("~/", NameBuff, MAXPATHL); expand_env("~/", NameBuff, MAXPATHL);
len = (int)strlen(NameBuff); int len = (int)strlen(NameBuff);
STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len); STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len);
} else { } else {
STRLCPY(NameBuff, fm->fname, MAXPATHL); STRLCPY(NameBuff, fm->fname, MAXPATHL);
@ -666,10 +663,10 @@ static void fname2fnum(xfmark_T *fm)
// Try to shorten the file name. // Try to shorten the file name.
os_dirname((char_u *)IObuff, IOSIZE); os_dirname((char_u *)IObuff, IOSIZE);
p = (char_u *)path_shorten_fname(NameBuff, (char *)IObuff); char *p = path_shorten_fname(NameBuff, IObuff);
// buflist_new() will call fmarks_check_names() // buflist_new() will call fmarks_check_names()
(void)buflist_new((char *)NameBuff, (char *)p, (linenr_T)1, 0); (void)buflist_new(NameBuff, p, (linenr_T)1, 0);
} }
} }
@ -935,8 +932,8 @@ void ex_delmarks(exarg_T *eap)
from = *p; from = *p;
to = p[2]; to = p[2];
if (!(lower ? ASCII_ISLOWER(p[2]) if (!(lower ? ASCII_ISLOWER(p[2])
: (digit ? ascii_isdigit(p[2]) : (digit ? ascii_isdigit(p[2])
: ASCII_ISUPPER(p[2]))) : ASCII_ISUPPER(p[2])))
|| to < from) { || to < from) {
semsg(_(e_invarg2), p); semsg(_(e_invarg2), p);
return; return;
@ -1056,12 +1053,11 @@ void ex_changes(exarg_T *eap)
if (got_int) { if (got_int) {
break; break;
} }
sprintf((char *)IObuff, "%c %3d %5ld %4d ", snprintf(IObuff, IOSIZE, "%c %3d %5ld %4d ",
i == curwin->w_changelistidx ? '>' : ' ', i == curwin->w_changelistidx ? '>' : ' ',
i > curwin->w_changelistidx ? i - curwin->w_changelistidx i > curwin->w_changelistidx ? i - curwin->w_changelistidx : curwin->w_changelistidx - i,
: curwin->w_changelistidx - i, (long)curbuf->b_changelist[i].mark.lnum,
(long)curbuf->b_changelist[i].mark.lnum, curbuf->b_changelist[i].mark.col);
curbuf->b_changelist[i].mark.col);
msg_outtrans((char *)IObuff); msg_outtrans((char *)IObuff);
name = (char_u *)mark_line(&curbuf->b_changelist[i].mark, 17); name = (char_u *)mark_line(&curbuf->b_changelist[i].mark, 17);
msg_outtrans_attr((char *)name, HL_ATTR(HLF_D)); msg_outtrans_attr((char *)name, HL_ATTR(HLF_D));
@ -1077,30 +1073,30 @@ void ex_changes(exarg_T *eap)
#define ONE_ADJUST(add) \ #define ONE_ADJUST(add) \
{ \ { \
lp = add; \ lp = add; \
if (*lp >= line1 && *lp <= line2) \ if (*lp >= line1 && *lp <= line2) { \
{ \ if (amount == MAXLNUM) { \
if (amount == MAXLNUM) \ *lp = 0; \
*lp = 0; \ } else { \
else \ *lp += amount; \
*lp += amount; \ } \
} else if (amount_after && *lp > line2) { \
*lp += amount_after; \
} \ } \
else if (amount_after && *lp > line2) \
*lp += amount_after; \
} }
// don't delete the line, just put at first deleted line // don't delete the line, just put at first deleted line
#define ONE_ADJUST_NODEL(add) \ #define ONE_ADJUST_NODEL(add) \
{ \ { \
lp = add; \ lp = add; \
if (*lp >= line1 && *lp <= line2) \ if (*lp >= line1 && *lp <= line2) { \
{ \ if (amount == MAXLNUM) { \
if (amount == MAXLNUM) \ *lp = line1; \
*lp = line1; \ } else { \
else \ *lp += amount; \
*lp += amount; \ } \
} else if (amount_after && *lp > line2) { \
*lp += amount_after; \
} \ } \
else if (amount_after && *lp > line2) \
*lp += amount_after; \
} }
// Adjust marks between line1 and line2 (inclusive) to move 'amount' lines. // Adjust marks between line1 and line2 (inclusive) to move 'amount' lines.
@ -1282,8 +1278,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, linenr_T amount
#define COL_ADJUST(pp) \ #define COL_ADJUST(pp) \
{ \ { \
posp = pp; \ posp = pp; \
if (posp->lnum == lnum && posp->col >= mincol) \ if (posp->lnum == lnum && posp->col >= mincol) { \
{ \
posp->lnum += lnum_amount; \ posp->lnum += lnum_amount; \
assert(col_amount > INT_MIN && col_amount <= INT_MAX); \ assert(col_amount > INT_MIN && col_amount <= INT_MAX); \
if (col_amount < 0 && posp->col <= (colnr_T) - col_amount) { \ if (col_amount < 0 && posp->col <= (colnr_T) - col_amount) { \
@ -1479,10 +1474,8 @@ const void *mark_jumplist_iter(const void *const iter, const win_T *const win, x
*fm = (xfmark_T)INIT_XFMARK; *fm = (xfmark_T)INIT_XFMARK;
return NULL; return NULL;
} }
const xfmark_T *const iter_mark = const xfmark_T *const iter_mark = iter == NULL ? &(win->w_jumplist[0])
(iter == NULL : (const xfmark_T *const)iter;
? &(win->w_jumplist[0])
: (const xfmark_T *const)iter);
*fm = *iter_mark; *fm = *iter_mark;
if (iter_mark == &(win->w_jumplist[win->w_jumplistlen - 1])) { if (iter_mark == &(win->w_jumplist[win->w_jumplistlen - 1])) {
return NULL; return NULL;
@ -1518,9 +1511,9 @@ const void *mark_global_iter(const void *const iter, char *const name, xfmark_T
return NULL; return NULL;
} }
size_t iter_off = (size_t)(iter_mark - &(namedfm[0])); size_t iter_off = (size_t)(iter_mark - &(namedfm[0]));
*name = (char)(iter_off < NMARKS *name = (char)(iter_off < NMARKS ?
? 'A' + (char)iter_off 'A' + (char)iter_off :
: '0' + (char)(iter_off - NMARKS)); '0' + (char)(iter_off - NMARKS));
*fm = *iter_mark; *fm = *iter_mark;
while ((size_t)(++iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)) { while ((size_t)(++iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)) {
if (iter_mark->fmark.mark.lnum) { if (iter_mark->fmark.mark.lnum) {
@ -1582,16 +1575,11 @@ const void *mark_buffer_iter(const void *const iter, const buf_T *const buf, cha
FUNC_ATTR_NONNULL_ARG(2, 3, 4) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(2, 3, 4) FUNC_ATTR_WARN_UNUSED_RESULT
{ {
*name = NUL; *name = NUL;
char mark_name = (char)(iter == NULL char mark_name = (char)(iter == NULL ? NUL :
? NUL iter == &(buf->b_last_cursor) ? '"' :
: (iter == &(buf->b_last_cursor) iter == &(buf->b_last_insert) ? '^' :
? '"' iter == &(buf->b_last_change) ? '.' :
: (iter == &(buf->b_last_insert) 'a' + (char)((const fmark_T *)iter - &(buf->b_namedm[0])));
? '^'
: (iter == &(buf->b_last_change)
? '.'
: 'a' + (char)((const fmark_T *)iter
- &(buf->b_namedm[0]))))));
const fmark_T *iter_mark = next_buffer_mark(buf, &mark_name); const fmark_T *iter_mark = next_buffer_mark(buf, &mark_name);
while (iter_mark != NULL && iter_mark->mark.lnum == 0) { while (iter_mark != NULL && iter_mark->mark.lnum == 0) {
iter_mark = next_buffer_mark(buf, &mark_name); iter_mark = next_buffer_mark(buf, &mark_name);