refactor: format with uncrustify #15741

This commit is contained in:
dundargoc
2021-09-22 15:25:38 +02:00
committed by GitHub
parent fb6f27e86f
commit 48e67b2294
13 changed files with 2654 additions and 2393 deletions

View File

@@ -3,25 +3,22 @@
#define EXTERN
#include <assert.h>
#include <msgpack.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <msgpack.h>
#include "nvim/ascii.h"
#include "nvim/channel.h"
#include "nvim/vim.h"
#include "nvim/main.h"
#include "nvim/aucmd.h"
#include "nvim/buffer.h"
#include "nvim/channel.h"
#include "nvim/charset.h"
#include "nvim/decoration.h"
#include "nvim/diff.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/decoration.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
@@ -30,29 +27,36 @@
#include "nvim/iconv.h"
#include "nvim/if_cscope.h"
#include "nvim/lua/executor.h"
#include "nvim/main.h"
#include "nvim/vim.h"
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
#include "nvim/garray.h"
#include "nvim/log.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/garray.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/move.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/os_unix.h"
#include "nvim/os/fileio.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/os_defs.h"
#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/profile.h"
#include "nvim/popupmnu.h"
#include "nvim/profile.h"
#include "nvim/quickfix.h"
#include "nvim/screen.h"
#include "nvim/shada.h"
#include "nvim/sign.h"
#include "nvim/state.h"
#include "nvim/strings.h"
@@ -61,24 +65,19 @@
#include "nvim/ui_compositor.h"
#include "nvim/version.h"
#include "nvim/window.h"
#include "nvim/shada.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/os/fileio.h"
#ifdef WIN32
# include "nvim/os/os_win_console.h"
#endif
#include "nvim/api/private/defs.h"
#include "nvim/api/private/dispatch.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/ui.h"
#include "nvim/event/loop.h"
#include "nvim/os/signal.h"
#include "nvim/event/process.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/msgpack_rpc/server.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/api/ui.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/dispatch.h"
#include "nvim/os/signal.h"
#ifndef WIN32
# include "nvim/os/pty_process_unix.h"
#endif
@@ -278,9 +277,9 @@ int main(int argc, char **argv)
TIME_MSG("expanding arguments");
if (params.diff_mode && params.window_count == -1)
params.window_count = 0; /* open up to 3 windows */
if (params.diff_mode && params.window_count == -1) {
params.window_count = 0; // open up to 3 windows
}
// Don't redraw until much later.
RedrawingDisabled++;
@@ -586,15 +585,16 @@ void getout(int exitval)
/* When running in Ex mode an error causes us to exit with a non-zero exit
* code. POSIX requires this, although it's not 100% clear from the
* standard. */
if (exmode_active)
if (exmode_active) {
exitval += ex_exitval;
}
set_vim_var_nr(VV_EXITING, exitval);
// Position the cursor on the last screen line, below all the text
ui_cursor_goto(Rows - 1, 0);
/* Optionally print hashtable efficiency. */
// Optionally print hashtable efficiency.
hash_debug_results();
if (v_dying <= 1) {
@@ -605,7 +605,7 @@ void getout(int exitval)
next_tp = tp->tp_next;
FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
if (wp->w_buffer == NULL) {
/* Autocmd must have close the buffer already, skip. */
// Autocmd must have close the buffer already, skip.
continue;
}
@@ -626,7 +626,7 @@ void getout(int exitval)
}
}
/* Trigger BufUnload for buffers that are loaded */
// Trigger BufUnload for buffers that are loaded
FOR_ALL_BUFFERS(buf) {
if (buf->b_ml.ml_mfp != NULL) {
bufref_T bufref;
@@ -675,7 +675,7 @@ void getout(int exitval)
if (did_emsg
) {
/* give the user a chance to read the (error) message */
// give the user a chance to read the (error) message
no_wait_return = FALSE;
wait_return(FALSE);
}
@@ -727,7 +727,7 @@ static void init_locale(void)
setlocale(LC_ALL, "");
# ifdef LC_NUMERIC
/* Make sure strtod() uses a decimal point, not a comma. */
// Make sure strtod() uses a decimal point, not a comma.
setlocale(LC_NUMERIC, "C");
# endif
@@ -789,7 +789,7 @@ static void command_line_scan(mparm_T *parmp)
want_argument = false;
c = argv[0][argv_idx++];
switch (c) {
case NUL: { // "nvim -" read from stdin
case NUL: // "nvim -" read from stdin
if (exmode_active) {
// "nvim -e -" silent mode
silent_mode = true;
@@ -805,8 +805,7 @@ static void command_line_scan(mparm_T *parmp)
}
argv_idx = -1; // skip to next argument
break;
}
case '-': { // "--" don't take any more option arguments
case '-': // "--" don't take any more option arguments
// "--help" give help message
// "--version" give version message
// "--noplugin[s]" skip plugins
@@ -862,100 +861,84 @@ static void command_line_scan(mparm_T *parmp)
parmp->clean = true;
set_option_value("shadafile", 0L, "NONE", 0);
} else {
if (argv[0][argv_idx])
if (argv[0][argv_idx]) {
mainerr(err_opt_unknown, argv[0]);
}
had_minmin = true;
}
if (!want_argument) {
argv_idx = -1; // skip to next argument
}
break;
}
case 'A': { // "-A" start in Arabic mode.
case 'A': // "-A" start in Arabic mode.
set_option_value("arabic", 1L, NULL, 0);
break;
}
case 'b': { // "-b" binary mode.
case 'b': // "-b" binary mode.
// Needs to be effective before expanding file names, because
// for Win32 this makes us edit a shortcut file itself,
// instead of the file it links to.
set_options_bin(curbuf->b_p_bin, 1, 0);
curbuf->b_p_bin = 1; // Binary file I/O.
break;
}
case 'D': { // "-D" Debugging
case 'D': // "-D" Debugging
parmp->use_debug_break_level = 9999;
break;
}
case 'd': { // "-d" 'diff'
case 'd': // "-d" 'diff'
parmp->diff_mode = true;
break;
}
case 'e': { // "-e" Ex mode
case 'e': // "-e" Ex mode
exmode_active = true;
break;
}
case 'E': { // "-E" Ex mode
case 'E': // "-E" Ex mode
exmode_active = true;
parmp->input_neverscript = true;
break;
}
case 'f': { // "-f" GUI: run in foreground.
case 'f': // "-f" GUI: run in foreground.
break;
}
case '?': // "-?" give help message (for MS-Windows)
case 'h': { // "-h" give help message
case 'h': // "-h" give help message
usage();
os_exit(0);
}
case 'H': { // "-H" start in Hebrew mode: rl + hkmap set.
case 'H': // "-H" start in Hebrew mode: rl + hkmap set.
p_hkmap = true;
set_option_value("rl", 1L, NULL, 0);
break;
}
case 'l': { // "-l" lisp mode, 'lisp' and 'showmatch' on.
case 'l': // "-l" lisp mode, 'lisp' and 'showmatch' on.
set_option_value("lisp", 1L, NULL, 0);
p_sm = true;
break;
}
case 'M': { // "-M" no changes or writing of files
case 'M': // "-M" no changes or writing of files
reset_modifiable();
FALLTHROUGH;
}
case 'm': { // "-m" no writing of files
case 'm': // "-m" no writing of files
p_write = false;
break;
}
case 'N': // "-N" Nocompatible
case 'X': // "-X" Do not connect to X server
// No-op
break;
case 'n': { // "-n" no swap file
case 'n': // "-n" no swap file
parmp->no_swap_file = true;
break;
}
case 'p': { // "-p[N]" open N tab pages
case 'p': // "-p[N]" open N tab pages
// default is 0: open window for each file
parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
parmp->window_layout = WIN_TABS;
break;
}
case 'o': { // "-o[N]" open N horizontal split windows
case 'o': // "-o[N]" open N horizontal split windows
// default is 0: open window for each file
parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
parmp->window_layout = WIN_HOR;
break;
}
case 'O': { // "-O[N]" open N vertical split windows
case 'O': // "-O[N]" open N vertical split windows
// default is 0: open window for each file
parmp->window_count = get_number_arg(argv[0], &argv_idx, 0);
parmp->window_layout = WIN_VER;
break;
}
case 'q': { // "-q" QuickFix mode
case 'q': // "-q" QuickFix mode
if (parmp->edit_type != EDIT_NONE) {
mainerr(err_too_many_args, argv[0]);
}
@@ -967,19 +950,16 @@ static void command_line_scan(mparm_T *parmp)
want_argument = true;
}
break;
}
case 'R': { // "-R" readonly mode
case 'R': // "-R" readonly mode
readonlymode = true;
curbuf->b_p_ro = true;
p_uc = 10000; // don't update very often
break;
}
case 'r': // "-r" recovery mode
case 'L': { // "-L" recovery mode
case 'L': // "-L" recovery mode
recoverymode = 1;
break;
}
case 's': {
case 's':
if (exmode_active) { // "-es" silent (batch) Ex-mode
silent_mode = true;
parmp->no_swap_file = true;
@@ -987,8 +967,7 @@ static void command_line_scan(mparm_T *parmp)
want_argument = true;
}
break;
}
case 't': { // "-t {tag}" or "-t{tag}" jump to tag
case 't': // "-t {tag}" or "-t{tag}" jump to tag
if (parmp->edit_type != EDIT_NONE) {
mainerr(err_too_many_args, argv[0]);
}
@@ -1000,12 +979,10 @@ static void command_line_scan(mparm_T *parmp)
want_argument = true;
}
break;
}
case 'v': {
case 'v':
version();
os_exit(0);
}
case 'V': { // "-V{N}" Verbose level
case 'V': // "-V{N}" Verbose level
// default is 10: a little bit verbose
p_verbose = get_number_arg(argv[0], &argv_idx, 10);
if (argv[0][argv_idx] != NUL) {
@@ -1013,8 +990,7 @@ static void command_line_scan(mparm_T *parmp)
argv_idx = (int)STRLEN(argv[0]);
}
break;
}
case 'w': { // "-w{number}" set window height
case 'w': // "-w{number}" set window height
// "-w {scriptout}" write to script
if (ascii_isdigit(((char_u *)argv[0])[argv_idx])) {
n = get_number_arg(argv[0], &argv_idx, 10);
@@ -1023,9 +999,8 @@ static void command_line_scan(mparm_T *parmp)
}
want_argument = true;
break;
}
case 'c': { // "-c{command}" or "-c {command}" exec command
case 'c': // "-c{command}" or "-c {command}" exec command
if (argv[0][argv_idx] != NUL) {
if (parmp->n_commands >= MAX_ARG_CMDS) {
mainerr(err_extra_cmd, NULL);
@@ -1035,20 +1010,17 @@ static void command_line_scan(mparm_T *parmp)
break;
}
FALLTHROUGH;
}
case 'S': // "-S {file}" execute Vim script
case 'i': // "-i {shada}" use for ShaDa file
case 'u': // "-u {vimrc}" vim inits file
case 'U': // "-U {gvimrc}" gvim inits file
case 'W': { // "-W {scriptout}" overwrite
case 'W': // "-W {scriptout}" overwrite
want_argument = true;
break;
}
default: {
default:
mainerr(err_opt_unknown, argv[0]);
}
}
// Handle option arguments with argument.
if (want_argument) {
@@ -1066,7 +1038,7 @@ static void command_line_scan(mparm_T *parmp)
switch (c) {
case 'c': // "-c {command}" execute command
case 'S': { // "-S {file}" execute Vim script
case 'S': // "-S {file}" execute Vim script
if (parmp->n_commands >= MAX_ARG_CMDS) {
mainerr(err_extra_cmd, NULL);
}
@@ -1094,9 +1066,8 @@ static void command_line_scan(mparm_T *parmp)
parmp->commands[parmp->n_commands++] = argv[0];
}
break;
}
case '-': {
case '-':
if (strequal(argv[-1], "--cmd")) {
// "--cmd {command}" execute command
if (parmp->n_pre_commands >= MAX_ARG_CMDS) {
@@ -1109,17 +1080,14 @@ static void command_line_scan(mparm_T *parmp)
}
// "--startuptime <file>" already handled
break;
}
case 'q': { // "-q {errorfile}" QuickFix mode
case 'q': // "-q {errorfile}" QuickFix mode
parmp->use_ef = (char_u *)argv[0];
break;
}
case 'i': { // "-i {shada}" use for shada
case 'i': // "-i {shada}" use for shada
set_option_value("shadafile", 0L, argv[0], 0);
break;
}
case 's': { // "-s {scriptin}" read from script file
if (scriptin[0] != NULL) {
@@ -1137,12 +1105,13 @@ scripterror:
// Replace the original stdin with the console input handle.
os_replace_stdin_to_conin();
#endif
FileDescriptor *const stdin_dup = file_open_fd_new(
&error, stdin_dup_fd, kFileReadOnly|kFileNonBlocking);
FileDescriptor *const stdin_dup = file_open_fd_new(&error, stdin_dup_fd,
kFileReadOnly|kFileNonBlocking);
assert(stdin_dup != NULL);
scriptin[0] = stdin_dup;
} else if ((scriptin[0] = file_open_new(
&error, argv[0], kFileReadOnly|kFileNonBlocking, 0)) == NULL) {
} else if ((scriptin[0] =
file_open_new(&error, argv[0], kFileReadOnly|kFileNonBlocking,
0)) == NULL) {
vim_snprintf((char *)IObuff, IOSIZE,
_("Cannot open for reading: \"%s\": %s\n"),
argv[0], os_strerror(error));
@@ -1153,19 +1122,16 @@ scripterror:
break;
}
case 't': { // "-t {tag}"
case 't': // "-t {tag}"
parmp->tagname = (char_u *)argv[0];
break;
}
case 'u': { // "-u {vimrc}" vim inits file
case 'u': // "-u {vimrc}" vim inits file
parmp->use_vimrc = argv[0];
break;
}
case 'U': { // "-U {gvimrc}" gvim inits file
case 'U': // "-U {gvimrc}" gvim inits file
break;
}
case 'w': { // "-w {nr}" 'window' value
case 'w': // "-w {nr}" 'window' value
// "-w {scriptout}" append to script file
if (ascii_isdigit(*((char_u *)argv[0]))) {
argv_idx = 0;
@@ -1175,8 +1141,7 @@ scripterror:
break;
}
FALLTHROUGH;
}
case 'W': { // "-W {scriptout}" overwrite script file
case 'W': // "-W {scriptout}" overwrite script file
if (scriptout != NULL) {
goto scripterror;
}
@@ -1190,7 +1155,6 @@ scripterror:
break;
}
}
}
} else { // File name argument.
argv_idx = -1; // skip to next argument
@@ -1334,10 +1298,11 @@ static char_u *get_fname(mparm_T *parmp, char_u *cwd)
static void set_window_layout(mparm_T *paramp)
{
if (paramp->diff_mode && paramp->window_layout == 0) {
if (diffopt_horizontal())
paramp->window_layout = WIN_HOR; /* use horizontal split */
else
paramp->window_layout = WIN_VER; /* use vertical split */
if (diffopt_horizontal()) {
paramp->window_layout = WIN_HOR; // use horizontal split
} else {
paramp->window_layout = WIN_VER; // use vertical split
}
}
}
@@ -1403,10 +1368,11 @@ static void handle_tag(char_u *tagname)
do_cmdline_cmd((char *)IObuff);
TIME_MSG("jumping to tag");
/* If the user doesn't want to edit the file then we quit here. */
if (swap_exists_did_quit)
// If the user doesn't want to edit the file then we quit here.
if (swap_exists_did_quit) {
getout(1);
}
}
}
/// Read text from stdin.
@@ -1443,15 +1409,18 @@ static void create_windows(mparm_T *parmp)
/*
* Create the number of windows that was requested.
*/
if (parmp->window_count == -1) /* was not set */
if (parmp->window_count == -1) { // was not set
parmp->window_count = 1;
if (parmp->window_count == 0)
}
if (parmp->window_count == 0) {
parmp->window_count = GARGCOUNT;
}
if (parmp->window_count > 1) {
// Don't change the windows if there was a command in vimrc that
// already split some windows
if (parmp->window_layout == 0)
if (parmp->window_layout == 0) {
parmp->window_layout = WIN_HOR;
}
if (parmp->window_layout == WIN_TABS) {
parmp->window_count = make_tabpages(parmp->window_count);
TIME_MSG("making tab pages");
@@ -1459,10 +1428,12 @@ static void create_windows(mparm_T *parmp)
parmp->window_count = make_windows(parmp->window_count,
parmp->window_layout == WIN_VER);
TIME_MSG("making windows");
} else
} else {
parmp->window_count = win_count();
} else
}
} else {
parmp->window_count = 1;
}
if (recoverymode) { // do recover
msg_scroll = true; // scroll message up
@@ -1482,17 +1453,20 @@ static void create_windows(mparm_T *parmp)
dorewind = TRUE;
while (done++ < 1000) {
if (dorewind) {
if (parmp->window_layout == WIN_TABS)
if (parmp->window_layout == WIN_TABS) {
goto_tabpage(1);
else
} else {
curwin = firstwin;
}
} else if (parmp->window_layout == WIN_TABS) {
if (curtab->tp_next == NULL)
if (curtab->tp_next == NULL) {
break;
}
goto_tabpage(0);
} else {
if (curwin->w_next == NULL)
if (curwin->w_next == NULL) {
break;
}
curwin = curwin->w_next;
}
dorewind = FALSE;
@@ -1506,13 +1480,13 @@ static void create_windows(mparm_T *parmp)
swap_exists_action = SEA_DIALOG;
set_buflisted(TRUE);
/* create memfile, read file */
// create memfile, read file
(void)open_buffer(FALSE, NULL, 0);
if (swap_exists_action == SEA_QUIT) {
if (got_int || only_one_window()) {
/* abort selected or quit and only one window */
did_emsg = FALSE; /* avoid hit-enter prompt */
// abort selected or quit and only one window
did_emsg = FALSE; // avoid hit-enter prompt
getout(1);
}
/* We can't close the window, it would disturb what
@@ -1521,20 +1495,22 @@ static void create_windows(mparm_T *parmp)
setfname(curbuf, NULL, NULL, false);
curwin->w_arg_idx = -1;
swap_exists_action = SEA_NONE;
} else
} else {
handle_swap_exists(NULL);
dorewind = TRUE; /* start again */
}
dorewind = TRUE; // start again
}
os_breakcheck();
if (got_int) {
(void)vgetc(); /* only break the file loading, not the rest */
(void)vgetc(); // only break the file loading, not the rest
break;
}
}
if (parmp->window_layout == WIN_TABS)
if (parmp->window_layout == WIN_TABS) {
goto_tabpage(1);
else
} else {
curwin = firstwin;
}
curbuf = curwin->w_buffer;
--autocmd_no_enter;
--autocmd_no_leave;
@@ -1545,7 +1521,7 @@ static void create_windows(mparm_T *parmp)
/// windows. make_windows() has already opened the windows.
static void edit_buffers(mparm_T *parmp, char_u *cwd)
{
int arg_idx; /* index in argument list */
int arg_idx; // index in argument list
int i;
bool advance = true;
win_T *win;
@@ -1557,7 +1533,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
++autocmd_no_enter;
++autocmd_no_leave;
/* When w_arg_idx is -1 remove the window (see create_windows()). */
// When w_arg_idx is -1 remove the window (see create_windows()).
if (curwin->w_arg_idx == -1) {
win_close(curwin, true);
advance = false;
@@ -1578,8 +1554,9 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
if (advance) {
if (parmp->window_layout == WIN_TABS) {
if (curtab->tp_next == NULL) /* just checking */
if (curtab->tp_next == NULL) { // just checking
break;
}
goto_tabpage(0);
// Temporarily reset 'shm' option to not print fileinfo when
// loading the other buffers. This would overwrite the already
@@ -1592,8 +1569,9 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
set_option_value("shm", 0L, buf, 0);
}
} else {
if (curwin->w_next == NULL) /* just checking */
if (curwin->w_next == NULL) { // just checking
break;
}
win_enter(curwin->w_next, false);
}
}
@@ -1610,10 +1588,10 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
? alist_name(&GARGLIST[arg_idx]) : NULL,
NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin);
if (swap_exists_did_quit) {
/* abort or quit selected */
// abort or quit selected
if (got_int || only_one_window()) {
/* abort selected and only one window */
did_emsg = FALSE; /* avoid hit-enter prompt */
// abort selected and only one window
did_emsg = FALSE; // avoid hit-enter prompt
getout(1);
}
win_close(curwin, true);
@@ -1626,7 +1604,7 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
}
os_breakcheck();
if (got_int) {
(void)vgetc(); /* only break the file loading, not the rest */
(void)vgetc(); // only break the file loading, not the rest
break;
}
}
@@ -1636,13 +1614,14 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
xfree(p_shm_save);
}
if (parmp->window_layout == WIN_TABS)
if (parmp->window_layout == WIN_TABS) {
goto_tabpage(1);
}
--autocmd_no_enter;
/* make the first window the current window */
// make the first window the current window
win = firstwin;
/* Avoid making a preview window the current window. */
// Avoid making a preview window the current window.
while (win->w_p_pvw) {
win = win->w_next;
if (win == NULL) {
@@ -1654,8 +1633,9 @@ static void edit_buffers(mparm_T *parmp, char_u *cwd)
--autocmd_no_leave;
TIME_MSG("editing files in windows");
if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS)
win_equal(curwin, false, 'b'); /* adjust heights */
if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS) {
win_equal(curwin, false, 'b'); // adjust heights
}
}
/*
@@ -1668,7 +1648,7 @@ static void exe_pre_commands(mparm_T *parmp)
int i;
if (cnt > 0) {
curwin->w_cursor.lnum = 0; /* just in case.. */
curwin->w_cursor.lnum = 0; // just in case..
sourcing_name = (char_u *)_("pre-vimrc command line");
current_sctx.sc_sid = SID_CMDARG;
for (i = 0; i < cnt; i++) {
@@ -1693,28 +1673,32 @@ static void exe_commands(mparm_T *parmp)
* with g`" was used.
*/
msg_scroll = TRUE;
if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1)
if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) {
curwin->w_cursor.lnum = 0;
}
sourcing_name = (char_u *)"command line";
current_sctx.sc_sid = SID_CARG;
current_sctx.sc_seq = 0;
for (i = 0; i < parmp->n_commands; i++) {
do_cmdline_cmd(parmp->commands[i]);
if (parmp->cmds_tofree[i])
if (parmp->cmds_tofree[i]) {
xfree(parmp->commands[i]);
}
}
sourcing_name = NULL;
current_sctx.sc_sid = 0;
if (curwin->w_cursor.lnum == 0) {
curwin->w_cursor.lnum = 1;
}
if (!exmode_active)
if (!exmode_active) {
msg_scroll = FALSE;
}
/* When started with "-q errorfile" jump to first error again. */
if (parmp->edit_type == EDIT_QF)
// When started with "-q errorfile" jump to first error again.
if (parmp->edit_type == EDIT_QF) {
qf_jump(NULL, 0, 0, FALSE);
}
TIME_MSG("executing command arguments");
}
@@ -1826,7 +1810,7 @@ static bool do_user_initialization(void)
memmove(vimrc, dir, dir_len);
vimrc[dir_len] = PATHSEP;
memmove(vimrc + dir_len + 1, path_tail, sizeof(path_tail));
if (do_source((char_u *) vimrc, true, DOSO_VIMRC) != FAIL) {
if (do_source((char_u *)vimrc, true, DOSO_VIMRC) != FAIL) {
do_exrc = p_exrc;
if (do_exrc) {
do_exrc = (path_full_compare((char_u *)VIMRC_FILE, (char_u *)vimrc,
@@ -2033,7 +2017,8 @@ static void usage(void)
*/
static void check_swap_exists_action(void)
{
if (swap_exists_action == SEA_QUIT)
if (swap_exists_action == SEA_QUIT) {
getout(1);
}
handle_swap_exists(NULL);
}

View File

@@ -8,20 +8,18 @@
// khash.h does not make its own copy of the key or value.
//
#include <stdlib.h>
#include <lauxlib.h>
#include <lua.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include "nvim/api/private/dispatch.h"
#include "nvim/lib/khash.h"
#include "nvim/map.h"
#include "nvim/map_defs.h"
#include "nvim/vim.h"
#include "nvim/memory.h"
#include "nvim/api/private/dispatch.h"
#include "nvim/lib/khash.h"
#include "nvim/vim.h"
#define cstr_t_hash kh_str_hash_func
#define cstr_t_eq kh_str_hash_equal
@@ -52,7 +50,7 @@
#define MAP_IMPL(T, U, ...) \
INITIALIZER_DECLARE(T, U, __VA_ARGS__); \
__KHASH_IMPL(T##_##U##_map,, T, U, 1, T##_hash, T##_eq) \
__KHASH_IMPL(T##_##U##_map, , T, U, 1, T##_hash, T##_eq) \
\
void map_##T##_##U##_destroy(Map(T, U) *map) \
{ \

View File

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

View File

@@ -49,9 +49,9 @@
#include <assert.h>
#include "nvim/marktree.h"
#include "nvim/lib/kvec.h"
#include "nvim/garray.h"
#include "nvim/lib/kvec.h"
#include "nvim/marktree.h"
#define T MT_BRANCH_FACTOR
#define ILEN (sizeof(mtnode_t)+(2 * T) * sizeof(void *))
@@ -137,7 +137,9 @@ static inline int marktree_getp_aux(const mtnode_t *x, mtkey_t k, int *r)
end = mid;
}
}
if (begin == x->n) { *rr = 1; return x->n - 1; }
if (begin == x->n) {
*rr = 1; return x->n - 1;
}
if ((*rr = key_cmp(k, x->key[begin])) < 0) {
begin--;
}
@@ -232,9 +234,8 @@ uint64_t marktree_put(MarkTree *b, int row, int col, bool right_gravity)
return id;
}
uint64_t marktree_put_pair(MarkTree *b,
int start_row, int start_col, bool start_right,
int end_row, int end_col, bool end_right)
uint64_t marktree_put_pair(MarkTree *b, int start_row, int start_col, bool start_right, int end_row,
int end_col, bool end_right)
{
uint64_t id = (b->next_id+=ID_INCR)|PAIRED;
uint64_t start_id = id|(start_right?RIGHT_GRAVITY:0);
@@ -594,8 +595,8 @@ bool marktree_itr_get(MarkTree *b, int row, int col, MarkTreeIter *itr)
itr, false, false, NULL);
}
bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr,
bool last, bool gravity, mtpos_t *oldbase)
bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool last, bool gravity,
mtpos_t *oldbase)
{
mtkey_t k = { .pos = p, .id = gravity ? RIGHT_GRAVITY : 0 };
if (last && !gravity) {
@@ -695,8 +696,7 @@ bool marktree_itr_next(MarkTree *b, MarkTreeIter *itr)
return marktree_itr_next_skip(b, itr, false, NULL);
}
static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip,
mtpos_t oldbase[])
static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, mtpos_t oldbase[])
{
if (!itr->node) {
return false;
@@ -833,10 +833,8 @@ static void swap_id(uint64_t *id1, uint64_t *id2)
*id2 = temp;
}
bool marktree_splice(MarkTree *b,
int start_line, int start_col,
int old_extent_line, int old_extent_col,
int new_extent_line, int new_extent_col)
bool marktree_splice(MarkTree *b, int start_line, int start_col, int old_extent_line,
int old_extent_col, int new_extent_line, int new_extent_col)
{
mtpos_t start = { start_line, start_col };
mtpos_t old_extent = { (int)old_extent_line, old_extent_col };
@@ -994,10 +992,8 @@ past_continue_same_node:
return moved;
}
void marktree_move_region(MarkTree *b,
int start_row, colnr_T start_col,
int extent_row, colnr_T extent_col,
int new_row, colnr_T new_col)
void marktree_move_region(MarkTree *b, int start_row, colnr_T start_col, int extent_row,
colnr_T extent_col, int new_row, colnr_T new_col)
{
mtpos_t start = { start_row, start_col }, size = { extent_row, extent_col };
mtpos_t end = size;
@@ -1114,8 +1110,7 @@ void marktree_check(MarkTree *b)
}
#ifndef NDEBUG
static size_t check_node(MarkTree *b, mtnode_t *x,
mtpos_t *last, bool *last_right)
static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_right)
{
assert(x->n <= 2 * T - 1);
// TODO(bfredl): too strict if checking "in repair" post-delete tree.

View File

@@ -2,6 +2,7 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <math.h>
#include <stdint.h>
#include <string.h>
@@ -21,9 +22,12 @@ int xfpclassify(double d)
m = 0xfffffffffffffULL & m;
switch (e) {
default: return FP_NORMAL;
case 0x000: return m ? FP_SUBNORMAL : FP_ZERO;
case 0x7ff: return m ? FP_NAN : FP_INFINITE;
default:
return FP_NORMAL;
case 0x000:
return m ? FP_SUBNORMAL : FP_ZERO;
case 0x7ff:
return m ? FP_NAN : FP_INFINITE;
}
}
int xisinf(double d)

View File

@@ -39,24 +39,24 @@
/// mf_fullname() make file name full path (use before first :cd)
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <string.h>
#include <stdbool.h>
#include <fcntl.h>
#include <string.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/memfile.h"
#include "nvim/assert.h"
#include "nvim/fileio.h"
#include "nvim/memfile.h"
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/assert.h"
#include "nvim/os/os.h"
#include "nvim/os/input.h"
#include "nvim/vim.h"
#define MEMFILE_PAGE_SIZE 4096 /// default page size
@@ -282,14 +282,16 @@ bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, unsigned page_count)
{
// check block number exists
if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min)
if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min) {
return NULL;
}
// see if it is in the cache
bhdr_T *hp = mf_find_hash(mfp, nr);
if (hp == NULL) { // not in the hash list
if (nr < 0 || nr >= mfp->mf_infile_count) // can't be in the file
if (nr < 0 || nr >= mfp->mf_infile_count) { // can't be in the file
return NULL;
}
// could check here if the block is in the free list
@@ -331,8 +333,9 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile)
mfp->mf_dirty = true;
}
hp->bh_flags = flags;
if (infile)
if (infile) {
mf_trans_add(mfp, hp); // may translate negative in positive nr
}
}
/// Signal block as no longer used (may put it in the free list).
@@ -381,32 +384,38 @@ int mf_sync(memfile_T *mfp, int flags)
// fails then we give up.
int status = OK;
bhdr_T *hp;
for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev)
for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) {
if (((flags & MFS_ALL) || hp->bh_bnum >= 0)
&& (hp->bh_flags & BH_DIRTY)
&& (status == OK || (hp->bh_bnum >= 0
&& hp->bh_bnum < mfp->mf_infile_count))) {
if ((flags & MFS_ZERO) && hp->bh_bnum != 0)
if ((flags & MFS_ZERO) && hp->bh_bnum != 0) {
continue;
}
if (mf_write(mfp, hp) == FAIL) {
if (status == FAIL) // double error: quit syncing
if (status == FAIL) { // double error: quit syncing
break;
}
status = FAIL;
}
if (flags & MFS_STOP) { // Stop when char available now.
if (os_char_avail())
if (os_char_avail()) {
break;
}
} else {
os_breakcheck();
}
if (got_int)
if (got_int) {
break;
}
}
}
// If the whole list is flushed, the memfile is not dirty anymore.
// In case of an error, dirty flag is also set, to avoid trying all the time.
if (hp == NULL || status == FAIL)
if (hp == NULL || status == FAIL) {
mfp->mf_dirty = false;
}
if (flags & MFS_FLUSH) {
if (os_fsync(mfp->mf_fd)) {
@@ -465,15 +474,17 @@ static void mf_ins_used(memfile_T *mfp, bhdr_T *hp)
/// Remove block from memfile's used list.
static void mf_rem_used(memfile_T *mfp, bhdr_T *hp)
{
if (hp->bh_next == NULL) // last block in used list
if (hp->bh_next == NULL) { // last block in used list
mfp->mf_used_last = hp->bh_prev;
else
} else {
hp->bh_next->bh_prev = hp->bh_prev;
}
if (hp->bh_prev == NULL) // first block in used list
if (hp->bh_prev == NULL) { // first block in used list
mfp->mf_used_first = hp->bh_next;
else
} else {
hp->bh_prev->bh_next = hp->bh_next;
}
}
/// Release as many blocks as possible.
@@ -554,8 +565,9 @@ static bhdr_T *mf_rem_free(memfile_T *mfp)
/// - Error reading file.
static int mf_read(memfile_T *mfp, bhdr_T *hp)
{
if (mfp->mf_fd < 0) // there is no file, can't read
if (mfp->mf_fd < 0) { // there is no file, can't read
return FAIL;
}
unsigned page_size = mfp->mf_page_size;
// TODO(elmart): Check (page_size * hp->bh_bnum) within off_T bounds.
@@ -592,12 +604,15 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
unsigned page_count; // number of pages written
unsigned size; // number of bytes written
if (mfp->mf_fd < 0) // there is no file, can't write
if (mfp->mf_fd < 0) { // there is no file, can't write
return FAIL;
}
if (hp->bh_bnum < 0) // must assign file block number
if (mf_trans_add(mfp, hp) == FAIL)
if (hp->bh_bnum < 0) { // must assign file block number
if (mf_trans_add(mfp, hp) == FAIL) {
return FAIL;
}
}
page_size = mfp->mf_page_size;
@@ -620,10 +635,11 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
PERROR(_("E296: Seek error in swap file write"));
return FAIL;
}
if (hp2 == NULL) // freed block, fill with dummy data
if (hp2 == NULL) { // freed block, fill with dummy data
page_count = 1;
else
} else {
page_count = hp2->bh_page_count;
}
size = page_size * page_count;
void *data = (hp2 == NULL) ? hp->bh_data : hp2->bh_data;
if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) {
@@ -631,19 +647,23 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
/// disk is full. We give the message again only after a successful
/// write or when hitting a key. We keep on trying, in case some
/// space becomes available.
if (!did_swapwrite_msg)
if (!did_swapwrite_msg) {
EMSG(_("E297: Write error in swap file"));
}
did_swapwrite_msg = true;
return FAIL;
}
did_swapwrite_msg = false;
if (hp2 != NULL) // written a non-dummy block
if (hp2 != NULL) { // written a non-dummy block
hp2->bh_flags &= ~BH_DIRTY;
if (nr + (blocknr_T)page_count > mfp->mf_infile_count) // appended to file
}
if (nr + (blocknr_T)page_count > mfp->mf_infile_count) { // appended to file
mfp->mf_infile_count = nr + page_count;
if (nr == hp->bh_bnum) // written the desired block
}
if (nr == hp->bh_bnum) { // written the desired block
break;
}
}
return OK;
}
@@ -653,8 +673,9 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
/// FAIL On failure.
static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
{
if (hp->bh_bnum >= 0) // it's already positive
if (hp->bh_bnum >= 0) { // it's already positive
return OK;
}
mf_blocknr_trans_item_T *np = xmalloc(sizeof(mf_blocknr_trans_item_T));
@@ -702,8 +723,9 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
mf_blocknr_trans_item_T *np =
(mf_blocknr_trans_item_T *)mf_hash_find(&mfp->mf_trans, old_nr);
if (np == NULL) // not found
if (np == NULL) { // not found
return old_nr;
}
mfp->mf_neg_count--;
blocknr_T new_bnum = np->nt_new_bnum;
@@ -834,8 +856,9 @@ static void mf_hash_free_all(mf_hashtab_T *mht)
static mf_hashitem_T *mf_hash_find(mf_hashtab_T *mht, blocknr_T key)
{
mf_hashitem_T *mhi = mht->mht_buckets[(size_t)key & mht->mht_mask];
while (mhi != NULL && mhi->mhi_key != key)
while (mhi != NULL && mhi->mhi_key != key) {
mhi = mhi->mhi_next;
}
return mhi;
}
@@ -845,8 +868,9 @@ static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
size_t idx = (size_t)mhi->mhi_key & mht->mht_mask;
mhi->mhi_next = mht->mht_buckets[idx];
mhi->mhi_prev = NULL;
if (mhi->mhi_next != NULL)
if (mhi->mhi_next != NULL) {
mhi->mhi_next->mhi_prev = mhi;
}
mht->mht_buckets[idx] = mhi;
mht->mht_count++;
@@ -861,14 +885,16 @@ static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
/// Remove item from hashtable. Item must be non NULL and within hashtable.
static void mf_hash_rem_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
{
if (mhi->mhi_prev == NULL)
if (mhi->mhi_prev == NULL) {
mht->mht_buckets[(size_t)mhi->mhi_key & mht->mht_mask] =
mhi->mhi_next;
else
} else {
mhi->mhi_prev->mhi_next = mhi->mhi_next;
}
if (mhi->mhi_next != NULL)
if (mhi->mhi_next != NULL) {
mhi->mhi_next->mhi_prev = mhi->mhi_prev;
}
mht->mht_count--;
@@ -884,8 +910,9 @@ static void mf_hash_grow(mf_hashtab_T *mht)
mf_hashitem_T **buckets = xcalloc(1, size);
int shift = 0;
while ((mht->mht_mask >> shift) != 0)
while ((mht->mht_mask >> shift) != 0) {
shift++;
}
for (size_t i = 0; i <= mht->mht_mask; i++) {
/// Traverse the items in the i-th original bucket and move them into
@@ -914,13 +941,16 @@ static void mf_hash_grow(mf_hashtab_T *mht)
}
}
for (size_t j = 0; j < MHT_GROWTH_FACTOR; j++)
if (tails[j] != NULL)
for (size_t j = 0; j < MHT_GROWTH_FACTOR; j++) {
if (tails[j] != NULL) {
tails[j]->mhi_next = NULL;
}
}
}
if (mht->mht_buckets != mht->mht_small_buckets)
if (mht->mht_buckets != mht->mht_small_buckets) {
xfree(mht->mht_buckets);
}
mht->mht_buckets = buckets;
mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1;

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +1,26 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// Various routines dealing with allocation and deallocation of memory.
// Various routines dealing with allocation and deallocation of memory.
#include <assert.h>
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/vim.h"
#include "nvim/api/vim.h"
#include "nvim/context.h"
#include "nvim/decoration.h"
#include "nvim/eval.h"
#include "nvim/highlight.h"
#include "nvim/lua/executor.h"
#include "nvim/memfile.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/ui.h"
#include "nvim/sign.h"
#include "nvim/api/vim.h"
#include "nvim/lua/executor.h"
#include "nvim/decoration.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#ifdef UNIT_TESTING
# define malloc(size) mem_malloc(size)
@@ -47,8 +47,9 @@ void try_to_free_memory(void)
{
static bool trying_to_free = false;
// avoid recursive calls
if (trying_to_free)
if (trying_to_free) {
return;
}
trying_to_free = true;
// free any scrollback text
@@ -182,7 +183,7 @@ void *xmallocz(size_t size)
}
void *ret = xmalloc(total_size);
((char*)ret)[size] = 0;
((char *)ret)[size] = 0;
return ret;
}
@@ -447,7 +448,7 @@ void *xmemrchr(const void *src, uint8_t c, size_t len)
{
while (len--) {
if (((uint8_t *)src)[len] == c) {
return (uint8_t *) src + len;
return (uint8_t *)src + len;
}
}
return NULL;
@@ -500,7 +501,7 @@ bool striequal(const char *a, const char *b)
void do_outofmem_msg(size_t size)
{
if (!did_outofmem_msg) {
/* Don't hide this message */
// Don't hide this message
emsg_silent = 0;
/* Must come first to avoid coming back here when printing the error
@@ -523,14 +524,15 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#if defined(EXITFREE)
#include "nvim/file_search.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.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/getchar.h"
@@ -538,8 +540,9 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
@@ -550,8 +553,6 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#include "nvim/syntax.h"
#include "nvim/tag.h"
#include "nvim/window.h"
#include "nvim/os/os.h"
#include "nvim/eval/typval.h"
/*
* Free everything that we allocated.
@@ -574,10 +575,11 @@ void free_all_mem(void)
// Don't want to trigger autocommands from here on.
block_autocmds();
/* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */
// Close all tabs and windows. Reset 'equalalways' to avoid redraws.
p_ea = false;
if (first_tabpage->tp_next != NULL)
if (first_tabpage->tp_next != NULL) {
do_cmdline_cmd("tabonly!");
}
if (!ONE_WINDOW) {
// to keep things simple, don't perform this
@@ -586,17 +588,17 @@ void free_all_mem(void)
do_cmdline_cmd("only!");
}
/* Free all spell info. */
// Free all spell info.
spell_free_all();
/* Clear user commands (before deleting buffers). */
// Clear user commands (before deleting buffers).
ex_comclear(NULL);
/* Clear menus. */
// Clear menus.
do_cmdline_cmd("aunmenu *");
do_cmdline_cmd("menutranslate clear");
/* Clear mappings, abbreviations, breakpoints. */
// Clear mappings, abbreviations, breakpoints.
do_cmdline_cmd("lmapclear");
do_cmdline_cmd("xmapclear");
do_cmdline_cmd("mapclear");
@@ -609,7 +611,7 @@ void free_all_mem(void)
free_titles();
free_findfile();
/* Obviously named calls. */
// Obviously named calls.
free_all_autocmds();
free_all_marks();
alist_clear(&global_alist);
@@ -627,25 +629,25 @@ void free_all_mem(void)
diff_clear(curtab);
clear_sb_text(true); // free any scrollback text
/* Free some global vars. */
// Free some global vars.
xfree(last_cmdline);
xfree(new_last_cmdline);
set_keep_msg(NULL, 0);
/* Clear cmdline history. */
// Clear cmdline history.
p_hi = 0;
init_history();
qf_free_all(NULL);
/* Free all location lists */
// Free all location lists
FOR_ALL_TAB_WINDOWS(tab, win) {
qf_free_all(win);
}
/* Close all script inputs. */
// Close all script inputs.
close_all_scripts();
/* Destroy all windows. Must come before freeing buffers. */
// Destroy all windows. Must come before freeing buffers.
win_free_all();
// Free all option values. Must come after closing windows.
@@ -653,13 +655,13 @@ void free_all_mem(void)
free_arshape_buf();
/* Clear registers. */
// Clear registers.
clear_registers();
ResetRedobuff();
ResetRedobuff();
/* highlight info */
// highlight info
free_highlight();
reset_last_sourcing();
@@ -667,10 +669,12 @@ void free_all_mem(void)
free_tabpage(first_tabpage);
first_tabpage = NULL;
/* message history */
for (;; )
if (delete_first_msg() == FAIL)
// message history
for (;; ) {
if (delete_first_msg() == FAIL) {
break;
}
}
eval_clear();
api_vim_free_all_mem();

View File

@@ -10,27 +10,27 @@
#include <inttypes.h>
#include <string.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/menu.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_docmd.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/keymap.h"
#include "nvim/memory.h"
#include "nvim/menu.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/keymap.h"
#include "nvim/garray.h"
#include "nvim/screen.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
#include "nvim/eval/typval.h"
#include "nvim/screen.h"
#include "nvim/vim.h"
#include "nvim/window.h"
#define MENUDEPTH 10 /* maximum depth of menus */
#define MENUDEPTH 10 // maximum depth of menus
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -43,8 +43,7 @@
/// The character for each menu mode
static char_u menu_mode_chars[] = { 'n', 'v', 's', 'o', 'i', 'c', 't' };
static char_u e_notsubmenu[] = N_(
"E327: Part of menu-item path is not sub-menu");
static char_u e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu");
static char_u e_othermode[] = N_("E328: Menu only exists in another mode");
static char_u e_nomenu[] = N_("E329: No menu \"%s\"");
@@ -63,8 +62,7 @@ static vimmenu_T **get_root_menu(const char_u *const name)
/// Do the :menu command and relatives.
/// @param eap Ex command arguments
void
ex_menu(exarg_T *eap)
void ex_menu(exarg_T *eap)
{
char_u *menu_path;
int modes;
@@ -109,8 +107,9 @@ ex_menu(exarg_T *eap)
if (STRNCMP(arg, "icon=", 5) == 0) {
arg += 5;
while (*arg != NUL && *arg != ' ') {
if (*arg == '\\')
if (*arg == '\\') {
STRMOVE(arg, arg + 1);
}
MB_PTR_ADV(arg);
}
if (*arg != NUL) {
@@ -139,11 +138,13 @@ ex_menu(exarg_T *eap)
} else if (eap->addr_count && eap->line2 != 0) {
pri_tab[0] = eap->line2;
i = 1;
} else
} else {
i = 0;
while (i < MENUDEPTH)
}
while (i < MENUDEPTH) {
pri_tab[i++] = 500;
pri_tab[MENUDEPTH] = -1; /* mark end of the table */
}
pri_tab[MENUDEPTH] = -1; // mark end of the table
/*
* Check for "disable" or "enable" argument.
@@ -195,32 +196,35 @@ ex_menu(exarg_T *eap)
}
if (menu_is_popup(menu_path)) {
for (i = 0; i < MENU_INDEX_TIP; ++i)
for (i = 0; i < MENU_INDEX_TIP; ++i) {
if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i);
menu_enable_recurse(*root_menu_ptr, p, MENU_ALL_MODES, enable);
xfree(p);
}
}
}
menu_enable_recurse(*root_menu_ptr, menu_path, modes, enable);
} else if (unmenu) {
/*
* Delete menu(s).
*/
if (STRCMP(menu_path, "*") == 0) /* meaning: remove all menus */
if (STRCMP(menu_path, "*") == 0) { // meaning: remove all menus
menu_path = (char_u *)"";
}
/*
* For the PopUp menu, remove a menu for each mode separately.
*/
if (menu_is_popup(menu_path)) {
for (i = 0; i < MENU_INDEX_TIP; ++i)
for (i = 0; i < MENU_INDEX_TIP; ++i) {
if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i);
remove_menu(root_menu_ptr, p, MENU_ALL_MODES, true);
xfree(p);
}
}
}
// Careful: remove_menu() changes menu_path
remove_menu(root_menu_ptr, menu_path, modes, false);
@@ -229,7 +233,7 @@ ex_menu(exarg_T *eap)
* Add menu(s).
* Replace special key codes.
*/
if (STRICMP(map_to, "<nop>") == 0) { /* "<Nop>" means nothing */
if (STRICMP(map_to, "<nop>") == 0) { // "<Nop>" means nothing
map_to = (char_u *)"";
map_buf = NULL;
} else if (modes & MENU_TIP_MODE) {
@@ -247,7 +251,7 @@ ex_menu(exarg_T *eap)
* For the PopUp menu, add a menu for each mode separately.
*/
if (menu_is_popup(menu_path)) {
for (i = 0; i < MENU_INDEX_TIP; ++i)
for (i = 0; i < MENU_INDEX_TIP; ++i) {
if (modes & (1 << i)) {
p = popup_mode_name(menu_path, i);
// Include all modes, to make ":amenu" work
@@ -256,6 +260,7 @@ ex_menu(exarg_T *eap)
xfree(p);
}
}
}
xfree(map_buf);
}
@@ -272,13 +277,8 @@ theend:
/// @param[out] menuarg menu entry
/// @param[] pri_tab priority table
/// @param[in] call_data Right hand side command
static int
add_menu_path(
const char_u *const menu_path,
vimmenu_T *menuarg,
const long *const pri_tab,
const char_u *const call_data
)
static int add_menu_path(const char_u *const menu_path, vimmenu_T *menuarg,
const long *const pri_tab, const char_u *const call_data)
{
char_u *path_name;
int modes = menuarg->modes;
@@ -298,7 +298,7 @@ add_menu_path(
char_u *en_name;
char_u *map_to = NULL;
/* Make a copy so we can stuff around with it, since it could be const */
// Make a copy so we can stuff around with it, since it could be const
path_name = vim_strsave(menu_path);
vimmenu_T **root_menu_ptr = get_root_menu(menu_path);
vimmenu_T **menup = root_menu_ptr;
@@ -317,12 +317,12 @@ add_menu_path(
}
dname = menu_text(name, NULL, NULL);
if (*dname == NUL) {
/* Only a mnemonic or accelerator is not valid. */
// Only a mnemonic or accelerator is not valid.
EMSG(_("E792: Empty menu name"));
goto erret;
}
/* See if it's already there */
// See if it's already there
lower_pri = menup;
menu = *menup;
while (menu != NULL) {
@@ -364,7 +364,7 @@ add_menu_path(
goto erret;
}
/* Not already there, so lets add it */
// Not already there, so lets add it
menu = xcalloc(1, sizeof(vimmenu_T));
menu->modes = modes;
@@ -387,7 +387,6 @@ add_menu_path(
*lower_pri = menu;
old_modes = 0;
} else {
old_modes = menu->modes;
@@ -419,16 +418,17 @@ add_menu_path(
*/
amenu = ((modes & (MENU_NORMAL_MODE | MENU_INSERT_MODE)) ==
(MENU_NORMAL_MODE | MENU_INSERT_MODE));
if (sys_menu)
if (sys_menu) {
modes &= ~old_modes;
}
if (menu != NULL && modes) {
p = (call_data == NULL) ? NULL : vim_strsave(call_data);
/* loop over all modes, may add more than one */
// loop over all modes, may add more than one
for (i = 0; i < MENU_MODES; ++i) {
if (modes & (1 << i)) {
/* free any old menu */
// free any old menu
free_menu_string(menu, i);
// For "amenu", may insert an extra character.
@@ -462,7 +462,7 @@ add_menu_path(
if (c == Ctrl_C) {
int len = (int)STRLEN(menu->strings[i]);
/* Append CTRL-\ CTRL-G to obey 'insertmode'. */
// Append CTRL-\ CTRL-G to obey 'insertmode'.
menu->strings[i][len] = Ctrl_BSL;
menu->strings[i][len + 1] = Ctrl_G;
menu->strings[i][len + 2] = NUL;
@@ -504,20 +504,17 @@ erret:
* Set the (sub)menu with the given name to enabled or disabled.
* Called recursively.
*/
static int menu_enable_recurse(vimmenu_T *menu,
char_u *name,
int modes,
int enable)
static int menu_enable_recurse(vimmenu_T *menu, char_u *name, int modes, int enable)
{
char_u *p;
if (menu == NULL)
return OK; /* Got to bottom of hierarchy */
/* Get name of this element in the menu hierarchy */
if (menu == NULL) {
return OK; // Got to bottom of hierarchy
}
// Get name of this element in the menu hierarchy
p = menu_name_skip(name);
/* Find the menu */
// Find the menu
while (menu != NULL) {
if (*name == NUL || *name == '*' || menu_name_equal(name, menu)) {
if (*p != NUL) {
@@ -539,9 +536,10 @@ static int menu_enable_recurse(vimmenu_T *menu,
* modes, so keep looping, otherwise we are just doing the named
* menu item (which has been found) so break here.
*/
if (*name != NUL && *name != '*')
if (*name != NUL && *name != '*') {
break;
}
}
menu = menu->next;
}
if (*name != NUL && *name != '*' && menu == NULL) {
@@ -553,42 +551,39 @@ static int menu_enable_recurse(vimmenu_T *menu,
return OK;
}
/*
* Remove the (sub)menu with the given name from the menu hierarchy
* Called recursively.
*/
static int
remove_menu (
vimmenu_T **menup,
char_u *name,
int modes,
bool silent /* don't give error messages */
)
/// Remove the (sub)menu with the given name from the menu hierarchy
/// Called recursively.
///
/// @param silent don't give error messages
static int remove_menu(vimmenu_T **menup, char_u *name, int modes, bool silent)
{
vimmenu_T *menu;
vimmenu_T *child;
char_u *p;
if (*menup == NULL)
return OK; /* Got to bottom of hierarchy */
/* Get name of this element in the menu hierarchy */
if (*menup == NULL) {
return OK; // Got to bottom of hierarchy
}
// Get name of this element in the menu hierarchy
p = menu_name_skip(name);
/* Find the menu */
// Find the menu
while ((menu = *menup) != NULL) {
if (*name == NUL || menu_name_equal(name, menu)) {
if (*p != NUL && menu->children == NULL) {
if (!silent)
if (!silent) {
EMSG(_(e_notsubmenu));
}
return FAIL;
}
if ((menu->modes & modes) != 0x0) {
if (remove_menu(&menu->children, p, modes, silent) == FAIL)
if (remove_menu(&menu->children, p, modes, silent) == FAIL) {
return FAIL;
}
} else if (*name != NUL) {
if (!silent)
if (!silent) {
EMSG(_(e_othermode));
}
return FAIL;
}
@@ -597,39 +592,45 @@ remove_menu (
* modes, so keep looping, otherwise we are just removing the named
* menu item (which has been found) so break here.
*/
if (*name != NUL)
if (*name != NUL) {
break;
}
/* Remove the menu item for the given mode[s]. If the menu item
* is no longer valid in ANY mode, delete it */
menu->modes &= ~modes;
if (modes & MENU_TIP_MODE)
free_menu_string(menu, MENU_INDEX_TIP);
if ((menu->modes & MENU_ALL_MODES) == 0)
free_menu(menup);
else
menup = &menu->next;
} else
menup = &menu->next;
}
if (*name != NUL) {
if (menu == NULL) {
if (!silent)
EMSG2(_(e_nomenu), name);
return FAIL;
}
/* Recalculate modes for menu based on the new updated children */
menu->modes &= ~modes;
child = menu->children;
for (; child != NULL; child = child->next)
menu->modes |= child->modes;
if (modes & MENU_TIP_MODE) {
free_menu_string(menu, MENU_INDEX_TIP);
}
if ((menu->modes & MENU_ALL_MODES) == 0) {
/* The menu item is no longer valid in ANY mode, so delete it */
free_menu(menup);
} else {
menup = &menu->next;
}
} else {
menup = &menu->next;
}
}
if (*name != NUL) {
if (menu == NULL) {
if (!silent) {
EMSG2(_(e_nomenu), name);
}
return FAIL;
}
// Recalculate modes for menu based on the new updated children
menu->modes &= ~modes;
child = menu->children;
for (; child != NULL; child = child->next) {
menu->modes |= child->modes;
}
if (modes & MENU_TIP_MODE) {
free_menu_string(menu, MENU_INDEX_TIP);
}
if ((menu->modes & MENU_ALL_MODES) == 0) {
// The menu item is no longer valid in ANY mode, so delete it
*menup = menu;
free_menu(menup);
}
@@ -657,10 +658,10 @@ static void free_menu(vimmenu_T **menup)
xfree(menu->en_name);
xfree(menu->en_dname);
xfree(menu->actext);
for (i = 0; i < MENU_MODES; i++)
for (i = 0; i < MENU_MODES; i++) {
free_menu_string(menu, i);
}
xfree(menu);
}
/*
@@ -671,11 +672,14 @@ static void free_menu_string(vimmenu_T *menu, int idx)
int count = 0;
int i;
for (i = 0; i < MENU_MODES; i++)
if (menu->strings[i] == menu->strings[idx])
for (i = 0; i < MENU_MODES; i++) {
if (menu->strings[i] == menu->strings[idx]) {
count++;
if (count == 1)
}
}
if (count == 1) {
xfree(menu->strings[idx]);
}
menu->strings[idx] = NULL;
}
@@ -826,8 +830,8 @@ static int show_menus(char_u *const path_name, int modes)
return FAIL;
}
/* Now we have found the matching menu, and we list the mappings */
/* Highlight title */
// Now we have found the matching menu, and we list the mappings
// Highlight title
MSG_PUTS_TITLE(_("\n--- Menus ---"));
show_menus_recursive(menu->parent, modes, 0);
@@ -840,15 +844,18 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
int i;
int bit;
if (menu != NULL && (menu->modes & modes) == 0x0)
if (menu != NULL && (menu->modes & modes) == 0x0) {
return;
}
if (menu != NULL) {
msg_putchar('\n');
if (got_int) /* "q" hit for "--more--" */
if (got_int) { // "q" hit for "--more--"
return;
for (i = 0; i < depth; i++)
}
for (i = 0; i < depth; i++) {
MSG_PUTS(" ");
}
if (menu->priority) {
msg_outnum((long)menu->priority);
MSG_PUTS(" ");
@@ -858,28 +865,33 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
}
if (menu != NULL && menu->children == NULL) {
for (bit = 0; bit < MENU_MODES; bit++)
for (bit = 0; bit < MENU_MODES; bit++) {
if ((menu->modes & modes & (1 << bit)) != 0) {
msg_putchar('\n');
if (got_int) /* "q" hit for "--more--" */
if (got_int) { // "q" hit for "--more--"
return;
for (i = 0; i < depth + 2; i++)
}
for (i = 0; i < depth + 2; i++) {
MSG_PUTS(" ");
}
msg_putchar(menu_mode_chars[bit]);
if (menu->noremap[bit] == REMAP_NONE)
if (menu->noremap[bit] == REMAP_NONE) {
msg_putchar('*');
else if (menu->noremap[bit] == REMAP_SCRIPT)
} else if (menu->noremap[bit] == REMAP_SCRIPT) {
msg_putchar('&');
else
} else {
msg_putchar(' ');
if (menu->silent[bit])
}
if (menu->silent[bit]) {
msg_putchar('s');
else
} else {
msg_putchar(' ');
if ((menu->modes & menu->enabled & (1 << bit)) == 0)
}
if ((menu->modes & menu->enabled & (1 << bit)) == 0) {
msg_putchar('-');
else
} else {
msg_putchar(' ');
}
MSG_PUTS(" ");
if (*menu->strings[bit] == NUL) {
msg_puts_attr("<Nop>", HL_ATTR(HLF_8));
@@ -887,18 +899,22 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
msg_outtrans_special(menu->strings[bit], false, 0);
}
}
}
} else {
if (menu == NULL) {
menu = root_menu;
depth--;
} else
} else {
menu = menu->children;
}
/* recursively show all children. Skip PopUp[nvoci]. */
for (; menu != NULL && !got_int; menu = menu->next)
if (!menu_is_hidden(menu->dname))
// recursively show all children. Skip PopUp[nvoci].
for (; menu != NULL && !got_int; menu = menu->next) {
if (!menu_is_hidden(menu->dname)) {
show_menus_recursive(menu, modes, depth + 1);
}
}
}
}
@@ -907,13 +923,12 @@ static void show_menus_recursive(vimmenu_T *menu, int modes, int depth)
*/
static vimmenu_T *expand_menu = NULL;
static int expand_modes = 0x0;
static int expand_emenu; /* TRUE for ":emenu" command */
static int expand_emenu; // TRUE for ":emenu" command
/*
* Work out what to complete when doing command line completion of menu names.
*/
char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
bool forceit)
char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg, bool forceit)
FUNC_ATTR_NONNULL_ALL
{
char_u *after_dot;
@@ -927,33 +942,38 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
xp->xp_context = EXPAND_UNSUCCESSFUL;
/* Check for priority numbers, enable and disable */
for (p = arg; *p; ++p)
if (!ascii_isdigit(*p) && *p != '.')
// Check for priority numbers, enable and disable
for (p = arg; *p; ++p) {
if (!ascii_isdigit(*p) && *p != '.') {
break;
}
}
if (!ascii_iswhite(*p)) {
if (STRNCMP(arg, "enable", 6) == 0
&& (arg[6] == NUL || ascii_iswhite(arg[6])))
&& (arg[6] == NUL || ascii_iswhite(arg[6]))) {
p = arg + 6;
else if (STRNCMP(arg, "disable", 7) == 0
&& (arg[7] == NUL || ascii_iswhite(arg[7])))
} else if (STRNCMP(arg, "disable", 7) == 0
&& (arg[7] == NUL || ascii_iswhite(arg[7]))) {
p = arg + 7;
else
} else {
p = arg;
}
}
while (*p != NUL && ascii_iswhite(*p))
while (*p != NUL && ascii_iswhite(*p)) {
++p;
}
arg = after_dot = p;
for (; *p && !ascii_iswhite(*p); ++p) {
if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL)
if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) {
p++;
else if (*p == '.')
} else if (*p == '.') {
after_dot = p + 1;
}
}
// ":popup" only uses menus, not entries
expand_menus = !((*cmd == 't' && cmd[1] == 'e') || *cmd == 'p');
@@ -966,12 +986,13 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
// With :menu though you might want to add a menu with the same name as
// one in another mode, so match menus from other modes too.
expand_modes = get_menu_cmd_modes(cmd, forceit, NULL, &unmenu);
if (!unmenu)
if (!unmenu) {
expand_modes = MENU_ALL_MODES;
}
menu = root_menu;
if (after_dot > arg) {
size_t path_len = (size_t) (after_dot - arg);
size_t path_len = (size_t)(after_dot - arg);
path_name = xmalloc(path_len);
STRLCPY(path_name, arg, path_len);
}
@@ -980,7 +1001,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
p = menu_name_skip(name);
while (menu != NULL) {
if (menu_name_equal(name, menu)) {
/* Found menu */
// Found menu
if ((*p != NUL && menu->children == NULL)
|| ((menu->modes & expand_modes) == 0x0)) {
/*
@@ -995,7 +1016,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, const char *cmd, char_u *arg,
menu = menu->next;
}
if (menu == NULL) {
/* No menu found with the name we were looking for */
// No menu found with the name we were looking for
xfree(path_name);
return NULL;
}
@@ -1023,31 +1044,34 @@ char_u *get_menu_name(expand_T *xp, int idx)
char_u *str;
static int should_advance = FALSE;
if (idx == 0) { /* first call: start at first item */
if (idx == 0) { // first call: start at first item
menu = expand_menu;
should_advance = false;
}
/* Skip PopUp[nvoci]. */
// Skip PopUp[nvoci].
while (menu != NULL && (menu_is_hidden(menu->dname)
|| menu_is_separator(menu->dname)
|| menu->children == NULL)) {
menu = menu->next;
}
if (menu == NULL) /* at end of linked list */
if (menu == NULL) { // at end of linked list
return NULL;
}
if (menu->modes & expand_modes)
if (should_advance)
if (menu->modes & expand_modes) {
if (should_advance) {
str = menu->en_dname;
else {
} else {
str = menu->dname;
if (menu->en_dname == NULL)
if (menu->en_dname == NULL) {
should_advance = TRUE;
}
else
}
} else {
str = (char_u *)"";
}
if (should_advance) {
// Advance to next menu entry.
@@ -1067,16 +1091,16 @@ char_u *get_menu_names(expand_T *xp, int idx)
{
static vimmenu_T *menu = NULL;
#define TBUFFER_LEN 256
static char_u tbuffer[TBUFFER_LEN]; /*hack*/
static char_u tbuffer[TBUFFER_LEN]; //hack
char_u *str;
static bool should_advance = false;
if (idx == 0) { /* first call: start at first item */
if (idx == 0) { // first call: start at first item
menu = expand_menu;
should_advance = false;
}
/* Skip Browse-style entries, popup menus and separators. */
// Skip Browse-style entries, popup menus and separators.
while (menu != NULL
&& (menu_is_hidden(menu->dname)
|| (expand_emenu && menu_is_separator(menu->dname))
@@ -1084,8 +1108,9 @@ char_u *get_menu_names(expand_T *xp, int idx)
menu = menu->next;
}
if (menu == NULL) /* at end of linked list */
if (menu == NULL) { // at end of linked list
return NULL;
}
if (menu->modes & expand_modes) {
if (menu->children != NULL) {
@@ -1102,17 +1127,18 @@ char_u *get_menu_names(expand_T *xp, int idx)
STRCAT(tbuffer, "\001");
str = tbuffer;
} else {
if (should_advance)
if (should_advance) {
str = menu->en_dname;
else {
} else {
str = menu->dname;
if (menu->en_dname == NULL) {
should_advance = true;
}
}
}
} else
} else {
str = (char_u *)"";
}
if (should_advance) {
// Advance to next menu entry.
@@ -1137,12 +1163,14 @@ char_u *menu_name_skip(char_u *const name)
for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) {
if (*p == '\\' || *p == Ctrl_V) {
STRMOVE(p, p + 1);
if (*p == NUL)
if (*p == NUL) {
break;
}
}
if (*p)
}
if (*p) {
*p++ = NUL;
}
return p;
}
@@ -1154,8 +1182,9 @@ static bool menu_name_equal(const char_u *const name, vimmenu_T *const menu)
{
if (menu->en_name != NULL
&& (menu_namecmp(name, menu->en_name)
|| menu_namecmp(name, menu->en_dname)))
|| menu_namecmp(name, menu->en_dname))) {
return true;
}
return menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname);
}
@@ -1163,9 +1192,11 @@ static bool menu_namecmp(const char_u *const name, const char_u *const mname)
{
int i;
for (i = 0; name[i] != NUL && name[i] != TAB; ++i)
if (name[i] != mname[i])
for (i = 0; name[i] != NUL && name[i] != TAB; ++i) {
if (name[i] != mname[i]) {
break;
}
}
return (name[i] == NUL || name[i] == TAB)
&& (mname[i] == NUL || mname[i] == TAB);
}
@@ -1180,45 +1211,39 @@ static bool menu_namecmp(const char_u *const name, const char_u *const mname)
/// to whether the command is a "nore" command.
/// @param[out] unmenu If not NULL, the flag it points to is set according
/// to whether the command is an "unmenu" command.
int
get_menu_cmd_modes(
const char *cmd,
bool forceit,
int *noremap,
int *unmenu
)
int get_menu_cmd_modes(const char *cmd, bool forceit, int *noremap, int *unmenu)
{
int modes;
switch (*cmd++) {
case 'v': /* vmenu, vunmenu, vnoremenu */
case 'v': // vmenu, vunmenu, vnoremenu
modes = MENU_VISUAL_MODE | MENU_SELECT_MODE;
break;
case 'x': /* xmenu, xunmenu, xnoremenu */
case 'x': // xmenu, xunmenu, xnoremenu
modes = MENU_VISUAL_MODE;
break;
case 's': /* smenu, sunmenu, snoremenu */
case 's': // smenu, sunmenu, snoremenu
modes = MENU_SELECT_MODE;
break;
case 'o': /* omenu */
case 'o': // omenu
modes = MENU_OP_PENDING_MODE;
break;
case 'i': /* imenu */
case 'i': // imenu
modes = MENU_INSERT_MODE;
break;
case 't':
modes = MENU_TIP_MODE; /* tmenu */
modes = MENU_TIP_MODE; // tmenu
break;
case 'c': /* cmenu */
case 'c': // cmenu
modes = MENU_CMDLINE_MODE;
break;
case 'a': /* amenu */
case 'a': // amenu
modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE | MENU_NORMAL_MODE
| MENU_VISUAL_MODE | MENU_SELECT_MODE
| MENU_OP_PENDING_MODE;
break;
case 'n':
if (*cmd != 'o') { /* nmenu, not noremenu */
if (*cmd != 'o') { // nmenu, not noremenu
modes = MENU_NORMAL_MODE;
break;
}
@@ -1235,10 +1260,12 @@ get_menu_cmd_modes(
}
}
if (noremap != NULL)
if (noremap != NULL) {
*noremap = (*cmd == 'n' ? REMAP_NONE : REMAP_YES);
if (unmenu != NULL)
}
if (unmenu != NULL) {
*unmenu = (*cmd == 'u');
}
return modes;
}
@@ -1277,24 +1304,28 @@ static char_u *menu_text(const char_u *str, int *mnemonic, char_u **actext)
char_u *p;
char_u *text;
/* Locate accelerator text, after the first TAB */
// Locate accelerator text, after the first TAB
p = vim_strchr(str, TAB);
if (p != NULL) {
if (actext != NULL)
if (actext != NULL) {
*actext = vim_strsave(p + 1);
}
assert(p >= str);
text = vim_strnsave(str, (size_t)(p - str));
} else
} else {
text = vim_strsave(str);
}
/* Find mnemonic characters "&a" and reduce "&&" to "&". */
// Find mnemonic characters "&a" and reduce "&&" to "&".
for (p = text; p != NULL; ) {
p = vim_strchr(p, '&');
if (p != NULL) {
if (p[1] == NUL) /* trailing "&" */
if (p[1] == NUL) { // trailing "&"
break;
if (mnemonic != NULL && p[1] != '&')
}
if (mnemonic != NULL && p[1] != '&') {
*mnemonic = p[1];
}
STRMOVE(p, p + 1);
p = p + 1;
}
@@ -1379,13 +1410,13 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu)
* select start and end. */
if ((curbuf->b_visual.vi_start.lnum == eap->line1)
&& (curbuf->b_visual.vi_end.lnum) == eap->line2) {
/* Set it up for visual mode - equivalent to gv. */
// Set it up for visual mode - equivalent to gv.
VIsual_mode = curbuf->b_visual.vi_mode;
tpos = curbuf->b_visual.vi_end;
curwin->w_cursor = curbuf->b_visual.vi_start;
curwin->w_curswant = curbuf->b_visual.vi_curswant;
} else {
/* Set it up for line-wise visual mode */
// Set it up for line-wise visual mode
VIsual_mode = 'V';
curwin->w_cursor.lnum = eap->line1;
curwin->w_cursor.col = 1;
@@ -1394,7 +1425,7 @@ static void execute_menu(const exarg_T *eap, vimmenu_T *menu)
tpos.coladd = 0;
}
/* Activate visual mode */
// Activate visual mode
VIsual_active = TRUE;
VIsual_reselect = TRUE;
check_cursor();
@@ -1484,15 +1515,15 @@ void ex_emenu(exarg_T *eap)
*/
typedef struct {
char_u *from; /* English name */
char_u *from_noamp; /* same, without '&' */
char_u *to; /* translated name */
char_u *from; // English name
char_u *from_noamp; // same, without '&'
char_u *to; // translated name
} menutrans_T;
static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE;
#define FREE_MENUTRANS(mt) \
menutrans_T* _mt = (mt); \
menutrans_T * _mt = (mt); \
xfree(_mt->from); \
xfree(_mt->from_noamp); \
xfree(_mt->to)
@@ -1507,8 +1538,9 @@ void ex_menutranslate(exarg_T *eap)
char_u *arg = eap->arg;
char_u *from, *from_noamp, *to;
if (menutrans_ga.ga_itemsize == 0)
if (menutrans_ga.ga_itemsize == 0) {
ga_init(&menutrans_ga, (int)sizeof(menutrans_T), 5);
}
/*
* ":menutrans clear": clear all translations.
@@ -1516,18 +1548,18 @@ void ex_menutranslate(exarg_T *eap)
if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) {
GA_DEEP_CLEAR(&menutrans_ga, menutrans_T, FREE_MENUTRANS);
/* Delete all "menutrans_" global variables. */
// Delete all "menutrans_" global variables.
del_menutrans_vars();
} else {
/* ":menutrans from to": add translation */
// ":menutrans from to": add translation
from = arg;
arg = menu_skip_part(arg);
to = skipwhite(arg);
*arg = NUL;
arg = menu_skip_part(to);
if (arg == to)
if (arg == to) {
EMSG(_(e_invarg));
else {
} else {
from = vim_strsave(from);
from_noamp = menu_text(from, NULL, NULL);
assert(arg >= to);
@@ -1536,7 +1568,7 @@ void ex_menutranslate(exarg_T *eap)
menu_translate_tab_and_shift(to);
menu_unescape_name(from);
menu_unescape_name(to);
menutrans_T* tp = GA_APPEND_VIA_PTR(menutrans_T, &menutrans_ga);
menutrans_T * tp = GA_APPEND_VIA_PTR(menutrans_T, &menutrans_ga);
tp->from = from;
tp->from_noamp = from_noamp;
tp->to = to;
@@ -1550,8 +1582,9 @@ void ex_menutranslate(exarg_T *eap)
static char_u *menu_skip_part(char_u *p)
{
while (*p != NUL && *p != '.' && !ascii_iswhite(*p)) {
if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL)
if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) {
++p;
}
++p;
}
return p;
@@ -1572,7 +1605,7 @@ static char_u *menutrans_lookup(char_u *name, int len)
}
}
/* Now try again while ignoring '&' characters. */
// Now try again while ignoring '&' characters.
char_u c = name[len];
name[len] = NUL;
dname = menu_text(name, NULL, NULL);
@@ -1611,16 +1644,17 @@ static char_u *menu_translate_tab_and_shift(char_u *arg_start)
char_u *arg = arg_start;
while (*arg && !ascii_iswhite(*arg)) {
if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL)
if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL) {
arg++;
else if (STRNICMP(arg, "<TAB>", 5) == 0) {
} else if (STRNICMP(arg, "<TAB>", 5) == 0) {
*arg = TAB;
STRMOVE(arg + 1, arg + 5);
}
arg++;
}
if (*arg != NUL)
if (*arg != NUL) {
*arg++ = NUL;
}
arg = skipwhite(arg);
return arg;

File diff suppressed because it is too large Load Diff

View File

@@ -7,37 +7,43 @@
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/misc1.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/event/stream.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/fold.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/buffer_updates.h"
#include "nvim/main.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/misc1.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
@@ -48,14 +54,8 @@
#include "nvim/tag.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h"
#include "nvim/event/stream.h"
#include "nvim/buffer.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "misc1.c.generated.h"
@@ -73,23 +73,23 @@ static garray_T ga_users = GA_EMPTY_INIT_VALUE;
* If "include_space" is set, include trailing whitespace while calculating the
* length.
*/
int get_leader_len(char_u *line, char_u **flags,
bool backward, bool include_space)
int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_space)
{
int i, j;
int result;
int got_com = FALSE;
int found_one;
char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
char_u *string; /* pointer to comment string */
char_u part_buf[COM_MAX_LEN]; // buffer for one option part
char_u *string; // pointer to comment string
char_u *list;
int middle_match_len = 0;
char_u *prev_list;
char_u *saved_flags = NULL;
result = i = 0;
while (ascii_iswhite(line[i])) /* leading white space is ignored */
while (ascii_iswhite(line[i])) { // leading white space is ignored
++i;
}
/*
* Repeat to match several nested comment strings.
@@ -102,51 +102,60 @@ int get_leader_len(char_u *line, char_u **flags,
for (list = curbuf->b_p_com; *list; ) {
/* Get one option part into part_buf[]. Advance "list" to next
* one. Put "string" at start of string. */
if (!got_com && flags != NULL)
*flags = list; /* remember where flags started */
if (!got_com && flags != NULL) {
*flags = list; // remember where flags started
}
prev_list = list;
(void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
string = vim_strchr(part_buf, ':');
if (string == NULL) /* missing ':', ignore this part */
if (string == NULL) { // missing ':', ignore this part
continue;
*string++ = NUL; /* isolate flags from string */
}
*string++ = NUL; // isolate flags from string
/* If we found a middle match previously, use that match when this
* is not a middle or end. */
if (middle_match_len != 0
&& vim_strchr(part_buf, COM_MIDDLE) == NULL
&& vim_strchr(part_buf, COM_END) == NULL)
&& vim_strchr(part_buf, COM_END) == NULL) {
break;
}
/* When we already found a nested comment, only accept further
* nested comments. */
if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) {
continue;
}
/* When 'O' flag present and using "O" command skip this one. */
if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
// When 'O' flag present and using "O" command skip this one.
if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) {
continue;
}
/* Line contents and string must match.
* When string starts with white space, must have some white space
* (but the amount does not need to match, there might be a mix of
* TABs and spaces). */
if (ascii_iswhite(string[0])) {
if (i == 0 || !ascii_iswhite(line[i - 1]))
continue; /* missing white space */
while (ascii_iswhite(string[0]))
if (i == 0 || !ascii_iswhite(line[i - 1])) {
continue; // missing white space
}
while (ascii_iswhite(string[0])) {
++string;
}
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
}
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) {
;
if (string[j] != NUL)
continue; /* string doesn't match */
}
if (string[j] != NUL) {
continue; // string doesn't match
}
/* When 'b' flag used, there must be white space or an
* end-of-line after the string in the line. */
if (vim_strchr(part_buf, COM_BLANK) != NULL
&& !ascii_iswhite(line[i + j]) && line[i + j] != NUL)
&& !ascii_iswhite(line[i + j]) && line[i + j] != NUL) {
continue;
}
/* We have found a match, stop searching unless this is a middle
* comment. The middle comment can be a substring of the end
@@ -160,13 +169,15 @@ int get_leader_len(char_u *line, char_u **flags,
}
continue;
}
if (middle_match_len != 0 && j > middle_match_len)
if (middle_match_len != 0 && j > middle_match_len) {
/* Use this match instead of the middle match, since it's a
* longer thus better match. */
middle_match_len = 0;
}
if (middle_match_len == 0)
if (middle_match_len == 0) {
i += j;
}
found_one = TRUE;
break;
}
@@ -174,30 +185,35 @@ int get_leader_len(char_u *line, char_u **flags,
if (middle_match_len != 0) {
/* Use the previously found middle match after failing to find a
* match with an end. */
if (!got_com && flags != NULL)
if (!got_com && flags != NULL) {
*flags = saved_flags;
}
i += middle_match_len;
found_one = TRUE;
}
/* No match found, stop scanning. */
if (!found_one)
// No match found, stop scanning.
if (!found_one) {
break;
}
result = i;
/* Include any trailing white space. */
while (ascii_iswhite(line[i]))
// Include any trailing white space.
while (ascii_iswhite(line[i])) {
++i;
}
if (include_space)
if (include_space) {
result = i;
}
/* If this comment doesn't nest, stop here. */
// If this comment doesn't nest, stop here.
got_com = TRUE;
if (vim_strchr(part_buf, COM_NEST) == NULL)
if (vim_strchr(part_buf, COM_NEST) == NULL) {
break;
}
}
return result;
}
@@ -218,7 +234,7 @@ int get_last_leader_offset(char_u *line, char_u **flags)
char_u *com_flags;
char_u *list;
int found_one;
char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
char_u part_buf[COM_MAX_LEN]; // buffer for one option part
/*
* Repeat to match several nested comment strings.
@@ -242,7 +258,7 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* happen. */
continue;
}
*string++ = NUL; /* Isolate flags from string. */
*string++ = NUL; // Isolate flags from string.
com_leader = string;
/*
@@ -252,16 +268,19 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* TABs and spaces).
*/
if (ascii_iswhite(string[0])) {
if (i == 0 || !ascii_iswhite(line[i - 1]))
if (i == 0 || !ascii_iswhite(line[i - 1])) {
continue;
}
while (ascii_iswhite(*string)) {
string++;
}
}
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) {
/* do nothing */;
if (string[j] != NUL)
}
if (string[j] != NUL) {
continue;
}
/*
* When 'b' flag used, there must be white space or an
@@ -290,23 +309,25 @@ int get_last_leader_offset(char_u *line, char_u **flags)
*/
found_one = TRUE;
if (flags)
if (flags) {
*flags = flags_save;
}
com_flags = flags_save;
break;
}
if (found_one) {
char_u part_buf2[COM_MAX_LEN]; /* buffer for one option part */
char_u part_buf2[COM_MAX_LEN]; // buffer for one option part
int len1, len2, off;
result = i;
/*
* If this comment nests, continue searching.
*/
if (vim_strchr(part_buf, COM_NEST) != NULL)
if (vim_strchr(part_buf, COM_NEST) != NULL) {
continue;
}
lower_check_bound = i;
@@ -316,36 +337,41 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* the comment leader correctly.
*/
while (ascii_iswhite(*com_leader))
while (ascii_iswhite(*com_leader)) {
++com_leader;
}
len1 = (int)STRLEN(com_leader);
for (list = curbuf->b_p_com; *list; ) {
char_u *flags_save = list;
(void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ",");
if (flags_save == com_flags)
if (flags_save == com_flags) {
continue;
}
string = vim_strchr(part_buf2, ':');
++string;
while (ascii_iswhite(*string))
while (ascii_iswhite(*string)) {
++string;
}
len2 = (int)STRLEN(string);
if (len2 == 0)
if (len2 == 0) {
continue;
}
/* Now we have to verify whether string ends with a substring
* beginning the com_leader. */
for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2; ) {
--off;
if (!STRNCMP(string + off, com_leader, len2 - off)) {
if (i - off < lower_check_bound)
if (i - off < lower_check_bound) {
lower_check_bound = i - off;
}
}
}
}
}
}
return result;
}
@@ -493,9 +519,9 @@ int get_keystroke(MultiQueue *events)
n = fix_input_buffer(buf + len, n);
len += n;
waited = 0;
} else if (len > 0)
++waited; /* keep track of the waiting time */
} else if (len > 0) {
++waited; // keep track of the waiting time
}
if (n > 0) { // found a termcode: adjust length
len = n;
}
@@ -503,19 +529,20 @@ int get_keystroke(MultiQueue *events)
continue;
}
/* Handle modifier and/or special key code. */
// Handle modifier and/or special key code.
n = buf[0];
if (n == K_SPECIAL) {
n = TO_SPECIAL(buf[1], buf[2]);
if (buf[1] == KS_MODIFIER
|| n == K_IGNORE
|| (is_mouse_key(n) && n != K_LEFTMOUSE)
) {
if (buf[1] == KS_MODIFIER)
|| (is_mouse_key(n) && n != K_LEFTMOUSE)) {
if (buf[1] == KS_MODIFIER) {
mod_mask = buf[2];
}
len -= 3;
if (len > 0)
if (len > 0) {
memmove(buf, buf + 3, (size_t)len);
}
continue;
}
break;
@@ -534,27 +561,25 @@ int get_keystroke(MultiQueue *events)
return n;
}
/*
* Get a number from the user.
* When "mouse_used" is not NULL allow using the mouse.
*/
int
get_number (
int colon, /* allow colon to abort */
int *mouse_used
)
/// Get a number from the user.
/// When "mouse_used" is not NULL allow using the mouse.
///
/// @param colon allow colon to abort
int get_number(int colon, int *mouse_used)
{
int n = 0;
int c;
int typed = 0;
if (mouse_used != NULL)
if (mouse_used != NULL) {
*mouse_used = FALSE;
}
/* When not printing messages, the user won't know what to type, return a
* zero (as if CR was hit). */
if (msg_silent != 0)
if (msg_silent != 0) {
return 0;
}
no_mapping++;
for (;; ) {
@@ -576,8 +601,9 @@ get_number (
break;
} else if (n == 0 && c == ':' && colon) {
stuffcharReadbuff(':');
if (!exmode_active)
if (!exmode_active) {
cmdline_row = msg_row;
}
skip_redraw = true; // skip redraw once
do_redraw = false;
break;
@@ -643,35 +669,40 @@ void msgmore(long n)
{
long pn;
if (global_busy /* no messages now, wait until global is finished */
|| !messaging()) /* 'lazyredraw' set, don't do messages now */
if (global_busy // no messages now, wait until global is finished
|| !messaging()) { // 'lazyredraw' set, don't do messages now
return;
}
/* We don't want to overwrite another important message, but do overwrite
* a previous "more lines" or "fewer lines" message, so that "5dd" and
* then "put" reports the last action. */
if (keep_msg != NULL && !keep_msg_more)
if (keep_msg != NULL && !keep_msg_more) {
return;
}
if (n > 0)
if (n > 0) {
pn = n;
else
} else {
pn = -n;
}
if (pn > p_report) {
if (pn == 1) {
if (n > 0)
if (n > 0) {
STRLCPY(msg_buf, _("1 more line"), MSG_BUF_LEN);
else
STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN);
} else {
if (n > 0)
STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN);
}
} else {
if (n > 0) {
vim_snprintf((char *)msg_buf, MSG_BUF_LEN,
_("%" PRId64 " more lines"), (int64_t)pn);
else
} else {
vim_snprintf((char *)msg_buf, MSG_BUF_LEN,
_("%" PRId64 " fewer lines"), (int64_t)pn);
}
}
if (got_int) {
xstrlcat((char *)msg_buf, _(" (Interrupted)"), MSG_BUF_LEN);
}
@@ -762,8 +793,9 @@ static void init_users(void)
char_u *get_users(expand_T *xp, int idx)
{
init_users();
if (idx < ga_users.ga_len)
if (idx < ga_users.ga_len) {
return ((char_u **)ga_users.ga_data)[idx];
}
return NULL;
}
@@ -780,10 +812,12 @@ int match_user(char_u *name)
init_users();
for (int i = 0; i < ga_users.ga_len; i++) {
if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0)
return 2; /* full match */
if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0)
result = 1; /* partial match */
if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) {
return 2; // full match
}
if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) {
result = 1; // partial match
}
}
return result;
}
@@ -921,8 +955,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
/// @param ret_len length of the stdout
///
/// @return an allocated string, or NULL for error.
char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags,
size_t *ret_len)
char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret_len)
{
char_u *buffer = NULL;
@@ -970,12 +1003,14 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags,
EMSG2(_(e_notread), tempname);
XFREE_CLEAR(buffer);
} else if (ret_len == NULL) {
/* Change NUL into SOH, otherwise the string is truncated. */
for (i = 0; i < len; ++i)
if (buffer[i] == NUL)
// Change NUL into SOH, otherwise the string is truncated.
for (i = 0; i < len; ++i) {
if (buffer[i] == NUL) {
buffer[i] = 1;
}
}
buffer[len] = NUL; /* make sure the buffer is terminated */
buffer[len] = NUL; // make sure the buffer is terminated
} else {
*ret_len = len;
}
@@ -991,10 +1026,12 @@ done:
*/
void FreeWild(int count, char_u **files)
{
if (count <= 0 || files == NULL)
if (count <= 0 || files == NULL) {
return;
while (count--)
}
while (count--) {
xfree(files[count]);
}
xfree(files);
}

View File

@@ -3,26 +3,26 @@
#include <stdbool.h>
#include "nvim/mouse.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/window.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/fold.h"
#include "nvim/memline.h"
#include "nvim/misc1.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/os_unix.h"
#include "nvim/plines.h"
#include "nvim/screen.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/screen.h"
#include "nvim/syntax.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
#include "nvim/os_unix.h"
#include "nvim/fold.h"
#include "nvim/diff.h"
#include "nvim/move.h"
#include "nvim/misc1.h"
#include "nvim/plines.h"
#include "nvim/cursor.h"
#include "nvim/buffer_defs.h"
#include "nvim/memline.h"
#include "nvim/charset.h"
#include "nvim/vim.h"
#include "nvim/window.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mouse.c.generated.h"
@@ -31,33 +31,34 @@
static linenr_T orig_topline = 0;
static int orig_topfill = 0;
// Move the cursor to the specified row and column on the screen.
// Change current window if necessary. Returns an integer with the
// CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
//
// The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
// The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
//
// If flags has MOUSE_FOCUS, then the current window will not be changed, and
// if the mouse is outside the window then the text will scroll, or if the
// mouse was previously on a status line, then the status line may be dragged.
//
// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
// cursor is moved unless the cursor was on a status line.
// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
// IN_SEP_LINE depending on where the cursor was clicked.
//
// If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
// the mouse is on the status line of the same window.
//
// If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
// the last call.
//
// If flags has MOUSE_SETPOS, nothing is done, only the current position is
// remembered.
int jump_to_mouse(int flags,
bool *inclusive, // used for inclusive operator, can be NULL
int which_button) // MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE
/// Move the cursor to the specified row and column on the screen.
/// Change current window if necessary. Returns an integer with the
/// CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
///
/// The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
/// The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
///
/// If flags has MOUSE_FOCUS, then the current window will not be changed, and
/// if the mouse is outside the window then the text will scroll, or if the
/// mouse was previously on a status line, then the status line may be dragged.
///
/// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
/// cursor is moved unless the cursor was on a status line.
/// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
/// IN_SEP_LINE depending on where the cursor was clicked.
///
/// If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
/// the mouse is on the status line of the same window.
///
/// If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
/// the last call.
///
/// If flags has MOUSE_SETPOS, nothing is done, only the current position is
/// remembered.
///
/// @param inclusive used for inclusive operator, can be NULL
/// @param which_button MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE
int jump_to_mouse(int flags, bool *inclusive, int which_button)
{
static int on_status_line = 0; // #lines below bottom of window
static int on_sep_line = 0; // on separator right of window
@@ -81,8 +82,9 @@ int jump_to_mouse(int flags,
if (flags & MOUSE_RELEASED) {
// On button release we may change window focus if positioned on a
// status line and no dragging happened.
if (dragwin != NULL && !did_drag)
if (dragwin != NULL && !did_drag) {
flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE);
}
dragwin = NULL;
did_drag = false;
}
@@ -109,15 +111,16 @@ retnomove:
prev_row = mouse_row;
prev_col = mouse_col;
if (flags & MOUSE_SETPOS)
if (flags & MOUSE_SETPOS) {
goto retnomove; // ugly goto...
}
old_curwin = curwin;
old_cursor = curwin->w_cursor;
if (!(flags & MOUSE_FOCUS)) {
if (row < 0 || col < 0) // check if it makes sense
if (row < 0 || col < 0) { // check if it makes sense
return IN_UNKNOWN;
}
// find the window where the row is in
wp = mouse_find_win(&grid, &row, &col);
@@ -151,11 +154,12 @@ retnomove:
// The rightmost character of the status line might be a vertical
// separator character if there is no connecting window to the right.
if (on_status_line && on_sep_line) {
if (stl_connected(wp))
if (stl_connected(wp)) {
on_sep_line = 0;
else
} else {
on_status_line = 0;
}
}
// Before jumping to another buffer, or moving the cursor for a left
// click, stop Visual mode.
@@ -181,25 +185,29 @@ retnomove:
// Only change window focus when not clicking on or dragging the
// status line. Do change focus when releasing the mouse button
// (MOUSE_FOCUS was set above if we dragged first).
if (dragwin == NULL || (flags & MOUSE_RELEASED))
if (dragwin == NULL || (flags & MOUSE_RELEASED)) {
win_enter(wp, true); // can make wp invalid!
}
// set topline, to be able to check for double click ourselves
if (curwin != old_curwin)
if (curwin != old_curwin) {
set_mouse_topline(curwin);
}
if (on_status_line) { // In (or below) status line
// Don't use start_arrow() if we're in the same window
if (curwin == old_curwin)
if (curwin == old_curwin) {
return IN_STATUS_LINE;
else
} else {
return IN_STATUS_LINE | CURSOR_MOVED;
}
}
if (on_sep_line) { // In (or below) status line
// Don't use start_arrow() if we're in the same window
if (curwin == old_curwin)
if (curwin == old_curwin) {
return IN_SEP_LINE;
else
} else {
return IN_SEP_LINE | CURSOR_MOVED;
}
}
curwin->w_cursor.lnum = curwin->w_topline;
} else if (on_status_line && which_button == MOUSE_LEFT) {
@@ -394,8 +402,9 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
if (!retval) {
// Compute the column without wrapping.
off = win_col_off(win) - win_col_off2(win);
if (col < off)
if (col < off) {
col = off;
}
col += row * (win->w_width_inner - off);
// add skip column (for long wrapping line)
col += win->w_skipcol;
@@ -436,18 +445,21 @@ win_T *mouse_find_win(int *gridp, int *rowp, int *colp)
fp = topframe;
*rowp -= firstwin->w_winrow;
for (;; ) {
if (fp->fr_layout == FR_LEAF)
if (fp->fr_layout == FR_LEAF) {
break;
}
if (fp->fr_layout == FR_ROW) {
for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) {
if (*colp < fp->fr_width)
if (*colp < fp->fr_width) {
break;
}
*colp -= fp->fr_width;
}
} else { // fr_layout == FR_COL
for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) {
if (*rowp < fp->fr_height)
if (*rowp < fp->fr_height) {
break;
}
*rowp -= fp->fr_height;
}
}

View File

@@ -18,7 +18,6 @@
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/move.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
@@ -27,17 +26,18 @@
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/misc1.h"
#include "nvim/plines.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/plines.h"
#include "nvim/popupmnu.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/window.h"
typedef struct {
linenr_T lnum; /* line number */
int fill; /* filler lines */
int height; /* height of added line */
linenr_T lnum; // line number
int fill; // filler lines
int height; // height of added line
} lineoff_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -85,7 +85,7 @@ static void comp_botline(win_T *wp)
lnum = last;
}
/* wp->w_botline is the line that is just below the window */
// wp->w_botline is the line that is just below the window
wp->w_botline = lnum;
wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
wp->w_viewport_invalid = true;
@@ -274,8 +274,7 @@ void update_topline(win_T *wp)
n += wp->w_filler_rows;
loff.height = 0;
while (loff.lnum < wp->w_botline
&& (loff.lnum + 1 < wp->w_botline || loff.fill == 0)
) {
&& (loff.lnum + 1 < wp->w_botline || loff.fill == 0)) {
n += loff.height;
if (n >= *so_ptr) {
break;
@@ -287,7 +286,7 @@ void update_topline(win_T *wp)
check_botline = false;
}
} else {
/* sufficient context, no need to scroll */
// sufficient context, no need to scroll
check_botline = false;
}
}
@@ -325,8 +324,7 @@ void update_topline(win_T *wp)
* Need to redraw when topline changed.
*/
if (wp->w_topline != old_topline
|| wp->w_topfill != old_topfill
) {
|| wp->w_topfill != old_topfill) {
dollar_vcol = -1;
if (wp->w_skipcol != 0) {
wp->w_skipcol = 0;
@@ -346,7 +344,7 @@ void update_topline(win_T *wp)
/*
* Update win->w_topline to move the cursor onto the screen.
*/
void update_topline_win(win_T* win)
void update_topline_win(win_T * win)
{
win_T *save_curwin;
switch_win(&save_curwin, NULL, win, NULL, true);
@@ -374,8 +372,7 @@ static bool check_top_offset(void)
{
long so = get_scrolloff_value(curwin);
if (curwin->w_cursor.lnum < curwin->w_topline + so
|| hasAnyFolding(curwin)
) {
|| hasAnyFolding(curwin)) {
lineoff_T loff;
loff.lnum = curwin->w_cursor.lnum;
loff.fill = 0;
@@ -385,8 +382,8 @@ static bool check_top_offset(void)
topline_back(curwin, &loff);
// Stop when included a line above the window.
if (loff.lnum < curwin->w_topline
|| (loff.lnum == curwin->w_topline && loff.fill > 0)
) {
|| (loff.lnum == curwin->w_topline &&
loff.fill > 0)) {
break;
}
n += loff.height;
@@ -420,8 +417,8 @@ void check_cursor_moved(win_T *wp)
wp->w_viewport_invalid = true;
} else if (wp->w_cursor.col != wp->w_valid_cursor.col
|| wp->w_leftcol != wp->w_valid_leftcol
|| wp->w_cursor.coladd != wp->w_valid_cursor.coladd
) {
|| wp->w_cursor.coladd !=
wp->w_valid_cursor.coladd) {
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
wp->w_valid_cursor.col = wp->w_cursor.col;
wp->w_valid_leftcol = wp->w_leftcol;
@@ -560,7 +557,7 @@ void validate_cursor(void)
*/
static void curs_rows(win_T *wp)
{
/* Check if wp->w_lines[].wl_size is invalid */
// Check if wp->w_lines[].wl_size is invalid
int all_invalid = (!redrawing()
|| wp->w_lines_valid == 0
|| wp->w_lines[0].wl_lnum > wp->w_topline);
@@ -569,27 +566,29 @@ static void curs_rows(win_T *wp)
for (linenr_T lnum = wp->w_topline; lnum < wp->w_cursor.lnum; ++i) {
bool valid = false;
if (!all_invalid && i < wp->w_lines_valid) {
if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid)
continue; /* skip changed or deleted lines */
if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) {
continue; // skip changed or deleted lines
}
if (wp->w_lines[i].wl_lnum == lnum) {
/* Check for newly inserted lines below this row, in which
* case we need to check for folded lines. */
if (!wp->w_buffer->b_mod_set
|| wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum
|| wp->w_buffer->b_mod_top
> wp->w_lines[i].wl_lastlnum + 1)
> wp->w_lines[i].wl_lastlnum + 1) {
valid = true;
}
} else if (wp->w_lines[i].wl_lnum > lnum) {
--i; /* hold at inserted lines */
--i; // hold at inserted lines
}
}
if (valid
&& (lnum != wp->w_topline || !wp->w_p_diff)
) {
&& (lnum != wp->w_topline || !wp->w_p_diff)) {
lnum = wp->w_lines[i].wl_lastlnum + 1;
/* Cursor inside folded lines, don't count this row */
if (lnum > wp->w_cursor.lnum)
// Cursor inside folded lines, don't count this row
if (lnum > wp->w_cursor.lnum) {
break;
}
wp->w_cline_row += wp->w_lines[i].wl_size;
} else {
linenr_T last = lnum;
@@ -613,7 +612,7 @@ static void curs_rows(win_T *wp)
wp->w_cline_height = plines_win_full(wp, wp->w_cursor.lnum, NULL,
&wp->w_cline_folded, true);
} else if (i > wp->w_lines_valid) {
/* a line that is too long to fit on the last screen line */
// a line that is too long to fit on the last screen line
wp->w_cline_height = 0;
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, NULL,
NULL, true, NULL);
@@ -645,10 +644,10 @@ void validate_virtcol_win(win_T *wp)
getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
wp->w_valid |= VALID_VIRTCOL;
if (wp->w_p_cuc
&& !pum_visible()
)
&& !pum_visible()) {
redraw_later(wp, SOME_VALID);
}
}
}
/*
@@ -718,8 +717,9 @@ int curwin_col_off(void)
*/
int win_col_off2(win_T *wp)
{
if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL)
if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) {
return number_width(wp) + 1;
}
return 0;
}
@@ -732,10 +732,7 @@ int curwin_col_off2(void)
// Also updates curwin->w_wrow and curwin->w_cline_row.
// Also updates curwin->w_leftcol.
// @param may_scroll when true, may scroll horizontally
void curs_columns(
win_T *wp,
int may_scroll
)
void curs_columns(win_T *wp, int may_scroll)
{
int n;
int width = 0;
@@ -765,9 +762,10 @@ void curs_columns(
getvvcol(wp, &wp->w_cursor, &startcol, &(wp->w_virtcol), &endcol);
}
/* remove '$' from change command when cursor moves onto it */
if (startcol > dollar_vcol)
// remove '$' from change command when cursor moves onto it
if (startcol > dollar_vcol) {
dollar_vcol = -1;
}
int extra = win_col_off(wp);
wp->w_wcol = wp->w_virtcol + extra;
@@ -782,8 +780,7 @@ void curs_columns(
wp->w_wcol = wp->w_width_inner - 1;
wp->w_wrow = wp->w_height_inner - 1;
} else if (wp->w_p_wrap
&& wp->w_width_inner != 0
) {
&& wp->w_width_inner != 0) {
width = textwidth + win_col_off2(wp);
// long line wrapping, adjust wp->w_wrow
@@ -803,8 +800,7 @@ void curs_columns(
}
}
} else if (may_scroll
&& !wp->w_cline_folded
) {
&& !wp->w_cline_folded) {
// No line wrapping: compute wp->w_leftcol if scrolling is on and line
// is not folded.
// If scrolling is off, wp->w_leftcol is assumed to be 0
@@ -836,8 +832,9 @@ void curs_columns(
new_leftcol = wp->w_leftcol + diff;
}
}
if (new_leftcol < 0)
if (new_leftcol < 0) {
new_leftcol = 0;
}
if (new_leftcol != (int)wp->w_leftcol) {
wp->w_leftcol = new_leftcol;
win_check_anchored_floats(wp);
@@ -872,8 +869,7 @@ void curs_columns(
&& wp->w_height_inner != 0
&& wp->w_cursor.lnum == wp->w_topline
&& width > 0
&& wp->w_width_inner != 0
) {
&& wp->w_width_inner != 0) {
/* Cursor past end of screen. Happens with a single line that does
* not fit on screen. Find a skipcol to show the text around the
* cursor. Avoid scrolling all the time. compute value of "extra":
@@ -972,8 +968,8 @@ void curs_columns(
/// @param[out] scolp start screen column
/// @param[out] ccolp cursor screen column
/// @param[out] ecolp end screen column
void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp,
int *ccolp, int *ecolp, bool local)
void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp, int *ecolp,
bool local)
{
colnr_T scol = 0, ccol = 0, ecol = 0;
int row = 0;
@@ -1041,39 +1037,42 @@ bool scrolldown(long line_count, int byfold)
{
int done = 0; // total # of physical lines done
/* Make sure w_topline is at the first of a sequence of folded lines. */
// Make sure w_topline is at the first of a sequence of folded lines.
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
validate_cursor(); /* w_wrow needs to be valid */
validate_cursor(); // w_wrow needs to be valid
while (line_count-- > 0) {
if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)
&& curwin->w_topfill < curwin->w_height_inner - 1) {
curwin->w_topfill++;
done++;
} else {
if (curwin->w_topline == 1)
if (curwin->w_topline == 1) {
break;
}
--curwin->w_topline;
curwin->w_topfill = 0;
/* A sequence of folded lines only counts for one logical line */
// A sequence of folded lines only counts for one logical line
linenr_T first;
if (hasFolding(curwin->w_topline, &first, NULL)) {
++done;
if (!byfold)
if (!byfold) {
line_count -= curwin->w_topline - first - 1;
}
curwin->w_botline -= curwin->w_topline - first;
curwin->w_topline = first;
} else {
done += plines_win_nofill(curwin, curwin->w_topline, true);
}
}
--curwin->w_botline; /* approximate w_botline */
--curwin->w_botline; // approximate w_botline
invalidate_botline();
}
curwin->w_wrow += done; /* keep w_wrow updated */
curwin->w_cline_row += done; /* keep w_cline_row updated */
curwin->w_wrow += done; // keep w_wrow updated
curwin->w_cline_row += done; // keep w_cline_row updated
if (curwin->w_cursor.lnum == curwin->w_topline)
if (curwin->w_cursor.lnum == curwin->w_topline) {
curwin->w_cline_row = 0;
}
check_topfill(curwin, true);
/*
@@ -1082,8 +1081,7 @@ bool scrolldown(long line_count, int byfold)
*/
int wrow = curwin->w_wrow;
if (curwin->w_p_wrap
&& curwin->w_width_inner != 0
) {
&& curwin->w_width_inner != 0) {
validate_virtcol();
validate_cheight();
wrow += curwin->w_cline_height - 1 -
@@ -1094,10 +1092,11 @@ bool scrolldown(long line_count, int byfold)
linenr_T first;
if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) {
--wrow;
if (first == 1)
if (first == 1) {
curwin->w_cursor.lnum = 1;
else
} else {
curwin->w_cursor.lnum = first - 1;
}
} else {
wrow -= plines_win(curwin, curwin->w_cursor.lnum--, true);
}
@@ -1106,7 +1105,7 @@ bool scrolldown(long line_count, int byfold)
moved = true;
}
if (moved) {
/* Move cursor to first line of closed fold. */
// Move cursor to first line of closed fold.
foldAdjustCursor();
coladvance(curwin->w_curswant);
}
@@ -1127,35 +1126,40 @@ bool scrollup(long line_count, int byfold)
// count each sequence of folded lines as one logical line
linenr_T lnum = curwin->w_topline;
while (line_count--) {
if (curwin->w_topfill > 0)
if (curwin->w_topfill > 0) {
--curwin->w_topfill;
else {
if (byfold)
} else {
if (byfold) {
(void)hasFolding(lnum, NULL, &lnum);
if (lnum >= curbuf->b_ml.ml_line_count)
}
if (lnum >= curbuf->b_ml.ml_line_count) {
break;
}
++lnum;
curwin->w_topfill = diff_check_fill(curwin, lnum);
}
}
/* approximate w_botline */
// approximate w_botline
curwin->w_botline += lnum - curwin->w_topline;
curwin->w_topline = lnum;
} else {
curwin->w_topline += line_count;
curwin->w_botline += line_count; /* approximate w_botline */
curwin->w_botline += line_count; // approximate w_botline
}
if (curwin->w_topline > curbuf->b_ml.ml_line_count)
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
curwin->w_topline = curbuf->b_ml.ml_line_count;
if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1)
}
if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) {
curwin->w_botline = curbuf->b_ml.ml_line_count + 1;
}
check_topfill(curwin, false);
if (hasAnyFolding(curwin))
/* Make sure w_topline is at the first of a sequence of folded lines. */
if (hasAnyFolding(curwin)) {
// Make sure w_topline is at the first of a sequence of folded lines.
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
}
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
if (curwin->w_cursor.lnum < curwin->w_topline) {
@@ -1171,14 +1175,10 @@ bool scrollup(long line_count, int byfold)
return moved;
}
/*
* Don't end up with too many filler lines in the window.
*/
void
check_topfill (
win_T *wp,
bool down /* when true scroll down when not enough space */
)
/// Don't end up with too many filler lines in the window.
///
/// @param down when true scroll down when not enough space
void check_topfill(win_T *wp, bool down)
{
if (wp->w_topfill > 0) {
int n = plines_win_nofill(wp, wp->w_topline, true);
@@ -1224,11 +1224,11 @@ void scrolldown_clamp(void)
< diff_check_fill(curwin, curwin->w_topline));
if (curwin->w_topline <= 1
&& !can_fill
)
&& !can_fill) {
return;
}
validate_cursor(); /* w_wrow needs to be valid */
validate_cursor(); // w_wrow needs to be valid
// Compute the row number of the last row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor
@@ -1254,7 +1254,7 @@ void scrolldown_clamp(void)
curwin->w_topfill = 0;
}
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
--curwin->w_botline; /* approximate w_botline */
--curwin->w_botline; // approximate w_botline
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
}
}
@@ -1266,11 +1266,11 @@ void scrolldown_clamp(void)
void scrollup_clamp(void)
{
if (curwin->w_topline == curbuf->b_ml.ml_line_count
&& curwin->w_topfill == 0
)
&& curwin->w_topfill == 0) {
return;
}
validate_cursor(); /* w_wrow needs to be valid */
validate_cursor(); // w_wrow needs to be valid
// Compute the row number of the first row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor
@@ -1381,15 +1381,16 @@ static void topline_botline(lineoff_T *lp)
void scroll_cursor_top(int min_scroll, int always)
{
int scrolled = 0;
linenr_T top; /* just above displayed lines */
linenr_T bot; /* just below displayed lines */
linenr_T top; // just above displayed lines
linenr_T bot; // just below displayed lines
linenr_T old_topline = curwin->w_topline;
linenr_T old_topfill = curwin->w_topfill;
linenr_T new_topline;
int off = (int)get_scrolloff_value(curwin);
if (mouse_dragging > 0)
if (mouse_dragging > 0) {
off = mouse_dragging - 1;
}
/*
* Decrease topline until:
@@ -1446,8 +1447,9 @@ void scroll_cursor_top(int min_scroll, int always)
* If scrolling is needed, scroll at least 'sj' lines.
*/
if ((new_topline >= curwin->w_topline || scrolled > min_scroll)
&& extra >= off)
&& extra >= off) {
break;
}
extra += i;
new_topline = top;
@@ -1467,22 +1469,25 @@ void scroll_cursor_top(int min_scroll, int always)
* If "always" is false, only adjust topline to a lower value, higher
* value may happen with wrapping lines
*/
if (new_topline < curwin->w_topline || always)
if (new_topline < curwin->w_topline || always) {
curwin->w_topline = new_topline;
if (curwin->w_topline > curwin->w_cursor.lnum)
}
if (curwin->w_topline > curwin->w_cursor.lnum) {
curwin->w_topline = curwin->w_cursor.lnum;
}
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
if (curwin->w_topfill > 0 && extra > off) {
curwin->w_topfill -= extra - off;
if (curwin->w_topfill < 0)
if (curwin->w_topfill < 0) {
curwin->w_topfill = 0;
}
}
check_topfill(curwin, false);
if (curwin->w_topline != old_topline
|| curwin->w_topfill != old_topfill
)
|| curwin->w_topfill != old_topfill) {
curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
}
curwin->w_valid |= VALID_TOPLINE;
curwin->w_viewport_invalid = true;
}
@@ -1501,9 +1506,9 @@ void set_empty_rows(win_T *wp, int used)
wp->w_empty_rows = wp->w_height_inner - used;
if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) {
wp->w_filler_rows = diff_check_fill(wp, wp->w_botline);
if (wp->w_empty_rows > wp->w_filler_rows)
if (wp->w_empty_rows > wp->w_filler_rows) {
wp->w_empty_rows -= wp->w_filler_rows;
else {
} else {
wp->w_filler_rows = wp->w_empty_rows;
wp->w_empty_rows = 0;
}
@@ -1552,9 +1557,9 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
set_empty_rows(curwin, used);
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
if (curwin->w_topline != old_topline
|| curwin->w_topfill != old_topfill
)
|| curwin->w_topfill != old_topfill) {
curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
}
} else {
validate_botline(curwin);
}
@@ -1567,9 +1572,10 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
// botline.
if (cln >= curwin->w_botline) {
scrolled = used;
if (cln == curwin->w_botline)
if (cln == curwin->w_botline) {
scrolled -= curwin->w_empty_rows;
}
}
/*
* Stop counting lines to scroll when
@@ -1595,8 +1601,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
|| boff.lnum + 1 > curbuf->b_ml.ml_line_count)
&& loff.lnum <= curwin->w_botline
&& (loff.lnum < curwin->w_botline
|| loff.fill >= fill_below_window)
) {
|| loff.fill >= fill_below_window)) {
break;
}
@@ -1612,9 +1617,8 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
}
if (loff.lnum >= curwin->w_botline
&& (loff.lnum > curwin->w_botline
|| loff.fill <= fill_below_window)
) {
/* Count screen lines that are below the window. */
|| loff.fill <= fill_below_window)) {
// Count screen lines that are below the window.
scrolled += loff.height;
if (loff.lnum == curwin->w_botline
&& loff.fill == 0) {
@@ -1634,18 +1638,17 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
extra += boff.height;
if (boff.lnum >= curwin->w_botline
|| (boff.lnum + 1 == curwin->w_botline
&& boff.fill > curwin->w_filler_rows)
) {
/* Count screen lines that are below the window. */
&& boff.fill > curwin->w_filler_rows)) {
// Count screen lines that are below the window.
scrolled += boff.height;
if (boff.lnum == curwin->w_botline
&& boff.fill == 0
)
&& boff.fill == 0) {
scrolled -= curwin->w_empty_rows;
}
}
}
}
}
linenr_T line_count;
// curwin->w_empty_rows is larger, no need to scroll
@@ -1665,9 +1668,10 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
i += boff.height;
++line_count;
}
if (i < scrolled) /* below curwin->w_botline, don't scroll */
if (i < scrolled) { // below curwin->w_botline, don't scroll
line_count = 9999;
}
}
/*
* Scroll up if the cursor is off the bottom of the screen a bit.
@@ -1713,7 +1717,7 @@ void scroll_cursor_halfway(int atend)
boff.fill = 0;
linenr_T topline = loff.lnum;
while (topline > 1) {
if (below <= above) { /* add a line below the cursor first */
if (below <= above) { // add a line below the cursor first
if (boff.lnum < curbuf->b_ml.ml_line_count) {
botline_forw(curwin, &boff);
used += boff.height;
@@ -1722,11 +1726,12 @@ void scroll_cursor_halfway(int atend)
}
below += boff.height;
} else {
++below; /* count a "~" line */
if (atend)
++below; // count a "~" line
if (atend) {
++used;
}
}
}
if (below > above) { // add a line above the cursor
topline_back(curwin, &loff);
@@ -1743,8 +1748,9 @@ void scroll_cursor_halfway(int atend)
topfill = loff.fill;
}
}
if (!hasFolding(topline, &curwin->w_topline, NULL))
if (!hasFolding(topline, &curwin->w_topline, NULL)) {
curwin->w_topline = topline;
}
curwin->w_topfill = topfill;
if (old_topline > curwin->w_topline + curwin->w_height_inner) {
curwin->w_botfill = false;
@@ -1793,12 +1799,12 @@ void cursor_correct(void)
* If there are sufficient file-lines above and below the cursor, we can
* return now.
*/
linenr_T cln = curwin->w_cursor.lnum; /* Cursor Line Number */
linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number
if (cln >= curwin->w_topline + above_wanted
&& cln < curwin->w_botline - below_wanted
&& !hasAnyFolding(curwin)
)
&& !hasAnyFolding(curwin)) {
return;
}
/*
* Narrow down the area where the cursor can be put by taking lines from
@@ -1808,9 +1814,9 @@ void cursor_correct(void)
*/
linenr_T topline = curwin->w_topline;
linenr_T botline = curwin->w_botline - 1;
/* count filler lines as context */
int above = curwin->w_topfill; /* screen lines above topline */
int below = curwin->w_filler_rows; /* screen lines below botline */
// count filler lines as context
int above = curwin->w_topfill; // screen lines above topline
int below = curwin->w_filler_rows; // screen lines below botline
while ((above < above_wanted || below < below_wanted) && topline < botline) {
if (below < below_wanted && (below <= above || above >= above_wanted)) {
if (hasFolding(botline, &botline, NULL)) {
@@ -1827,17 +1833,18 @@ void cursor_correct(void)
above += plines_win_nofill(curwin, topline, true);
}
/* Count filler lines below this line as context. */
if (topline < botline)
// Count filler lines below this line as context.
if (topline < botline) {
above += diff_check_fill(curwin, topline + 1);
}
++topline;
}
}
if (topline == botline || botline == 0)
if (topline == botline || botline == 0) {
curwin->w_cursor.lnum = topline;
else if (topline > botline)
} else if (topline > botline) {
curwin->w_cursor.lnum = botline;
else {
} else {
if (cln < topline && curwin->w_topline > 1) {
curwin->w_cursor.lnum = topline;
curwin->w_valid &=
@@ -1867,7 +1874,7 @@ int onepage(Direction dir, long count)
linenr_T old_topline = curwin->w_topline;
long so = get_scrolloff_value(curwin);
if (curbuf->b_ml.ml_line_count == 1) { /* nothing to do */
if (curbuf->b_ml.ml_line_count == 1) { // nothing to do
beep_flush();
return FAIL;
}
@@ -1893,16 +1900,18 @@ int onepage(Direction dir, long count)
loff.fill = 0;
if (dir == FORWARD) {
if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) {
/* Vi compatible scrolling */
if (p_window <= 2)
// Vi compatible scrolling
if (p_window <= 2) {
++curwin->w_topline;
else
} else {
curwin->w_topline += p_window - 2;
if (curwin->w_topline > curbuf->b_ml.ml_line_count)
}
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
curwin->w_topline = curbuf->b_ml.ml_line_count;
}
curwin->w_cursor.lnum = curwin->w_topline;
} else if (curwin->w_botline > curbuf->b_ml.ml_line_count) {
/* at end of file */
// at end of file
curwin->w_topline = curbuf->b_ml.ml_line_count;
curwin->w_topfill = 0;
curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
@@ -1920,23 +1929,26 @@ int onepage(Direction dir, long count)
curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|
VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
}
} else { /* dir == BACKWARDS */
} else { // dir == BACKWARDS
if (curwin->w_topline == 1) {
/* Include max number of filler lines */
// Include max number of filler lines
max_topfill();
continue;
}
if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) {
/* Vi compatible scrolling (sort of) */
if (p_window <= 2)
// Vi compatible scrolling (sort of)
if (p_window <= 2) {
--curwin->w_topline;
else
} else {
curwin->w_topline -= p_window - 2;
if (curwin->w_topline < 1)
}
if (curwin->w_topline < 1) {
curwin->w_topline = 1;
}
curwin->w_cursor.lnum = curwin->w_topline + p_window - 1;
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
}
continue;
}
@@ -1967,12 +1979,12 @@ int onepage(Direction dir, long count)
n += loff.height;
}
}
if (loff.lnum < 1) { /* at begin of file */
if (loff.lnum < 1) { // at begin of file
curwin->w_topline = 1;
max_topfill();
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
} else {
/* Go two lines forward again. */
// Go two lines forward again.
topline_botline(&loff);
botline_forw(curwin, &loff);
botline_forw(curwin, &loff);
@@ -1984,14 +1996,14 @@ int onepage(Direction dir, long count)
* very long lines. */
if (loff.lnum >= curwin->w_topline
&& (loff.lnum > curwin->w_topline
|| loff.fill >= curwin->w_topfill)
) {
|| loff.fill >= curwin->w_topfill)) {
/* First try using the maximum number of filler lines. If
* that's not enough, backup one line. */
loff.fill = curwin->w_topfill;
if (curwin->w_topfill < diff_check_fill(curwin,
curwin->w_topline))
curwin->w_topline)) {
max_topfill();
}
if (curwin->w_topfill == loff.fill) {
--curwin->w_topline;
curwin->w_topfill = 0;
@@ -2059,9 +2071,9 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
lp->height = plines_win_nofill(curwin, lp->lnum, true);
}
int h1 = lp->height;
if (h1 > min_height)
return; /* no overlap */
if (h1 > min_height) {
return; // no overlap
}
lineoff_T loff0 = *lp;
if (dir > 0) {
botline_forw(curwin, lp);
@@ -2070,7 +2082,7 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
}
int h2 = lp->height;
if (h2 == MAXCOL || h2 + h1 > min_height) {
*lp = loff0; /* no overlap */
*lp = loff0; // no overlap
return;
}
@@ -2082,7 +2094,7 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
}
int h3 = lp->height;
if (h3 == MAXCOL || h3 + h2 > min_height) {
*lp = loff0; /* no overlap */
*lp = loff0; // no overlap
return;
}
@@ -2093,10 +2105,11 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
topline_back(curwin, lp);
}
int h4 = lp->height;
if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height)
*lp = loff1; /* 1 line overlap */
else
*lp = loff2; /* 2 lines overlap */
if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) {
*lp = loff1; // 1 line overlap
} else {
*lp = loff2; // 2 lines overlap
}
return;
}
@@ -2129,8 +2142,9 @@ void halfpage(bool flag, linenr_T Prenum)
} else {
i = plines_win_nofill(curwin, curwin->w_topline, true);
n -= i;
if (n < 0 && scrolled > 0)
if (n < 0 && scrolled > 0) {
break;
}
(void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline);
++curwin->w_topline;
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
@@ -2148,9 +2162,9 @@ void halfpage(bool flag, linenr_T Prenum)
* Correct w_botline for changed w_topline.
* Won't work when there are filler lines.
*/
if (curwin->w_p_diff)
if (curwin->w_p_diff) {
curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
else {
} else {
room += i;
do {
i = plines_win(curwin, curwin->w_botline, true);
@@ -2173,8 +2187,9 @@ void halfpage(bool flag, linenr_T Prenum)
&curwin->w_cursor.lnum);
++curwin->w_cursor.lnum;
}
} else
} else {
curwin->w_cursor.lnum += n;
}
check_cursor_lnum();
}
} else {
@@ -2189,8 +2204,9 @@ void halfpage(bool flag, linenr_T Prenum)
} else {
i = plines_win_nofill(curwin, curwin->w_topline - 1, true);
n -= i;
if (n < 0 && scrolled > 0)
if (n < 0 && scrolled > 0) {
break;
}
--curwin->w_topline;
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
curwin->w_topfill = 0;
@@ -2206,19 +2222,20 @@ void halfpage(bool flag, linenr_T Prenum)
// When hit top of the file: move cursor up.
if (n > 0) {
if (curwin->w_cursor.lnum <= (linenr_T)n)
if (curwin->w_cursor.lnum <= (linenr_T)n) {
curwin->w_cursor.lnum = 1;
else if (hasAnyFolding(curwin)) {
} else if (hasAnyFolding(curwin)) {
while (--n >= 0 && curwin->w_cursor.lnum > 1) {
--curwin->w_cursor.lnum;
(void)hasFolding(curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
}
} else
} else {
curwin->w_cursor.lnum -= n;
}
}
/* Move cursor to first line of closed fold. */
}
// Move cursor to first line of closed fold.
foldAdjustCursor();
check_topfill(curwin, !flag);
cursor_correct();
@@ -2245,7 +2262,7 @@ void do_check_cursorbind(void)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp;
curbuf = curwin->w_buffer;
/* skip original window and windows with 'noscrollbind' */
// skip original window and windows with 'noscrollbind'
if (curwin != old_curwin && curwin->w_p_crb) {
if (curwin->w_p_diff) {
curwin->w_cursor.lnum =