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

View File

@@ -8,20 +8,18 @@
// khash.h does not make its own copy of the key or value. // 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 <stdbool.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <lua.h> #include "nvim/api/private/dispatch.h"
#include <lauxlib.h> #include "nvim/lib/khash.h"
#include "nvim/map.h" #include "nvim/map.h"
#include "nvim/map_defs.h" #include "nvim/map_defs.h"
#include "nvim/vim.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/api/private/dispatch.h" #include "nvim/vim.h"
#include "nvim/lib/khash.h"
#define cstr_t_hash kh_str_hash_func #define cstr_t_hash kh_str_hash_func
#define cstr_t_eq kh_str_hash_equal #define cstr_t_eq kh_str_hash_equal

View File

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

View File

@@ -49,9 +49,9 @@
#include <assert.h> #include <assert.h>
#include "nvim/marktree.h"
#include "nvim/lib/kvec.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/lib/kvec.h"
#include "nvim/marktree.h"
#define T MT_BRANCH_FACTOR #define T MT_BRANCH_FACTOR
#define ILEN (sizeof(mtnode_t)+(2 * T) * sizeof(void *)) #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; 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) { if ((*rr = key_cmp(k, x->key[begin])) < 0) {
begin--; begin--;
} }
@@ -232,9 +234,8 @@ uint64_t marktree_put(MarkTree *b, int row, int col, bool right_gravity)
return id; return id;
} }
uint64_t marktree_put_pair(MarkTree *b, uint64_t marktree_put_pair(MarkTree *b, int start_row, int start_col, bool start_right, int end_row,
int start_row, int start_col, bool start_right, int end_col, bool end_right)
int end_row, int end_col, bool end_right)
{ {
uint64_t id = (b->next_id+=ID_INCR)|PAIRED; uint64_t id = (b->next_id+=ID_INCR)|PAIRED;
uint64_t start_id = id|(start_right?RIGHT_GRAVITY:0); 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); itr, false, false, NULL);
} }
bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool last, bool gravity,
bool last, bool gravity, mtpos_t *oldbase) mtpos_t *oldbase)
{ {
mtkey_t k = { .pos = p, .id = gravity ? RIGHT_GRAVITY : 0 }; mtkey_t k = { .pos = p, .id = gravity ? RIGHT_GRAVITY : 0 };
if (last && !gravity) { if (last && !gravity) {
@@ -695,8 +696,7 @@ bool marktree_itr_next(MarkTree *b, MarkTreeIter *itr)
return marktree_itr_next_skip(b, itr, false, NULL); return marktree_itr_next_skip(b, itr, false, NULL);
} }
static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, mtpos_t oldbase[])
mtpos_t oldbase[])
{ {
if (!itr->node) { if (!itr->node) {
return false; return false;
@@ -833,10 +833,8 @@ static void swap_id(uint64_t *id1, uint64_t *id2)
*id2 = temp; *id2 = temp;
} }
bool marktree_splice(MarkTree *b, bool marktree_splice(MarkTree *b, int start_line, int start_col, int old_extent_line,
int start_line, int start_col, int old_extent_col, int new_extent_line, int new_extent_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 start = { start_line, start_col };
mtpos_t old_extent = { (int)old_extent_line, old_extent_col }; mtpos_t old_extent = { (int)old_extent_line, old_extent_col };
@@ -994,10 +992,8 @@ past_continue_same_node:
return moved; return moved;
} }
void marktree_move_region(MarkTree *b, void marktree_move_region(MarkTree *b, int start_row, colnr_T start_col, int extent_row,
int start_row, colnr_T start_col, colnr_T extent_col, int new_row, colnr_T new_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 start = { start_row, start_col }, size = { extent_row, extent_col };
mtpos_t end = size; mtpos_t end = size;
@@ -1114,8 +1110,7 @@ void marktree_check(MarkTree *b)
} }
#ifndef NDEBUG #ifndef NDEBUG
static size_t check_node(MarkTree *b, mtnode_t *x, static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_right)
mtpos_t *last, bool *last_right)
{ {
assert(x->n <= 2 * T - 1); assert(x->n <= 2 * T - 1);
// TODO(bfredl): too strict if checking "in repair" post-delete tree. // 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 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@@ -21,9 +22,12 @@ int xfpclassify(double d)
m = 0xfffffffffffffULL & m; m = 0xfffffffffffffULL & m;
switch (e) { switch (e) {
default: return FP_NORMAL; default:
case 0x000: return m ? FP_SUBNORMAL : FP_ZERO; return FP_NORMAL;
case 0x7ff: return m ? FP_NAN : FP_INFINITE; case 0x000:
return m ? FP_SUBNORMAL : FP_ZERO;
case 0x7ff:
return m ? FP_NAN : FP_INFINITE;
} }
} }
int xisinf(double d) int xisinf(double d)

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -5,22 +5,22 @@
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h>
#include "nvim/vim.h" #include "nvim/api/vim.h"
#include "nvim/context.h" #include "nvim/context.h"
#include "nvim/decoration.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/highlight.h" #include "nvim/highlight.h"
#include "nvim/lua/executor.h"
#include "nvim/memfile.h" #include "nvim/memfile.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/ui.h"
#include "nvim/sign.h" #include "nvim/sign.h"
#include "nvim/api/vim.h" #include "nvim/ui.h"
#include "nvim/lua/executor.h" #include "nvim/vim.h"
#include "nvim/decoration.h"
#ifdef UNIT_TESTING #ifdef UNIT_TESTING
# define malloc(size) mem_malloc(size) # define malloc(size) mem_malloc(size)
@@ -47,8 +47,9 @@ void try_to_free_memory(void)
{ {
static bool trying_to_free = false; static bool trying_to_free = false;
// avoid recursive calls // avoid recursive calls
if (trying_to_free) if (trying_to_free) {
return; return;
}
trying_to_free = true; trying_to_free = true;
// free any scrollback text // free any scrollback text
@@ -500,7 +501,7 @@ bool striequal(const char *a, const char *b)
void do_outofmem_msg(size_t size) void do_outofmem_msg(size_t size)
{ {
if (!did_outofmem_msg) { if (!did_outofmem_msg) {
/* Don't hide this message */ // Don't hide this message
emsg_silent = 0; emsg_silent = 0;
/* Must come first to avoid coming back here when printing the error /* 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) #if defined(EXITFREE)
#include "nvim/file_search.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/diff.h" #include "nvim/diff.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/fold.h" #include "nvim/fold.h"
#include "nvim/getchar.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/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/ops.h" #include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/quickfix.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/syntax.h"
#include "nvim/tag.h" #include "nvim/tag.h"
#include "nvim/window.h" #include "nvim/window.h"
#include "nvim/os/os.h"
#include "nvim/eval/typval.h"
/* /*
* Free everything that we allocated. * Free everything that we allocated.
@@ -574,10 +575,11 @@ void free_all_mem(void)
// Don't want to trigger autocommands from here on. // Don't want to trigger autocommands from here on.
block_autocmds(); 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; p_ea = false;
if (first_tabpage->tp_next != NULL) if (first_tabpage->tp_next != NULL) {
do_cmdline_cmd("tabonly!"); do_cmdline_cmd("tabonly!");
}
if (!ONE_WINDOW) { if (!ONE_WINDOW) {
// to keep things simple, don't perform this // to keep things simple, don't perform this
@@ -586,17 +588,17 @@ void free_all_mem(void)
do_cmdline_cmd("only!"); do_cmdline_cmd("only!");
} }
/* Free all spell info. */ // Free all spell info.
spell_free_all(); spell_free_all();
/* Clear user commands (before deleting buffers). */ // Clear user commands (before deleting buffers).
ex_comclear(NULL); ex_comclear(NULL);
/* Clear menus. */ // Clear menus.
do_cmdline_cmd("aunmenu *"); do_cmdline_cmd("aunmenu *");
do_cmdline_cmd("menutranslate clear"); do_cmdline_cmd("menutranslate clear");
/* Clear mappings, abbreviations, breakpoints. */ // Clear mappings, abbreviations, breakpoints.
do_cmdline_cmd("lmapclear"); do_cmdline_cmd("lmapclear");
do_cmdline_cmd("xmapclear"); do_cmdline_cmd("xmapclear");
do_cmdline_cmd("mapclear"); do_cmdline_cmd("mapclear");
@@ -609,7 +611,7 @@ void free_all_mem(void)
free_titles(); free_titles();
free_findfile(); free_findfile();
/* Obviously named calls. */ // Obviously named calls.
free_all_autocmds(); free_all_autocmds();
free_all_marks(); free_all_marks();
alist_clear(&global_alist); alist_clear(&global_alist);
@@ -627,25 +629,25 @@ void free_all_mem(void)
diff_clear(curtab); diff_clear(curtab);
clear_sb_text(true); // free any scrollback text clear_sb_text(true); // free any scrollback text
/* Free some global vars. */ // Free some global vars.
xfree(last_cmdline); xfree(last_cmdline);
xfree(new_last_cmdline); xfree(new_last_cmdline);
set_keep_msg(NULL, 0); set_keep_msg(NULL, 0);
/* Clear cmdline history. */ // Clear cmdline history.
p_hi = 0; p_hi = 0;
init_history(); init_history();
qf_free_all(NULL); qf_free_all(NULL);
/* Free all location lists */ // Free all location lists
FOR_ALL_TAB_WINDOWS(tab, win) { FOR_ALL_TAB_WINDOWS(tab, win) {
qf_free_all(win); qf_free_all(win);
} }
/* Close all script inputs. */ // Close all script inputs.
close_all_scripts(); close_all_scripts();
/* Destroy all windows. Must come before freeing buffers. */ // Destroy all windows. Must come before freeing buffers.
win_free_all(); win_free_all();
// Free all option values. Must come after closing windows. // Free all option values. Must come after closing windows.
@@ -653,13 +655,13 @@ void free_all_mem(void)
free_arshape_buf(); free_arshape_buf();
/* Clear registers. */ // Clear registers.
clear_registers(); clear_registers();
ResetRedobuff(); ResetRedobuff();
ResetRedobuff(); ResetRedobuff();
/* highlight info */ // highlight info
free_highlight(); free_highlight();
reset_last_sourcing(); reset_last_sourcing();
@@ -667,10 +669,12 @@ void free_all_mem(void)
free_tabpage(first_tabpage); free_tabpage(first_tabpage);
first_tabpage = NULL; first_tabpage = NULL;
/* message history */ // message history
for (;; ) for (;; ) {
if (delete_first_msg() == FAIL) if (delete_first_msg() == FAIL) {
break; break;
}
}
eval_clear(); eval_clear();
api_vim_free_all_mem(); api_vim_free_all_mem();

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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