aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/mark.c')
-rw-r--r--src/nvim/mark.c526
1 files changed, 276 insertions, 250 deletions
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 0b14089550..b296bf39cf 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -7,35 +7,35 @@
#include <assert.h>
#include <inttypes.h>
-#include <string.h>
#include <limits.h>
+#include <string.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/mark.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/diff.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
+#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
-#include "nvim/extmark.h"
+#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/normal.h"
#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
+#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/search.h"
#include "nvim/sign.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
-#include "nvim/os/os.h"
-#include "nvim/os/time.h"
-#include "nvim/os/input.h"
+#include "nvim/vim.h"
/*
* This file contains routines to maintain and manipulate marks.
@@ -94,17 +94,19 @@ int setmark_pos(int c, pos_T *pos, int fnum)
{
int i;
- /* Check for a special key (may cause islower() to crash). */
- if (c < 0)
+ // Check for a special key (may cause islower() to crash).
+ if (c < 0) {
return FAIL;
+ }
if (c == '\'' || c == '`') {
if (pos == &curwin->w_cursor) {
setpcmark();
- /* keep it even when the cursor doesn't move */
+ // keep it even when the cursor doesn't move
curwin->w_prev_pcmark = curwin->w_pcmark;
- } else
+ } else {
curwin->w_pcmark = *pos;
+ }
return OK;
}
@@ -166,11 +168,12 @@ int setmark_pos(int c, pos_T *pos, int fnum)
*/
void setpcmark(void)
{
- xfmark_T *fm;
+ xfmark_T *fm;
- /* for :global the mark is set only once */
- if (global_busy || listcmd_busy || cmdmod.keepjumps)
+ // for :global the mark is set only once
+ if (global_busy || listcmd_busy || cmdmod.keepjumps) {
return;
+ }
curwin->w_prev_pcmark = curwin->w_pcmark;
curwin->w_pcmark = curwin->w_cursor;
@@ -189,7 +192,7 @@ void setpcmark(void)
}
}
- /* If jumplist is full: remove oldest entry */
+ // If jumplist is full: remove oldest entry
if (++curwin->w_jumplistlen > JUMPLISTSIZE) {
curwin->w_jumplistlen = JUMPLISTSIZE;
free_xfmark(curwin->w_jumplist[0]);
@@ -214,7 +217,7 @@ void checkpcmark(void)
&& (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 */
+ curwin->w_prev_pcmark.lnum = 0; // Show it has been checked
}
}
@@ -223,18 +226,20 @@ void checkpcmark(void)
*/
pos_T *movemark(int count)
{
- pos_T *pos;
- xfmark_T *jmp;
+ pos_T *pos;
+ xfmark_T *jmp;
cleanup_jumplist(curwin, true);
- if (curwin->w_jumplistlen == 0) /* nothing to jump to */
+ if (curwin->w_jumplistlen == 0) { // nothing to jump to
return (pos_T *)NULL;
+ }
for (;; ) {
if (curwin->w_jumplistidx + count < 0
- || curwin->w_jumplistidx + count >= curwin->w_jumplistlen)
+ || curwin->w_jumplistidx + count >= curwin->w_jumplistlen) {
return (pos_T *)NULL;
+ }
/*
* if first CTRL-O or CTRL-I command after a jump, add cursor position
@@ -243,30 +248,34 @@ pos_T *movemark(int count)
*/
if (curwin->w_jumplistidx == curwin->w_jumplistlen) {
setpcmark();
- --curwin->w_jumplistidx; /* skip the new entry */
- if (curwin->w_jumplistidx + count < 0)
+ --curwin->w_jumplistidx; // skip the new entry
+ if (curwin->w_jumplistidx + count < 0) {
return (pos_T *)NULL;
+ }
}
curwin->w_jumplistidx += count;
jmp = curwin->w_jumplist + curwin->w_jumplistidx;
- if (jmp->fmark.fnum == 0)
+ if (jmp->fmark.fnum == 0) {
fname2fnum(jmp);
+ }
if (jmp->fmark.fnum != curbuf->b_fnum) {
- /* jump to other file */
- if (buflist_findnr(jmp->fmark.fnum) == NULL) { /* Skip this one .. */
+ // jump to other file
+ if (buflist_findnr(jmp->fmark.fnum) == NULL) { // Skip this one ..
count += count < 0 ? -1 : 1;
continue;
}
if (buflist_getfile(jmp->fmark.fnum, jmp->fmark.mark.lnum,
- 0, FALSE) == FAIL)
+ 0, FALSE) == FAIL) {
return (pos_T *)NULL;
- /* Set lnum again, autocommands my have changed it */
+ }
+ // Set lnum again, autocommands my have changed it
curwin->w_cursor = jmp->fmark.mark;
pos = (pos_T *)-1;
- } else
+ } else {
pos = &(jmp->fmark.mark);
+ }
return pos;
}
}
@@ -278,20 +287,24 @@ pos_T *movechangelist(int count)
{
int n;
- if (curbuf->b_changelistlen == 0) /* nothing to jump to */
+ if (curbuf->b_changelistlen == 0) { // nothing to jump to
return (pos_T *)NULL;
+ }
n = curwin->w_changelistidx;
if (n + count < 0) {
- if (n == 0)
+ if (n == 0) {
return (pos_T *)NULL;
+ }
n = 0;
} else if (n + count >= curbuf->b_changelistlen) {
- if (n == curbuf->b_changelistlen - 1)
+ if (n == curbuf->b_changelistlen - 1) {
return (pos_T *)NULL;
+ }
n = curbuf->b_changelistlen - 1;
- } else
+ } else {
n += count;
+ }
curwin->w_changelistidx = n;
return &(curbuf->b_changelist[n].mark);
}
@@ -319,16 +332,17 @@ pos_T *getmark(int c, bool changefile)
pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
{
- pos_T *posp;
- pos_T *startp, *endp;
+ pos_T *posp;
+ pos_T *startp, *endp;
static pos_T pos_copy;
posp = NULL;
/* Check for special key, can't be a mark name and might cause islower()
* to crash. */
- if (c < 0)
+ if (c < 0) {
return posp;
+ }
if (c > '~') { // check for islower()/isupper()
} else if (c == '\'' || c == '`') { // previous context mark
pos_copy = curwin->w_pcmark; // need to make a copy because
@@ -351,13 +365,13 @@ pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
pos = curwin->w_cursor;
listcmd_busy = true; // avoid that '' is changed
if (findpar(&oa.inclusive,
- c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE)) {
+ c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE)) {
pos_copy = curwin->w_cursor;
posp = &pos_copy;
}
curwin->w_cursor = pos;
listcmd_busy = slcb;
- } else if (c == '(' || c == ')') { /* to previous/next sentence */
+ } else if (c == '(' || c == ')') { // to previous/next sentence
pos_T pos;
bool slcb = listcmd_busy;
@@ -369,7 +383,7 @@ pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
}
curwin->w_cursor = pos;
listcmd_busy = slcb;
- } else if (c == '<' || c == '>') { /* start/end of visual area */
+ } else if (c == '<' || c == '>') { // start/end of visual area
startp = &buf->b_visual.vi_start;
endp = &buf->b_visual.vi_end;
if (((c == '<') == lt(*startp, *endp) || endp->lnum == 0)
@@ -383,63 +397,62 @@ pos_T *getmark_buf_fnum(buf_T *buf, int c, bool changefile, int *fnum)
if (buf->b_visual.vi_mode == 'V') {
pos_copy = *posp;
posp = &pos_copy;
- if (c == '<')
+ if (c == '<') {
pos_copy.col = 0;
- else
+ } else {
pos_copy.col = MAXCOL;
+ }
pos_copy.coladd = 0;
}
- } else if (ASCII_ISLOWER(c)) { /* normal named mark */
+ } else if (ASCII_ISLOWER(c)) { // normal named mark
posp = &(buf->b_namedm[c - 'a'].mark);
- } else if (ASCII_ISUPPER(c) || ascii_isdigit(c)) { /* named file mark */
- if (ascii_isdigit(c))
+ } else if (ASCII_ISUPPER(c) || ascii_isdigit(c)) { // named file mark
+ if (ascii_isdigit(c)) {
c = c - '0' + NMARKS;
- else
+ } else {
c -= 'A';
+ }
posp = &(namedfm[c].fmark.mark);
if (namedfm[c].fmark.fnum == 0) {
fname2fnum(&namedfm[c]);
}
- if (fnum != NULL)
+ if (fnum != NULL) {
*fnum = namedfm[c].fmark.fnum;
- else if (namedfm[c].fmark.fnum != buf->b_fnum) {
- /* mark is in another file */
+ } else if (namedfm[c].fmark.fnum != buf->b_fnum) {
+ // mark is in another file
posp = &pos_copy;
if (namedfm[c].fmark.mark.lnum != 0
&& changefile && namedfm[c].fmark.fnum) {
if (buflist_getfile(namedfm[c].fmark.fnum,
- (linenr_T)1, GETF_SETMARK, FALSE) == OK) {
- /* Set the lnum now, autocommands could have changed it */
+ (linenr_T)1, GETF_SETMARK, FALSE) == OK) {
+ // Set the lnum now, autocommands could have changed it
curwin->w_cursor = namedfm[c].fmark.mark;
return (pos_T *)-1;
}
- pos_copy.lnum = -1; /* can't get file */
- } else
+ pos_copy.lnum = -1; // can't get file
+ } else {
pos_copy.lnum = 0; /* mark exists, but is not valid in
current buffer */
+ }
}
}
return posp;
}
-/*
- * Search for the next named mark in the current file.
- *
- * Returns pointer to pos_T of the next mark or NULL if no mark is found.
- */
-pos_T *
-getnextmark (
- pos_T *startpos, /* where to start */
- int dir, /* direction for search */
- int begin_line
-)
+/// Search for the next named mark in the current file.
+///
+/// @param startpos where to start
+/// @param dir direction for search
+///
+/// @return pointer to pos_T of the next mark or NULL if no mark is found.
+pos_T *getnextmark(pos_T *startpos, int dir, int begin_line)
{
int i;
- pos_T *result = NULL;
+ pos_T *result = NULL;
pos_T pos;
pos = *startpos;
@@ -448,21 +461,24 @@ getnextmark (
* position must be in a previous line.
* When searching forward and leaving the cursor on the first non-blank,
* position must be in a next line. */
- if (dir == BACKWARD && begin_line)
+ if (dir == BACKWARD && begin_line) {
pos.col = 0;
- else if (dir == FORWARD && begin_line)
+ } else if (dir == FORWARD && begin_line) {
pos.col = MAXCOL;
+ }
for (i = 0; i < NMARKS; i++) {
if (curbuf->b_namedm[i].mark.lnum > 0) {
if (dir == FORWARD) {
if ((result == NULL || lt(curbuf->b_namedm[i].mark, *result))
- && lt(pos, curbuf->b_namedm[i].mark))
+ && lt(pos, curbuf->b_namedm[i].mark)) {
result = &curbuf->b_namedm[i].mark;
+ }
} else {
if ((result == NULL || lt(*result, curbuf->b_namedm[i].mark))
- && lt(curbuf->b_namedm[i].mark, pos))
+ && lt(curbuf->b_namedm[i].mark, pos)) {
result = &curbuf->b_namedm[i].mark;
+ }
}
}
}
@@ -494,10 +510,11 @@ static void fname2fnum(xfmark_T *fm)
expand_env((char_u *)"~/", NameBuff, MAXPATHL);
len = (int)STRLEN(NameBuff);
STRLCPY(NameBuff + len, fm->fname + 2, MAXPATHL - len);
- } else
+ } else {
STRLCPY(NameBuff, fm->fname, MAXPATHL);
+ }
- /* Try to shorten the file name. */
+ // Try to shorten the file name.
os_dirname(IObuff, IOSIZE);
p = path_shorten_fname(NameBuff, IObuff);
@@ -513,14 +530,16 @@ static void fname2fnum(xfmark_T *fm)
*/
void fmarks_check_names(buf_T *buf)
{
- char_u *name = buf->b_ffname;
+ char_u *name = buf->b_ffname;
int i;
- if (buf->b_ffname == NULL)
+ if (buf->b_ffname == NULL) {
return;
+ }
- for (i = 0; i < NGLOBALMARKS; ++i)
+ for (i = 0; i < NGLOBALMARKS; ++i) {
fmarks_check_one(&namedfm[i], name, buf);
+ }
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
for (i = 0; i < wp->w_jumplistlen; ++i) {
@@ -552,8 +571,9 @@ int check_mark(pos_T *pos)
if (pos->lnum <= 0) {
/* lnum is negative if mark is in another file can can't get that
* file, error message already give then. */
- if (pos->lnum == 0)
+ if (pos->lnum == 0) {
EMSG(_(e_marknotset));
+ }
return FAIL;
}
if (pos->lnum > curbuf->b_ml.ml_line_count) {
@@ -593,8 +613,9 @@ void clrallmarks(buf_T *const buf)
*/
char_u *fm_getname(fmark_T *fmark, int lead_len)
{
- if (fmark->fnum == curbuf->b_fnum) /* current buffer */
+ if (fmark->fnum == curbuf->b_fnum) { // current buffer
return mark_line(&(fmark->mark), lead_len);
+ }
return buflist_nr2name(fmark->fnum, FALSE, TRUE);
}
@@ -604,11 +625,12 @@ char_u *fm_getname(fmark_T *fmark, int lead_len)
*/
static char_u *mark_line(pos_T *mp, int lead_len)
{
- char_u *s, *p;
+ char_u *s, *p;
int len;
- if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
+ if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) {
return vim_strsave((char_u *)"-invalid-");
+ }
assert(Columns >= 0 && (size_t)Columns <= SIZE_MAX);
// Allow for up to 5 bytes per character.
s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (size_t)Columns * 5);
@@ -617,8 +639,9 @@ static char_u *mark_line(pos_T *mp, int lead_len)
len = 0;
for (p = s; *p != NUL; MB_PTR_ADV(p)) {
len += ptr2cells(p);
- if (len >= Columns - lead_len)
+ if (len >= Columns - lead_len) {
break;
+ }
}
*p = NUL;
return s;
@@ -629,28 +652,32 @@ static char_u *mark_line(pos_T *mp, int lead_len)
*/
void ex_marks(exarg_T *eap)
{
- char_u *arg = eap->arg;
+ char_u *arg = eap->arg;
int i;
- char_u *name;
- pos_T *posp, *startp, *endp;
+ char_u *name;
+ pos_T *posp, *startp, *endp;
- if (arg != NULL && *arg == NUL)
+ if (arg != NULL && *arg == NUL) {
arg = NULL;
+ }
show_one_mark('\'', arg, &curwin->w_pcmark, NULL, true);
- for (i = 0; i < NMARKS; ++i)
+ for (i = 0; i < NMARKS; ++i) {
show_one_mark(i + 'a', arg, &curbuf->b_namedm[i].mark, NULL, true);
+ }
for (i = 0; i < NGLOBALMARKS; ++i) {
- if (namedfm[i].fmark.fnum != 0)
+ if (namedfm[i].fmark.fnum != 0) {
name = fm_getname(&namedfm[i].fmark, 15);
- else
+ } else {
name = namedfm[i].fname;
+ }
if (name != NULL) {
show_one_mark(i >= NMARKS ? i - NMARKS + '0' : i + 'A',
- arg, &namedfm[i].fmark.mark, name,
- namedfm[i].fmark.fnum == curbuf->b_fnum);
- if (namedfm[i].fmark.fnum != 0)
+ arg, &namedfm[i].fmark.mark, name,
+ namedfm[i].fmark.fnum == curbuf->b_fnum);
+ if (namedfm[i].fmark.fnum != 0) {
xfree(name);
+ }
}
}
show_one_mark('"', arg, &curbuf->b_last_cursor.mark, NULL, true);
@@ -673,14 +700,8 @@ void ex_marks(exarg_T *eap)
show_one_mark(-1, arg, NULL, NULL, false);
}
-static void
-show_one_mark(
- int c,
- char_u *arg,
- pos_T *p,
- char_u *name_arg,
- int current // in current file
-)
+/// @param current in current file
+static void show_one_mark(int c, char_u *arg, pos_T *p, char_u *name_arg, int current)
{
static bool did_title = false;
bool mustfree = false;
@@ -731,41 +752,42 @@ show_one_mark(
*/
void ex_delmarks(exarg_T *eap)
{
- char_u *p;
+ char_u *p;
int from, to;
int i;
int lower;
int digit;
int n;
- if (*eap->arg == NUL && eap->forceit)
- /* clear all marks */
+ if (*eap->arg == NUL && eap->forceit) {
+ // clear all marks
clrallmarks(curbuf);
- else if (eap->forceit)
+ } else if (eap->forceit) {
EMSG(_(e_invarg));
- else if (*eap->arg == NUL)
+ } else if (*eap->arg == NUL) {
EMSG(_(e_argreq));
- else {
- /* clear specified marks only */
+ } else {
+ // clear specified marks only
for (p = eap->arg; *p != NUL; ++p) {
lower = ASCII_ISLOWER(*p);
digit = ascii_isdigit(*p);
if (lower || digit || ASCII_ISUPPER(*p)) {
if (p[1] == '-') {
- /* clear range of marks */
+ // clear range of marks
from = *p;
to = p[2];
if (!(lower ? ASCII_ISLOWER(p[2])
- : (digit ? ascii_isdigit(p[2])
- : ASCII_ISUPPER(p[2])))
+ : (digit ? ascii_isdigit(p[2])
+ : ASCII_ISUPPER(p[2])))
|| to < from) {
EMSG2(_(e_invarg2), p);
return;
}
p += 2;
- } else
- /* clear one lower case mark */
+ } else {
+ // clear one lower case mark
from = to = *p;
+ }
for (i = from; i <= to; ++i) {
if (lower) {
@@ -781,19 +803,29 @@ void ex_delmarks(exarg_T *eap)
XFREE_CLEAR(namedfm[n].fname);
}
}
- } else
+ } else {
switch (*p) {
- case '"': CLEAR_FMARK(&curbuf->b_last_cursor); break;
- case '^': CLEAR_FMARK(&curbuf->b_last_insert); break;
- case '.': CLEAR_FMARK(&curbuf->b_last_change); break;
- case '[': curbuf->b_op_start.lnum = 0; break;
- case ']': curbuf->b_op_end.lnum = 0; break;
- case '<': curbuf->b_visual.vi_start.lnum = 0; break;
- case '>': curbuf->b_visual.vi_end.lnum = 0; break;
- case ' ': break;
- default: EMSG2(_(e_invarg2), p);
+ case '"':
+ CLEAR_FMARK(&curbuf->b_last_cursor); break;
+ case '^':
+ CLEAR_FMARK(&curbuf->b_last_insert); break;
+ case '.':
+ CLEAR_FMARK(&curbuf->b_last_change); break;
+ case '[':
+ curbuf->b_op_start.lnum = 0; break;
+ case ']':
+ curbuf->b_op_end.lnum = 0; break;
+ case '<':
+ curbuf->b_visual.vi_start.lnum = 0; break;
+ case '>':
+ curbuf->b_visual.vi_end.lnum = 0; break;
+ case ' ':
+ break;
+ default:
+ EMSG2(_(e_invarg2), p);
return;
}
+ }
}
}
}
@@ -804,7 +836,7 @@ void ex_delmarks(exarg_T *eap)
void ex_jumps(exarg_T *eap)
{
int i;
- char_u *name;
+ char_u *name;
cleanup_jumplist(curwin, true);
// Highlight title
@@ -825,11 +857,11 @@ void ex_jumps(exarg_T *eap)
break;
}
sprintf((char *)IObuff, "%c %2d %5ld %4d ",
- i == curwin->w_jumplistidx ? '>' : ' ',
- i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx
- : curwin->w_jumplistidx - i,
- curwin->w_jumplist[i].fmark.mark.lnum,
- curwin->w_jumplist[i].fmark.mark.col);
+ i == curwin->w_jumplistidx ? '>' : ' ',
+ i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx
+ : curwin->w_jumplistidx - i,
+ curwin->w_jumplist[i].fmark.mark.lnum,
+ curwin->w_jumplist[i].fmark.mark.col);
msg_outtrans(IObuff);
msg_outtrans_attr(name,
curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
@@ -839,8 +871,9 @@ void ex_jumps(exarg_T *eap)
}
ui_flush();
}
- if (curwin->w_jumplistidx == curwin->w_jumplistlen)
+ if (curwin->w_jumplistidx == curwin->w_jumplistlen) {
MSG_PUTS("\n>");
+ }
}
void ex_clearjumps(exarg_T *eap)
@@ -856,7 +889,7 @@ void ex_clearjumps(exarg_T *eap)
void ex_changes(exarg_T *eap)
{
int i;
- char_u *name;
+ char_u *name;
// Highlight title
MSG_PUTS_TITLE(_("\nchange line col text"));
@@ -864,14 +897,15 @@ void ex_changes(exarg_T *eap)
for (i = 0; i < curbuf->b_changelistlen && !got_int; ++i) {
if (curbuf->b_changelist[i].mark.lnum != 0) {
msg_putchar('\n');
- if (got_int)
+ if (got_int) {
break;
+ }
sprintf((char *)IObuff, "%c %3d %5ld %4d ",
- i == curwin->w_changelistidx ? '>' : ' ',
- i > curwin->w_changelistidx ? i - curwin->w_changelistidx
- : curwin->w_changelistidx - i,
- (long)curbuf->b_changelist[i].mark.lnum,
- curbuf->b_changelist[i].mark.col);
+ i == curwin->w_changelistidx ? '>' : ' ',
+ i > curwin->w_changelistidx ? i - curwin->w_changelistidx
+ : curwin->w_changelistidx - i,
+ (long)curbuf->b_changelist[i].mark.lnum,
+ curbuf->b_changelist[i].mark.col);
msg_outtrans(IObuff);
name = mark_line(&curbuf->b_changelist[i].mark, 17);
msg_outtrans_attr(name, HL_ATTR(HLF_D));
@@ -880,8 +914,9 @@ void ex_changes(exarg_T *eap)
}
ui_flush();
}
- if (curwin->w_changelistidx == curbuf->b_changelistlen)
+ if (curwin->w_changelistidx == curbuf->b_changelistlen) {
MSG_PUTS("\n>");
+ }
}
#define one_adjust(add) \
@@ -890,27 +925,27 @@ void ex_changes(exarg_T *eap)
if (*lp >= line1 && *lp <= line2) \
{ \
if (amount == MAXLNUM) \
- *lp = 0; \
+ *lp = 0; \
else \
- *lp += amount; \
+ *lp += amount; \
} \
else if (amount_after && *lp > line2) \
- *lp += amount_after; \
+ *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) \
{ \
lp = add; \
if (*lp >= line1 && *lp <= line2) \
{ \
if (amount == MAXLNUM) \
- *lp = line1; \
+ *lp = line1; \
else \
- *lp += amount; \
+ *lp += amount; \
} \
else if (amount_after && *lp > line2) \
- *lp += amount_after; \
+ *lp += amount_after; \
}
/*
@@ -922,13 +957,9 @@ void ex_changes(exarg_T *eap)
* 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);
+ * or: mark_adjust(56, 55, MAXLNUM, 2);
*/
-void mark_adjust(linenr_T line1,
- linenr_T line2,
- long amount,
- long amount_after,
- ExtmarkOp op)
+void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after, ExtmarkOp op)
{
mark_adjust_internal(line1, line2, amount, amount_after, true, op);
}
@@ -938,54 +969,56 @@ void mark_adjust(linenr_T line1,
// This is only useful when folds need to be moved in a way different to
// calling foldMarkAdjust() with arguments line1, line2, amount, amount_after,
// for an example of why this may be necessary, see do_move().
-void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount,
- long amount_after,
+void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount, long amount_after,
ExtmarkOp op)
{
mark_adjust_internal(line1, line2, amount, amount_after, false, op);
}
-static void mark_adjust_internal(linenr_T line1, linenr_T line2,
- long amount, long amount_after,
- bool adjust_folds,
- ExtmarkOp op)
+static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, long amount_after,
+ bool adjust_folds, ExtmarkOp op)
{
int i;
int fnum = curbuf->b_fnum;
- linenr_T *lp;
+ linenr_T *lp;
static pos_T initpos = { 1, 0, 0 };
- if (line2 < line1 && amount_after == 0L) /* nothing to do */
+ if (line2 < line1 && amount_after == 0L) { // nothing to do
return;
+ }
if (!cmdmod.lockmarks) {
- /* named marks, lower case and upper case */
+ // 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)
+ 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)
+ if (namedfm[i].fmark.fnum == fnum) {
one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
+ }
}
- /* last Insert position */
+ // last Insert position
one_adjust(&(curbuf->b_last_insert.mark.lnum));
- /* last change position */
+ // 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))
+ // 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)
+ // list of change positions
+ for (i = 0; i < curbuf->b_changelistlen; ++i) {
one_adjust_nodel(&(curbuf->b_changelist[i].mark.lnum));
+ }
- /* Visual area */
+ // Visual area
one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum));
one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum));
@@ -1008,15 +1041,16 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
}
}
- /* previous context mark */
+ // previous context mark
one_adjust(&(curwin->w_pcmark.lnum));
- /* previous pcmark */
+ // previous pcmark
one_adjust(&(curwin->w_prev_pcmark.lnum));
- /* saved cursor for formatting */
- if (saved_cursor.lnum != 0)
+ // 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.
@@ -1034,7 +1068,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
if (win->w_buffer == curbuf) {
if (!cmdmod.lockmarks) {
- /* marks in the tag stack */
+ // 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));
@@ -1042,7 +1076,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
}
}
- /* the displayed Visual area */
+ // 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));
@@ -1052,13 +1086,13 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
* other than the current window */
if (win != curwin) {
if (win->w_topline >= line1 && win->w_topline <= line2) {
- if (amount == MAXLNUM) { /* topline is deleted */
+ 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 */
+ } else { // keep topline on the same line
win->w_topline += amount;
}
win->w_topfill = 0;
@@ -1067,14 +1101,14 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
win->w_topfill = 0;
}
if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2) {
- if (amount == MAXLNUM) { /* line with cursor is deleted */
+ 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 */
+ } else { // keep cursor on the same line
win->w_cursor.lnum += amount;
}
} else if (amount_after && win->w_cursor.lnum > line2) {
@@ -1088,11 +1122,11 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
}
}
- /* adjust diffs */
+ // adjust diffs
diff_mark_adjust(line1, line2, amount, amount_after);
}
-/* This code is used often, needs to be fast. */
+// This code is used often, needs to be fast.
#define col_adjust(pp) \
{ \
posp = pp; \
@@ -1115,56 +1149,58 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2,
// position.
// "spaces_removed" is the number of spaces that were removed, matters when the
// cursor is inside them.
-void mark_col_adjust(
- linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount,
- int spaces_removed)
+void mark_col_adjust(linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount,
+ int spaces_removed)
{
int i;
int fnum = curbuf->b_fnum;
- pos_T *posp;
+ pos_T *posp;
- if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks)
- return; /* nothing to do */
-
- /* named marks, lower case and upper case */
+ if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks) {
+ return; // nothing to do
+ }
+ // named marks, lower case and upper case
for (i = 0; i < NMARKS; i++) {
col_adjust(&(curbuf->b_namedm[i].mark));
- if (namedfm[i].fmark.fnum == fnum)
+ if (namedfm[i].fmark.fnum == fnum) {
col_adjust(&(namedfm[i].fmark.mark));
+ }
}
for (i = NMARKS; i < NGLOBALMARKS; i++) {
- if (namedfm[i].fmark.fnum == fnum)
+ if (namedfm[i].fmark.fnum == fnum) {
col_adjust(&(namedfm[i].fmark.mark));
+ }
}
- /* last Insert position */
+ // last Insert position
col_adjust(&(curbuf->b_last_insert.mark));
- /* last change position */
+ // last change position
col_adjust(&(curbuf->b_last_change.mark));
- /* list of change positions */
- for (i = 0; i < curbuf->b_changelistlen; ++i)
+ // list of change positions
+ for (i = 0; i < curbuf->b_changelistlen; ++i) {
col_adjust(&(curbuf->b_changelist[i].mark));
+ }
- /* Visual area */
+ // Visual area
col_adjust(&(curbuf->b_visual.vi_start));
col_adjust(&(curbuf->b_visual.vi_end));
- /* previous context mark */
+ // previous context mark
col_adjust(&(curwin->w_pcmark));
- /* previous pcmark */
+ // previous pcmark
col_adjust(&(curwin->w_prev_pcmark));
- /* saved cursor for formatting */
+ // saved cursor for formatting
col_adjust(&saved_cursor);
/*
* Adjust items in all windows related to the current buffer.
*/
FOR_ALL_WINDOWS_IN_TAB(win, curtab) {
- /* marks in the jumplist */
+ // marks in the jumplist
for (i = 0; i < win->w_jumplistlen; ++i) {
if (win->w_jumplist[i].fmark.fnum == fnum) {
col_adjust(&(win->w_jumplist[i].fmark.mark));
@@ -1172,14 +1208,14 @@ void mark_col_adjust(
}
if (win->w_buffer == curbuf) {
- /* marks in the tag stack */
+ // marks in the tag stack
for (i = 0; i < win->w_tagstacklen; i++) {
if (win->w_tagstack[i].fmark.fnum == fnum) {
col_adjust(&(win->w_tagstack[i].fmark.mark));
}
}
- /* cursor position for other windows with the same buffer */
+ // cursor position for other windows with the same buffer
if (win != curwin) {
col_adjust(&win->w_cursor);
}
@@ -1269,8 +1305,9 @@ void copy_jumplist(win_T *from, win_T *to)
for (i = 0; i < from->w_jumplistlen; ++i) {
to->w_jumplist[i] = from->w_jumplist[i];
- if (from->w_jumplist[i].fname != NULL)
+ if (from->w_jumplist[i].fname != NULL) {
to->w_jumplist[i].fname = vim_strsave(from->w_jumplist[i].fname);
+ }
}
to->w_jumplistlen = from->w_jumplistlen;
to->w_jumplistidx = from->w_jumplistidx;
@@ -1287,18 +1324,17 @@ void copy_jumplist(win_T *from, win_T *to)
///
/// @return Pointer that needs to be passed to next `mark_jumplist_iter` call or
/// NULL if iteration is over.
-const void *mark_jumplist_iter(const void *const iter, const win_T *const win,
- xfmark_T *const fm)
+const void *mark_jumplist_iter(const void *const iter, const win_T *const win, xfmark_T *const fm)
FUNC_ATTR_NONNULL_ARG(2, 3) FUNC_ATTR_WARN_UNUSED_RESULT
{
if (iter == NULL && win->w_jumplistlen == 0) {
- *fm = (xfmark_T) {{{0, 0, 0}, 0, 0, NULL}, NULL};
+ *fm = (xfmark_T) { { { 0, 0, 0 }, 0, 0, NULL }, NULL };
return NULL;
}
const xfmark_T *const iter_mark =
- (iter == NULL
+ (iter == NULL
? &(win->w_jumplist[0])
- : (const xfmark_T *const) iter);
+ : (const xfmark_T *const)iter);
*fm = *iter_mark;
if (iter_mark == &(win->w_jumplist[win->w_jumplistlen - 1])) {
return NULL;
@@ -1318,30 +1354,29 @@ const void *mark_jumplist_iter(const void *const iter, const win_T *const win,
///
/// @return Pointer that needs to be passed to next `mark_global_iter` call or
/// NULL if iteration is over.
-const void *mark_global_iter(const void *const iter, char *const name,
- xfmark_T *const fm)
+const void *mark_global_iter(const void *const iter, char *const name, xfmark_T *const fm)
FUNC_ATTR_NONNULL_ARG(2, 3) FUNC_ATTR_WARN_UNUSED_RESULT
{
*name = NUL;
const xfmark_T *iter_mark = (iter == NULL
? &(namedfm[0])
- : (const xfmark_T *const) iter);
- while ((size_t) (iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)
+ : (const xfmark_T *const)iter);
+ while ((size_t)(iter_mark - &(namedfm[0])) < ARRAY_SIZE(namedfm)
&& !iter_mark->fmark.mark.lnum) {
iter_mark++;
}
- if ((size_t) (iter_mark - &(namedfm[0])) == ARRAY_SIZE(namedfm)
+ if ((size_t)(iter_mark - &(namedfm[0])) == ARRAY_SIZE(namedfm)
|| !iter_mark->fmark.mark.lnum) {
return NULL;
}
- size_t iter_off = (size_t) (iter_mark - &(namedfm[0]));
- *name = (char) (iter_off < NMARKS
- ? 'A' + (char) iter_off
- : '0' + (char) (iter_off - NMARKS));
+ size_t iter_off = (size_t)(iter_mark - &(namedfm[0]));
+ *name = (char)(iter_off < NMARKS
+ ? 'A' + (char)iter_off
+ : '0' + (char)(iter_off - NMARKS));
*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) {
- return (const void *) iter_mark;
+ return (const void *)iter_mark;
}
}
return NULL;
@@ -1358,34 +1393,27 @@ const void *mark_global_iter(const void *const iter, char *const name,
/// behaviour is undefined.
///
/// @return Pointer to the next mark or NULL.
-static inline const fmark_T *next_buffer_mark(const buf_T *const buf,
- char *const mark_name)
+static inline const fmark_T *next_buffer_mark(const buf_T *const buf, char *const mark_name)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
switch (*mark_name) {
- case NUL: {
- *mark_name = '"';
- return &(buf->b_last_cursor);
- }
- case '"': {
- *mark_name = '^';
- return &(buf->b_last_insert);
- }
- case '^': {
- *mark_name = '.';
- return &(buf->b_last_change);
- }
- case '.': {
- *mark_name = 'a';
- return &(buf->b_namedm[0]);
- }
- case 'z': {
- return NULL;
- }
- default: {
- (*mark_name)++;
- return &(buf->b_namedm[*mark_name - 'a']);
- }
+ case NUL:
+ *mark_name = '"';
+ return &(buf->b_last_cursor);
+ case '"':
+ *mark_name = '^';
+ return &(buf->b_last_insert);
+ case '^':
+ *mark_name = '.';
+ return &(buf->b_last_change);
+ case '.':
+ *mark_name = 'a';
+ return &(buf->b_namedm[0]);
+ case 'z':
+ return NULL;
+ default:
+ (*mark_name)++;
+ return &(buf->b_namedm[*mark_name - 'a']);
}
}
@@ -1401,12 +1429,12 @@ static inline const fmark_T *next_buffer_mark(const buf_T *const buf,
///
/// @return Pointer that needs to be passed to next `mark_buffer_iter` call or
/// NULL if iteration is over.
-const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
- char *const name, fmark_T *const fm)
+const void *mark_buffer_iter(const void *const iter, const buf_T *const buf, char *const name,
+ fmark_T *const fm)
FUNC_ATTR_NONNULL_ARG(2, 3, 4) FUNC_ATTR_WARN_UNUSED_RESULT
{
*name = NUL;
- char mark_name = (char) (iter == NULL
+ char mark_name = (char)(iter == NULL
? NUL
: (iter == &(buf->b_last_cursor)
? '"'
@@ -1414,8 +1442,8 @@ const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
? '^'
: (iter == &(buf->b_last_change)
? '.'
- : 'a' + (char) ((const fmark_T *)iter
- - &(buf->b_namedm[0]))))));
+ : 'a' + (char)((const fmark_T *)iter
+ - &(buf->b_namedm[0]))))));
const fmark_T *iter_mark = next_buffer_mark(buf, &mark_name);
while (iter_mark != NULL && iter_mark->mark.lnum == 0) {
iter_mark = next_buffer_mark(buf, &mark_name);
@@ -1423,14 +1451,14 @@ const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
if (iter_mark == NULL) {
return NULL;
}
- size_t iter_off = (size_t) (iter_mark - &(buf->b_namedm[0]));
+ size_t iter_off = (size_t)(iter_mark - &(buf->b_namedm[0]));
if (mark_name) {
*name = mark_name;
} else {
- *name = (char) ('a' + (char) iter_off);
+ *name = (char)('a' + (char)iter_off);
}
*fm = *iter_mark;
- return (const void *) iter_mark;
+ return (const void *)iter_mark;
}
/// Set global mark
@@ -1467,8 +1495,7 @@ bool mark_set_global(const char name, const xfmark_T fm, const bool update)
/// later then existing one.
///
/// @return true on success, false on failure.
-bool mark_set_local(const char name, buf_T *const buf,
- const fmark_T fm, const bool update)
+bool mark_set_local(const char name, buf_T *const buf, const fmark_T fm, const bool update)
FUNC_ATTR_NONNULL_ALL
{
fmark_T *fm_tgt = NULL;
@@ -1556,8 +1583,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp)
// Add information about mark 'mname' to list 'l'
-static int add_mark(list_T *l, const char *mname, const pos_T *pos, int bufnr,
- const char *fname)
+static int add_mark(list_T *l, const char *mname, const pos_T *pos, int bufnr, const char *fname)
FUNC_ATTR_NONNULL_ARG(1, 2, 3)
{
if (pos->lnum <= 0) {