diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2021-10-02 23:41:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-02 14:41:50 -0700 |
commit | 8c74c895b300bcee5fa937a2329d1d4756567b42 (patch) | |
tree | db733caa6606e7850b73d94abe56f91caf6658d2 | |
parent | 09307e64df3fd072d69201629a3b5bf719d42d55 (diff) | |
download | rneovim-8c74c895b300bcee5fa937a2329d1d4756567b42.tar.gz rneovim-8c74c895b300bcee5fa937a2329d1d4756567b42.tar.bz2 rneovim-8c74c895b300bcee5fa937a2329d1d4756567b42.zip |
refactor: format with uncrustify #15872
* refactor: format with uncrustify
* refactor: fix function parameter comments
-rw-r--r-- | src/nvim/tag.c | 1557 | ||||
-rw-r--r-- | src/nvim/ugrid.c | 9 | ||||
-rw-r--r-- | src/nvim/ui.c | 72 | ||||
-rw-r--r-- | src/nvim/ui_bridge.c | 25 | ||||
-rw-r--r-- | src/nvim/ui_compositor.c | 61 | ||||
-rw-r--r-- | src/nvim/undo.c | 626 | ||||
-rw-r--r-- | src/nvim/version.c | 30 | ||||
-rw-r--r-- | src/uncrustify.cfg | 15 |
8 files changed, 1235 insertions, 1160 deletions
diff --git a/src/nvim/tag.c b/src/nvim/tag.c index c63cdad098..2d73954daa 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -10,9 +10,7 @@ #include <stdbool.h> #include <string.h> -#include "nvim/vim.h" #include "nvim/ascii.h" -#include "nvim/tag.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/cursor.h" @@ -22,18 +20,21 @@ #include "nvim/ex_cmds2.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" +#include "nvim/file_search.h" #include "nvim/fileio.h" #include "nvim/fold.h" +#include "nvim/garray.h" #include "nvim/if_cscope.h" #include "nvim/mark.h" #include "nvim/mbyte.h" +#include "nvim/memory.h" #include "nvim/message.h" #include "nvim/misc1.h" -#include "nvim/file_search.h" -#include "nvim/garray.h" -#include "nvim/memory.h" #include "nvim/move.h" #include "nvim/option.h" +#include "nvim/os/input.h" +#include "nvim/os/os.h" +#include "nvim/os/time.h" #include "nvim/os_unix.h" #include "nvim/path.h" #include "nvim/quickfix.h" @@ -41,30 +42,29 @@ #include "nvim/screen.h" #include "nvim/search.h" #include "nvim/strings.h" +#include "nvim/tag.h" #include "nvim/ui.h" +#include "nvim/vim.h" #include "nvim/window.h" -#include "nvim/os/os.h" -#include "nvim/os/time.h" -#include "nvim/os/input.h" /* * Structure to hold pointers to various items in a tag line. */ typedef struct tag_pointers { // filled in by parse_tag_line(): - char_u *tagname; // start of tag name (skip "file:") - char_u *tagname_end; // char after tag name - char_u *fname; // first char of file name - char_u *fname_end; // char after file name - char_u *command; // first char of command + char_u *tagname; // start of tag name (skip "file:") + char_u *tagname_end; // char after tag name + char_u *fname; // first char of file name + char_u *fname_end; // char after file name + char_u *command; // first char of command // filled in by parse_match(): - char_u *command_end; // first char after command - char_u *tag_fname; // file name of the tags file. This is used + char_u *command_end; // first char after command + char_u *tag_fname; // file name of the tags file. This is used // when 'tr' is set. - char_u *tagkind; // "kind:" value - char_u *tagkind_end; // end of tagkind - char_u *user_data; // user_data string - char_u *user_data_end; // end of user_data + char_u *tagkind; // "kind:" value + char_u *tagkind_end; // end of tagkind + char_u *user_data; // user_data string + char_u *user_data_end; // end of user_data linenr_T tagline; // "line:" value } tagptrs_T; @@ -72,11 +72,11 @@ typedef struct tag_pointers { * Structure to hold info about the tag pattern being used. */ typedef struct { - char_u *pat; /* the pattern */ - int len; /* length of pat[] */ - char_u *head; /* start of pattern head */ - int headlen; /* length of head[] */ - regmatch_T regmatch; /* regexp program, may be NULL */ + char_u *pat; // the pattern + int len; // length of pat[] + char_u *head; // start of pattern head + int headlen; // length of head[] + regmatch_T regmatch; // regexp program, may be NULL } pat_T; // The matching tags are first stored in one of the hash tables. In @@ -93,11 +93,11 @@ typedef struct { #define MT_MASK 7 // mask for printing priority #define MT_COUNT 16 -static char *mt_names[MT_COUNT/2] = -{"FSC", "F C", "F ", "FS ", " SC", " C", " ", " S "}; +static char *mt_names[MT_COUNT/2] = +{ "FSC", "F C", "F ", "FS ", " SC", " C", " ", " S " }; -#define NOTAGFILE 99 /* return value for jumpto_tag */ -static char_u *nofile_fname = NULL; /* fname for NOTAGFILE error */ +#define NOTAGFILE 99 // return value for jumpto_tag +static char_u *nofile_fname = NULL; // fname for NOTAGFILE error #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -111,7 +111,7 @@ static char_u *recurmsg static char_u *tfu_inv_ret_msg = (char_u *)N_("E987: invalid return value from tagfunc"); -static char_u *tagmatchname = NULL; /* name of last used tag */ +static char_u *tagmatchname = NULL; // name of last used tag /* * Tag for preview window is remembered separately, to avoid messing up the @@ -124,36 +124,31 @@ static int tfu_in_use = false; // disallow recursive call of tagfunc // Used instead of NUL to separate tag fields in the growarrays. #define TAG_SEP 0x02 -/* - * Jump to tag; handling of tag commands and tag stack - * - * *tag != NUL: ":tag {tag}", jump to new tag, add to tag stack - * - * type == DT_TAG: ":tag [tag]", jump to newer position or same tag again - * type == DT_HELP: like DT_TAG, but don't use regexp. - * type == DT_POP: ":pop" or CTRL-T, jump to old position - * type == DT_NEXT: jump to next match of same tag - * type == DT_PREV: jump to previous match of same tag - * type == DT_FIRST: jump to first match of same tag - * type == DT_LAST: jump to last match of same tag - * type == DT_SELECT: ":tselect [tag]", select tag from a list of all matches - * type == DT_JUMP: ":tjump [tag]", jump to tag or select tag from a list - * type == DT_CSCOPE: use cscope to find the tag - * type == DT_LTAG: use location list for displaying tag matches - * type == DT_FREE: free cached matches - * - * for cscope, returns TRUE if we jumped to tag or aborted, FALSE otherwise - */ -int -do_tag( - char_u *tag, // tag (pattern) to jump to - int type, - int count, - int forceit, // :ta with ! - int verbose // print "tag not found" message -) +/// Jump to tag; handling of tag commands and tag stack +/// +/// *tag != NUL: ":tag {tag}", jump to new tag, add to tag stack +/// +/// type == DT_TAG: ":tag [tag]", jump to newer position or same tag again +/// type == DT_HELP: like DT_TAG, but don't use regexp. +/// type == DT_POP: ":pop" or CTRL-T, jump to old position +/// type == DT_NEXT: jump to next match of same tag +/// type == DT_PREV: jump to previous match of same tag +/// type == DT_FIRST: jump to first match of same tag +/// type == DT_LAST: jump to last match of same tag +/// type == DT_SELECT: ":tselect [tag]", select tag from a list of all matches +/// type == DT_JUMP: ":tjump [tag]", jump to tag or select tag from a list +/// type == DT_CSCOPE: use cscope to find the tag +/// type == DT_LTAG: use location list for displaying tag matches +/// type == DT_FREE: free cached matches +/// +/// for cscope, returns TRUE if we jumped to tag or aborted, FALSE otherwise +/// +/// @param tag tag (pattern) to jump to +/// @param forceit :ta with ! +/// @param verbose print "tag not found" message +int do_tag(char_u *tag, int type, int count, int forceit, int verbose) { - taggy_T *tagstack = curwin->w_tagstack; + taggy_T *tagstack = curwin->w_tagstack; int tagstackidx = curwin->w_tagstackidx; int tagstacklen = curwin->w_tagstacklen; int cur_match = 0; @@ -170,16 +165,16 @@ do_tag( fmark_T saved_fmark; int jumped_to_tag = false; int new_num_matches; - char_u **new_matches; + char_u **new_matches; int use_tagstack; int skip_msg = false; char_u *buf_ffname = curbuf->b_ffname; // name for priority computation int use_tfu = 1; - /* remember the matches for the last used tag */ + // remember the matches for the last used tag static int num_matches = 0; - static int max_num_matches = 0; /* limit used for match search */ - static char_u **matches = NULL; + static int max_num_matches = 0; // limit used for match search + static char_u **matches = NULL; static int flags; if (tfu_in_use) { @@ -189,7 +184,7 @@ do_tag( #ifdef EXITFREE if (type == DT_FREE) { - /* remove the list of matches */ + // remove the list of matches FreeWild(num_matches, matches); cs_free_tags(); num_matches = 0; @@ -207,7 +202,7 @@ do_tag( free_string_option(nofile_fname); nofile_fname = NULL; - clearpos(&saved_fmark.mark); /* shutup gcc 4.0 */ + clearpos(&saved_fmark.mark); // shutup gcc 4.0 saved_fmark.fnum = 0; // Don't add a tag to the tagstack if 'tagstack' has been reset. @@ -226,7 +221,7 @@ do_tag( use_tagstack = true; } - /* new pattern, add to the tag stack */ + // new pattern, add to the tag stack if (*tag != NUL && (type == DT_TAG || type == DT_SELECT || type == DT_JUMP || type == DT_LTAG @@ -252,7 +247,7 @@ do_tag( tagstack_clear_entry(&tagstack[--tagstacklen]); } - /* if the tagstack is full: remove oldest entry */ + // if the tagstack is full: remove oldest entry if (++tagstacklen > TAGSTACKSIZE) { tagstacklen = TAGSTACKSIZE; tagstack_clear_entry(&tagstack[0]); @@ -293,7 +288,7 @@ do_tag( * way to the bottom now. */ tagstackidx = 0; - } else if (tagstackidx >= tagstacklen) { // count == 0? + } else if (tagstackidx >= tagstacklen) { // count == 0? EMSG(_(topmsg)); goto end_do_tag; } @@ -321,8 +316,9 @@ do_tag( curwin->w_cursor.col = saved_fmark.mark.col; curwin->w_set_curswant = true; check_cursor(); - if ((fdo_flags & FDO_TAG) && old_KeyTyped) + if ((fdo_flags & FDO_TAG) && old_KeyTyped) { foldOpenCursor(); + } // remove the old list of matches FreeWild(num_matches, matches); @@ -333,8 +329,7 @@ do_tag( } if (type == DT_TAG - || type == DT_LTAG - ) { + || type == DT_LTAG) { if (g_do_tagpreview != 0) { cur_match = ptag_entry.cur_match; cur_fnum = ptag_entry.cur_fnum; @@ -350,7 +345,7 @@ do_tag( tagstackidx = tagstacklen - 1; EMSG(_(topmsg)); save_pos = false; - } else if (tagstackidx < 0) { // must have been count == 0 + } else if (tagstackidx < 0) { // must have been count == 0 EMSG(_(bottommsg)); tagstackidx = 0; goto end_do_tag; @@ -367,23 +362,28 @@ do_tag( cur_match = ptag_entry.cur_match; cur_fnum = ptag_entry.cur_fnum; } else { - if (--tagstackidx < 0) + if (--tagstackidx < 0) { tagstackidx = 0; + } cur_match = tagstack[tagstackidx].cur_match; cur_fnum = tagstack[tagstackidx].cur_fnum; } switch (type) { - case DT_FIRST: cur_match = count - 1; break; + case DT_FIRST: + cur_match = count - 1; break; case DT_SELECT: case DT_JUMP: case DT_CSCOPE: - case DT_LAST: cur_match = MAXCOL - 1; break; - case DT_NEXT: cur_match += count; break; - case DT_PREV: cur_match -= count; break; + case DT_LAST: + cur_match = MAXCOL - 1; break; + case DT_NEXT: + cur_match += count; break; + case DT_PREV: + cur_match -= count; break; } - if (cur_match >= MAXCOL) + if (cur_match >= MAXCOL) { cur_match = MAXCOL - 1; - else if (cur_match < 0) { + } else if (cur_match < 0) { EMSG(_("E425: Cannot go before first matching tag")); skip_msg = true; cur_match = 0; @@ -424,8 +424,9 @@ do_tag( if (cur_fnum != curbuf->b_fnum) { buf_T *buf = buflist_findnr(cur_fnum); - if (buf != NULL) + if (buf != NULL) { buf_ffname = buf->b_ffname; + } } /* @@ -433,7 +434,7 @@ do_tag( */ for (;; ) { int other_name; - char_u *name; + char_u *name; // When desired match not found yet, try to find it (and others). if (use_tagstack) { @@ -466,8 +467,9 @@ do_tag( if (!no_regexp && *name == '/') { flags = TAG_REGEXP; ++name; - } else + } else { flags = TAG_NOIC; + } if (type == DT_CSCOPE) { flags = TAG_CSCOPE; @@ -490,9 +492,9 @@ do_tag( * to the start. Avoids that the order changes when using * ":tnext" and jumping to another file. */ if (!new_tag && !other_name) { - int j, k; - int idx = 0; - tagptrs_T tagp, tagp2; + int j, k; + int idx = 0; + tagptrs_T tagp, tagp2; // Find the position of each old match in the new list. Need // to use parse_match() to find the tag line. @@ -517,8 +519,9 @@ do_tag( } if (num_matches <= 0) { - if (verbose) + if (verbose) { EMSG2(_("E426: tag not found: %s"), name); + } g_do_tagpreview = 0; } else { bool ask_for_selection = false; @@ -533,7 +536,7 @@ do_tag( } else if (type == DT_SELECT || (type == DT_JUMP && num_matches > 1)) { print_tag_list(new_tag, use_tagstack, num_matches, matches); ask_for_selection = true; - } else if (type == DT_LTAG) { + } else if (type == DT_LTAG) { if (add_llist_tags(tag, num_matches, matches) == FAIL) { goto end_do_tag; } @@ -563,16 +566,17 @@ do_tag( * There will be an EMSG("file doesn't exist") below then. */ if ((type == DT_NEXT || type == DT_FIRST) && nofile_fname == NULL) { - if (num_matches == 1) + if (num_matches == 1) { EMSG(_("E427: There is only one matching tag")); - else + } else { EMSG(_("E428: Cannot go beyond last matching tag")); + } skip_msg = true; } cur_match = num_matches - 1; } if (use_tagstack) { - tagptrs_T tagp2; + tagptrs_T tagp2; tagstack[tagstackidx].cur_match = cur_match; tagstack[tagstackidx].cur_fnum = cur_fnum; @@ -581,12 +585,12 @@ do_tag( if (use_tfu && parse_match(matches[cur_match], &tagp2) == OK && tagp2.user_data) { XFREE_CLEAR(tagstack[tagstackidx].user_data); - tagstack[tagstackidx].user_data = vim_strnsave( - tagp2.user_data, tagp2.user_data_end - tagp2.user_data); + tagstack[tagstackidx].user_data = vim_strnsave(tagp2.user_data, + tagp2.user_data_end - tagp2.user_data); } tagstackidx++; - } else if (g_do_tagpreview != 0) { + } else if (g_do_tagpreview != 0) { ptag_entry.cur_match = cur_match; ptag_entry.cur_fnum = cur_fnum; } @@ -595,8 +599,9 @@ do_tag( * Only when going to try the next match, report that the previous * file didn't exist. Otherwise an EMSG() is given below. */ - if (nofile_fname != NULL && error_cur_match != cur_match) + if (nofile_fname != NULL && error_cur_match != cur_match) { smsg(_("File \"%s\" does not exist"), nofile_fname); + } ic = (matches[cur_match][0] & MT_IC_OFF); @@ -631,7 +636,7 @@ do_tag( // Let the SwapExists event know what tag we are jumping to. vim_snprintf((char *)IObuff, IOSIZE, ":ta %s\r", name); - set_vim_var_string(VV_SWAPCOMMAND, (char *) IObuff, -1); + set_vim_var_string(VV_SWAPCOMMAND, (char *)IObuff, -1); /* * Jump to the desired match. @@ -648,11 +653,12 @@ do_tag( && (max_num_matches != MAXCOL || cur_match < num_matches - 1))) { error_cur_match = cur_match; - if (use_tagstack) + if (use_tagstack) { --tagstackidx; - if (type == DT_PREV) + } + if (type == DT_PREV) { --cur_match; - else { + } else { type = DT_NEXT; ++cur_match; } @@ -662,8 +668,9 @@ do_tag( } else { /* We may have jumped to another window, check that * tagstackidx is still valid. */ - if (use_tagstack && tagstackidx > curwin->w_tagstacklen) + if (use_tagstack && tagstackidx > curwin->w_tagstacklen) { tagstackidx = curwin->w_tagstackidx; + } jumped_to_tag = true; } } @@ -684,331 +691,322 @@ end_do_tag: // // List all the matching tags. // -static void -print_tag_list( - int new_tag, - int use_tagstack, - int num_matches, - char_u **matches) +static void print_tag_list(int new_tag, int use_tagstack, int num_matches, char_u **matches) { - taggy_T *tagstack = curwin->w_tagstack; - int tagstackidx = curwin->w_tagstackidx; - int i; - char_u *p; - char_u *command_end; - tagptrs_T tagp; - int taglen; - int attr; - - // Assume that the first match indicates how long the tags can - // be, and align the file names to that. - parse_match(matches[0], &tagp); - taglen = (int)(tagp.tagname_end - tagp.tagname + 2); - if (taglen < 18) { - taglen = 18; - } - if (taglen > Columns - 25) { - taglen = MAXCOL; - } - if (msg_col == 0) { - msg_didout = false; // overwrite previous message - } - msg_start(); - msg_puts_attr(_(" # pri kind tag"), HL_ATTR(HLF_T)); - msg_clr_eos(); + taggy_T *tagstack = curwin->w_tagstack; + int tagstackidx = curwin->w_tagstackidx; + int i; + char_u *p; + char_u *command_end; + tagptrs_T tagp; + int taglen; + int attr; + + // Assume that the first match indicates how long the tags can + // be, and align the file names to that. + parse_match(matches[0], &tagp); + taglen = (int)(tagp.tagname_end - tagp.tagname + 2); + if (taglen < 18) { + taglen = 18; + } + if (taglen > Columns - 25) { + taglen = MAXCOL; + } + if (msg_col == 0) { + msg_didout = false; // overwrite previous message + } + msg_start(); + msg_puts_attr(_(" # pri kind tag"), HL_ATTR(HLF_T)); + msg_clr_eos(); + taglen_advance(taglen); + msg_puts_attr(_("file\n"), HL_ATTR(HLF_T)); + + for (i = 0; i < num_matches && !got_int; i++) { + parse_match(matches[i], &tagp); + if (!new_tag && ( + (g_do_tagpreview != 0 + && i == ptag_entry.cur_match) + || (use_tagstack + && i == tagstack[tagstackidx].cur_match))) { + *IObuff = '>'; + } else { + *IObuff = ' '; + } + vim_snprintf((char *)IObuff + 1, IOSIZE - 1, + "%2d %s ", i + 1, + mt_names[matches[i][0] & MT_MASK]); + msg_puts((char *)IObuff); + if (tagp.tagkind != NULL) { + msg_outtrans_len(tagp.tagkind, + (int)(tagp.tagkind_end - tagp.tagkind)); + } + msg_advance(13); + msg_outtrans_len_attr(tagp.tagname, + (int)(tagp.tagname_end - tagp.tagname), + HL_ATTR(HLF_T)); + msg_putchar(' '); taglen_advance(taglen); - msg_puts_attr(_("file\n"), HL_ATTR(HLF_T)); - - for (i = 0; i < num_matches && !got_int; i++) { - parse_match(matches[i], &tagp); - if (!new_tag && ( - (g_do_tagpreview != 0 - && i == ptag_entry.cur_match) - || (use_tagstack - && i == tagstack[tagstackidx].cur_match))) { - *IObuff = '>'; - } else { - *IObuff = ' '; + + // Find out the actual file name. If it is long, truncate + // it and put "..." in the middle + p = tag_full_fname(&tagp); + if (p != NULL) { + msg_outtrans_attr(p, HL_ATTR(HLF_D)); + XFREE_CLEAR(p); + } + if (msg_col > 0) { + msg_putchar('\n'); + } + if (got_int) { + break; + } + msg_advance(15); + + // print any extra fields + command_end = tagp.command_end; + if (command_end != NULL) { + p = command_end + 3; + while (*p && *p != '\r' && *p != '\n') { + while (*p == TAB) { + p++; } - vim_snprintf((char *)IObuff + 1, IOSIZE - 1, - "%2d %s ", i + 1, - mt_names[matches[i][0] & MT_MASK]); - msg_puts((char *)IObuff); - if (tagp.tagkind != NULL) { - msg_outtrans_len(tagp.tagkind, - (int)(tagp.tagkind_end - tagp.tagkind)); + + // skip "file:" without a value (static tag) + if (STRNCMP(p, "file:", 5) == 0 && ascii_isspace(p[5])) { + p += 5; + continue; } - msg_advance(13); - msg_outtrans_len_attr(tagp.tagname, - (int)(tagp.tagname_end - tagp.tagname), - HL_ATTR(HLF_T)); - msg_putchar(' '); - taglen_advance(taglen); - - // Find out the actual file name. If it is long, truncate - // it and put "..." in the middle - p = tag_full_fname(&tagp); - if (p != NULL) { - msg_outtrans_attr(p, HL_ATTR(HLF_D)); - XFREE_CLEAR(p); + // skip "kind:<kind>" and "<kind>" + if (p == tagp.tagkind + || (p + 5 == tagp.tagkind + && STRNCMP(p, "kind:", 5) == 0)) { + p = tagp.tagkind_end; + continue; } - if (msg_col > 0) { + // print all other extra fields + attr = HL_ATTR(HLF_CM); + while (*p && *p != '\r' && *p != '\n') { + if (msg_col + ptr2cells(p) >= Columns) { msg_putchar('\n'); + if (got_int) { + break; + } + msg_advance(15); + } + p = msg_outtrans_one(p, attr); + if (*p == TAB) { + msg_puts_attr(" ", attr); + break; + } + if (*p == ':') { + attr = 0; + } } + } + if (msg_col > 15) { + msg_putchar('\n'); if (got_int) { - break; + break; } msg_advance(15); + } + } else { + for (p = tagp.command; + *p && *p != '\r' && *p != '\n'; + p++) { + } + command_end = p; + } - // print any extra fields - command_end = tagp.command_end; - if (command_end != NULL) { - p = command_end + 3; - while (*p && *p != '\r' && *p != '\n') { - while (*p == TAB) { - p++; - } - - // skip "file:" without a value (static tag) - if (STRNCMP(p, "file:", 5) == 0 && ascii_isspace(p[5])) { - p += 5; - continue; - } - // skip "kind:<kind>" and "<kind>" - if (p == tagp.tagkind - || (p + 5 == tagp.tagkind - && STRNCMP(p, "kind:", 5) == 0)) { - p = tagp.tagkind_end; - continue; - } - // print all other extra fields - attr = HL_ATTR(HLF_CM); - while (*p && *p != '\r' && *p != '\n') { - if (msg_col + ptr2cells(p) >= Columns) { - msg_putchar('\n'); - if (got_int) { - break; - } - msg_advance(15); - } - p = msg_outtrans_one(p, attr); - if (*p == TAB) { - msg_puts_attr(" ", attr); - break; - } - if (*p == ':') { - attr = 0; - } - } - } - if (msg_col > 15) { - msg_putchar('\n'); - if (got_int) { - break; - } - msg_advance(15); - } - } else { - for (p = tagp.command; - *p && *p != '\r' && *p != '\n'; - p++) { - } - command_end = p; - } - - // Put the info (in several lines) at column 15. - // Don't display "/^" and "?^". - p = tagp.command; - if (*p == '/' || *p == '?') { - p++; - if (*p == '^') { - p++; - } - } - // Remove leading whitespace from pattern - while (p != command_end && ascii_isspace(*p)) { - p++; - } + // Put the info (in several lines) at column 15. + // Don't display "/^" and "?^". + p = tagp.command; + if (*p == '/' || *p == '?') { + p++; + if (*p == '^') { + p++; + } + } + // Remove leading whitespace from pattern + while (p != command_end && ascii_isspace(*p)) { + p++; + } - while (p != command_end) { - if (msg_col + (*p == TAB ? 1 : ptr2cells(p)) > Columns) { - msg_putchar('\n'); - } - if (got_int) { - break; - } - msg_advance(15); + while (p != command_end) { + if (msg_col + (*p == TAB ? 1 : ptr2cells(p)) > Columns) { + msg_putchar('\n'); + } + if (got_int) { + break; + } + msg_advance(15); - // skip backslash used for escaping a command char or - // a backslash - if (*p == '\\' && (*(p + 1) == *tagp.command - || *(p + 1) == '\\')) { - p++; - } + // skip backslash used for escaping a command char or + // a backslash + if (*p == '\\' && (*(p + 1) == *tagp.command + || *(p + 1) == '\\')) { + p++; + } - if (*p == TAB) { - msg_putchar(' '); - p++; - } else { - p = msg_outtrans_one(p, 0); - } + if (*p == TAB) { + msg_putchar(' '); + p++; + } else { + p = msg_outtrans_one(p, 0); + } - // don't display the "$/;\"" and "$?;\"" - if (p == command_end - 2 && *p == '$' - && *(p + 1) == *tagp.command) { - break; - } - // don't display matching '/' or '?' - if (p == command_end - 1 && *p == *tagp.command - && (*p == '/' || *p == '?')) { - break; - } - } - if (msg_col) { - msg_putchar('\n'); - } - os_breakcheck(); + // don't display the "$/;\"" and "$?;\"" + if (p == command_end - 2 && *p == '$' + && *(p + 1) == *tagp.command) { + break; + } + // don't display matching '/' or '?' + if (p == command_end - 1 && *p == *tagp.command + && (*p == '/' || *p == '?')) { + break; + } } - if (got_int) { - got_int = false; // only stop the listing + if (msg_col) { + msg_putchar('\n'); } + os_breakcheck(); + } + if (got_int) { + got_int = false; // only stop the listing + } } // // Add the matching tags to the location list for the current // window. // -static int -add_llist_tags( - char_u *tag, - int num_matches, - char_u **matches) +static int add_llist_tags(char_u *tag, int num_matches, char_u **matches) { - list_T *list; - char_u tag_name[128 + 1]; - char_u *fname; - char_u *cmd; - int i; - char_u *p; - tagptrs_T tagp; - - fname = xmalloc(MAXPATHL + 1); - cmd = xmalloc(CMDBUFFSIZE + 1); - list = tv_list_alloc(0); - - for (i = 0; i < num_matches; i++) { - int len, cmd_len; - long lnum; - dict_T *dict; - - parse_match(matches[i], &tagp); - - // Save the tag name - len = (int)(tagp.tagname_end - tagp.tagname); - if (len > 128) { - len = 128; - } - xstrlcpy((char *)tag_name, (const char *)tagp.tagname, len + 1); - tag_name[len] = NUL; + list_T *list; + char_u tag_name[128 + 1]; + char_u *fname; + char_u *cmd; + int i; + char_u *p; + tagptrs_T tagp; - // Save the tag file name - p = tag_full_fname(&tagp); - if (p == NULL) { - continue; - } - xstrlcpy((char *)fname, (const char *)p, MAXPATHL); - XFREE_CLEAR(p); - - // Get the line number or the search pattern used to locate - // the tag. - lnum = 0; - if (isdigit(*tagp.command)) { - // Line number is used to locate the tag - lnum = atol((char *)tagp.command); - } else { - char_u *cmd_start, *cmd_end; + fname = xmalloc(MAXPATHL + 1); + cmd = xmalloc(CMDBUFFSIZE + 1); + list = tv_list_alloc(0); - // Search pattern is used to locate the tag + for (i = 0; i < num_matches; i++) { + int len, cmd_len; + long lnum; + dict_T *dict; - // Locate the end of the command - cmd_start = tagp.command; - cmd_end = tagp.command_end; - if (cmd_end == NULL) { - for (p = tagp.command; - *p && *p != '\r' && *p != '\n'; p++) { - } - cmd_end = p; - } + parse_match(matches[i], &tagp); - // Now, cmd_end points to the character after the - // command. Adjust it to point to the last - // character of the command. - cmd_end--; + // Save the tag name + len = (int)(tagp.tagname_end - tagp.tagname); + if (len > 128) { + len = 128; + } + xstrlcpy((char *)tag_name, (const char *)tagp.tagname, len + 1); + tag_name[len] = NUL; - // Skip the '/' and '?' characters at the - // beginning and end of the search pattern. - if (*cmd_start == '/' || *cmd_start == '?') { - cmd_start++; - } + // Save the tag file name + p = tag_full_fname(&tagp); + if (p == NULL) { + continue; + } + xstrlcpy((char *)fname, (const char *)p, MAXPATHL); + XFREE_CLEAR(p); + + // Get the line number or the search pattern used to locate + // the tag. + lnum = 0; + if (isdigit(*tagp.command)) { + // Line number is used to locate the tag + lnum = atol((char *)tagp.command); + } else { + char_u *cmd_start, *cmd_end; - if (*cmd_end == '/' || *cmd_end == '?') { - cmd_end--; - } + // Search pattern is used to locate the tag - len = 0; - cmd[0] = NUL; + // Locate the end of the command + cmd_start = tagp.command; + cmd_end = tagp.command_end; + if (cmd_end == NULL) { + for (p = tagp.command; + *p && *p != '\r' && *p != '\n'; p++) { + } + cmd_end = p; + } - // If "^" is present in the tag search pattern, then - // copy it first. - if (*cmd_start == '^') { - STRCPY(cmd, "^"); - cmd_start++; - len++; - } + // Now, cmd_end points to the character after the + // command. Adjust it to point to the last + // character of the command. + cmd_end--; - // Precede the tag pattern with \V to make it very - // nomagic. - STRCAT(cmd, "\\V"); - len += 2; + // Skip the '/' and '?' characters at the + // beginning and end of the search pattern. + if (*cmd_start == '/' || *cmd_start == '?') { + cmd_start++; + } - cmd_len = (int)(cmd_end - cmd_start + 1); - if (cmd_len > (CMDBUFFSIZE - 5)) { - cmd_len = CMDBUFFSIZE - 5; - } - snprintf((char *)cmd + len, CMDBUFFSIZE + 1 - len, - "%.*s", cmd_len, cmd_start); - len += cmd_len; - - if (cmd[len - 1] == '$') { - // Replace '$' at the end of the search pattern - // with '\$' - cmd[len - 1] = '\\'; - cmd[len] = '$'; - len++; - } + if (*cmd_end == '/' || *cmd_end == '?') { + cmd_end--; + } - cmd[len] = NUL; - } + len = 0; + cmd[0] = NUL; - dict = tv_dict_alloc(); - tv_list_append_dict(list, dict); + // If "^" is present in the tag search pattern, then + // copy it first. + if (*cmd_start == '^') { + STRCPY(cmd, "^"); + cmd_start++; + len++; + } - tv_dict_add_str(dict, S_LEN("text"), (const char *)tag_name); - tv_dict_add_str(dict, S_LEN("filename"), (const char *)fname); - tv_dict_add_nr(dict, S_LEN("lnum"), lnum); - if (lnum == 0) { - tv_dict_add_str(dict, S_LEN("pattern"), (const char *)cmd); - } + // Precede the tag pattern with \V to make it very + // nomagic. + STRCAT(cmd, "\\V"); + len += 2; + + cmd_len = (int)(cmd_end - cmd_start + 1); + if (cmd_len > (CMDBUFFSIZE - 5)) { + cmd_len = CMDBUFFSIZE - 5; + } + snprintf((char *)cmd + len, CMDBUFFSIZE + 1 - len, + "%.*s", cmd_len, cmd_start); + len += cmd_len; + + if (cmd[len - 1] == '$') { + // Replace '$' at the end of the search pattern + // with '\$' + cmd[len - 1] = '\\'; + cmd[len] = '$'; + len++; + } + + cmd[len] = NUL; } - vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag); - set_errorlist(curwin, list, ' ', IObuff, NULL); + dict = tv_dict_alloc(); + tv_list_append_dict(list, dict); - tv_list_free(list); - XFREE_CLEAR(fname); - XFREE_CLEAR(cmd); + tv_dict_add_str(dict, S_LEN("text"), (const char *)tag_name); + tv_dict_add_str(dict, S_LEN("filename"), (const char *)fname); + tv_dict_add_nr(dict, S_LEN("lnum"), lnum); + if (lnum == 0) { + tv_dict_add_str(dict, S_LEN("pattern"), (const char *)cmd); + } + } - return OK; + vim_snprintf((char *)IObuff, IOSIZE, "ltag %s", tag); + set_errorlist(curwin, list, ' ', IObuff, NULL); + + tv_list_free(list); + XFREE_CLEAR(fname); + XFREE_CLEAR(cmd); + + return OK; } /* @@ -1024,8 +1022,9 @@ static void taglen_advance(int l) if (l == MAXCOL) { msg_putchar('\n'); msg_advance(24); - } else + } else { msg_advance(13 + l); + } } /* @@ -1034,18 +1033,19 @@ static void taglen_advance(int l) void do_tags(exarg_T *eap) { int i; - char_u *name; - taggy_T *tagstack = curwin->w_tagstack; + char_u *name; + taggy_T *tagstack = curwin->w_tagstack; int tagstackidx = curwin->w_tagstackidx; int tagstacklen = curwin->w_tagstacklen; - /* Highlight title */ + // Highlight title MSG_PUTS_TITLE(_("\n # TO tag FROM line in file/text")); for (i = 0; i < tagstacklen; ++i) { if (tagstack[i].tagname != NULL) { name = fm_getname(&(tagstack[i].fmark), 30); - if (name == NULL) /* file name not available */ + if (name == NULL) { // file name not available continue; + } msg_putchar('\n'); vim_snprintf((char *)IObuff, IOSIZE, "%c%2d %2d %-15s %5ld ", @@ -1059,10 +1059,11 @@ void do_tags(exarg_T *eap) ? HL_ATTR(HLF_D) : 0); xfree(name); } - ui_flush(); /* show one line at a time */ + ui_flush(); // show one line at a time } - if (tagstackidx == tagstacklen) /* idx at top of stack */ + if (tagstackidx == tagstacklen) { // idx at top of stack MSG_PUTS("\n>"); + } } @@ -1078,15 +1079,17 @@ static int tag_strnicmp(char_u *s1, char_u *s2, size_t len) while (len > 0) { i = TOUPPER_ASC(*s1) - TOUPPER_ASC(*s2); - if (i != 0) - return i; /* this character different */ - if (*s1 == NUL) - break; /* strings match until NUL */ + if (i != 0) { + return i; // this character different + } + if (*s1 == NUL) { + break; // strings match until NUL + } ++s1; ++s2; --len; } - return 0; /* strings match */ + return 0; // strings match } @@ -1100,48 +1103,54 @@ static void prepare_pats(pat_T *pats, int has_re) if (has_re) { /* When the pattern starts with '^' or "\\<", binary searching can be * used (much faster). */ - if (pats->pat[0] == '^') + if (pats->pat[0] == '^') { pats->head = pats->pat + 1; - else if (pats->pat[0] == '\\' && pats->pat[1] == '<') + } else if (pats->pat[0] == '\\' && pats->pat[1] == '<') { pats->head = pats->pat + 2; - if (pats->head == pats->pat) + } + if (pats->head == pats->pat) { pats->headlen = 0; - else + } else { for (pats->headlen = 0; pats->head[pats->headlen] != NUL; - ++pats->headlen) + ++pats->headlen) { if (vim_strchr((char_u *)(p_magic ? ".[~*\\$" : "\\$"), - pats->head[pats->headlen]) != NULL) + pats->head[pats->headlen]) != NULL) { break; - if (p_tl != 0 && pats->headlen > p_tl) /* adjust for 'taglength' */ + } + } + } + if (p_tl != 0 && pats->headlen > p_tl) { // adjust for 'taglength' pats->headlen = p_tl; + } } - if (has_re) + if (has_re) { pats->regmatch.regprog = vim_regcomp(pats->pat, p_magic ? RE_MAGIC : 0); - else + } else { pats->regmatch.regprog = NULL; + } } -// -// Call the user-defined function to generate a list of tags used by -// find_tags(). -// -// Return OK if at least 1 tag has been successfully found, -// NOTDONE if the function returns v:null, and FAIL otherwise. -// -static int find_tagfunc_tags( - char_u *pat, // pattern supplied to the user-defined function - garray_T *ga, // the tags will be placed here - int *match_count, // here the number of tags found will be placed - int flags, // flags from find_tags (TAG_*) - char_u *buf_ffname) // name of buffer for priority +/// Call the user-defined function to generate a list of tags used by +/// find_tags(). +/// +/// Return OK if at least 1 tag has been successfully found, +/// NOTDONE if the function returns v:null, and FAIL otherwise. +/// +/// @param pat pattern supplied to the user-defined function +/// @param ga the tags will be placed here +/// @param match_count here the number of tags found will be placed +/// @param flags flags from find_tags (TAG_*) +/// @param buf_ffname name of buffer for priority +static int find_tagfunc_tags(char_u *pat, garray_T *ga, int *match_count, int flags, + char_u *buf_ffname) { - pos_T save_pos; - list_T *taglist; - int ntags = 0; - int result = FAIL; - typval_T args[4]; - typval_T rettv; + pos_T save_pos; + list_T *taglist; + int ntags = 0; + int result = FAIL; + typval_T args[4]; + typval_T rettv; char_u flagString[4]; taggy_T *tag = &curwin->w_tagstack[curwin->w_tagstackidx]; @@ -1195,12 +1204,12 @@ static int find_tagfunc_tags( taglist = rettv.vval.v_list; TV_LIST_ITER_CONST(taglist, li, { - char_u *res_name; - char_u *res_fname; - char_u *res_cmd; - char_u *res_kind; - int has_extra = 0; - int name_only = flags & TAG_NAMES; + char_u *res_name; + char_u *res_fname; + char_u *res_cmd; + char_u *res_kind; + int has_extra = 0; + int name_only = flags & TAG_NAMES; if (TV_LIST_ITEM_TV(li)->v_type != VAR_DICT) { EMSG(_(tfu_inv_ret_msg)); @@ -1326,50 +1335,46 @@ static int find_tagfunc_tags( return result; } -/* - * find_tags() - search for tags in tags files - * - * Return FAIL if search completely failed (*num_matches will be 0, *matchesp - * will be NULL), OK otherwise. - * - * There is a priority in which type of tag is recognized. - * - * 6. A static or global tag with a full matching tag for the current file. - * 5. A global tag with a full matching tag for another file. - * 4. A static tag with a full matching tag for another file. - * 3. A static or global tag with an ignore-case matching tag for the - * current file. - * 2. A global tag with an ignore-case matching tag for another file. - * 1. A static tag with an ignore-case matching tag for another file. - * - * Tags in an emacs-style tags file are always global. - * - * flags: - * TAG_HELP only search for help tags - * TAG_NAMES only return name of tag - * TAG_REGEXP use "pat" as a regexp - * TAG_NOIC don't always ignore case - * TAG_KEEP_LANG keep language - * TAG_CSCOPE use cscope results for tags - * TAG_NO_TAGFUNC do not call the 'tagfunc' function - */ -int -find_tags( - char_u *pat, // pattern to search for - int *num_matches, // return: number of matches found - char_u ***matchesp, // return: array of matches found - int flags, - int mincount, /* MAXCOL: find all matches - other: minimal number of matches */ - char_u *buf_ffname /* name of buffer for priority */ -) +/// find_tags() - search for tags in tags files +/// +/// Return FAIL if search completely failed (*num_matches will be 0, *matchesp +/// will be NULL), OK otherwise. +/// +/// There is a priority in which type of tag is recognized. +/// +/// 6. A static or global tag with a full matching tag for the current file. +/// 5. A global tag with a full matching tag for another file. +/// 4. A static tag with a full matching tag for another file. +/// 3. A static or global tag with an ignore-case matching tag for the +/// current file. +/// 2. A global tag with an ignore-case matching tag for another file. +/// 1. A static tag with an ignore-case matching tag for another file. +/// +/// Tags in an emacs-style tags file are always global. +/// +/// flags: +/// TAG_HELP only search for help tags +/// TAG_NAMES only return name of tag +/// TAG_REGEXP use "pat" as a regexp +/// TAG_NOIC don't always ignore case +/// TAG_KEEP_LANG keep language +/// TAG_CSCOPE use cscope results for tags +/// TAG_NO_TAGFUNC do not call the 'tagfunc' function +/// +/// @param pat pattern to search for +/// @param num_matches return: number of matches found +/// @param matchesp return: array of matches found +/// @param mincount MAXCOL: find all matches other: minimal number of matches */ +/// @param buf_ffname name of buffer for priority +int find_tags(char_u *pat, int *num_matches, char_u ***matchesp, int flags, int mincount, + char_u *buf_ffname) { - FILE *fp; - char_u *lbuf; /* line buffer */ - int lbuf_size = LSIZE; /* length of lbuf */ - char_u *tag_fname; /* name of tag file */ - tagname_T tn; /* info for get_tagfname() */ - int first_file; /* trying first tag file */ + FILE *fp; + char_u *lbuf; // line buffer + int lbuf_size = LSIZE; // length of lbuf + char_u *tag_fname; // name of tag file + tagname_T tn; // info for get_tagfname() + int first_file; // trying first tag file tagptrs_T tagp; bool did_open = false; // did open a tag file bool stop_searching = false; // stop when match found or error @@ -1377,8 +1382,8 @@ find_tags( int is_static; // current tag line is static int is_current; // file name matches bool eof = false; // found end-of-file - char_u *p; - char_u *s; + char_u *p; + char_u *s; int i; int tag_file_sorted = NUL; // !_TAG_FILE_SORTED value struct tag_search_info { // Binary search file offsets @@ -1396,17 +1401,17 @@ find_tags( off_T offset; int round; enum { - TS_START, /* at start of file */ - TS_LINEAR /* linear searching forward, till EOF */ - , TS_BINARY, /* binary searching */ - TS_SKIP_BACK, /* skipping backwards */ - TS_STEP_FORWARD /* stepping forwards */ - } state; /* Current search state */ + TS_START, // at start of file + TS_LINEAR // linear searching forward, till EOF + , TS_BINARY, // binary searching + TS_SKIP_BACK, // skipping backwards + TS_STEP_FORWARD // stepping forwards + } state; // Current search state int cmplen; - int match; /* matches */ - int match_no_ic = 0; /* matches with rm_ic == FALSE */ - int match_re; /* match with regexp */ + int match; // matches + int match_no_ic = 0; // matches with rm_ic == FALSE + int match_re; // match with regexp int matchoff = 0; int save_emsg_off; @@ -1416,16 +1421,16 @@ find_tags( hashtab_T ht_match[MT_COUNT]; // stores matches by key hash_T hash = 0; int match_count = 0; // number of matches found - char_u **matches; + char_u **matches; int mtt; int help_save; int help_pri = 0; - char_u *help_lang_find = NULL; // lang to be found + char_u *help_lang_find = NULL; // lang to be found char_u help_lang[3]; // lang of current tags file - char_u *saved_pat = NULL; // copy of pat[] + char_u *saved_pat = NULL; // copy of pat[] bool is_txt = false; - pat_T orgpat; /* holds unconverted pattern info */ + pat_T orgpat; // holds unconverted pattern info vimconv_T vimconv; int findall = (mincount == MAXCOL || mincount == TAG_MANY); @@ -1447,22 +1452,22 @@ find_tags( // Change the value of 'ignorecase' according to 'tagcase' for the // duration of this function. switch (curbuf->b_tc_flags ? curbuf->b_tc_flags : tc_flags) { - case TC_FOLLOWIC: - break; - case TC_IGNORE: - p_ic = true; - break; - case TC_MATCH: - p_ic = false; - break; - case TC_FOLLOWSCS: - p_ic = ignorecase(pat); - break; - case TC_SMART: - p_ic = ignorecase_opt(pat, true, true); - break; - default: - abort(); + case TC_FOLLOWIC: + break; + case TC_IGNORE: + p_ic = true; + break; + case TC_MATCH: + p_ic = false; + break; + case TC_FOLLOWSCS: + p_ic = ignorecase(pat); + break; + case TC_SMART: + p_ic = ignorecase_opt(pat, true, true); + break; + default: + abort(); } help_save = curbuf->b_help; @@ -1480,7 +1485,7 @@ find_tags( hash_init(&ht_match[mtt]); } - STRCPY(tag_fname, "from cscope"); /* for error messages */ + STRCPY(tag_fname, "from cscope"); // for error messages /* * Initialize a few variables @@ -1506,15 +1511,17 @@ find_tags( orgpat.len -= 3; } } - if (p_tl != 0 && orgpat.len > p_tl) /* adjust for 'taglength' */ + if (p_tl != 0 && orgpat.len > p_tl) { // adjust for 'taglength' orgpat.len = p_tl; + } save_emsg_off = emsg_off; - emsg_off = TRUE; /* don't want error for invalid RE here */ + emsg_off = TRUE; // don't want error for invalid RE here prepare_pats(&orgpat, has_re); emsg_off = save_emsg_off; - if (has_re && orgpat.regmatch.regprog == NULL) + if (has_re && orgpat.regmatch.regprog == NULL) { goto findtag_end; + } // This is only to avoid a compiler warning for using search_info // uninitialised. @@ -1580,8 +1587,9 @@ find_tags( /* When searching for a specific language skip tags files * for other languages. */ if (help_lang_find != NULL - && STRICMP(help_lang, help_lang_find) != 0) + && STRICMP(help_lang, help_lang_find) != 0) { continue; + } /* For CTRL-] in a help file prefer a match with the same * language. */ @@ -1591,23 +1599,26 @@ find_tags( && (i = (int)STRLEN(curbuf->b_fname)) > 4 && curbuf->b_fname[i - 1] == 'x' && curbuf->b_fname[i - 4] == '.' - && STRNICMP(curbuf->b_fname + i - 3, help_lang, 2) == 0) + && STRNICMP(curbuf->b_fname + i - 3, help_lang, 2) == 0) { help_pri = 0; - else { + } else { help_pri = 1; for (s = p_hlg; *s != NUL; ++s) { - if (STRNICMP(s, help_lang, 2) == 0) + if (STRNICMP(s, help_lang, 2) == 0) { break; + } ++help_pri; - if ((s = vim_strchr(s, ',')) == NULL) + if ((s = vim_strchr(s, ',')) == NULL) { break; + } } if (s == NULL || *s == NUL) { /* Language not in 'helplang': use last, prefer English, * unless found already. */ ++help_pri; - if (STRICMP(help_lang, "en") != 0) + if (STRICMP(help_lang, "en") != 0) { ++help_pri; + } } } } @@ -1624,7 +1635,7 @@ find_tags( } did_open = true; // remember that we found at least one file - state = TS_START; /* we're at the start of the file */ + state = TS_START; // we're at the start of the file /* * Read and parse the lines in the file one by one @@ -1636,8 +1647,9 @@ find_tags( } else { fast_breakcheck(); } - if ((flags & TAG_INS_COMP)) /* Double brackets for gcc */ + if ((flags & TAG_INS_COMP)) { // Double brackets for gcc ins_compl_check_keys(30, false); + } if (got_int || compl_interrupted) { stop_searching = true; break; @@ -1649,18 +1661,20 @@ find_tags( retval = OK; break; } - if (get_it_again) + if (get_it_again) { goto line_read_in; + } /* * For binary search: compute the next offset to use. */ if (state == TS_BINARY) { offset = search_info.low_offset + ((search_info.high_offset - search_info.low_offset) / 2); - if (offset == search_info.curr_offset) - break; /* End the binary search without a match. */ - else + if (offset == search_info.curr_offset) { + break; // End the binary search without a match. + } else { search_info.curr_offset = offset; + } } else if (state == TS_SKIP_BACK) { // Skipping back (after a match during binary search). search_info.curr_offset -= lbuf_size * 2; @@ -1676,7 +1690,7 @@ find_tags( * start of the next line. */ if (state == TS_BINARY || state == TS_SKIP_BACK) { - /* Adjust the search file offset to the correct position */ + // Adjust the search file offset to the correct position search_info.curr_offset_used = search_info.curr_offset; vim_fseek(fp, search_info.curr_offset, SEEK_SET); eof = vim_fgets(lbuf, lbuf_size, fp); @@ -1691,13 +1705,13 @@ find_tags( } eof = vim_fgets(lbuf, lbuf_size, fp); } - /* skip empty and blank lines */ + // skip empty and blank lines while (!eof && vim_isblankline(lbuf)) { search_info.curr_offset = vim_ftell(fp); eof = vim_fgets(lbuf, lbuf_size, fp); } if (eof) { - /* Hit end of file. Skip backwards. */ + // Hit end of file. Skip backwards. state = TS_SKIP_BACK; search_info.match_offset = vim_ftell(fp); search_info.curr_offset = search_info.curr_offset_used; @@ -1708,7 +1722,7 @@ find_tags( * Not jumping around in the file: Read the next line. */ else { - /* skip empty and blank lines */ + // skip empty and blank lines do { eof = use_cscope ? cs_fgets(lbuf, lbuf_size) @@ -1716,13 +1730,13 @@ find_tags( } while (!eof && vim_isblankline(lbuf)); if (eof) { - break; /* end of file */ + break; // end of file } } line_read_in: if (vimconv.vc_type != CONV_NONE) { - char_u *conv_line; + char_u *conv_line; int len; /* Convert every line. Converting the pattern from 'enc' to @@ -1730,7 +1744,7 @@ line_read_in: * not recognized. */ conv_line = string_convert(&vimconv, lbuf, NULL); if (conv_line != NULL) { - /* Copy or swap lbuf and conv_line. */ + // Copy or swap lbuf and conv_line. len = (int)STRLEN(conv_line) + 1; if (len > lbuf_size) { xfree(lbuf); @@ -1754,30 +1768,33 @@ line_read_in: * case is folded lower case letters sort before "_". */ if (STRNCMP(lbuf, "!_TAG_", 6) <= 0 || (lbuf[0] == '!' && ASCII_ISLOWER(lbuf[1]))) { - if (STRNCMP(lbuf, "!_TAG_", 6) != 0) + if (STRNCMP(lbuf, "!_TAG_", 6) != 0) { /* Non-header item before the header, e.g. "!" itself. */ goto parse_line; + } /* * Read header line. */ - if (STRNCMP(lbuf, "!_TAG_FILE_SORTED\t", 18) == 0) + if (STRNCMP(lbuf, "!_TAG_FILE_SORTED\t", 18) == 0) { tag_file_sorted = lbuf[18]; + } if (STRNCMP(lbuf, "!_TAG_FILE_ENCODING\t", 20) == 0) { /* Prepare to convert every line from the specified * encoding to 'encoding'. */ - for (p = lbuf + 20; *p > ' ' && *p < 127; ++p) + for (p = lbuf + 20; *p > ' ' && *p < 127; ++p) { ; + } *p = NUL; convert_setup(&vimconv, lbuf + 20, p_enc); } - /* Read the next line. Unrecognized flags are ignored. */ + // Read the next line. Unrecognized flags are ignored. continue; } - /* Headers ends. */ + // Headers ends. /* * When there is no tag head, or ignoring case, need to do a @@ -1788,18 +1805,19 @@ line_read_in: * flag set. * For cscope, it's always linear. */ - if (linear || use_cscope) + if (linear || use_cscope) { state = TS_LINEAR; - else if (tag_file_sorted == NUL) + } else if (tag_file_sorted == NUL) { state = TS_BINARY; - else if (tag_file_sorted == '1') + } else if (tag_file_sorted == '1') { state = TS_BINARY; - else if (tag_file_sorted == '2') { + } else if (tag_file_sorted == '2') { state = TS_BINARY; sortic = true; orgpat.regmatch.rm_ic = (p_ic || !noic); - } else + } else { state = TS_LINEAR; + } if (state == TS_BINARY && orgpat.regmatch.rm_ic && !sortic) { /* Binary search won't work for ignoring case, use linear @@ -1865,20 +1883,23 @@ parse_line: * there is no regexp, or the tag is too short. */ cmplen = (int)(tagp.tagname_end - tagp.tagname); - if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */ + if (p_tl != 0 && cmplen > p_tl) { // adjust for 'taglength' cmplen = p_tl; - if (has_re && orgpat.headlen < cmplen) + } + if (has_re && orgpat.headlen < cmplen) { cmplen = orgpat.headlen; - else if (state == TS_LINEAR && orgpat.headlen != cmplen) + } else if (state == TS_LINEAR && orgpat.headlen != cmplen) { continue; + } if (state == TS_BINARY) { /* * Simplistic check for unsorted tags file. */ i = (int)tagp.tagname[0]; - if (sortic) + if (sortic) { i = TOUPPER_ASC(tagp.tagname[0]); + } if (i < search_info.low_char || i > search_info.high_char) { sort_error = true; } @@ -1886,21 +1907,23 @@ parse_line: /* * Compare the current tag with the searched tag. */ - if (sortic) + if (sortic) { tagcmp = tag_strnicmp(tagp.tagname, orgpat.head, - (size_t)cmplen); - else + (size_t)cmplen); + } else { tagcmp = STRNCMP(tagp.tagname, orgpat.head, cmplen); + } /* * A match with a shorter tag means to search forward. * A match with a longer tag means to search backward. */ if (tagcmp == 0) { - if (cmplen < orgpat.headlen) + if (cmplen < orgpat.headlen) { tagcmp = -1; - else if (cmplen > orgpat.headlen) + } else if (cmplen > orgpat.headlen) { tagcmp = 1; + } } if (tagcmp == 0) { @@ -1915,37 +1938,40 @@ parse_line: search_info.curr_offset = vim_ftell(fp); if (search_info.curr_offset < search_info.high_offset) { search_info.low_offset = search_info.curr_offset; - if (sortic) + if (sortic) { search_info.low_char = TOUPPER_ASC(tagp.tagname[0]); - else + } else { search_info.low_char = tagp.tagname[0]; + } continue; } } if (tagcmp > 0 && search_info.curr_offset != search_info.high_offset) { search_info.high_offset = search_info.curr_offset; - if (sortic) + if (sortic) { search_info.high_char = TOUPPER_ASC(tagp.tagname[0]); - else + } else { search_info.high_char = tagp.tagname[0]; + } continue; } - /* No match yet and are at the end of the binary search. */ + // No match yet and are at the end of the binary search. break; - } else if (state == TS_SKIP_BACK) { + } else if (state == TS_SKIP_BACK) { assert(cmplen >= 0); - if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) + if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) { state = TS_STEP_FORWARD; - else + } else { /* Have to skip back more. Restore the curr_offset * used, otherwise we get stuck at a long line. */ search_info.curr_offset = search_info.curr_offset_used; + } continue; - } else if (state == TS_STEP_FORWARD) { + } else if (state == TS_STEP_FORWARD) { assert(cmplen >= 0); if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) { if ((off_T)vim_ftell(fp) > search_info.match_offset) { @@ -1954,23 +1980,27 @@ parse_line: continue; // before first match } } - } else - /* skip this match if it can't match */ - assert(cmplen >= 0); - if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) + } else { + // skip this match if it can't match + assert(cmplen >= 0); + } + if (mb_strnicmp(tagp.tagname, orgpat.head, (size_t)cmplen) != 0) { continue; + } // Can be a matching tag, isolate the file name and command. tagp.fname = tagp.tagname_end + 1; tagp.fname_end = vim_strchr(tagp.fname, TAB); tagp.command = tagp.fname_end + 1; - if (tagp.fname_end == NULL) + if (tagp.fname_end == NULL) { i = FAIL; - else + } else { i = OK; - } else + } + } else { i = parse_tag_line(lbuf, - &tagp); + &tagp); + } if (i == FAIL) { line_error = true; break; @@ -1981,20 +2011,23 @@ parse_line: * a regexp). */ cmplen = (int)(tagp.tagname_end - tagp.tagname); - if (p_tl != 0 && cmplen > p_tl) /* adjust for 'taglength' */ + if (p_tl != 0 && cmplen > p_tl) { // adjust for 'taglength' cmplen = p_tl; - /* if tag length does not match, don't try comparing */ - if (orgpat.len != cmplen) + } + // if tag length does not match, don't try comparing + if (orgpat.len != cmplen) { match = FALSE; - else { + } else { if (orgpat.regmatch.rm_ic) { assert(cmplen >= 0); match = mb_strnicmp(tagp.tagname, orgpat.pat, (size_t)cmplen) == 0; - if (match) + if (match) { match_no_ic = (STRNCMP(tagp.tagname, orgpat.pat, - cmplen) == 0); - } else + cmplen) == 0); + } + } else { match = (STRNCMP(tagp.tagname, orgpat.pat, cmplen) == 0); + } } /* @@ -2012,7 +2045,7 @@ parse_line: if (orgpat.regmatch.rm_ic) { orgpat.regmatch.rm_ic = FALSE; match_no_ic = vim_regexec(&orgpat.regmatch, tagp.tagname, - (colnr_T)0); + (colnr_T)0); orgpat.regmatch.rm_ic = TRUE; } } @@ -2025,7 +2058,7 @@ parse_line: int len = 0; if (use_cscope) { - /* Don't change the ordering, always use the same table. */ + // Don't change the ordering, always use the same table. mtt = MT_GL_OTH; } else { // Decide in which array to store this match. @@ -2035,27 +2068,31 @@ parse_line: // Decide in which of the sixteen tables to store this match. if (is_static) { - if (is_current) + if (is_current) { mtt = MT_ST_CUR; - else + } else { mtt = MT_ST_OTH; + } } else { - if (is_current) + if (is_current) { mtt = MT_GL_CUR; - else + } else { mtt = MT_GL_OTH; + } } - if (orgpat.regmatch.rm_ic && !match_no_ic) + if (orgpat.regmatch.rm_ic && !match_no_ic) { mtt += MT_IC_OFF; - if (match_re) + } + if (match_re) { mtt += MT_RE_OFF; + } } // Add the found match in ht_match[mtt] and ga_match[mtt]. // Store the info we need later, which depends on the kind of // tags we are dealing with. if (help_only) { -# define ML_EXTRA 3 +#define ML_EXTRA 3 // Append the help-heuristic number after the tagname, for // sorting it later. The heuristic is ignored for // detecting duplicates. @@ -2074,7 +2111,7 @@ parse_line: + help_pri); *tagp.tagname_end = TAB; - } else if (name_only) { + } else if (name_only) { if (get_it_again) { char_u *temp_end = tagp.command; @@ -2148,7 +2185,7 @@ parse_line: hash_add_item(&ht_match[mtt], hi, mfp, hash); ga_grow(&ga_match[mtt], 1); ((char_u **)(ga_match[mtt].ga_data)) - [ga_match[mtt].ga_len++] = mfp; + [ga_match[mtt].ga_len++] = mfp; match_count++; } else { // duplicate tag, drop it @@ -2156,9 +2193,10 @@ parse_line: } } } - if (use_cscope && eof) + if (use_cscope && eof) { break; - } /* forever */ + } + } // forever if (line_error) { EMSG2(_("E431: Format error in tags file \"%s\""), tag_fname); @@ -2169,10 +2207,12 @@ parse_line: line_error = false; } - if (!use_cscope) + if (!use_cscope) { fclose(fp); - if (vimconv.vc_type != CONV_NONE) + } + if (vimconv.vc_type != CONV_NONE) { convert_setup(&vimconv, NULL, NULL); + } tag_file_sorted = NUL; if (sort_error) { @@ -2188,27 +2228,31 @@ parse_line: stop_searching = true; } - if (stop_searching || use_cscope) + if (stop_searching || use_cscope) { break; + } + } // end of for-each-file loop - } /* end of for-each-file loop */ - - if (!use_cscope) + if (!use_cscope) { tagname_free(&tn); + } /* stop searching when already did a linear search, or when TAG_NOIC * used, and 'ignorecase' not set or already did case-ignore search */ - if (stop_searching || linear || (!p_ic && noic) || orgpat.regmatch.rm_ic) + if (stop_searching || linear || (!p_ic && noic) || orgpat.regmatch.rm_ic) { break; - if (use_cscope) + } + if (use_cscope) { break; - orgpat.regmatch.rm_ic = TRUE; /* try another time while ignoring case */ + } + orgpat.regmatch.rm_ic = TRUE; // try another time while ignoring case } if (!stop_searching) { - if (!did_open && verbose) /* never opened any tags file */ + if (!did_open && verbose) { // never opened any tags file EMSG(_("E433: No tags file")); - retval = OK; /* It's OK even when no tag found */ + } + retval = OK; // It's OK even when no tag found } findtag_end: @@ -2220,13 +2264,15 @@ findtag_end: * Move the matches from the ga_match[] arrays into one list of * matches. When retval == FAIL, free the matches. */ - if (retval == FAIL) + if (retval == FAIL) { match_count = 0; + } - if (match_count > 0) + if (match_count > 0) { matches = xmalloc(match_count * sizeof(char_u *)); - else + } else { matches = NULL; + } match_count = 0; for (mtt = 0; mtt < MT_COUNT; mtt++) { for (i = 0; i < ga_match[mtt].ga_len; i++) { @@ -2275,7 +2321,7 @@ static void found_tagfile_cb(char_u *fname, void *cookie) char_u *const tag_fname = vim_strsave(fname); #ifdef BACKSLASH_IN_FILENAME - slash_adjust(tag_fname); + slash_adjust(tag_fname); #endif simplify_filename(tag_fname); GA_APPEND(char_u *, &tag_fnames, tag_fname); @@ -2293,24 +2339,22 @@ void free_tag_stuff(void) #endif -/* - * Get the next name of a tag file from the tag file list. - * For help files, use "tags" file only. - * - * Return FAIL if no more tag file names, OK otherwise. - */ -int -get_tagfname( - tagname_T *tnp, // holds status info - int first, // TRUE when first file name is wanted - char_u *buf // pointer to buffer of MAXPATHL chars -) +/// Get the next name of a tag file from the tag file list. +/// For help files, use "tags" file only. +/// +/// @param tnp holds status info +/// @param first TRUE when first file name is wanted +/// @param buf pointer to buffer of MAXPATHL chars +/// +/// @return FAIL if no more tag file names, OK otherwise. +int get_tagfname(tagname_T *tnp, int first, char_u *buf) { - char_u *fname = NULL; - char_u *r_ptr; + char_u *fname = NULL; + char_u *r_ptr; - if (first) + if (first) { memset(tnp, 0, sizeof(tagname_T)); + } if (curbuf->b_help) { /* @@ -2328,8 +2372,9 @@ get_tagfname( if (tnp->tn_hf_idx >= tag_fnames.ga_len) { /* Not found in 'runtimepath', use 'helpfile', if it exists and * wasn't used yet, replacing "help.txt" with "tags". */ - if (tnp->tn_hf_idx > tag_fnames.ga_len || *p_hf == NUL) + if (tnp->tn_hf_idx > tag_fnames.ga_len || *p_hf == NUL) { return FAIL; + } ++tnp->tn_hf_idx; STRCPY(buf, p_hf); STRCPY(path_tail(buf), "tags"); @@ -2367,14 +2412,15 @@ get_tagfname( for (;; ) { if (tnp->tn_did_filefind_init) { fname = vim_findfile(tnp->tn_search_ctx); - if (fname != NULL) + if (fname != NULL) { break; + } tnp->tn_did_filefind_init = FALSE; } else { - char_u *filename = NULL; + char_u *filename = NULL; - /* Stop when used all parts of 'tags'. */ + // Stop when used all parts of 'tags'. if (*tnp->tn_np == NUL) { vim_findfile_cleanup(tnp->tn_search_ctx); tnp->tn_search_ctx = NULL; @@ -2395,12 +2441,13 @@ get_tagfname( *filename++ = NUL; tnp->tn_search_ctx = vim_findfile_init(buf, filename, - r_ptr, 100, - FALSE, /* don't free visited list */ - FINDFILE_FILE, /* we search for a file */ - tnp->tn_search_ctx, TRUE, curbuf->b_ffname); - if (tnp->tn_search_ctx != NULL) + r_ptr, 100, + FALSE, // don't free visited list + FINDFILE_FILE, // we search for a file + tnp->tn_search_ctx, TRUE, curbuf->b_ffname); + if (tnp->tn_search_ctx != NULL) { tnp->tn_did_filefind_init = TRUE; + } } } @@ -2420,43 +2467,44 @@ void tagname_free(tagname_T *tnp) ga_clear_strings(&tag_fnames); } -/* - * Parse one line from the tags file. Find start/end of tag name, start/end of - * file name and start of search pattern. - * - * If is_etag is TRUE, tagp->fname and tagp->fname_end are not set. - * - * Return FAIL if there is a format error in this line, OK otherwise. - */ -static int -parse_tag_line( - char_u *lbuf, // line to be parsed - tagptrs_T *tagp -) +/// Parse one line from the tags file. Find start/end of tag name, start/end of +/// file name and start of search pattern. +/// +/// If is_etag is TRUE, tagp->fname and tagp->fname_end are not set. +/// +/// @param lbuf line to be parsed +/// +/// @return FAIL if there is a format error in this line, OK otherwise. +static int parse_tag_line(char_u *lbuf, tagptrs_T *tagp) { - char_u *p; + char_u *p; - /* Isolate the tagname, from lbuf up to the first white */ + // Isolate the tagname, from lbuf up to the first white tagp->tagname = lbuf; p = vim_strchr(lbuf, TAB); - if (p == NULL) + if (p == NULL) { return FAIL; + } tagp->tagname_end = p; - /* Isolate file name, from first to second white space */ - if (*p != NUL) + // Isolate file name, from first to second white space + if (*p != NUL) { ++p; + } tagp->fname = p; p = vim_strchr(p, TAB); - if (p == NULL) + if (p == NULL) { return FAIL; + } tagp->fname_end = p; - /* find start of search command, after second white space */ - if (*p != NUL) + // find start of search command, after second white space + if (*p != NUL) { ++p; - if (*p == NUL) + } + if (*p == NUL) { return FAIL; + } tagp->command = p; return OK; @@ -2466,12 +2514,12 @@ parse_tag_line( * Check if tagname is a static tag * * Static tags produced by the older ctags program have the format: - * 'file:tag file /pattern'. + * 'file:tag file /pattern'. * This is only recognized when both occurrence of 'file' are the same, to * avoid recognizing "string::string" or ":exit". * * Static tags produced by the new ctags program have the format: - * 'tag file /pattern/;"<Tab>file:' " + * 'tag file /pattern/;"<Tab>file:' " * * Return TRUE if it is a static tag and adjust *tagname to the real tag. * Return FALSE if it is not a static tag. @@ -2484,8 +2532,9 @@ static bool test_for_static(tagptrs_T *tagp) p = tagp->command; while ((p = vim_strchr(p, '\t')) != NULL) { ++p; - if (STRNCMP(p, "file:", 5) == 0) + if (STRNCMP(p, "file:", 5) == 0) { return TRUE; + } } return FALSE; @@ -2501,32 +2550,29 @@ static size_t matching_line_len(const char_u *const lbuf) return (p - lbuf) + STRLEN(p); } -/* - * Parse a line from a matching tag. Does not change the line itself. - * - * The line that we get looks like this: - * Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf> - * other tag: <mtt><tag_fname><NUL><NUL><lbuf> - * without Emacs tags: <mtt><tag_fname><NUL><lbuf> - * - * Return OK or FAIL. - */ -static int -parse_match( - char_u *lbuf, // input: matching line - tagptrs_T *tagp // output: pointers into the line -) +/// Parse a line from a matching tag. Does not change the line itself. +/// +/// The line that we get looks like this: +/// Emacs tag: <mtt><tag_fname><NUL><ebuf><NUL><lbuf> +/// other tag: <mtt><tag_fname><NUL><NUL><lbuf> +/// without Emacs tags: <mtt><tag_fname><NUL><lbuf> +/// +/// @param lbuf input: matching line +/// @param tagp output: pointers into the line +/// +/// @return OK or FAIL. +static int parse_match(char_u *lbuf, tagptrs_T *tagp) { int retval; - char_u *p; - char_u *pc, *pt; + char_u *p; + char_u *pc, *pt; tagp->tag_fname = lbuf + 1; lbuf += STRLEN(tagp->tag_fname) + 2; - /* Find search pattern and the file name for non-etags. */ + // Find search pattern and the file name for non-etags. retval = parse_tag_line(lbuf, - tagp); + tagp); tagp->tagkind = NULL; tagp->user_data = NULL; @@ -2534,7 +2580,7 @@ parse_match( tagp->command_end = NULL; if (retval == OK) { - /* Try to find a kind field: "kind:<kind>" or just "<kind>"*/ + // Try to find a kind field: "kind:<kind>" or just "<kind>" p = tagp->command; if (find_extra(&p) == OK) { tagp->command_end = p; @@ -2562,8 +2608,9 @@ parse_match( if (pc == NULL || (pt != NULL && pc > pt)) { tagp->tagkind = p; } - if (pt == NULL) + if (pt == NULL) { break; + } p = pt; MB_PTR_ADV(p); } @@ -2602,32 +2649,30 @@ static char_u *tag_full_fname(tagptrs_T *tagp) return fullname; } -/* - * Jump to a tag that has been found in one of the tag files - * - * returns OK for success, NOTAGFILE when file not found, FAIL otherwise. - */ -static int jumpto_tag( - const char_u *lbuf_arg, // line from the tags file for this tag - int forceit, // :ta with ! - int keep_help // keep help flag (FALSE for cscope) -) +/// Jump to a tag that has been found in one of the tag files +/// +/// @param lbuf_arg line from the tags file for this tag +/// @param forceit :ta with ! +/// @param keep_help keep help flag (FALSE for cscope) +/// +/// @return OK for success, NOTAGFILE when file not found, FAIL otherwise. +static int jumpto_tag(const char_u *lbuf_arg, int forceit, int keep_help) { int save_magic; bool save_p_ws; int save_p_scs, save_p_ic; linenr_T save_lnum; - char_u *str; - char_u *pbuf; /* search pattern buffer */ - char_u *pbuf_end; - char_u *tofree_fname = NULL; - char_u *fname; + char_u *str; + char_u *pbuf; // search pattern buffer + char_u *pbuf_end; + char_u *tofree_fname = NULL; + char_u *fname; tagptrs_T tagp; int retval = FAIL; int getfile_result = GETFILE_UNUSED; int search_options; - win_T *curwin_save = NULL; - char_u *full_fname = NULL; + win_T *curwin_save = NULL; + char_u *full_fname = NULL; const bool old_KeyTyped = KeyTyped; // getting the file may reset it const int l_g_do_tagpreview = g_do_tagpreview; const size_t len = matching_line_len(lbuf_arg) + 1; @@ -2636,7 +2681,7 @@ static int jumpto_tag( pbuf = xmalloc(LSIZE); - /* parse the match line into the tagp structure */ + // parse the match line into the tagp structure if (parse_match(lbuf, &tagp) == FAIL) { tagp.fname_end = NULL; goto erret; @@ -2646,7 +2691,7 @@ static int jumpto_tag( *tagp.fname_end = NUL; fname = tagp.fname; - /* copy the command to pbuf[], remove trailing CR/NL */ + // copy the command to pbuf[], remove trailing CR/NL str = tagp.command; for (pbuf_end = pbuf; *str && *str != '\n' && *str != '\r'; ) { *pbuf_end++ = *str++; @@ -2680,8 +2725,8 @@ static int jumpto_tag( * autocommand event (e.g., http://sys/file). */ if (!os_path_exists(fname) - && !has_autocmd(EVENT_BUFREADCMD, fname, NULL) - ) { + && !has_autocmd(EVENT_BUFREADCMD, fname, + NULL)) { retval = NOTAGFILE; xfree(nofile_fname); nofile_fname = vim_strsave(fname); @@ -2692,8 +2737,8 @@ static int jumpto_tag( if (l_g_do_tagpreview != 0) { - postponed_split = 0; /* don't split again below */ - curwin_save = curwin; /* Save current window */ + postponed_split = 0; // don't split again below + curwin_save = curwin; // Save current window /* * If we are reusing a window, we may change dir when @@ -2750,10 +2795,11 @@ static int jumpto_tag( if (keep_help) { /* A :ta from a help file will keep the b_help flag set. For ":ptag" * we need to use the flag from the window where we came from. */ - if (l_g_do_tagpreview != 0) + if (l_g_do_tagpreview != 0) { keep_help_flag = curwin_save->w_buffer->b_help; - else + } else { keep_help_flag = curbuf->b_help; + } } if (getfile_result == GETFILE_UNUSED) { @@ -2777,10 +2823,11 @@ static int jumpto_tag( * command. If 'cpoptions' does not contain 't', the search pattern * is not stored. */ - if (vim_strchr(p_cpo, CPO_TAGPAT) != NULL) + if (vim_strchr(p_cpo, CPO_TAGPAT) != NULL) { search_options = 0; - else + } else { search_options = SEARCH_KEEP; + } /* * If the command is a search, try here. @@ -2791,14 +2838,15 @@ static int jumpto_tag( * anything following. */ str = pbuf; - if (pbuf[0] == '/' || pbuf[0] == '?') + if (pbuf[0] == '/' || pbuf[0] == '?') { str = skip_regexp(pbuf + 1, pbuf[0], FALSE, NULL) + 1; - if (str > pbuf_end - 1) { /* search command with nothing following */ + } + if (str > pbuf_end - 1) { // search command with nothing following save_p_ws = p_ws; save_p_ic = p_ic; save_p_scs = p_scs; - p_ws = true; /* need 'wrapscan' for backward searches */ - p_ic = FALSE; /* don't ignore case now */ + p_ws = true; // need 'wrapscan' for backward searches + p_ic = FALSE; // don't ignore case now p_scs = FALSE; save_lnum = curwin->w_cursor.lnum; if (tagp.tagline > 0) { @@ -2898,15 +2946,17 @@ static int jumpto_tag( * For a help buffer: Put the cursor line at the top of the window, * the help subject will be below it. */ - if (curbuf->b_help) + if (curbuf->b_help) { set_topline(curwin, curwin->w_cursor.lnum); - if ((fdo_flags & FDO_TAG) && old_KeyTyped) + } + if ((fdo_flags & FDO_TAG) && old_KeyTyped) { foldOpenCursor(); + } } if (l_g_do_tagpreview != 0 && curwin != curwin_save && win_valid(curwin_save)) { - /* Return cursor to where we were */ + // Return cursor to where we were validate_cursor(); redraw_later(curwin, VALID); win_enter(curwin_save, true); @@ -2935,11 +2985,10 @@ erret: // If 'tagrelative' option set, change fname (name of file containing tag) // according to tag_fname (name of tag file containing fname). // Returns a pointer to allocated memory. -static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, - const bool expand) +static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, const bool expand) { - char_u *p; - char_u *expanded_fname = NULL; + char_u *p; + char_u *expanded_fname = NULL; expand_T xpc; /* @@ -2949,9 +2998,10 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, ExpandInit(&xpc); xpc.xp_context = EXPAND_FILES; expanded_fname = ExpandOne(&xpc, fname, NULL, - WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); - if (expanded_fname != NULL) + WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); + if (expanded_fname != NULL) { fname = expanded_fname; + } } char_u *retval; @@ -2961,13 +3011,14 @@ static char_u *expand_tag_fname(char_u *fname, char_u *const tag_fname, retval = xmalloc(MAXPATHL); STRCPY(retval, tag_fname); STRLCPY(retval + (p - tag_fname), fname, - MAXPATHL - (p - tag_fname)); + MAXPATHL - (p - tag_fname)); /* * Translate names like "src/a/../b/file.c" into "src/b/file.c". */ simplify_filename(retval); - } else + } else { retval = vim_strsave(fname); + } xfree(expanded_fname); @@ -2984,9 +3035,9 @@ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname, { int c; int retval = FALSE; - char_u *fullname; + char_u *fullname; - if (buf_ffname != NULL) { /* if the buffer has a name */ + if (buf_ffname != NULL) { // if the buffer has a name { c = *fname_end; *fname_end = NUL; @@ -3053,13 +3104,8 @@ static void tagstack_clear_entry(taggy_T *item) XFREE_CLEAR(item->user_data); } -int -expand_tags ( - int tagnames, /* expand tag names */ - char_u *pat, - int *num_file, - char_u ***file -) +/// @param tagnames expand tag names +int expand_tags(int tagnames, char_u *pat, int *num_file, char_u ***file) { int i; int extra_flag; @@ -3116,17 +3162,13 @@ expand_tags ( } -/* - * Add a tag field to the dictionary "dict". - * Return OK or FAIL. - */ -static int -add_tag_field( - dict_T *dict, - const char *field_name, - const char_u *start, // start of the value - const char_u *end // after the value; can be NULL -) +/// Add a tag field to the dictionary "dict". +/// Return OK or FAIL. +/// +/// @param start start of the value +/// @param end after the value; can be NULL +static int add_tag_field(dict_T *dict, const char *field_name, const char_u *start, + const char_u *end) FUNC_ATTR_NONNULL_ARG(1, 2) { int len = 0; @@ -3145,12 +3187,14 @@ add_tag_field( if (start != NULL) { if (end == NULL) { end = start + STRLEN(start); - while (end > start && (end[-1] == '\r' || end[-1] == '\n')) + while (end > start && (end[-1] == '\r' || end[-1] == '\n')) { --end; + } } len = (int)(end - start); - if (len > MAXPATHL - 1) + if (len > MAXPATHL - 1) { len = MAXPATHL - 1; + } STRLCPY(buf, start, len + 1); } buf[len] = NUL; @@ -3165,9 +3209,9 @@ add_tag_field( int get_tags(list_T *list, char_u *pat, char_u *buf_fname) { int num_matches, i, ret; - char_u **matches; - char_u *full_fname; - dict_T *dict; + char_u **matches; + char_u *full_fname; + dict_T *dict; tagptrs_T tp; bool is_static; @@ -3178,7 +3222,7 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) int parse_result = parse_match(matches[i], &tp); // Avoid an unused variable warning in release builds. - (void) parse_result; + (void)parse_result; assert(parse_result == OK); is_static = test_for_static(&tp); @@ -3216,29 +3260,35 @@ int get_tags(list_T *list, char_u *pat, char_u *buf_fname) // skip "file:" (static tag) p += 4; } else if (!ascii_iswhite(*p)) { - char_u *s, *n; + char_u *s, *n; int len; /* Add extra field as a dict entry. Fields are * separated by Tabs. */ n = p; - while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') + while (*p != NUL && *p >= ' ' && *p < 127 && *p != ':') { ++p; + } len = (int)(p - n); if (*p == ':' && len > 0) { s = ++p; - while (*p != NUL && *p >= ' ') + while (*p != NUL && *p >= ' ') { ++p; + } n[len] = NUL; - if (add_tag_field(dict, (char *)n, s, p) == FAIL) + if (add_tag_field(dict, (char *)n, s, p) == FAIL) { ret = FAIL; + } n[len] = ':'; - } else - /* Skip field without colon. */ - while (*p != NUL && *p >= ' ') + } else { + // Skip field without colon. + while (*p != NUL && *p >= ' ') { ++p; - if (*p == NUL) + } + } + if (*p == NUL) { break; + } } } } @@ -3319,14 +3369,8 @@ static void tagstack_shift(win_T *wp) } // Push a new item to the tag stack -static void tagstack_push_item( - win_T *wp, - char_u *tagname, - int cur_fnum, - int cur_match, - pos_T mark, - int fnum, - char_u *user_data) +static void tagstack_push_item(win_T *wp, char_u *tagname, int cur_fnum, int cur_match, pos_T mark, + int fnum, char_u *user_data) { taggy_T *tagstack = wp->w_tagstack; int idx = wp->w_tagstacklen; // top of the stack @@ -3382,13 +3426,12 @@ static void tagstack_push_items(win_T *wp, list_T *l) if (mark.col > 0) { mark.col--; } - tagstack_push_item( - wp, - tagname, - (int)tv_dict_get_number(itemdict, "bufnr"), - (int)tv_dict_get_number(itemdict, "matchnr") - 1, - mark, fnum, - (char_u *)tv_dict_get_string(itemdict, "user_data", true)); + tagstack_push_item(wp, + tagname, + (int)tv_dict_get_number(itemdict, "bufnr"), + (int)tv_dict_get_number(itemdict, "matchnr") - 1, + mark, fnum, + (char_u *)tv_dict_get_string(itemdict, "user_data", true)); } } diff --git a/src/nvim/ugrid.c b/src/nvim/ugrid.c index 9e4aaff878..ef84cdf334 100644 --- a/src/nvim/ugrid.c +++ b/src/nvim/ugrid.c @@ -2,14 +2,14 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include <assert.h> +#include <limits.h> #include <stdbool.h> #include <stdio.h> -#include <limits.h> #include "nvim/assert.h" -#include "nvim/vim.h" -#include "nvim/ui.h" #include "nvim/ugrid.h" +#include "nvim/ui.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ugrid.c.generated.h" @@ -79,8 +79,7 @@ void ugrid_scroll(UGrid *grid, int top, int bot, int left, int right, int count) } } -static void clear_region(UGrid *grid, int top, int bot, int left, int right, - sattr_T attr) +static void clear_region(UGrid *grid, int top, int bot, int left, int right, sattr_T attr) { for (int row = top; row <= bot; row++) { UGRID_FOREACH_CELL(grid, row, left, right+1, { diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 09709d0f43..aad72af025 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -3,40 +3,40 @@ #include <assert.h> #include <inttypes.h> +#include <limits.h> #include <stdbool.h> #include <string.h> -#include <limits.h> -#include "nvim/vim.h" -#include "nvim/log.h" +#include "nvim/ascii.h" #include "nvim/aucmd.h" -#include "nvim/ui.h" #include "nvim/charset.h" #include "nvim/cursor.h" +#include "nvim/cursor_shape.h" #include "nvim/diff.h" +#include "nvim/event/loop.h" #include "nvim/ex_cmds2.h" #include "nvim/ex_getln.h" #include "nvim/fold.h" +#include "nvim/garray.h" +#include "nvim/highlight.h" +#include "nvim/log.h" #include "nvim/main.h" -#include "nvim/ascii.h" -#include "nvim/misc1.h" #include "nvim/mbyte.h" -#include "nvim/garray.h" #include "nvim/memory.h" +#include "nvim/misc1.h" #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/option.h" -#include "nvim/os_unix.h" -#include "nvim/event/loop.h" -#include "nvim/os/time.h" #include "nvim/os/input.h" #include "nvim/os/signal.h" +#include "nvim/os/time.h" +#include "nvim/os_unix.h" #include "nvim/popupmnu.h" #include "nvim/screen.h" -#include "nvim/highlight.h" +#include "nvim/ui.h" #include "nvim/ui_compositor.h" +#include "nvim/vim.h" #include "nvim/window.h" -#include "nvim/cursor_shape.h" #ifdef FEAT_TUI # include "nvim/tui/tui.h" #else @@ -70,9 +70,9 @@ static int pending_has_mouse = -1; static size_t uilog_seen = 0; static char uilog_last_event[1024] = { 0 }; -#ifndef EXITFREE -#define entered_free_all_mem false -#endif +# ifndef EXITFREE +# define entered_free_all_mem false +# endif # define UI_LOG(funname) \ do { \ @@ -95,7 +95,7 @@ static char uilog_last_event[1024] = { 0 }; // UI_CALL invokes a function on all registered UI instances. // This is called by code generated by generators/gen_api_ui_events.lua // C code should use ui_call_{funname} instead. -# define UI_CALL(cond, funname, ...) \ +#define UI_CALL(cond, funname, ...) \ do { \ bool any_call = false; \ for (size_t i = 0; i < ui_count; i++) { \ @@ -115,7 +115,7 @@ static char uilog_last_event[1024] = { 0 }; #endif #ifndef EXITFREE -#undef entered_free_all_mem +# undef entered_free_all_mem #endif void ui_init(void) @@ -382,8 +382,8 @@ void ui_set_ext_option(UI *ui, UIExtension ext, bool active) } } -void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, - int clearattr, bool wrap) +void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, int clearattr, + bool wrap) { assert(0 <= row && row < grid->Rows); LineFlags flags = wrap ? kLineFlagWrap : 0; @@ -515,23 +515,23 @@ void ui_check_mouse(void) // normal editing mode (not at hit-return message). for (char_u *p = p_mouse; *p; p++) { switch (*p) { - case 'a': - if (vim_strchr((char_u *)MOUSE_A, checkfor) != NULL) { - has_mouse = true; - return; - } - break; - case MOUSE_HELP: - if (checkfor != MOUSE_RETURN && curbuf->b_help) { - has_mouse = true; - return; - } - break; - default: - if (checkfor == *p) { - has_mouse = true; - return; - } + case 'a': + if (vim_strchr((char_u *)MOUSE_A, checkfor) != NULL) { + has_mouse = true; + return; + } + break; + case MOUSE_HELP: + if (checkfor != MOUSE_RETURN && curbuf->b_help) { + has_mouse = true; + return; + } + break; + default: + if (checkfor == *p) { + has_mouse = true; + return; + } } } } diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c index bc64414ecf..3402df817a 100644 --- a/src/nvim/ui_bridge.c +++ b/src/nvim/ui_bridge.c @@ -5,18 +5,18 @@ // Used by the built-in TUI and libnvim-based UIs. #include <assert.h> +#include <limits.h> #include <stdbool.h> #include <stdio.h> -#include <limits.h> +#include "nvim/api/private/helpers.h" #include "nvim/log.h" #include "nvim/main.h" -#include "nvim/vim.h" -#include "nvim/ui.h" #include "nvim/memory.h" -#include "nvim/ui_bridge.h" #include "nvim/ugrid.h" -#include "nvim/api/private/helpers.h" +#include "nvim/ui.h" +#include "nvim/ui_bridge.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui_bridge.c.generated.h" @@ -26,8 +26,7 @@ // Schedule a function call on the UI bridge thread. #define UI_BRIDGE_CALL(ui, name, argc, ...) \ - ((UIBridgeData *)ui)->scheduler( \ - event_create(ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui)) + ((UIBridgeData *)ui)->scheduler(event_create(ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui)) #define INT2PTR(i) ((void *)(intptr_t)i) #define PTR2INT(p) ((Integer)(intptr_t)p) @@ -138,8 +137,8 @@ static void ui_bridge_stop_event(void **argv) ui->stop(ui); } -static void ui_bridge_hl_attr_define(UI *ui, Integer id, HlAttrs attrs, - HlAttrs cterm_attrs, Array info) +static void ui_bridge_hl_attr_define(UI *ui, Integer id, HlAttrs attrs, HlAttrs cterm_attrs, + Array info) { HlAttrs *a = xmalloc(sizeof(HlAttrs)); *a = attrs; @@ -163,11 +162,9 @@ static void ui_bridge_raw_line_event(void **argv) xfree(argv[8]); xfree(argv[9]); } -static void ui_bridge_raw_line(UI *ui, Integer grid, Integer row, - Integer startcol, Integer endcol, - Integer clearcol, Integer clearattr, - LineFlags flags, const schar_T *chunk, - const sattr_T *attrs) +static void ui_bridge_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Integer endcol, + Integer clearcol, Integer clearattr, LineFlags flags, + const schar_T *chunk, const sattr_T *attrs) { size_t ncol = (size_t)(endcol-startcol); schar_T *c = xmemdup(chunk, ncol * sizeof(schar_T)); diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 9c9aec1cf5..7a0f68cfeb 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -7,27 +7,27 @@ // Layer-based compositing: https://en.wikipedia.org/wiki/Digital_compositing #include <assert.h> +#include <limits.h> #include <stdbool.h> #include <stdio.h> -#include <limits.h> +#include "nvim/api/private/helpers.h" +#include "nvim/ascii.h" +#include "nvim/highlight.h" #include "nvim/lib/kvec.h" #include "nvim/log.h" +#include "nvim/lua/executor.h" #include "nvim/main.h" -#include "nvim/ascii.h" -#include "nvim/vim.h" -#include "nvim/ui.h" -#include "nvim/highlight.h" #include "nvim/memory.h" #include "nvim/message.h" +#include "nvim/os/os.h" #include "nvim/popupmnu.h" -#include "nvim/ui_compositor.h" -#include "nvim/ugrid.h" #include "nvim/screen.h" #include "nvim/syntax.h" -#include "nvim/api/private/helpers.h" -#include "nvim/lua/executor.h" -#include "nvim/os/os.h" +#include "nvim/ugrid.h" +#include "nvim/ui.h" +#include "nvim/ui_compositor.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui_compositor.c.generated.h" @@ -123,8 +123,8 @@ bool ui_comp_should_draw(void) /// TODO(bfredl): later on the compositor should just use win_float_pos events, /// though that will require slight event order adjustment: emit the win_pos /// events in the beginning of update_screen(0), rather than in ui_flush() -bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, - bool valid, bool on_top) +bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, bool valid, + bool on_top) { bool moved; @@ -257,8 +257,7 @@ static void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) } } -static void ui_comp_grid_cursor_goto(UI *ui, Integer grid_handle, - Integer r, Integer c) +static void ui_comp_grid_cursor_goto(UI *ui, Integer grid_handle, Integer r, Integer c) { if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid_handle)) { return; @@ -304,8 +303,7 @@ ScreenGrid *ui_comp_mouse_focus(int row, int col) /// Baseline implementation. This is always correct, but we can sometimes /// do something more efficient (where efficiency means smaller deltas to /// the downstream UI.) -static void compose_line(Integer row, Integer startcol, Integer endcol, - LineFlags flags) +static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlags flags) { // If rightleft is set, startcol may be -1. In such cases, the assertions // will fail because no overlap is found. Adjust startcol to prevent it. @@ -447,8 +445,8 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, (const sattr_T *)attrbuf+skipstart); } -static void compose_debug(Integer startrow, Integer endrow, Integer startcol, - Integer endcol, int syn_id, bool delay) +static void compose_debug(Integer startrow, Integer endrow, Integer startcol, Integer endcol, + int syn_id, bool delay) { if (!(rdb_flags & RDB_COMPOSITOR)) { return; @@ -479,8 +477,7 @@ static void debug_delay(Integer lines) } -static void compose_area(Integer startrow, Integer endrow, - Integer startcol, Integer endcol) +static void compose_area(Integer startrow, Integer endrow, Integer startcol, Integer endcol) { compose_debug(startrow, endrow, startcol, endcol, dbghl_recompose, true); endrow = MIN(endrow, default_grid.Rows); @@ -505,11 +502,9 @@ void ui_comp_compose_grid(ScreenGrid *grid) } } -static void ui_comp_raw_line(UI *ui, Integer grid, Integer row, - Integer startcol, Integer endcol, - Integer clearcol, Integer clearattr, - LineFlags flags, const schar_T *chunk, - const sattr_T *attrs) +static void ui_comp_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Integer endcol, + Integer clearcol, Integer clearattr, LineFlags flags, + const schar_T *chunk, const sattr_T *attrs) { if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid)) { return; @@ -529,11 +524,11 @@ static void ui_comp_raw_line(UI *ui, Integer grid, Integer row, // when resizing nvim, a window will be attempted to be drawn on the older // and possibly larger global screen size. if (row >= default_grid.Rows) { - DLOG("compositor: invalid row %"PRId64" on grid %"PRId64, row, grid); + DLOG("compositor: invalid row %" PRId64 " on grid %" PRId64, row, grid); return; } if (clearcol > default_grid.Columns) { - DLOG("compositor: invalid last column %"PRId64" on grid %"PRId64, + DLOG("compositor: invalid last column %" PRId64 " on grid %" PRId64, clearcol, grid); if (startcol >= default_grid.Columns) { return; @@ -572,8 +567,8 @@ void ui_comp_set_screen_valid(bool valid) } } -static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, - Boolean scrolled, String sep_char) +static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrolled, + String sep_char) { msg_grid.comp_row = (int)row; if (scrolled && row > 0) { @@ -617,9 +612,8 @@ static bool curgrid_covered_above(int row) return kv_size(layers)-(above_msg?1:0) > curgrid->comp_index+1; } -static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, - Integer bot, Integer left, Integer right, - Integer rows, Integer cols) +static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, Integer left, + Integer right, Integer rows, Integer cols) { if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid)) { return; @@ -653,8 +647,7 @@ static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, } } -static void ui_comp_grid_resize(UI *ui, Integer grid, - Integer width, Integer height) +static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer height) { if (grid == 1) { ui_composed_call_grid_resize(1, width, height); diff --git a/src/nvim/undo.c b/src/nvim/undo.c index fb96d7e6ff..af214815f8 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -71,52 +71,51 @@ /* Uncomment the next line for including the u_check() function. This warns * for errors in the debug information. */ -/* #define U_DEBUG 1 */ -#define UH_MAGIC 0x18dade /* value for uh_magic when in use */ -#define UE_MAGIC 0xabc123 /* value for ue_magic when in use */ +// #define U_DEBUG 1 +#define UH_MAGIC 0x18dade // value for uh_magic when in use +#define UE_MAGIC 0xabc123 // value for ue_magic when in use #include <assert.h> +#include <fcntl.h> #include <inttypes.h> #include <limits.h> #include <stdbool.h> #include <string.h> -#include <fcntl.h> #include "auto/config.h" - -#include "nvim/buffer.h" #include "nvim/ascii.h" +#include "nvim/buffer.h" +#include "nvim/buffer_updates.h" #include "nvim/change.h" -#include "nvim/undo.h" #include "nvim/cursor.h" #include "nvim/edit.h" +#include "nvim/extmark.h" #include "nvim/fileio.h" #include "nvim/fold.h" -#include "nvim/buffer_updates.h" -#include "nvim/pos.h" // MAXLNUM +#include "nvim/garray.h" +#include "nvim/lib/kvec.h" #include "nvim/mark.h" -#include "nvim/extmark.h" #include "nvim/memline.h" +#include "nvim/memory.h" #include "nvim/message.h" #include "nvim/misc1.h" -#include "nvim/memory.h" -#include "nvim/garray.h" #include "nvim/option.h" +#include "nvim/os/os.h" +#include "nvim/os/time.h" #include "nvim/os_unix.h" #include "nvim/path.h" +#include "nvim/pos.h" // MAXLNUM #include "nvim/sha256.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/types.h" -#include "nvim/os/os.h" -#include "nvim/os/time.h" -#include "nvim/lib/kvec.h" +#include "nvim/undo.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "undo.c.generated.h" #endif -/* used in undo_end() to report number of added and deleted lines */ +// used in undo_end() to report number of added and deleted lines static long u_newcount, u_oldcount; /* @@ -136,13 +135,12 @@ static int seen_b_u_curhead; static int seen_b_u_newhead; static int header_count; -static void u_check_tree(u_header_T *uhp, - u_header_T *exp_uh_next, - u_header_T *exp_uh_alt_prev) { +static void u_check_tree(u_header_T *uhp, u_header_T *exp_uh_next, u_header_T *exp_uh_alt_prev) { u_entry_T *uep; - if (uhp == NULL) + if (uhp == NULL) { return; + } ++header_count; if (uhp == curbuf->b_u_curhead && ++seen_b_u_curhead > 1) { EMSG("b_u_curhead found twice (looping?)"); @@ -153,22 +151,22 @@ static void u_check_tree(u_header_T *uhp, return; } - if (uhp->uh_magic != UH_MAGIC) + if (uhp->uh_magic != UH_MAGIC) { EMSG("uh_magic wrong (may be using freed memory)"); - else { - /* Check pointers back are correct. */ + } else { + // Check pointers back are correct. if (uhp->uh_next.ptr != exp_uh_next) { EMSG("uh_next wrong"); smsg("expected: 0x%x, actual: 0x%x", - exp_uh_next, uhp->uh_next.ptr); + exp_uh_next, uhp->uh_next.ptr); } if (uhp->uh_alt_prev.ptr != exp_uh_alt_prev) { EMSG("uh_alt_prev wrong"); smsg("expected: 0x%x, actual: 0x%x", - exp_uh_alt_prev, uhp->uh_alt_prev.ptr); + exp_uh_alt_prev, uhp->uh_alt_prev.ptr); } - /* Check the undo tree at this header. */ + // Check the undo tree at this header. for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) { if (uep->ue_magic != UE_MAGIC) { EMSG("ue_magic wrong (may be using freed memory)"); @@ -176,10 +174,10 @@ static void u_check_tree(u_header_T *uhp, } } - /* Check the next alt tree. */ + // Check the next alt tree. u_check_tree(uhp->uh_alt_next.ptr, uhp->uh_next.ptr, uhp); - /* Check the next header in this branch. */ + // Check the next header in this branch. u_check_tree(uhp->uh_prev.ptr, uhp, NULL); } } @@ -192,14 +190,16 @@ static void u_check(int newhead_may_be_NULL) { u_check_tree(curbuf->b_u_oldhead, NULL, NULL); if (seen_b_u_newhead == 0 && curbuf->b_u_oldhead != NULL - && !(newhead_may_be_NULL && curbuf->b_u_newhead == NULL)) + && !(newhead_may_be_NULL && curbuf->b_u_newhead == NULL)) { EMSGN("b_u_newhead invalid: 0x%x", curbuf->b_u_newhead); - if (curbuf->b_u_curhead != NULL && seen_b_u_curhead == 0) + } + if (curbuf->b_u_curhead != NULL && seen_b_u_curhead == 0) { EMSGN("b_u_curhead invalid: 0x%x", curbuf->b_u_curhead); + } if (header_count != curbuf->b_u_numhead) { EMSG("b_u_numhead invalid"); smsg("expected: %" PRId64 ", actual: %" PRId64, - (int64_t)header_count, (int64_t)curbuf->b_u_numhead); + (int64_t)header_count, (int64_t)curbuf->b_u_numhead); } } @@ -228,11 +228,12 @@ int u_save_cursor(void) int u_save(linenr_T top, linenr_T bot) { if (top >= bot || bot > (curbuf->b_ml.ml_line_count + 1)) { - return FAIL; /* rely on caller to do error messages */ + return FAIL; // rely on caller to do error messages } - if (top + 2 == bot) + if (top + 2 == bot) { u_saveline((linenr_T)(top + 1)); + } return u_savecommon(curbuf, top, bot, (linenr_T)0, false); } @@ -268,9 +269,8 @@ int u_inssub(linenr_T lnum) */ int u_savedel(linenr_T lnum, long nlines) { - return u_savecommon( - curbuf, lnum - 1, lnum + nlines, - nlines == curbuf->b_ml.ml_line_count ? 2 : lnum, false); + return u_savecommon(curbuf, lnum - 1, lnum + nlines, + nlines == curbuf->b_ml.ml_line_count ? 2 : lnum, false); } /// Return true when undo is allowed. Otherwise print an error message and @@ -327,16 +327,14 @@ static inline void zero_fmark_additional_data(fmark_T *fmarks) * Careful: may trigger autocommands that reload the buffer. * Returns FAIL when lines could not be saved, OK otherwise. */ -int u_savecommon(buf_T *buf, - linenr_T top, linenr_T bot, - linenr_T newbot, int reload) +int u_savecommon(buf_T *buf, linenr_T top, linenr_T bot, linenr_T newbot, int reload) { linenr_T lnum; long i; - u_header_T *uhp; - u_header_T *old_curhead; - u_entry_T *uep; - u_entry_T *prev_uep; + u_header_T *uhp; + u_header_T *old_curhead; + u_entry_T *uep; + u_entry_T *prev_uep; long size; if (!reload) { @@ -381,8 +379,9 @@ int u_savecommon(buf_T *buf, #ifdef U_DEBUG uhp->uh_magic = UH_MAGIC; #endif - } else + } else { uhp = NULL; + } /* * If we undid more than we redid, move the entry lists before and @@ -399,7 +398,7 @@ int u_savecommon(buf_T *buf, */ while (buf->b_u_numhead > get_undolevel(buf) && buf->b_u_oldhead != NULL) { - u_header_T *uhfree = buf->b_u_oldhead; + u_header_T *uhfree = buf->b_u_oldhead; if (uhfree == old_curhead) { // Can't reconnect the branch, delete all of it. @@ -459,11 +458,12 @@ int u_savecommon(buf_T *buf, uhp->uh_walk = 0; uhp->uh_entry = NULL; uhp->uh_getbot_entry = NULL; - uhp->uh_cursor = curwin->w_cursor; /* save cursor pos. for undo */ - if (virtual_active() && curwin->w_cursor.coladd > 0) + uhp->uh_cursor = curwin->w_cursor; // save cursor pos. for undo + if (virtual_active() && curwin->w_cursor.coladd > 0) { uhp->uh_cursor_vcol = getviscol(); - else + } else { uhp->uh_cursor_vcol = -1; + } // save changed and buffer empty flag for undo uhp->uh_flags = (buf->b_changed ? UH_CHANGED : 0) + @@ -499,8 +499,9 @@ int u_savecommon(buf_T *buf, uep = u_get_headentry(buf); prev_uep = NULL; for (i = 0; i < 10; ++i) { - if (uep == NULL) + if (uep == NULL) { break; + } /* If lines have been inserted/deleted we give up. * Also when the line was included in a multi-line save. */ @@ -509,14 +510,14 @@ int u_savecommon(buf_T *buf, != (uep->ue_bot == 0 ? buf->b_ml.ml_line_count + 1 : uep->ue_bot)) - : uep->ue_lcount != buf->b_ml.ml_line_count) + : uep->ue_lcount != buf->b_ml.ml_line_count) || (uep->ue_size > 1 && top >= uep->ue_top && top + 2 <= uep->ue_top + uep->ue_size + 1)) { break; } - /* If it's the same line we can skip saving it again. */ + // If it's the same line we can skip saving it again. if (uep->ue_size == 1 && uep->ue_top == top) { if (i > 0) { /* It's not the last entry: get ue_bot for the last @@ -609,25 +610,25 @@ int u_savecommon(buf_T *buf, // magic at start of undofile -# define UF_START_MAGIC "Vim\237UnDo\345" -# define UF_START_MAGIC_LEN 9 +#define UF_START_MAGIC "Vim\237UnDo\345" +#define UF_START_MAGIC_LEN 9 // magic at start of header -# define UF_HEADER_MAGIC 0x5fd0 +#define UF_HEADER_MAGIC 0x5fd0 // magic after last header -# define UF_HEADER_END_MAGIC 0xe7aa +#define UF_HEADER_END_MAGIC 0xe7aa // magic at start of entry -# define UF_ENTRY_MAGIC 0xf518 +#define UF_ENTRY_MAGIC 0xf518 // magic after last entry -# define UF_ENTRY_END_MAGIC 0x3581 +#define UF_ENTRY_END_MAGIC 0x3581 // 2-byte undofile version number -# define UF_VERSION 3 +#define UF_VERSION 3 -/* extra fields for header */ -# define UF_LAST_SAVE_NR 1 +// extra fields for header +#define UF_LAST_SAVE_NR 1 -/* extra fields for uhp */ -# define UHP_SAVE_NR 1 +// extra fields for uhp +#define UHP_SAVE_NR 1 static char_u e_not_open[] = N_("E828: Cannot open undo file for writing: %s"); @@ -640,7 +641,7 @@ void u_compute_hash(buf_T *buf, char_u *hash) { context_sha256_T ctx; linenr_T lnum; - char_u *p; + char_u *p; sha256_start(&ctx); for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) { @@ -688,7 +689,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) // Loop over 'undodir'. When reading find the first file that exists. // When not reading use the first directory that exists or ".". - dirp = (char *) p_udir; + dirp = (char *)p_udir; while (*dirp != NUL) { size_t dir_len = copy_option_part((char_u **)&dirp, (char_u *)dir_name, MAXPATHL, ","); @@ -698,7 +699,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) const size_t ffname_len = strlen(ffname); undo_file_name = xmalloc(ffname_len + 6); memmove(undo_file_name, ffname, ffname_len + 1); - char *const tail = (char *) path_tail((char_u *) undo_file_name); + char *const tail = (char *)path_tail((char_u *)undo_file_name); const size_t tail_len = strlen(tail); memmove(tail + 1, tail, tail_len + 1); *tail = '.'; @@ -754,8 +755,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) /// /// @param[in] mesg Identifier of the corruption kind. /// @param[in] file_name File in which error occurred. -static void corruption_error(const char *const mesg, - const char *const file_name) +static void corruption_error(const char *const mesg, const char *const file_name) FUNC_ATTR_NONNULL_ALL { EMSG3(_("E825: Corrupted undo file (%s): %s"), mesg, file_name); @@ -763,8 +763,8 @@ static void corruption_error(const char *const mesg, static void u_free_uhp(u_header_T *uhp) { - u_entry_T *nuep; - u_entry_T *uep; + u_entry_T *nuep; + u_entry_T *uep; uep = uhp->uh_entry; while (uep != NULL) { @@ -890,8 +890,7 @@ static bool serialize_uhp(bufinfo_T *bi, u_header_T *uhp) return true; } -static u_header_T *unserialize_uhp(bufinfo_T *bi, - const char *file_name) +static u_header_T *unserialize_uhp(bufinfo_T *bi, const char *file_name) { u_header_T *uhp = xmalloc(sizeof(u_header_T)); memset(uhp, 0, sizeof(u_header_T)); @@ -999,7 +998,7 @@ static bool serialize_extmark(bufinfo_T *bi, ExtmarkUndoObject extup) undo_write_bytes(bi, (uintmax_t)extup.type, 4); if (!undo_write(bi, (uint8_t *)&(extup.data.splice), sizeof(ExtmarkSplice))) { - return false; + return false; } } else if (extup.type == kExtmarkMove) { undo_write_bytes(bi, (uintmax_t)UF_ENTRY_MAGIC, 2); @@ -1013,8 +1012,7 @@ static bool serialize_extmark(bufinfo_T *bi, ExtmarkUndoObject extup) return true; } -static ExtmarkUndoObject *unserialize_extmark(bufinfo_T *bi, bool *error, - const char *filename) +static ExtmarkUndoObject *unserialize_extmark(bufinfo_T *bi, bool *error, const char *filename) { UndoObjectType type; uint8_t *buf = NULL; @@ -1039,7 +1037,7 @@ static ExtmarkUndoObject *unserialize_extmark(bufinfo_T *bi, bool *error, } extup->data.move = *(ExtmarkMove *)buf; } else { - goto error; + goto error; } xfree(buf); @@ -1080,8 +1078,7 @@ static bool serialize_uep(bufinfo_T *bi, u_entry_T *uep) return true; } -static u_entry_T *unserialize_uep(bufinfo_T * bi, bool *error, - const char *file_name) +static u_entry_T *unserialize_uep(bufinfo_T * bi, bool *error, const char *file_name) { u_entry_T *uep = xmalloc(sizeof(u_entry_T)); memset(uep, 0, sizeof(u_entry_T)); @@ -1171,24 +1168,23 @@ static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info) /// @param[in] buf Buffer for which undo file is written. /// @param[in] hash Hash value of the buffer text. Must have #UNDO_HASH_SIZE /// size. -void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, - char_u *const hash) +void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, char_u *const hash) FUNC_ATTR_NONNULL_ARG(3, 4) { - u_header_T *uhp; + u_header_T *uhp; char *file_name; int mark; #ifdef U_DEBUG int headers_written = 0; #endif int fd; - FILE *fp = NULL; + FILE *fp = NULL; int perm; bool write_ok = false; bufinfo_T bi; if (name == NULL) { - file_name = u_get_undo_file_name((char *) buf->b_ffname, false); + file_name = u_get_undo_file_name((char *)buf->b_ffname, false); if (file_name == NULL) { if (p_verbose > 0) { verbose_enter(); @@ -1198,7 +1194,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, return; } } else { - file_name = (char *) name; + file_name = (char *)name; } /* @@ -1221,16 +1217,18 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, * file, and delete it. */ if (os_path_exists((char_u *)file_name)) { if (name == NULL || !forceit) { - /* Check we can read it and it's an undo file. */ + // Check we can read it and it's an undo file. fd = os_open(file_name, O_RDONLY, 0); if (fd < 0) { if (name != NULL || p_verbose > 0) { - if (name == NULL) + if (name == NULL) { verbose_enter(); + } smsg(_("Will not overwrite with undo file, cannot read: %s"), file_name); - if (name == NULL) + if (name == NULL) { verbose_leave(); + } } goto theend; } else { @@ -1240,12 +1238,14 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, if (len < UF_START_MAGIC_LEN || memcmp(mbuf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) { if (name != NULL || p_verbose > 0) { - if (name == NULL) + if (name == NULL) { verbose_enter(); + } smsg(_("Will not overwrite, this is not an undo file: %s"), file_name); - if (name == NULL) + if (name == NULL) { verbose_leave(); + } } goto theend; } @@ -1276,7 +1276,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, } #ifdef U_DEBUG - /* Check there is no problem in undo info before writing. */ + // Check there is no problem in undo info before writing. u_check(FALSE); #endif @@ -1323,7 +1323,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, mark = ++lastmark; uhp = buf->b_u_oldhead; while (uhp != NULL) { - /* Serialize current UHP if we haven't seen it */ + // Serialize current UHP if we haven't seen it if (uhp->uh_walk != mark) { uhp->uh_walk = mark; #ifdef U_DEBUG @@ -1334,19 +1334,20 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, } } - /* Now walk through the tree - algorithm from undo_time(). */ - if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != mark) + // Now walk through the tree - algorithm from undo_time(). + if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != mark) { uhp = uhp->uh_prev.ptr; - else if (uhp->uh_alt_next.ptr != NULL - && uhp->uh_alt_next.ptr->uh_walk != mark) + } else if (uhp->uh_alt_next.ptr != NULL + && uhp->uh_alt_next.ptr->uh_walk != mark) { uhp = uhp->uh_alt_next.ptr; - else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL - && uhp->uh_next.ptr->uh_walk != mark) + } else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL + && uhp->uh_next.ptr->uh_walk != mark) { uhp = uhp->uh_next.ptr; - else if (uhp->uh_alt_prev.ptr != NULL) + } else if (uhp->uh_alt_prev.ptr != NULL) { uhp = uhp->uh_alt_prev.ptr; - else + } else { uhp = uhp->uh_next.ptr; + } } if (undo_write_bytes(&bi, (uintmax_t)UF_HEADER_END_MAGIC, 2)) { @@ -1361,14 +1362,15 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, write_error: fclose(fp); - if (!write_ok) + if (!write_ok) { EMSG2(_("E829: write error in undo file: %s"), file_name); + } #ifdef HAVE_ACL if (buf->b_ffname != NULL) { vim_acl_T acl; - /* For systems that support ACL: get the ACL from the original file. */ + // For systems that support ACL: get the ACL from the original file. acl = mch_get_acl(buf->b_ffname); mch_set_acl((char_u *)file_name, acl); mch_free_acl(acl); @@ -1376,8 +1378,9 @@ write_error: #endif theend: - if (file_name != name) + if (file_name != name) { xfree(file_name); + } } /// Loads the undo tree from an undo file. @@ -1385,8 +1388,7 @@ theend: /// a bit more verbose. /// Otherwise use curbuf->b_ffname to generate the undo file name. /// "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. -void u_read_undo(char *name, const char_u *hash, - const char_u *orig_name FUNC_ATTR_UNUSED) +void u_read_undo(char *name, const char_u *hash, const char_u *orig_name FUNC_ATTR_UNUSED) FUNC_ATTR_NONNULL_ARG(2) { u_header_T **uhp_table = NULL; @@ -1394,7 +1396,7 @@ void u_read_undo(char *name, const char_u *hash, char *file_name; if (name == NULL) { - file_name = u_get_undo_file_name((char *) curbuf->b_ffname, true); + file_name = u_get_undo_file_name((char *)curbuf->b_ffname, true); if (file_name == NULL) { return; } @@ -1418,7 +1420,7 @@ void u_read_undo(char *name, const char_u *hash, } #endif } else { - file_name = (char *) name; + file_name = (char *)name; } if (p_verbose > 0) { @@ -1465,7 +1467,7 @@ void u_read_undo(char *name, const char_u *hash, verbose_enter(); } give_warning((char_u *) - _("File contents changed, cannot use undo info"), true); + _("File contents changed, cannot use undo info"), true); if (name == NULL) { verbose_leave(); } @@ -1508,15 +1510,15 @@ void u_read_undo(char *name, const char_u *hash, } int what = undo_read_byte(&bi); switch (what) { - case UF_LAST_SAVE_NR: - last_save_nr = undo_read_4c(&bi); - break; + case UF_LAST_SAVE_NR: + last_save_nr = undo_read_4c(&bi); + break; - default: - // field not supported, skip - while (--len >= 0) { - (void)undo_read_byte(&bi); - } + default: + // field not supported, skip + while (--len >= 0) { + (void)undo_read_byte(&bi); + } } } @@ -1559,7 +1561,7 @@ void u_read_undo(char *name, const char_u *hash, size_t amount = num_head * sizeof(int) + 1; int *uhp_table_used = xmalloc(amount); memset(uhp_table_used, 0, amount); -# define SET_FLAG(j) ++ uhp_table_used[j] +# define SET_FLAG(j) ++uhp_table_used[j] #else # define SET_FLAG(j) #endif @@ -1666,10 +1668,11 @@ void u_read_undo(char *name, const char_u *hash, error: xfree(line_ptr); if (uhp_table != NULL) { - for (long i = 0; i < num_read_uhps; i++) + for (long i = 0; i < num_read_uhps; i++) { if (uhp_table[i] != NULL) { u_free_uhp(uhp_table[i]); } + } xfree(uhp_table); } @@ -1844,7 +1847,7 @@ bool u_undo_and_forget(int count) to_forget->uh_alt_next.ptr = NULL; curbuf->b_u_curhead->uh_alt_prev.ptr = to_forget->uh_alt_prev.ptr; curbuf->b_u_seq_cur = curbuf->b_u_curhead->uh_next.ptr ? - curbuf->b_u_curhead->uh_next.ptr->uh_seq : 0; + curbuf->b_u_curhead->uh_next.ptr->uh_seq : 0; } else if (curbuf->b_u_newhead) { curbuf->b_u_seq_cur = curbuf->b_u_newhead->uh_seq; } @@ -1876,8 +1879,9 @@ static void u_doit(int startcount, bool quiet, bool do_buf_event) u_newcount = 0; u_oldcount = 0; - if (curbuf->b_ml.ml_flags & ML_EMPTY) + if (curbuf->b_ml.ml_flags & ML_EMPTY) { u_oldcount = -1; + } while (count--) { /* Do the change warning now, so that it triggers FileChangedRO when * needed. This may cause the file to be reloaded, that must happen @@ -1894,7 +1898,7 @@ static void u_doit(int startcount, bool quiet, bool do_buf_event) } // nothing to undo if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL) { - /* stick curbuf->b_u_curhead at end */ + // stick curbuf->b_u_curhead at end curbuf->b_u_curhead = curbuf->b_u_oldhead; beep_flush(); if (count == startcount - 1) { @@ -1919,8 +1923,9 @@ static void u_doit(int startcount, bool quiet, bool do_buf_event) /* Advance for next redo. Set "newhead" when at the end of the * redoable changes. */ - if (curbuf->b_u_curhead->uh_prev.ptr == NULL) + if (curbuf->b_u_curhead->uh_prev.ptr == NULL) { curbuf->b_u_newhead = curbuf->b_u_curhead; + } curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev.ptr; } } @@ -1941,8 +1946,8 @@ void undo_time(long step, bool sec, bool file, bool absolute) long closest_start; long closest_seq = 0; long val; - u_header_T *uhp = NULL; - u_header_T *last; + u_header_T *uhp = NULL; + u_header_T *last; int mark; int nomark = 0; // shut up compiler int round; @@ -1958,8 +1963,9 @@ void undo_time(long step, bool sec, bool file, bool absolute) u_newcount = 0; u_oldcount = 0; - if (curbuf->b_ml.ml_flags & ML_EMPTY) + if (curbuf->b_ml.ml_flags & ML_EMPTY) { u_oldcount = -1; + } /* "target" is the node below which we want to be. * Init "closest" to a value we can't reach. */ @@ -1975,23 +1981,26 @@ void undo_time(long step, bool sec, bool file, bool absolute) * the last write, count that as moving one file-write, so * that ":earlier 1f" undoes all changes since the last save. */ uhp = curbuf->b_u_curhead; - if (uhp != NULL) + if (uhp != NULL) { uhp = uhp->uh_next.ptr; - else + } else { uhp = curbuf->b_u_newhead; - if (uhp != NULL && uhp->uh_save_nr != 0) + } + if (uhp != NULL && uhp->uh_save_nr != 0) { /* "uh_save_nr" was set in the last block, that means * there were no changes since the last write */ target = curbuf->b_u_save_nr_cur + step; - else - /* count the changes since the last write as one step */ + } else { + // count the changes since the last write as one step target = curbuf->b_u_save_nr_cur + step + 1; - if (target <= 0) + } + if (target <= 0) { /* Go to before first write: before the oldest change. Use * the sequence number for that. */ dofile = false; + } } else { - /* Moving forward to a newer write. */ + // Moving forward to a newer write. target = curbuf->b_u_save_nr_cur + step; if (target > curbuf->b_u_save_nr_last) { /* Go to after last write: after the latest change. Use @@ -2000,11 +2009,13 @@ void undo_time(long step, bool sec, bool file, bool absolute) dofile = false; } } - } else + } else { target = curbuf->b_u_seq_cur + step; + } if (step < 0) { - if (target < 0) + if (target < 0) { target = 0; + } closest = -1; } else { if (dosec) { @@ -2044,10 +2055,11 @@ void undo_time(long step, bool sec, bool file, bool absolute) mark = ++lastmark; nomark = ++lastmark; - if (curbuf->b_u_curhead == NULL) /* at leaf of the tree */ + if (curbuf->b_u_curhead == NULL) { // at leaf of the tree uhp = curbuf->b_u_newhead; - else + } else { uhp = curbuf->b_u_curhead; + } while (uhp != NULL) { uhp->uh_walk = mark; @@ -2065,17 +2077,17 @@ void undo_time(long step, bool sec, bool file, bool absolute) * "b_u_seq_cur"). When the timestamp is equal find the * highest/lowest sequence number. */ if ((step < 0 ? uhp->uh_seq <= curbuf->b_u_seq_cur - : uhp->uh_seq > curbuf->b_u_seq_cur) + : uhp->uh_seq > curbuf->b_u_seq_cur) && ((dosec && val == closest) ? (step < 0 ? uhp->uh_seq < closest_seq - : uhp->uh_seq > closest_seq) - : closest == closest_start + : uhp->uh_seq > closest_seq) + : closest == closest_start || (val > target ? (closest > target ? val - target <= closest - target : val - target <= target - closest) - : (closest > target + : (closest > target ? target - val <= closest - target : target - val <= target - closest)))) { closest = val; @@ -2090,38 +2102,41 @@ void undo_time(long step, bool sec, bool file, bool absolute) break; } - /* go down in the tree if we haven't been there */ + // go down in the tree if we haven't been there if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark - && uhp->uh_prev.ptr->uh_walk != mark) + && uhp->uh_prev.ptr->uh_walk != mark) { uhp = uhp->uh_prev.ptr; - - /* go to alternate branch if we haven't been there */ + } + // go to alternate branch if we haven't been there else if (uhp->uh_alt_next.ptr != NULL && uhp->uh_alt_next.ptr->uh_walk != nomark - && uhp->uh_alt_next.ptr->uh_walk != mark) + && uhp->uh_alt_next.ptr->uh_walk != mark) { uhp = uhp->uh_alt_next.ptr; - + } /* go up in the tree if we haven't been there and we are at the * start of alternate branches */ else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL && uhp->uh_next.ptr->uh_walk != nomark && uhp->uh_next.ptr->uh_walk != mark) { - /* If still at the start we don't go through this change. */ - if (uhp == curbuf->b_u_curhead) + // If still at the start we don't go through this change. + if (uhp == curbuf->b_u_curhead) { uhp->uh_walk = nomark; + } uhp = uhp->uh_next.ptr; } else { - /* need to backtrack; mark this node as useless */ + // need to backtrack; mark this node as useless uhp->uh_walk = nomark; - if (uhp->uh_alt_prev.ptr != NULL) + if (uhp->uh_alt_prev.ptr != NULL) { uhp = uhp->uh_alt_prev.ptr; - else + } else { uhp = uhp->uh_next.ptr; + } } } - if (uhp != NULL) /* found it */ + if (uhp != NULL) { // found it break; + } if (absolute) { EMSGN(_("E830: Undo number %" PRId64 " not found"), step); @@ -2129,10 +2144,11 @@ void undo_time(long step, bool sec, bool file, bool absolute) } if (closest == closest_start) { - if (step < 0) + if (step < 0) { MSG(_("Already at oldest change")); - else + } else { MSG(_("Already at newest change")); + } return; } @@ -2153,10 +2169,11 @@ target_zero: change_warning(curbuf, 0); uhp = curbuf->b_u_curhead; - if (uhp == NULL) + if (uhp == NULL) { uhp = curbuf->b_u_newhead; - else + } else { uhp = uhp->uh_next.ptr; + } if (uhp == NULL || (target > 0 && uhp->uh_walk != mark) || (uhp->uh_seq == target && !above)) { @@ -2264,21 +2281,21 @@ target_zero: /// @param do_buf_event If `true`, send buffer updates. static void u_undoredo(int undo, bool do_buf_event) { - char_u **newarray = NULL; + char_u **newarray = NULL; linenr_T oldsize; linenr_T newsize; linenr_T top, bot; linenr_T lnum; linenr_T newlnum = MAXLNUM; long i; - u_entry_T *uep, *nuep; - u_entry_T *newlist = NULL; + u_entry_T *uep, *nuep; + u_entry_T *newlist = NULL; int old_flags; int new_flags; fmark_T namedm[NMARKS]; visualinfo_T visualinfo; bool empty_buffer; // buffer became empty - u_header_T *curhead = curbuf->b_u_curhead; + u_header_T *curhead = curbuf->b_u_curhead; /* Don't want autocommands using the undo structures here, they are * invalid till the end. */ @@ -2307,8 +2324,9 @@ static void u_undoredo(int undo, bool do_buf_event) for (uep = curhead->uh_entry; uep != NULL; uep = nuep) { top = uep->ue_top; bot = uep->ue_bot; - if (bot == 0) + if (bot == 0) { bot = curbuf->b_ml.ml_line_count + 1; + } if (top > curbuf->b_ml.ml_line_count || top >= bot || bot > curbuf->b_ml.ml_line_count + 1) { unblock_autocmds(); @@ -2317,8 +2335,8 @@ static void u_undoredo(int undo, bool do_buf_event) return; } - oldsize = bot - top - 1; /* number of lines before undo */ - newsize = uep->ue_size; /* number of lines after undo */ + oldsize = bot - top - 1; // number of lines before undo + newsize = uep->ue_size; // number of lines after undo if (top < newlnum) { /* If the saved cursor is somewhere in this undo block, move it to @@ -2332,13 +2350,15 @@ static void u_undoredo(int undo, bool do_buf_event) /* Use the first line that actually changed. Avoids that * undoing auto-formatting puts the cursor in the previous * line. */ - for (i = 0; i < newsize && i < oldsize; ++i) - if (STRCMP(uep->ue_array[i], ml_get(top + 1 + i)) != 0) + for (i = 0; i < newsize && i < oldsize; ++i) { + if (STRCMP(uep->ue_array[i], ml_get(top + 1 + i)) != 0) { break; + } + } if (i == newsize && newlnum == MAXLNUM && uep->ue_next == NULL) { newlnum = top; curwin->w_cursor.lnum = newlnum + 1; - } else if (i < newsize) { + } else if (i < newsize) { newlnum = top + i; curwin->w_cursor.lnum = newlnum + 1; } @@ -2347,12 +2367,12 @@ static void u_undoredo(int undo, bool do_buf_event) empty_buffer = false; - /* delete the lines between top and bot and save them in newarray */ + // delete the lines between top and bot and save them in newarray if (oldsize > 0) { newarray = xmalloc(sizeof(char_u *) * (size_t)oldsize); - /* delete backwards, it goes faster in most cases */ + // delete backwards, it goes faster in most cases for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum) { - /* what can we do when we run out of memory? */ + // what can we do when we run out of memory? newarray[i] = u_save_line(lnum); /* remember we deleted the last line in the buffer, and a * dummy empty line will be inserted */ @@ -2361,10 +2381,11 @@ static void u_undoredo(int undo, bool do_buf_event) } ml_delete(lnum, false); } - } else + } else { newarray = NULL; + } - /* insert the lines in u_array between top and bot */ + // insert the lines in u_array between top and bot if (newsize) { for (lnum = top, i = 0; i < newsize; ++i, ++lnum) { /* @@ -2395,13 +2416,15 @@ static void u_undoredo(int undo, bool do_buf_event) changed_lines(top + 1, 0, bot, newsize - oldsize, do_buf_event); - /* set '[ and '] mark */ - if (top + 1 < curbuf->b_op_start.lnum) + // set '[ and '] mark + if (top + 1 < curbuf->b_op_start.lnum) { curbuf->b_op_start.lnum = top + 1; - if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) + } + if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) { curbuf->b_op_end.lnum = top + 1; - else if (top + newsize > curbuf->b_op_end.lnum) + } else if (top + newsize > curbuf->b_op_end.lnum) { curbuf->b_op_end.lnum = top + newsize; + } u_newcount += newsize; u_oldcount += oldsize; @@ -2424,7 +2447,7 @@ static void u_undoredo(int undo, bool do_buf_event) undo_info = kv_A(curhead->uh_extmark, i); extmark_apply_undo(undo_info, undo); } - // redo + // redo } else { for (i = 0; i < (int)kv_size(curhead->uh_extmark); i++) { undo_info = kv_A(curhead->uh_extmark, i); @@ -2482,17 +2505,20 @@ static void u_undoredo(int undo, bool do_buf_event) * Otherwise the cursor should go to the first undone line. */ if (curhead->uh_cursor.lnum + 1 == curwin->w_cursor.lnum - && curwin->w_cursor.lnum > 1) + && curwin->w_cursor.lnum > 1) { --curwin->w_cursor.lnum; + } if (curwin->w_cursor.lnum <= curbuf->b_ml.ml_line_count) { if (curhead->uh_cursor.lnum == curwin->w_cursor.lnum) { curwin->w_cursor.col = curhead->uh_cursor.col; - if (virtual_active() && curhead->uh_cursor_vcol >= 0) + if (virtual_active() && curhead->uh_cursor_vcol >= 0) { coladvance((colnr_T)curhead->uh_cursor_vcol); - else + } else { curwin->w_cursor.coladd = 0; - } else + } + } else { beginline(BL_SOL | BL_FIX); + } } else { /* We get here with the current cursor line being past the end (eg * after adding lines at the end of the file, and then undoing it). @@ -2502,23 +2528,25 @@ static void u_undoredo(int undo, bool do_buf_event) curwin->w_cursor.coladd = 0; } - /* Make sure the cursor is on an existing line and column. */ + // Make sure the cursor is on an existing line and column. check_cursor(); - /* Remember where we are for "g-" and ":earlier 10s". */ + // Remember where we are for "g-" and ":earlier 10s". curbuf->b_u_seq_cur = curhead->uh_seq; - if (undo) + if (undo) { /* We are below the previous undo. However, to make ":earlier 1s" * work we compute this as being just above the just undone change. */ curbuf->b_u_seq_cur = curhead->uh_next.ptr ? - curhead->uh_next.ptr->uh_seq : 0; + curhead->uh_next.ptr->uh_seq : 0; + } - /* Remember where we are for ":earlier 1f" and ":later 1f". */ + // Remember where we are for ":earlier 1f" and ":later 1f". if (curhead->uh_save_nr != 0) { - if (undo) + if (undo) { curbuf->b_u_save_nr_cur = curhead->uh_save_nr - 1; - else + } else { curbuf->b_u_save_nr_cur = curhead->uh_save_nr; + } } /* The timestamp can be the same for multiple changes, just use the one of @@ -2534,17 +2562,18 @@ static void u_undoredo(int undo, bool do_buf_event) /// If we deleted or added lines, report the number of less/more lines. /// Otherwise, report the number of changes (this may be incorrect /// in some cases, but it's better than nothing). -static void u_undo_end( - bool did_undo, ///< just did an undo - bool absolute, ///< used ":undo N" - bool quiet) +/// +/// @param did_undo just did an undo +/// @param absolute used ":undo N" +static void u_undo_end(bool did_undo, bool absolute, bool quiet) { - char *msgstr; - u_header_T *uhp; + char *msgstr; + u_header_T *uhp; char_u msgbuf[80]; - if ((fdo_flags & FDO_UNDO) && KeyTyped) + if ((fdo_flags & FDO_UNDO) && KeyTyped) { foldOpenCursor(); + } if (quiet || global_busy // no messages until global is finished @@ -2552,28 +2581,30 @@ static void u_undo_end( return; } - if (curbuf->b_ml.ml_flags & ML_EMPTY) + if (curbuf->b_ml.ml_flags & ML_EMPTY) { --u_newcount; + } u_oldcount -= u_newcount; - if (u_oldcount == -1) + if (u_oldcount == -1) { msgstr = N_("more line"); - else if (u_oldcount < 0) + } else if (u_oldcount < 0) { msgstr = N_("more lines"); - else if (u_oldcount == 1) + } else if (u_oldcount == 1) { msgstr = N_("line less"); - else if (u_oldcount > 1) + } else if (u_oldcount > 1) { msgstr = N_("fewer lines"); - else { + } else { u_oldcount = u_newcount; - if (u_newcount == 1) + if (u_newcount == 1) { msgstr = N_("change"); - else + } else { msgstr = N_("changes"); + } } if (curbuf->b_u_curhead != NULL) { - /* For ":undo N" we prefer a "after #N" message. */ + // For ":undo N" we prefer a "after #N" message. if (absolute && curbuf->b_u_curhead->uh_next.ptr != NULL) { uhp = curbuf->b_u_curhead->uh_next.ptr; did_undo = false; @@ -2600,14 +2631,13 @@ static void u_undo_end( } } - smsg_attr_keep( - 0, - _("%" PRId64 " %s; %s #%" PRId64 " %s"), - u_oldcount < 0 ? (int64_t)-u_oldcount : (int64_t)u_oldcount, - _(msgstr), - did_undo ? _("before") : _("after"), - uhp == NULL ? (int64_t)0L : (int64_t)uhp->uh_seq, - msgbuf); + smsg_attr_keep(0, + _("%" PRId64 " %s; %s #%" PRId64 " %s"), + u_oldcount < 0 ? (int64_t)-u_oldcount : (int64_t)u_oldcount, + _(msgstr), + did_undo ? _("before") : _("after"), + uhp == NULL ? (int64_t)0L : (int64_t)uhp->uh_seq, + msgbuf); } /// u_sync: stop adding to the current entry list @@ -2634,7 +2664,7 @@ void u_sync(bool force) void ex_undolist(exarg_T *eap) { garray_T ga; - u_header_T *uhp; + u_header_T *uhp; int mark; int nomark; int changes = 1; @@ -2657,28 +2687,29 @@ void ex_undolist(exarg_T *eap) add_time(IObuff + STRLEN(IObuff), IOSIZE - STRLEN(IObuff), uhp->uh_time); if (uhp->uh_save_nr > 0) { - while (STRLEN(IObuff) < 33) + while (STRLEN(IObuff) < 33) { STRCAT(IObuff, " "); + } vim_snprintf_add((char *)IObuff, IOSIZE, - " %3ld", uhp->uh_save_nr); + " %3ld", uhp->uh_save_nr); } GA_APPEND(char_u *, &ga, vim_strsave(IObuff)); } uhp->uh_walk = mark; - /* go down in the tree if we haven't been there */ + // go down in the tree if we haven't been there if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark && uhp->uh_prev.ptr->uh_walk != mark) { uhp = uhp->uh_prev.ptr; ++changes; } - /* go to alternate branch if we haven't been there */ + // go to alternate branch if we haven't been there else if (uhp->uh_alt_next.ptr != NULL && uhp->uh_alt_next.ptr->uh_walk != nomark - && uhp->uh_alt_next.ptr->uh_walk != mark) + && uhp->uh_alt_next.ptr->uh_walk != mark) { uhp = uhp->uh_alt_next.ptr; - + } /* go up in the tree if we haven't been there and we are at the * start of alternate branches */ else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL @@ -2687,20 +2718,20 @@ void ex_undolist(exarg_T *eap) uhp = uhp->uh_next.ptr; --changes; } else { - /* need to backtrack; mark this node as done */ + // need to backtrack; mark this node as done uhp->uh_walk = nomark; - if (uhp->uh_alt_prev.ptr != NULL) + if (uhp->uh_alt_prev.ptr != NULL) { uhp = uhp->uh_alt_prev.ptr; - else { + } else { uhp = uhp->uh_next.ptr; --changes; } } } - if (GA_EMPTY(&ga)) + if (GA_EMPTY(&ga)) { MSG(_("Nothing to undo")); - else { + } else { sort_strings((char_u **)ga.ga_data, ga.ga_len); msg_start(); @@ -2757,17 +2788,18 @@ void u_unchanged(buf_T *buf) */ void u_find_first_changed(void) { - u_header_T *uhp = curbuf->b_u_newhead; - u_entry_T *uep; + u_header_T *uhp = curbuf->b_u_newhead; + u_entry_T *uep; linenr_T lnum; - if (curbuf->b_u_curhead != NULL || uhp == NULL) - return; /* undid something in an autocmd? */ - - /* Check that the last undo block was for the whole file. */ + if (curbuf->b_u_curhead != NULL || uhp == NULL) { + return; // undid something in an autocmd? + } + // Check that the last undo block was for the whole file. uep = uhp->uh_entry; - if (uep->ue_top != 0 || uep->ue_bot != 0) + if (uep->ue_top != 0 || uep->ue_bot != 0) { return; + } for (lnum = 1; lnum < curbuf->b_ml.ml_line_count && lnum <= uep->ue_size; lnum++) { @@ -2778,7 +2810,7 @@ void u_find_first_changed(void) } } if (curbuf->b_ml.ml_line_count != uep->ue_size) { - /* lines added or deleted at the end, put the cursor there */ + // lines added or deleted at the end, put the cursor there clearpos(&(uhp->uh_cursor)); uhp->uh_cursor.lnum = lnum; } @@ -2790,27 +2822,30 @@ void u_find_first_changed(void) */ void u_update_save_nr(buf_T *buf) { - u_header_T *uhp; + u_header_T *uhp; ++buf->b_u_save_nr_last; buf->b_u_save_nr_cur = buf->b_u_save_nr_last; uhp = buf->b_u_curhead; - if (uhp != NULL) + if (uhp != NULL) { uhp = uhp->uh_next.ptr; - else + } else { uhp = buf->b_u_newhead; - if (uhp != NULL) + } + if (uhp != NULL) { uhp->uh_save_nr = buf->b_u_save_nr_last; + } } static void u_unch_branch(u_header_T *uhp) { - u_header_T *uh; + u_header_T *uh; for (uh = uhp; uh != NULL; uh = uh->uh_prev.ptr) { uh->uh_flags |= UH_CHANGED; - if (uh->uh_alt_next.ptr != NULL) - u_unch_branch(uh->uh_alt_next.ptr); /* recursive */ + if (uh->uh_alt_next.ptr != NULL) { + u_unch_branch(uh->uh_alt_next.ptr); // recursive + } } } @@ -2829,11 +2864,11 @@ static u_entry_T *u_get_headentry(buf_T *buf) /* * u_getbot(): compute the line number of the previous u_save - * It is called only when b_u_synced is false. + * It is called only when b_u_synced is false. */ static void u_getbot(buf_T *buf) { - u_entry_T *uep; + u_entry_T *uep; linenr_T extra; uep = u_get_headentry(buf); // check for corrupt undo list @@ -2864,95 +2899,91 @@ static void u_getbot(buf_T *buf) buf->b_u_synced = true; } -/* - * Free one header "uhp" and its entry list and adjust the pointers. - */ -static void -u_freeheader( - buf_T *buf, - u_header_T *uhp, - u_header_T **uhpp // if not NULL reset when freeing this header -) +/// Free one header "uhp" and its entry list and adjust the pointers. +/// +/// @param uhpp if not NULL reset when freeing this header +static void u_freeheader(buf_T *buf, u_header_T *uhp, u_header_T **uhpp) { - u_header_T *uhap; + u_header_T *uhap; /* When there is an alternate redo list free that branch completely, * because we can never go there. */ - if (uhp->uh_alt_next.ptr != NULL) + if (uhp->uh_alt_next.ptr != NULL) { u_freebranch(buf, uhp->uh_alt_next.ptr, uhpp); + } - if (uhp->uh_alt_prev.ptr != NULL) + if (uhp->uh_alt_prev.ptr != NULL) { uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL; + } - /* Update the links in the list to remove the header. */ - if (uhp->uh_next.ptr == NULL) + // Update the links in the list to remove the header. + if (uhp->uh_next.ptr == NULL) { buf->b_u_oldhead = uhp->uh_prev.ptr; - else + } else { uhp->uh_next.ptr->uh_prev.ptr = uhp->uh_prev.ptr; + } - if (uhp->uh_prev.ptr == NULL) + if (uhp->uh_prev.ptr == NULL) { buf->b_u_newhead = uhp->uh_next.ptr; - else + } else { for (uhap = uhp->uh_prev.ptr; uhap != NULL; - uhap = uhap->uh_alt_next.ptr) + uhap = uhap->uh_alt_next.ptr) { uhap->uh_next.ptr = uhp->uh_next.ptr; + } + } u_freeentries(buf, uhp, uhpp); } -/* - * Free an alternate branch and any following alternate branches. - */ -static void -u_freebranch( - buf_T *buf, - u_header_T *uhp, - u_header_T **uhpp // if not NULL reset when freeing this header -) +/// Free an alternate branch and any following alternate branches. +/// +/// @param uhpp if not NULL reset when freeing this header +static void u_freebranch(buf_T *buf, u_header_T *uhp, u_header_T **uhpp) { - u_header_T *tofree, *next; + u_header_T *tofree, *next; /* If this is the top branch we may need to use u_freeheader() to update * all the pointers. */ if (uhp == buf->b_u_oldhead) { - while (buf->b_u_oldhead != NULL) + while (buf->b_u_oldhead != NULL) { u_freeheader(buf, buf->b_u_oldhead, uhpp); + } return; } - if (uhp->uh_alt_prev.ptr != NULL) + if (uhp->uh_alt_prev.ptr != NULL) { uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL; + } next = uhp; while (next != NULL) { tofree = next; - if (tofree->uh_alt_next.ptr != NULL) - u_freebranch(buf, tofree->uh_alt_next.ptr, uhpp); /* recursive */ + if (tofree->uh_alt_next.ptr != NULL) { + u_freebranch(buf, tofree->uh_alt_next.ptr, uhpp); // recursive + } next = tofree->uh_prev.ptr; u_freeentries(buf, tofree, uhpp); } } -/* - * Free all the undo entries for one header and the header itself. - * This means that "uhp" is invalid when returning. - */ -static void -u_freeentries( - buf_T *buf, - u_header_T *uhp, - u_header_T **uhpp // if not NULL reset when freeing this header -) +/// Free all the undo entries for one header and the header itself. +/// This means that "uhp" is invalid when returning. +/// +/// @param uhpp if not NULL reset when freeing this header +static void u_freeentries(buf_T *buf, u_header_T *uhp, u_header_T **uhpp) { - u_entry_T *uep, *nuep; + u_entry_T *uep, *nuep; - /* Check for pointers to the header that become invalid now. */ - if (buf->b_u_curhead == uhp) + // Check for pointers to the header that become invalid now. + if (buf->b_u_curhead == uhp) { buf->b_u_curhead = NULL; - if (buf->b_u_newhead == uhp) - buf->b_u_newhead = NULL; /* freeing the newest entry */ - if (uhpp != NULL && uhp == *uhpp) + } + if (buf->b_u_newhead == uhp) { + buf->b_u_newhead = NULL; // freeing the newest entry + } + if (uhpp != NULL && uhp == *uhpp) { *uhpp = NULL; + } for (uep = uhp->uh_entry; uep != NULL; uep = nuep) { nuep = uep->ue_next; @@ -2973,8 +3004,9 @@ u_freeentries( */ static void u_freeentry(u_entry_T *uep, long n) { - while (n > 0) + while (n > 0) { xfree(uep->ue_array[--n]); + } xfree((char_u *)uep->ue_array); #ifdef U_DEBUG uep->ue_magic = 0; @@ -2999,16 +3031,19 @@ void u_clearall(buf_T *buf) */ void u_saveline(linenr_T lnum) { - if (lnum == curbuf->b_u_line_lnum) /* line is already saved */ + if (lnum == curbuf->b_u_line_lnum) { // line is already saved return; - if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) /* should never happen */ + } + if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) { // should never happen return; + } u_clearline(); curbuf->b_u_line_lnum = lnum; - if (curwin->w_cursor.lnum == lnum) + if (curwin->w_cursor.lnum == lnum) { curbuf->b_u_line_colnr = curwin->w_cursor.col; - else + } else { curbuf->b_u_line_colnr = 0; + } curbuf->b_u_line_ptr = u_save_line(lnum); } @@ -3033,7 +3068,7 @@ void u_clearline(void) void u_undoline(void) { colnr_T t; - char_u *oldp; + char_u *oldp; if (curbuf->b_u_line_ptr == NULL || curbuf->b_u_line_lnum > curbuf->b_ml.ml_line_count) { @@ -3054,8 +3089,9 @@ void u_undoline(void) curbuf->b_u_line_ptr = oldp; t = curbuf->b_u_line_colnr; - if (curwin->w_cursor.lnum == curbuf->b_u_line_lnum) + if (curwin->w_cursor.lnum == curbuf->b_u_line_lnum) { curbuf->b_u_line_colnr = curwin->w_cursor.col; + } curwin->w_cursor.col = t; curwin->w_cursor.lnum = curbuf->b_u_line_lnum; check_cursor_col(); @@ -3106,8 +3142,8 @@ bool bufIsChanged(buf_T *buf) { // In a "prompt" buffer we do respect 'modified', so that we can control // closing the window by setting or resetting that option. - return (!bt_dontwrite(buf) || bt_prompt(buf)) - && (buf->b_changed || file_ff_differs(buf, true)); + return (!bt_dontwrite(buf) || bt_prompt(buf)) + && (buf->b_changed || file_ff_differs(buf, true)); } // Return true if any buffer has changes. Also buffers that are not written. diff --git a/src/nvim/version.c b/src/nvim/version.c index 7c197f1b7f..a42164903d 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -6,32 +6,32 @@ /// Nvim was forked from Vim 7.4.160. /// Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred). -#include <inttypes.h> #include <assert.h> +#include <inttypes.h> #include <limits.h> #include "nvim/api/private/helpers.h" -#include "nvim/vim.h" #include "nvim/ascii.h" #include "nvim/buffer.h" -#include "nvim/iconv.h" -#include "nvim/version.h" #include "nvim/charset.h" +#include "nvim/iconv.h" +#include "nvim/lua/executor.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/screen.h" #include "nvim/strings.h" -#include "nvim/lua/executor.h" +#include "nvim/version.h" +#include "nvim/vim.h" // version info generated by the build system #include "auto/versiondef.h" // for ":version", ":intro", and "nvim --version" #ifndef NVIM_VERSION_MEDIUM -#define NVIM_VERSION_MEDIUM "v" STR(NVIM_VERSION_MAJOR)\ -"." STR(NVIM_VERSION_MINOR) "." STR(NVIM_VERSION_PATCH)\ -NVIM_VERSION_PRERELEASE +# define NVIM_VERSION_MEDIUM "v" STR(NVIM_VERSION_MAJOR)\ + "." STR(NVIM_VERSION_MINOR) "." STR(NVIM_VERSION_PATCH)\ + NVIM_VERSION_PRERELEASE #endif #define NVIM_VERSION_LONG "NVIM " NVIM_VERSION_MEDIUM @@ -50,23 +50,23 @@ char *version_cflags = "Compilation: " NVIM_VERSION_CFLAGS; static char *features[] = { #ifdef HAVE_ACL -"+acl", + "+acl", #else -"-acl", + "-acl", #endif #if defined(HAVE_ICONV) -"+iconv", + "+iconv", #else -"-iconv", + "-iconv", #endif #ifdef FEAT_TUI -"+tui", + "+tui", #else -"-tui", + "-tui", #endif -NULL + NULL }; // clang-format off diff --git a/src/uncrustify.cfg b/src/uncrustify.cfg index 05f133fa49..db0c50ff22 100644 --- a/src/uncrustify.cfg +++ b/src/uncrustify.cfg @@ -1,4 +1,4 @@ -# Uncrustify-0.73.0-186-03faf73c5 +# Uncrustify-0.73.0-195-1f883c691 # # General options @@ -535,14 +535,21 @@ sp_inside_braces_struct = ignore # ignore/add/remove/force/not_defined sp_inside_braces_oc_dict = ignore # ignore/add/remove/force/not_defined # Add or remove space after open brace in an unnamed temporary -# direct-list-initialization. +# direct-list-initialization +# if statement is a brace_init_lst +# works only if sp_brace_brace is set to ignore. sp_after_type_brace_init_lst_open = ignore # ignore/add/remove/force/not_defined # Add or remove space before close brace in an unnamed temporary -# direct-list-initialization. +# direct-list-initialization +# if statement is a brace_init_lst +# works only if sp_brace_brace is set to ignore. sp_before_type_brace_init_lst_close = ignore # ignore/add/remove/force/not_defined -# Add or remove space inside an unnamed temporary direct-list-initialization. +# Add or remove space inside an unnamed temporary direct-list-initialization +# if statement is a brace_init_lst +# works only if sp_brace_brace is set to ignore +# works only if sp_before_type_brace_init_lst_close is set to ignore. sp_inside_type_brace_init_lst = ignore # ignore/add/remove/force/not_defined # Add or remove space inside '{' and '}'. |