refactor: format with uncrustify #15726

This commit is contained in:
dundargoc 2021-09-20 15:53:38 +02:00 committed by GitHub
parent 490e09c6d8
commit 30fefee684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2210 additions and 2116 deletions

View File

@ -145,13 +145,16 @@ void do_debug(char_u *cmd)
p = skipwhite(cmdline); p = skipwhite(cmdline);
if (*p != NUL) { if (*p != NUL) {
switch (*p) { switch (*p) {
case 'c': last_cmd = CMD_CONT; case 'c':
last_cmd = CMD_CONT;
tail = "ont"; tail = "ont";
break; break;
case 'n': last_cmd = CMD_NEXT; case 'n':
last_cmd = CMD_NEXT;
tail = "ext"; tail = "ext";
break; break;
case 's': last_cmd = CMD_STEP; case 's':
last_cmd = CMD_STEP;
tail = "tep"; tail = "tep";
break; break;
case 'f': case 'f':
@ -164,10 +167,12 @@ void do_debug(char_u *cmd)
tail = "inish"; tail = "inish";
} }
break; break;
case 'q': last_cmd = CMD_QUIT; case 'q':
last_cmd = CMD_QUIT;
tail = "uit"; tail = "uit";
break; break;
case 'i': last_cmd = CMD_INTERRUPT; case 'i':
last_cmd = CMD_INTERRUPT;
tail = "nterrupt"; tail = "nterrupt";
break; break;
case 'b': case 'b':
@ -190,7 +195,8 @@ void do_debug(char_u *cmd)
last_cmd = CMD_DOWN; last_cmd = CMD_DOWN;
tail = "own"; tail = "own";
break; break;
default: last_cmd = 0; default:
last_cmd = 0;
} }
if (last_cmd != 0) { if (last_cmd != 0) {
// Check that the tail matches. // Check that the tail matches.
@ -712,12 +718,10 @@ void ex_breaklist(exarg_T *eap)
/// Find a breakpoint for a function or sourced file. /// Find a breakpoint for a function or sourced file.
/// Returns line number at which to break; zero when no matching breakpoint. /// Returns line number at which to break; zero when no matching breakpoint.
linenr_T linenr_T dbg_find_breakpoint(bool file, // true for a file, false for a function
dbg_find_breakpoint(
bool file, // true for a file, false for a function
char_u *fname, // file or function name char_u *fname, // file or function name
linenr_T after // after this line number linenr_T after // after this line number
) )
{ {
return debuggy_find(file, fname, after, &dbg_breakp, NULL); return debuggy_find(file, fname, after, &dbg_breakp, NULL);
} }
@ -734,14 +738,12 @@ bool has_profiling(bool file, char_u *fname, bool *fp)
} }
/// Common code for dbg_find_breakpoint() and has_profiling(). /// Common code for dbg_find_breakpoint() and has_profiling().
static linenr_T static linenr_T debuggy_find(bool file, // true for a file, false for a function
debuggy_find(
bool file, // true for a file, false for a function
char_u *fname, // file or function name char_u *fname, // file or function name
linenr_T after, // after this line number linenr_T after, // after this line number
garray_T *gap, // either &dbg_breakp or &prof_ga garray_T *gap, // either &dbg_breakp or &prof_ga
bool *fp // if not NULL: return forceit bool *fp // if not NULL: return forceit
) )
{ {
struct debuggy *bp; struct debuggy *bp;
linenr_T lnum = 0; linenr_T lnum = 0;

View File

@ -1,13 +1,13 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "nvim/vim.h"
#include "nvim/lua/executor.h"
#include "nvim/extmark.h"
#include "nvim/decoration.h" #include "nvim/decoration.h"
#include "nvim/extmark.h"
#include "nvim/highlight.h"
#include "nvim/lua/executor.h"
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/syntax.h" #include "nvim/syntax.h"
#include "nvim/highlight.h" #include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "decoration.c.generated.h" # include "decoration.c.generated.h"
@ -28,11 +28,7 @@ static PMap(uint64_t) hl_decors;
/// @param pos_start Cursor position to start the highlighting at /// @param pos_start Cursor position to start the highlighting at
/// @param pos_end Cursor position to end the highlighting at /// @param pos_end Cursor position to end the highlighting at
/// @param offset Move the whole highlighting this many columns to the right /// @param offset Move the whole highlighting this many columns to the right
void bufhl_add_hl_pos_offset(buf_T *buf, void bufhl_add_hl_pos_offset(buf_T *buf, int src_id, int hl_id, lpos_T pos_start, lpos_T pos_end,
int src_id,
int hl_id,
lpos_T pos_start,
lpos_T pos_end,
colnr_T offset) colnr_T offset)
{ {
colnr_T hl_start = 0; colnr_T hl_start = 0;
@ -217,8 +213,8 @@ bool decor_redraw_line(buf_T *buf, int row, DecorState *state)
return true; // TODO(bfredl): be more precise return true; // TODO(bfredl): be more precise
} }
static void decor_add(DecorState *state, int start_row, int start_col, static void decor_add(DecorState *state, int start_row, int start_col, int end_row, int end_col,
int end_row, int end_col, Decoration *decor, bool owned) Decoration *decor, bool owned)
{ {
int attr_id = decor->hl_id > 0 ? syn_id2attr(decor->hl_id) : 0; int attr_id = decor->hl_id > 0 ? syn_id2attr(decor->hl_id) : 0;
@ -238,8 +234,7 @@ static void decor_add(DecorState *state, int start_row, int start_col,
kv_A(state->active, index) = range; kv_A(state->active, index) = range;
} }
int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, DecorState *state)
DecorState *state)
{ {
if (col <= state->col_until) { if (col <= state->col_until) {
return state->current; return state->current;
@ -355,8 +350,7 @@ bool decor_redraw_eol(buf_T *buf, DecorState *state, int *eol_attr, int eol_col)
return has_virttext; return has_virttext;
} }
void decor_add_ephemeral(int start_row, int start_col, int end_row, int end_col, void decor_add_ephemeral(int start_row, int start_col, int end_row, int end_col, Decoration *decor)
Decoration *decor)
{ {
if (end_row == -1) { if (end_row == -1) {
end_row = start_row; end_row = start_row;

View File

@ -13,14 +13,12 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include "nvim/vim.h"
#include "xdiff/xdiff.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/diff.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/change.h" #include "nvim/change.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.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_docmd.h" #include "nvim/ex_docmd.h"
@ -29,19 +27,21 @@
#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/memory.h"
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/normal.h" #include "nvim/normal.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/strings.h" #include "nvim/strings.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 "xdiff/xdiff.h"
#include "nvim/os/shell.h"
static int diff_busy = false; // using diff structs, don't change them static int diff_busy = false; // using diff structs, don't change them
static bool diff_need_update = false; // ex_diffupdate needs to be called static bool diff_need_update = false; // ex_diffupdate needs to be called
@ -119,7 +119,6 @@ void diff_buf_delete(buf_T *buf)
/// @param win /// @param win
void diff_buf_adjust(win_T *win) void diff_buf_adjust(win_T *win)
{ {
if (!win->w_p_diff) { if (!win->w_p_diff) {
// When there is no window showing a diff for this buffer, remove // When there is no window showing a diff for this buffer, remove
// it from the diffs. // it from the diffs.
@ -242,8 +241,7 @@ void diff_invalidate(buf_T *buf)
/// @param line2 /// @param line2
/// @param amount /// @param amount
/// @param amount_after /// @param amount_after
void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
long amount_after)
{ {
// Handle all tab pages that use the current buffer in a diff. // Handle all tab pages that use the current buffer in a diff.
FOR_ALL_TABS(tp) { FOR_ALL_TABS(tp) {
@ -267,8 +265,8 @@ void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount,
/// @param line2 /// @param line2
/// @param amount /// @param amount
/// @amount_after /// @amount_after
static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T line2, long amount,
linenr_T line2, long amount, long amount_after) long amount_after)
{ {
if (diff_internal()) { if (diff_internal()) {
// Will update diffs before redrawing. Set _invalid to update the // Will update diffs before redrawing. Set _invalid to update the
@ -509,7 +507,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1,
/// @param dp /// @param dp
/// ///
/// @return The new diff block. /// @return The new diff block.
static diff_T* diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) static diff_T * diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp)
{ {
diff_T *dnew = xmalloc(sizeof(*dnew)); diff_T *dnew = xmalloc(sizeof(*dnew));
@ -789,9 +787,7 @@ static int diff_write(buf_T *buf, diffin_T *din)
/// @param dio /// @param dio
/// @param idx_orig /// @param idx_orig
/// @param eap can be NULL /// @param eap can be NULL
static void diff_try_update(diffio_T *dio, static void diff_try_update(diffio_T *dio, int idx_orig, exarg_T *eap)
int idx_orig,
exarg_T *eap)
{ {
buf_T *buf; buf_T *buf;
int idx_new; int idx_new;
@ -1123,9 +1119,9 @@ static int diff_file(diffio_T *dio)
(diff_flags & DIFF_IBLANK) ? "-B " : "", (diff_flags & DIFF_IBLANK) ? "-B " : "",
(diff_flags & DIFF_ICASE) ? "-i " : "", (diff_flags & DIFF_ICASE) ? "-i " : "",
tmp_orig, tmp_new); tmp_orig, tmp_new);
append_redir(cmd, len, (char *) p_srr, tmp_diff); append_redir(cmd, len, (char *)p_srr, tmp_diff);
block_autocmds(); // Avoid ShellCmdPost stuff block_autocmds(); // Avoid ShellCmdPost stuff
(void)call_shell((char_u *) cmd, (void)call_shell((char_u *)cmd,
kShellOptFilter | kShellOptSilent | kShellOptDoOut, kShellOptFilter | kShellOptSilent | kShellOptDoOut,
NULL); NULL);
unblock_autocmds(); unblock_autocmds();
@ -1171,8 +1167,8 @@ void ex_diffpatch(exarg_T *eap)
#ifdef UNIX #ifdef UNIX
// Get the absolute path of the patchfile, changing directory below. // Get the absolute path of the patchfile, changing directory below.
fullname = FullName_save((char *)eap->arg, false); fullname = FullName_save((char *)eap->arg, false);
esc_name = vim_strsave_shellescape( esc_name =
(fullname != NULL ? (char_u *)fullname : eap->arg), true, true); vim_strsave_shellescape((fullname != NULL ? (char_u *)fullname : eap->arg), true, true);
#else #else
esc_name = vim_strsave_shellescape(eap->arg, true, true); esc_name = vim_strsave_shellescape(eap->arg, true, true);
#endif #endif
@ -1324,8 +1320,8 @@ void ex_diffsplit(exarg_T *eap)
if (bufref_valid(&old_curbuf)) { if (bufref_valid(&old_curbuf)) {
// Move the cursor position to that of the old window. // Move the cursor position to that of the old window.
curwin->w_cursor.lnum = diff_get_corresponding_line( curwin->w_cursor.lnum = diff_get_corresponding_line(old_curbuf.br_buf,
old_curbuf.br_buf, old_curwin->w_cursor.lnum); old_curwin->w_cursor.lnum);
} }
} }
// Now that lines are folded scroll to show the cursor at the same // Now that lines are folded scroll to show the cursor at the same
@ -1724,8 +1720,7 @@ static void diff_read(int idx_orig, int idx_new, diffout_T *dout)
/// @param dp /// @param dp
/// @param idx_orig /// @param idx_orig
/// @param idx_new /// @param idx_new
static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new)
int idx_new)
{ {
long off; long off;
@ -1912,8 +1907,7 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2)
// Compare the characters at "p1" and "p2". If they are equal (possibly // Compare the characters at "p1" and "p2". If they are equal (possibly
// ignoring case) return true and set "len" to the number of bytes. // ignoring case) return true and set "len" to the number of bytes.
static bool diff_equal_char(const char_u *const p1, const char_u *const p2, static bool diff_equal_char(const char_u *const p1, const char_u *const p2, int *const len)
int *const len)
{ {
const int l = utfc_ptr2len(p1); const int l = utfc_ptr2len(p1);
@ -3035,10 +3029,7 @@ linenr_T diff_lnum_win(linenr_T lnum, win_T *wp)
/// Handle an ED style diff line. /// Handle an ED style diff line.
/// Return FAIL if the line does not contain diff info. /// Return FAIL if the line does not contain diff info.
/// ///
static int parse_diff_ed(char_u *line, static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new,
linenr_T *lnum_orig,
long *count_orig,
linenr_T *lnum_new,
long *count_new) long *count_new)
{ {
char_u *p; char_u *p;
@ -3093,11 +3084,8 @@ static int parse_diff_ed(char_u *line,
/// Parses unified diff with zero(!) context lines. /// Parses unified diff with zero(!) context lines.
/// Return FAIL if there is no diff information in "line". /// Return FAIL if there is no diff information in "line".
/// ///
static int parse_diff_unified(char_u *line, static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig,
linenr_T *lnum_orig, linenr_T *lnum_new, long *count_new)
long *count_orig,
linenr_T *lnum_new,
long *count_new)
{ {
char_u *p; char_u *p;
long oldline, oldcount, newline, newcount; long oldline, oldcount, newline, newcount;

View File

@ -6,26 +6,26 @@
/// code for digraphs /// code for digraphs
#include <assert.h> #include <assert.h>
#include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/digraph.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/digraph.h"
#include "nvim/ex_cmds2.h" #include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/getchar.h"
#include "nvim/misc1.h"
#include "nvim/mbyte.h"
#include "nvim/message.h"
#include "nvim/memory.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/normal.h" #include "nvim/normal.h"
#include "nvim/os/input.h"
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/os/input.h" #include "nvim/vim.h"
typedef int result_T; typedef int result_T;
@ -40,7 +40,7 @@ typedef struct digraph {
# include "digraph.c.generated.h" # include "digraph.c.generated.h"
#endif #endif
// digraphs added by the user // digraphs added by the user
static garray_T user_digraphs = {0, 0, (int)sizeof(digr_T), 10, NULL}; static garray_T user_digraphs = { 0, 0, (int)sizeof(digr_T), 10, NULL };
/// Note: Characters marked with XX are not included literally, because some /// Note: Characters marked with XX are not included literally, because some
/// compilers cannot handle them (Amiga SAS/C is the most picky one). /// compilers cannot handle them (Amiga SAS/C is the most picky one).
@ -1557,7 +1557,7 @@ static int getexactdigraph(int char1, int char2, bool meta_char)
// Search user digraphs first. // Search user digraphs first.
digr_T *dp = (digr_T *)user_digraphs.ga_data; digr_T *dp = (digr_T *)user_digraphs.ga_data;
for (int i = 0; i < user_digraphs.ga_len; ++i) { for (int i = 0; i < user_digraphs.ga_len; ++i) {
if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) { if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) {
retval = dp->result; retval = dp->result;
break; break;
} }
@ -1569,7 +1569,7 @@ static int getexactdigraph(int char1, int char2, bool meta_char)
dp = digraphdefault; dp = digraphdefault;
for (int i = 0; dp->char1 != 0; ++i) { for (int i = 0; dp->char1 != 0; ++i) {
if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) { if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) {
retval = dp->result; retval = dp->result;
break; break;
} }
@ -1821,7 +1821,7 @@ typedef struct {
/// @return NULL if OK, an error message for failure. This only needs to be /// @return NULL if OK, an error message for failure. This only needs to be
/// used when setting the option, not later when the value has already /// used when setting the option, not later when the value has already
/// been checked. /// been checked.
char_u* keymap_init(void) char_u * keymap_init(void)
{ {
curbuf->b_kmap_state &= ~KEYMAP_INIT; curbuf->b_kmap_state &= ~KEYMAP_INIT;

File diff suppressed because it is too large Load Diff

View File

@ -6,51 +6,51 @@
/// Some more functions for command line commands /// Some more functions for command line commands
#include <assert.h> #include <assert.h>
#include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/vim.h"
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
# include <locale.h> # include <locale.h>
#endif #endif
#include "nvim/ex_cmds2.h" #include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/change.h" #include "nvim/change.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/debugger.h" #include "nvim/debugger.h"
#include "nvim/eval/userfunc.h" #include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_eval.h" #include "nvim/ex_eval.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/garray.h"
#include "nvim/lua/executor.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/memory.h"
#include "nvim/move.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/fs_defs.h"
#include "nvim/os/shell.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/profile.h"
#include "nvim/quickfix.h" #include "nvim/quickfix.h"
#include "nvim/regexp.h" #include "nvim/regexp.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/undo.h" #include "nvim/undo.h"
#include "nvim/version.h" #include "nvim/version.h"
#include "nvim/window.h" #include "nvim/window.h"
#include "nvim/profile.h"
#include "nvim/os/shell.h"
#include "nvim/os/fs_defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/defs.h"
#include "nvim/lua/executor.h"
/// Growarray to store info about already sourced scripts. /// Growarray to store info about already sourced scripts.
@ -362,9 +362,9 @@ static void profile_init(scriptitem_T *si)
} }
/// Save time when starting to invoke another script or function. /// Save time when starting to invoke another script or function.
void script_prof_save( ///
proftime_T *tm // place to store wait time /// @param tm place to store wait time
) void script_prof_save(proftime_T *tm)
{ {
scriptitem_T *si; scriptitem_T *si;
@ -1037,8 +1037,7 @@ static bool editing_arg_idx(win_T *win)
|| (win->w_buffer->b_fnum || (win->w_buffer->b_fnum
!= WARGLIST(win)[win->w_arg_idx].ae_fnum != WARGLIST(win)[win->w_arg_idx].ae_fnum
&& (win->w_buffer->b_ffname == NULL && (win->w_buffer->b_ffname == NULL
|| !(path_full_compare( || !(path_full_compare(alist_name(&WARGLIST(win)[win->w_arg_idx]),
alist_name(&WARGLIST(win)[win->w_arg_idx]),
win->w_buffer->b_ffname, true, true) & kEqualFiles)))); win->w_buffer->b_ffname, true, true) & kEqualFiles))));
} }
@ -1940,9 +1939,7 @@ static char_u *get_str_line(int c, void *cookie, int indent, bool do_concat)
return ga.ga_data; return ga.ga_data;
} }
static int source_using_linegetter(void *cookie, static int source_using_linegetter(void *cookie, LineGetter fgetline, const char *traceback_name)
LineGetter fgetline,
const char *traceback_name)
{ {
char_u *save_sourcing_name = sourcing_name; char_u *save_sourcing_name = sourcing_name;
linenr_T save_sourcing_lnum = sourcing_lnum; linenr_T save_sourcing_lnum = sourcing_lnum;
@ -1951,7 +1948,7 @@ static int source_using_linegetter(void *cookie,
sourcing_name = (char_u *)traceback_name; sourcing_name = (char_u *)traceback_name;
} else { } else {
snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf), snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf),
"%s called at %s:%"PRIdLINENR, traceback_name, save_sourcing_name, "%s called at %s:%" PRIdLINENR, traceback_name, save_sourcing_name,
save_sourcing_lnum); save_sourcing_lnum);
sourcing_name = sourcing_name_buf; sourcing_name = sourcing_name_buf;
} }
@ -2743,8 +2740,7 @@ void do_finish(exarg_T *eap, int reanimate)
bool source_finished(LineGetter fgetline, void *cookie) bool source_finished(LineGetter fgetline, void *cookie)
{ {
return getline_equal(fgetline, cookie, getsourceline) return getline_equal(fgetline, cookie, getsourceline)
&& ((struct source_cookie *)getline_cookie( && ((struct source_cookie *)getline_cookie(fgetline, cookie))->finished;
fgetline, cookie))->finished;
} }
/// ":checktime [buffer]" /// ":checktime [buffer]"

View File

@ -7,23 +7,23 @@
/// ///
/// Functions for Ex command line for the +eval feature. /// Functions for Ex command line for the +eval feature.
#include <assert.h> #include <assert.h>
#include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/debugger.h"
#include "nvim/ex_eval.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/debugger.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/eval/userfunc.h" #include "nvim/eval/userfunc.h"
#include "nvim/ex_cmds2.h" #include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/message.h" #include "nvim/ex_eval.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/regexp.h" #include "nvim/regexp.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ex_eval.c.generated.h" # include "ex_eval.c.generated.h"
@ -111,8 +111,9 @@ int aborting(void)
*/ */
void update_force_abort(void) void update_force_abort(void)
{ {
if (cause_abort) if (cause_abort) {
force_abort = TRUE; force_abort = TRUE;
}
} }
/* /*
@ -248,8 +249,9 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
*/ */
if (msg_list != NULL) { if (msg_list != NULL) {
plist = msg_list; plist = msg_list;
while (*plist != NULL) while (*plist != NULL) {
plist = &(*plist)->next; plist = &(*plist)->next;
}
elem = xmalloc(sizeof(struct msglist)); elem = xmalloc(sizeof(struct msglist));
elem->msg = vim_strsave(mesg); elem->msg = vim_strsave(mesg);
@ -259,19 +261,20 @@ bool cause_errthrow(const char_u *mesg, bool severe, bool *ignore)
if (plist == msg_list || severe) { if (plist == msg_list || severe) {
char_u *tmsg; char_u *tmsg;
/* Skip the extra "Vim " prefix for message "E458". */ // Skip the extra "Vim " prefix for message "E458".
tmsg = elem->msg; tmsg = elem->msg;
if (STRNCMP(tmsg, "Vim E", 5) == 0 if (STRNCMP(tmsg, "Vim E", 5) == 0
&& ascii_isdigit(tmsg[5]) && ascii_isdigit(tmsg[5])
&& ascii_isdigit(tmsg[6]) && ascii_isdigit(tmsg[6])
&& ascii_isdigit(tmsg[7]) && ascii_isdigit(tmsg[7])
&& tmsg[8] == ':' && tmsg[8] == ':'
&& tmsg[9] == ' ') && tmsg[9] == ' ') {
(*msg_list)->throw_msg = &tmsg[4]; (*msg_list)->throw_msg = &tmsg[4];
else } else {
(*msg_list)->throw_msg = tmsg; (*msg_list)->throw_msg = tmsg;
} }
} }
}
return true; return true;
} }
} }
@ -320,17 +323,19 @@ void do_errthrow(cstack_T *cstack, char_u *cmdname)
/* If no exception is to be thrown or the conversion should be done after /* If no exception is to be thrown or the conversion should be done after
* returning to a previous invocation of do_one_cmd(), do nothing. */ * returning to a previous invocation of do_one_cmd(), do nothing. */
if (msg_list == NULL || *msg_list == NULL) if (msg_list == NULL || *msg_list == NULL) {
return; return;
}
if (throw_exception(*msg_list, ET_ERROR, cmdname) == FAIL) if (throw_exception(*msg_list, ET_ERROR, cmdname) == FAIL) {
free_msglist(*msg_list); free_msglist(*msg_list);
else { } else {
if (cstack != NULL) if (cstack != NULL) {
do_throw(cstack); do_throw(cstack);
else } else {
need_rethrow = TRUE; need_rethrow = TRUE;
} }
}
*msg_list = NULL; *msg_list = NULL;
} }
@ -375,15 +380,14 @@ int do_intthrow(cstack_T *cstack)
do_throw(cstack); do_throw(cstack);
} }
#ifdef THROW_TEST #ifdef THROW_TEST
} }
#endif #endif
return true; return true;
} }
// Get an exception message that is to be stored in current_exception->value. // Get an exception message that is to be stored in current_exception->value.
char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname, char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname, int *should_free)
int *should_free)
{ {
char_u *ret, *mesg; char_u *ret, *mesg;
char_u *p, *val; char_u *p, *val;
@ -434,7 +438,7 @@ char_u *get_exception_string(void *value, except_type_T type, char_u *cmdname,
} }
} else { } else {
*should_free = FALSE; *should_free = FALSE;
ret = (char_u *) value; ret = (char_u *)value;
} }
return ret; return ret;
@ -466,14 +470,16 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname)
excp = xmalloc(sizeof(except_T)); excp = xmalloc(sizeof(except_T));
if (type == ET_ERROR) if (type == ET_ERROR) {
/* Store the original message and prefix the exception value with /* Store the original message and prefix the exception value with
* "Vim:" or, if a command name is given, "Vim(cmdname):". */ * "Vim:" or, if a command name is given, "Vim(cmdname):". */
excp->messages = (struct msglist *)value; excp->messages = (struct msglist *)value;
}
excp->value = get_exception_string(value, type, cmdname, &should_free); excp->value = get_exception_string(value, type, cmdname, &should_free);
if (excp->value == NULL && should_free) if (excp->value == NULL && should_free) {
goto nomem; goto nomem;
}
excp->type = type; excp->type = type;
excp->throw_name = vim_strsave(sourcing_name == NULL excp->throw_name = vim_strsave(sourcing_name == NULL
@ -483,25 +489,28 @@ static int throw_exception(void *value, except_type_T type, char_u *cmdname)
if (p_verbose >= 13 || debug_break_level > 0) { if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent; int save_msg_silent = msg_silent;
if (debug_break_level > 0) if (debug_break_level > 0) {
msg_silent = FALSE; /* display messages */ msg_silent = FALSE; // display messages
else } else {
verbose_enter(); verbose_enter();
}
++no_wait_return; ++no_wait_return;
if (debug_break_level > 0 || *p_vfile == NUL) if (debug_break_level > 0 || *p_vfile == NUL) {
msg_scroll = TRUE; /* always scroll up, don't overwrite */ msg_scroll = TRUE; // always scroll up, don't overwrite
}
smsg(_("Exception thrown: %s"), excp->value); smsg(_("Exception thrown: %s"), excp->value);
msg_puts("\n"); // don't overwrite this either msg_puts("\n"); // don't overwrite this either
if (debug_break_level > 0 || *p_vfile == NUL) if (debug_break_level > 0 || *p_vfile == NUL) {
cmdline_row = msg_row; cmdline_row = msg_row;
}
--no_wait_return; --no_wait_return;
if (debug_break_level > 0) if (debug_break_level > 0) {
msg_silent = save_msg_silent; msg_silent = save_msg_silent;
else } else {
verbose_leave(); verbose_leave();
} }
}
current_exception = excp; current_exception = excp;
return OK; return OK;
@ -535,13 +544,15 @@ static void discard_exception(except_T *excp, bool was_finished)
int save_msg_silent = msg_silent; int save_msg_silent = msg_silent;
saved_IObuff = vim_strsave(IObuff); saved_IObuff = vim_strsave(IObuff);
if (debug_break_level > 0) if (debug_break_level > 0) {
msg_silent = FALSE; /* display messages */ msg_silent = FALSE; // display messages
else } else {
verbose_enter(); verbose_enter();
}
++no_wait_return; ++no_wait_return;
if (debug_break_level > 0 || *p_vfile == NUL) if (debug_break_level > 0 || *p_vfile == NUL) {
msg_scroll = TRUE; /* always scroll up, don't overwrite */ msg_scroll = TRUE; // always scroll up, don't overwrite
}
smsg(was_finished ? _("Exception finished: %s") smsg(was_finished ? _("Exception finished: %s")
: _("Exception discarded: %s"), : _("Exception discarded: %s"),
excp->value); excp->value);
@ -558,10 +569,12 @@ static void discard_exception(except_T *excp, bool was_finished)
xstrlcpy((char *)IObuff, (const char *)saved_IObuff, IOSIZE); xstrlcpy((char *)IObuff, (const char *)saved_IObuff, IOSIZE);
xfree(saved_IObuff); xfree(saved_IObuff);
} }
if (excp->type != ET_INTERRUPT) if (excp->type != ET_INTERRUPT) {
xfree(excp->value); xfree(excp->value);
if (excp->type == ET_ERROR) }
if (excp->type == ET_ERROR) {
free_msglist(excp->messages); free_msglist(excp->messages);
}
xfree(excp->throw_name); xfree(excp->throw_name);
xfree(excp); xfree(excp);
} }
@ -586,7 +599,7 @@ static void catch_exception(except_T *excp)
{ {
excp->caught = caught_stack; excp->caught = caught_stack;
caught_stack = excp; caught_stack = excp;
set_vim_var_string(VV_EXCEPTION, (char *) excp->value, -1); set_vim_var_string(VV_EXCEPTION, (char *)excp->value, -1);
if (*excp->throw_name != NUL) { if (*excp->throw_name != NUL) {
if (excp->throw_lnum != 0) { if (excp->throw_lnum != 0) {
vim_snprintf((char *)IObuff, IOSIZE, _("%s, line %" PRId64), vim_snprintf((char *)IObuff, IOSIZE, _("%s, line %" PRId64),
@ -594,7 +607,7 @@ static void catch_exception(except_T *excp)
} else { } else {
vim_snprintf((char *)IObuff, IOSIZE, "%s", excp->throw_name); vim_snprintf((char *)IObuff, IOSIZE, "%s", excp->throw_name);
} }
set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1); set_vim_var_string(VV_THROWPOINT, (char *)IObuff, -1);
} else { } else {
// throw_name not set on an exception from a command that was typed. // throw_name not set on an exception from a command that was typed.
set_vim_var_string(VV_THROWPOINT, NULL, -1); set_vim_var_string(VV_THROWPOINT, NULL, -1);
@ -603,25 +616,28 @@ static void catch_exception(except_T *excp)
if (p_verbose >= 13 || debug_break_level > 0) { if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent; int save_msg_silent = msg_silent;
if (debug_break_level > 0) if (debug_break_level > 0) {
msg_silent = FALSE; /* display messages */ msg_silent = FALSE; // display messages
else } else {
verbose_enter(); verbose_enter();
}
++no_wait_return; ++no_wait_return;
if (debug_break_level > 0 || *p_vfile == NUL) if (debug_break_level > 0 || *p_vfile == NUL) {
msg_scroll = TRUE; /* always scroll up, don't overwrite */ msg_scroll = TRUE; // always scroll up, don't overwrite
}
smsg(_("Exception caught: %s"), excp->value); smsg(_("Exception caught: %s"), excp->value);
msg_puts("\n"); // don't overwrite this either msg_puts("\n"); // don't overwrite this either
if (debug_break_level > 0 || *p_vfile == NUL) if (debug_break_level > 0 || *p_vfile == NUL) {
cmdline_row = msg_row; cmdline_row = msg_row;
}
--no_wait_return; --no_wait_return;
if (debug_break_level > 0) if (debug_break_level > 0) {
msg_silent = save_msg_silent; msg_silent = save_msg_silent;
else } else {
verbose_leave(); verbose_leave();
} }
}
} }
/* /*
@ -634,7 +650,7 @@ static void finish_exception(except_T *excp)
} }
caught_stack = caught_stack->caught; caught_stack = caught_stack->caught;
if (caught_stack != NULL) { if (caught_stack != NULL) {
set_vim_var_string(VV_EXCEPTION, (char *) caught_stack->value, -1); set_vim_var_string(VV_EXCEPTION, (char *)caught_stack->value, -1);
if (*caught_stack->throw_name != NUL) { if (*caught_stack->throw_name != NUL) {
if (caught_stack->throw_lnum != 0) { if (caught_stack->throw_lnum != 0) {
vim_snprintf((char *)IObuff, IOSIZE, vim_snprintf((char *)IObuff, IOSIZE,
@ -644,7 +660,7 @@ static void finish_exception(except_T *excp)
vim_snprintf((char *)IObuff, IOSIZE, "%s", vim_snprintf((char *)IObuff, IOSIZE, "%s",
caught_stack->throw_name); caught_stack->throw_name);
} }
set_vim_var_string(VV_THROWPOINT, (char *) IObuff, -1); set_vim_var_string(VV_THROWPOINT, (char *)IObuff, -1);
} else { } else {
// throw_name not set on an exception from a command that was // throw_name not set on an exception from a command that was
// typed. // typed.
@ -688,7 +704,7 @@ static void report_pending(int action, int pending, void *value)
case RP_RESUME: case RP_RESUME:
mesg = _("%s resumed"); mesg = _("%s resumed");
break; break;
/* case RP_DISCARD: */ // case RP_DISCARD:
default: default:
mesg = _("%s discarded"); mesg = _("%s discarded");
break; break;
@ -708,7 +724,7 @@ static void report_pending(int action, int pending, void *value)
s = ":finish"; s = ":finish";
break; break;
case CSTP_RETURN: case CSTP_RETURN:
/* ":return" command producing value, allocated */ // ":return" command producing value, allocated
s = (char *)get_return_cmd(value); s = (char *)get_return_cmd(value);
break; break;
@ -718,30 +734,34 @@ static void report_pending(int action, int pending, void *value)
mesg, _("Exception")); mesg, _("Exception"));
mesg = (char *)concat_str(IObuff, (char_u *)": %s"); mesg = (char *)concat_str(IObuff, (char_u *)": %s");
s = (char *)((except_T *)value)->value; s = (char *)((except_T *)value)->value;
} else if ((pending & CSTP_ERROR) && (pending & CSTP_INTERRUPT)) } else if ((pending & CSTP_ERROR) && (pending & CSTP_INTERRUPT)) {
s = _("Error and interrupt"); s = _("Error and interrupt");
else if (pending & CSTP_ERROR) } else if (pending & CSTP_ERROR) {
s = _("Error"); s = _("Error");
else /* if (pending & CSTP_INTERRUPT) */ } else { // if (pending & CSTP_INTERRUPT)
s = _("Interrupt"); s = _("Interrupt");
} }
}
save_msg_silent = msg_silent; save_msg_silent = msg_silent;
if (debug_break_level > 0) if (debug_break_level > 0) {
msg_silent = FALSE; /* display messages */ msg_silent = FALSE; // display messages
}
++no_wait_return; ++no_wait_return;
msg_scroll = TRUE; /* always scroll up, don't overwrite */ msg_scroll = TRUE; // always scroll up, don't overwrite
smsg(mesg, s); smsg(mesg, s);
msg_puts("\n"); // don't overwrite this either msg_puts("\n"); // don't overwrite this either
cmdline_row = msg_row; cmdline_row = msg_row;
--no_wait_return; --no_wait_return;
if (debug_break_level > 0) if (debug_break_level > 0) {
msg_silent = save_msg_silent; msg_silent = save_msg_silent;
}
if (pending == CSTP_RETURN) if (pending == CSTP_RETURN) {
xfree(s); xfree(s);
else if (pending & CSTP_THROW) } else if (pending & CSTP_THROW) {
xfree(mesg); xfree(mesg);
}
} }
/* /*
@ -751,12 +771,14 @@ static void report_pending(int action, int pending, void *value)
void report_make_pending(int pending, void *value) void report_make_pending(int pending, void *value)
{ {
if (p_verbose >= 14 || debug_break_level > 0) { if (p_verbose >= 14 || debug_break_level > 0) {
if (debug_break_level <= 0) if (debug_break_level <= 0) {
verbose_enter(); verbose_enter();
}
report_pending(RP_MAKE, pending, value); report_pending(RP_MAKE, pending, value);
if (debug_break_level <= 0) if (debug_break_level <= 0) {
verbose_leave(); verbose_leave();
} }
}
} }
/* /*
@ -766,12 +788,14 @@ void report_make_pending(int pending, void *value)
void report_resume_pending(int pending, void *value) void report_resume_pending(int pending, void *value)
{ {
if (p_verbose >= 14 || debug_break_level > 0) { if (p_verbose >= 14 || debug_break_level > 0) {
if (debug_break_level <= 0) if (debug_break_level <= 0) {
verbose_enter(); verbose_enter();
}
report_pending(RP_RESUME, pending, value); report_pending(RP_RESUME, pending, value);
if (debug_break_level <= 0) if (debug_break_level <= 0) {
verbose_leave(); verbose_leave();
} }
}
} }
/* /*
@ -781,12 +805,14 @@ void report_resume_pending(int pending, void *value)
void report_discard_pending(int pending, void *value) void report_discard_pending(int pending, void *value)
{ {
if (p_verbose >= 14 || debug_break_level > 0) { if (p_verbose >= 14 || debug_break_level > 0) {
if (debug_break_level <= 0) if (debug_break_level <= 0) {
verbose_enter(); verbose_enter();
}
report_pending(RP_DISCARD, pending, value); report_pending(RP_DISCARD, pending, value);
if (debug_break_level <= 0) if (debug_break_level <= 0) {
verbose_leave(); verbose_leave();
} }
}
} }
// ":eval". // ":eval".
@ -808,9 +834,9 @@ void ex_if(exarg_T *eap)
int result; int result;
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E579: :if nesting too deep"); eap->errmsg = (char_u *)N_("E579: :if nesting too deep");
else { } else {
++cstack->cs_idx; ++cstack->cs_idx;
cstack->cs_flags[cstack->cs_idx] = 0; cstack->cs_flags[cstack->cs_idx] = 0;
@ -820,12 +846,14 @@ void ex_if(exarg_T *eap)
result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip); result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip);
if (!skip && !error) { if (!skip && !error) {
if (result) if (result) {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE; cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE;
} else }
/* set TRUE, so this conditional will never get active */ } else {
// set TRUE, so this conditional will never get active
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
} }
}
} }
/* /*
@ -884,13 +912,15 @@ void ex_else(exarg_T *eap)
skip = TRUE; skip = TRUE;
} }
/* if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it */ // if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it
if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE) { if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE) {
if (eap->errmsg == NULL) if (eap->errmsg == NULL) {
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
skip = TRUE; /* don't evaluate an ":elseif" */ }
} else skip = TRUE; // don't evaluate an ":elseif"
} else {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE; cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE;
}
/* /*
* When debugging or a breakpoint was encountered, display the debug prompt * When debugging or a breakpoint was encountered, display the debug prompt
@ -917,15 +947,18 @@ void ex_else(exarg_T *eap)
* case, the parsing error will be ignored by emsg(). */ * case, the parsing error will be ignored by emsg(). */
if (!skip && !error) { if (!skip && !error) {
if (result) if (result) {
cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE; cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE;
else } else {
cstack->cs_flags[cstack->cs_idx] = 0; cstack->cs_flags[cstack->cs_idx] = 0;
} else if (eap->errmsg == NULL) }
/* set TRUE, so this conditional will never get active */ } else if (eap->errmsg == NULL) {
// set TRUE, so this conditional will never get active
cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; cstack->cs_flags[cstack->cs_idx] = CSF_TRUE;
} else }
} else {
cstack->cs_flags[cstack->cs_idx] |= CSF_ELSE; cstack->cs_flags[cstack->cs_idx] |= CSF_ELSE;
}
} }
/* /*
@ -938,9 +971,9 @@ void ex_while(exarg_T *eap)
int result; int result;
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E585: :while/:for nesting too deep"); eap->errmsg = (char_u *)N_("E585: :while/:for nesting too deep");
else { } else {
/* /*
* The loop flag is set when we have jumped back from the matching * The loop flag is set when we have jumped back from the matching
* ":endwhile" or ":endfor". When not set, need to initialise this * ":endwhile" or ":endfor". When not set, need to initialise this
@ -972,16 +1005,17 @@ void ex_while(exarg_T *eap)
fi = cstack->cs_forinfo[cstack->cs_idx]; fi = cstack->cs_forinfo[cstack->cs_idx];
error = FALSE; error = FALSE;
} else { } else {
/* Evaluate the argument and get the info in a structure. */ // Evaluate the argument and get the info in a structure.
fi = eval_for_line(eap->arg, &error, &eap->nextcmd, skip); fi = eval_for_line(eap->arg, &error, &eap->nextcmd, skip);
cstack->cs_forinfo[cstack->cs_idx] = fi; cstack->cs_forinfo[cstack->cs_idx] = fi;
} }
/* use the element at the start of the list and advance */ // use the element at the start of the list and advance
if (!error && fi != NULL && !skip) if (!error && fi != NULL && !skip) {
result = next_for_item(fi, eap->arg); result = next_for_item(fi, eap->arg);
else } else {
result = FALSE; result = FALSE;
}
if (!result) { if (!result) {
free_for_info(fi); free_for_info(fi);
@ -1003,10 +1037,11 @@ void ex_while(exarg_T *eap)
* the list, show the debug prompt at the ":endwhile"/":endfor" as * the list, show the debug prompt at the ":endwhile"/":endfor" as
* if there was a ":break" in a ":while"/":for" evaluating to * if there was a ":break" in a ":while"/":for" evaluating to
* TRUE. */ * TRUE. */
if (!skip && !error) if (!skip && !error) {
cstack->cs_flags[cstack->cs_idx] |= CSF_TRUE; cstack->cs_flags[cstack->cs_idx] |= CSF_TRUE;
} }
} }
}
} }
/* /*
@ -1017,9 +1052,9 @@ void ex_continue(exarg_T *eap)
int idx; int idx;
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E586: :continue without :while or :for"); eap->errmsg = (char_u *)N_("E586: :continue without :while or :for");
else { } else {
/* Try to find the matching ":while". This might stop at a try /* Try to find the matching ":while". This might stop at a try
* conditional not in its finally clause (which is then to be executed * conditional not in its finally clause (which is then to be executed
* next). Therefore, deactivate all conditionals except the ":while" * next). Therefore, deactivate all conditionals except the ":while"
@ -1033,7 +1068,7 @@ void ex_continue(exarg_T *eap)
* Set CSL_HAD_CONT, so do_cmdline() will jump back to the * Set CSL_HAD_CONT, so do_cmdline() will jump back to the
* matching ":while". * matching ":while".
*/ */
cstack->cs_lflags |= CSL_HAD_CONT; /* let do_cmdline() handle it */ cstack->cs_lflags |= CSL_HAD_CONT; // let do_cmdline() handle it
} else { } else {
/* If a try conditional not in its finally clause is reached first, /* If a try conditional not in its finally clause is reached first,
* make the ":continue" pending for execution at the ":endtry". */ * make the ":continue" pending for execution at the ":endtry". */
@ -1085,24 +1120,26 @@ void ex_endwhile(exarg_T *eap)
csf = CSF_FOR; csf = CSF_FOR;
} }
if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = err; eap->errmsg = err;
else { } else {
fl = cstack->cs_flags[cstack->cs_idx]; fl = cstack->cs_flags[cstack->cs_idx];
if (!(fl & csf)) { if (!(fl & csf)) {
/* If we are in a ":while" or ":for" but used the wrong endloop /* If we are in a ":while" or ":for" but used the wrong endloop
* command, do not rewind to the next enclosing ":for"/":while". */ * command, do not rewind to the next enclosing ":for"/":while". */
if (fl & CSF_WHILE) if (fl & CSF_WHILE) {
eap->errmsg = (char_u *)_("E732: Using :endfor with :while"); eap->errmsg = (char_u *)_("E732: Using :endfor with :while");
else if (fl & CSF_FOR) } else if (fl & CSF_FOR) {
eap->errmsg = (char_u *)_("E733: Using :endwhile with :for"); eap->errmsg = (char_u *)_("E733: Using :endwhile with :for");
} }
}
if (!(fl & (CSF_WHILE | CSF_FOR))) { if (!(fl & (CSF_WHILE | CSF_FOR))) {
if (!(fl & CSF_TRY)) if (!(fl & CSF_TRY)) {
eap->errmsg = e_endif; eap->errmsg = e_endif;
else if (fl & CSF_FINALLY) } else if (fl & CSF_FINALLY) {
eap->errmsg = e_endtry; eap->errmsg = e_endtry;
/* Try to find the matching ":while" and report what's missing. */ }
// Try to find the matching ":while" and report what's missing.
for (idx = cstack->cs_idx; idx > 0; --idx) { for (idx = cstack->cs_idx; idx > 0; --idx) {
fl = cstack->cs_flags[idx]; fl = cstack->cs_flags[idx];
if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) { if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) {
@ -1111,10 +1148,11 @@ void ex_endwhile(exarg_T *eap)
eap->errmsg = err; eap->errmsg = err;
return; return;
} }
if (fl & csf) if (fl & csf) {
break; break;
} }
/* Cleanup and rewind all contained (and unclosed) conditionals. */ }
// Cleanup and rewind all contained (and unclosed) conditionals.
(void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); (void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE);
rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel);
} }
@ -1130,8 +1168,9 @@ void ex_endwhile(exarg_T *eap)
*/ */
else if (cstack->cs_flags[cstack->cs_idx] & CSF_TRUE else if (cstack->cs_flags[cstack->cs_idx] & CSF_TRUE
&& !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE) && !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE)
&& dbg_check_skipped(eap)) && dbg_check_skipped(eap)) {
(void)do_intthrow(cstack); (void)do_intthrow(cstack);
}
/* /*
* Set loop flag, so do_cmdline() will jump back to the matching * Set loop flag, so do_cmdline() will jump back to the matching
@ -1216,14 +1255,15 @@ void do_throw(cstack_T *cstack)
* the matching catch clause or the finally clause. * the matching catch clause or the finally clause.
*/ */
if (!(cstack->cs_flags[idx] & CSF_CAUGHT)) { if (!(cstack->cs_flags[idx] & CSF_CAUGHT)) {
if (cstack->cs_flags[idx] & CSF_ACTIVE) if (cstack->cs_flags[idx] & CSF_ACTIVE) {
cstack->cs_flags[idx] |= CSF_THROWN; cstack->cs_flags[idx] |= CSF_THROWN;
else } else {
/* THROWN may have already been set for a catchable exception /* THROWN may have already been set for a catchable exception
* that has been discarded. Ensure it is reset for the new * that has been discarded. Ensure it is reset for the new
* exception. */ * exception. */
cstack->cs_flags[idx] &= ~CSF_THROWN; cstack->cs_flags[idx] &= ~CSF_THROWN;
} }
}
cstack->cs_flags[idx] &= ~CSF_ACTIVE; cstack->cs_flags[idx] &= ~CSF_ACTIVE;
cstack->cs_exception[idx] = current_exception; cstack->cs_exception[idx] = current_exception;
} }
@ -1237,9 +1277,9 @@ void ex_try(exarg_T *eap)
int skip; int skip;
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_idx == CSTACK_LEN - 1) if (cstack->cs_idx == CSTACK_LEN - 1) {
eap->errmsg = (char_u *)N_("E601: :try nesting too deep"); eap->errmsg = (char_u *)N_("E601: :try nesting too deep");
else { } else {
++cstack->cs_idx; ++cstack->cs_idx;
++cstack->cs_trylevel; ++cstack->cs_trylevel;
cstack->cs_flags[cstack->cs_idx] = CSF_TRY; cstack->cs_flags[cstack->cs_idx] = CSF_TRY;
@ -1278,7 +1318,6 @@ void ex_try(exarg_T *eap)
emsg_silent = 0; emsg_silent = 0;
} }
} }
} }
} }
@ -1309,20 +1348,23 @@ void ex_catch(exarg_T *eap)
eap->errmsg = get_end_emsg(cstack); eap->errmsg = get_end_emsg(cstack);
skip = TRUE; skip = TRUE;
} }
for (idx = cstack->cs_idx; idx > 0; --idx) for (idx = cstack->cs_idx; idx > 0; --idx) {
if (cstack->cs_flags[idx] & CSF_TRY) if (cstack->cs_flags[idx] & CSF_TRY) {
break; break;
}
}
if (cstack->cs_flags[idx] & CSF_FINALLY) { if (cstack->cs_flags[idx] & CSF_FINALLY) {
/* Give up for a ":catch" after ":finally" and ignore it. /* Give up for a ":catch" after ":finally" and ignore it.
* Just parse. */ * Just parse. */
eap->errmsg = (char_u *)N_("E604: :catch after :finally"); eap->errmsg = (char_u *)N_("E604: :catch after :finally");
give_up = TRUE; give_up = TRUE;
} else } else {
rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR, rewind_conditionals(cstack, idx, CSF_WHILE | CSF_FOR,
&cstack->cs_looplevel); &cstack->cs_looplevel);
} }
}
if (ends_excmd(*eap->arg)) { /* no argument, catch all errors */ if (ends_excmd(*eap->arg)) { // no argument, catch all errors
pat = (char_u *)".*"; pat = (char_u *)".*";
end = NULL; end = NULL;
eap->nextcmd = find_nextcmd(eap->arg); eap->nextcmd = find_nextcmd(eap->arg);
@ -1430,8 +1472,9 @@ void ex_catch(exarg_T *eap)
} }
} }
if (end != NULL) if (end != NULL) {
eap->nextcmd = find_nextcmd(end); eap->nextcmd = find_nextcmd(end);
}
} }
/* /*
@ -1444,23 +1487,26 @@ void ex_finally(exarg_T *eap)
int pending = CSTP_NONE; int pending = CSTP_NONE;
cstack_T *const cstack = eap->cstack; cstack_T *const cstack = eap->cstack;
if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) if (cstack->cs_trylevel <= 0 || cstack->cs_idx < 0) {
eap->errmsg = (char_u *)N_("E606: :finally without :try"); eap->errmsg = (char_u *)N_("E606: :finally without :try");
else { } else {
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack); eap->errmsg = get_end_emsg(cstack);
for (idx = cstack->cs_idx - 1; idx > 0; --idx) for (idx = cstack->cs_idx - 1; idx > 0; --idx) {
if (cstack->cs_flags[idx] & CSF_TRY) if (cstack->cs_flags[idx] & CSF_TRY) {
break; break;
}
}
/* Make this error pending, so that the commands in the following /* Make this error pending, so that the commands in the following
* finally clause can be executed. This overrules also a pending * finally clause can be executed. This overrules also a pending
* ":continue", ":break", ":return", or ":finish". */ * ":continue", ":break", ":return", or ":finish". */
pending = CSTP_ERROR; pending = CSTP_ERROR;
} else } else {
idx = cstack->cs_idx; idx = cstack->cs_idx;
}
if (cstack->cs_flags[idx] & CSF_FINALLY) { if (cstack->cs_flags[idx] & CSF_FINALLY) {
/* Give up for a multiple ":finally" and ignore it. */ // Give up for a multiple ":finally" and ignore it.
eap->errmsg = (char_u *)N_("E607: multiple :finally"); eap->errmsg = (char_u *)N_("E607: multiple :finally");
return; return;
} }
@ -1585,7 +1631,7 @@ void ex_endtry(exarg_T *eap)
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) {
eap->errmsg = get_end_emsg(cstack); eap->errmsg = get_end_emsg(cstack);
/* Find the matching ":try" and report what's missing. */ // Find the matching ":try" and report what's missing.
idx = cstack->cs_idx; idx = cstack->cs_idx;
do do
--idx; --idx;
@ -1656,11 +1702,12 @@ void ex_endtry(exarg_T *eap)
if (!skip) { if (!skip) {
pending = cstack->cs_pending[idx]; pending = cstack->cs_pending[idx];
cstack->cs_pending[idx] = CSTP_NONE; cstack->cs_pending[idx] = CSTP_NONE;
if (pending == CSTP_RETURN) if (pending == CSTP_RETURN) {
rettv = cstack->cs_rettv[idx]; rettv = cstack->cs_rettv[idx];
else if (pending & CSTP_THROW) } else if (pending & CSTP_THROW) {
current_exception = cstack->cs_exception[idx]; current_exception = cstack->cs_exception[idx];
} }
}
/* /*
* Discard anything pending on an error, interrupt, or throw in the * Discard anything pending on an error, interrupt, or throw in the
@ -1788,7 +1835,7 @@ void enter_cleanup(cleanup_T *csp)
did_emsg = got_int = need_rethrow = false; did_emsg = got_int = need_rethrow = false;
current_exception = NULL; current_exception = NULL;
/* Report if required by the 'verbose' option or when debugging. */ // Report if required by the 'verbose' option or when debugging.
report_make_pending(pending, csp->exception); report_make_pending(pending, csp->exception);
} else { } else {
csp->pending = CSTP_NONE; csp->pending = CSTP_NONE;
@ -1815,8 +1862,9 @@ void leave_cleanup(cleanup_T *csp)
{ {
int pending = csp->pending; int pending = csp->pending;
if (pending == CSTP_NONE) /* nothing to do */ if (pending == CSTP_NONE) { // nothing to do
return; return;
}
/* If there was an aborting error, an interrupt, or an uncaught exception /* If there was an aborting error, an interrupt, or an uncaught exception
* after the corresponding call to enter_cleanup(), discard what has been * after the corresponding call to enter_cleanup(), discard what has been
@ -1832,9 +1880,10 @@ void leave_cleanup(cleanup_T *csp)
/* If an error was about to be converted to an exception when /* If an error was about to be converted to an exception when
* enter_cleanup() was called, free the message list. */ * enter_cleanup() was called, free the message list. */
if (msg_list != NULL) if (msg_list != NULL) {
free_global_msglist(); free_global_msglist();
} }
}
/* /*
* If there was no new error, interrupt, or throw between the calls * If there was no new error, interrupt, or throw between the calls
* to enter_cleanup() and leave_cleanup(), restore the pending * to enter_cleanup() and leave_cleanup(), restore the pending
@ -1846,9 +1895,9 @@ void leave_cleanup(cleanup_T *csp)
* called, we need to rethrow it. Make it the exception currently * called, we need to rethrow it. Make it the exception currently
* being thrown. * being thrown.
*/ */
if (pending & CSTP_THROW) if (pending & CSTP_THROW) {
current_exception = csp->exception; current_exception = csp->exception;
}
/* /*
* If an error was about to be converted to an exception when * If an error was about to be converted to an exception when
* enter_cleanup() was called, let "cause_abort" take the part of * enter_cleanup() was called, let "cause_abort" take the part of
@ -1871,8 +1920,7 @@ void leave_cleanup(cleanup_T *csp)
} }
// Report if required by the 'verbose' option or when debugging. // Report if required by the 'verbose' option or when debugging.
report_resume_pending( report_resume_pending(pending, ((pending & CSTP_THROW) ? (void *)current_exception : NULL));
pending, ((pending & CSTP_THROW) ? (void *)current_exception : NULL));
} }
} }
@ -1948,15 +1996,17 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/ */
if (!(cstack->cs_flags[idx] & CSF_FINALLY)) { if (!(cstack->cs_flags[idx] & CSF_FINALLY)) {
if ((cstack->cs_flags[idx] & CSF_ACTIVE) if ((cstack->cs_flags[idx] & CSF_ACTIVE)
&& (cstack->cs_flags[idx] & CSF_CAUGHT)) && (cstack->cs_flags[idx] & CSF_CAUGHT)) {
finish_exception((except_T *)cstack->cs_exception[idx]); finish_exception((except_T *)cstack->cs_exception[idx]);
}
/* Stop at this try conditional - except the try block never /* Stop at this try conditional - except the try block never
* got active (because of an inactive surrounding conditional * got active (because of an inactive surrounding conditional
* or when the ":try" appeared after an error or interrupt or * or when the ":try" appeared after an error or interrupt or
* throw). */ * throw). */
if (cstack->cs_flags[idx] & CSF_TRUE) { if (cstack->cs_flags[idx] & CSF_TRUE) {
if (searched_cond == 0 && !inclusive) if (searched_cond == 0 && !inclusive) {
break; break;
}
stop = TRUE; stop = TRUE;
} }
} }
@ -1967,13 +2017,15 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
* If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT, * If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT,
* check first whether "emsg_silent" needs to be restored. */ * check first whether "emsg_silent" needs to be restored. */
if (cstack->cs_flags[idx] & searched_cond) { if (cstack->cs_flags[idx] & searched_cond) {
if (!inclusive) if (!inclusive) {
break; break;
}
stop = TRUE; stop = TRUE;
} }
cstack->cs_flags[idx] &= ~CSF_ACTIVE; cstack->cs_flags[idx] &= ~CSF_ACTIVE;
if (stop && searched_cond != (CSF_TRY | CSF_SILENT)) if (stop && searched_cond != (CSF_TRY | CSF_SILENT)) {
break; break;
}
/* /*
* When leaving a try conditional that reset "emsg_silent" on its * When leaving a try conditional that reset "emsg_silent" on its
@ -1990,9 +2042,10 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
xfree(elem); xfree(elem);
cstack->cs_flags[idx] &= ~CSF_SILENT; cstack->cs_flags[idx] &= ~CSF_SILENT;
} }
if (stop) if (stop) {
break; break;
} }
}
return idx; return idx;
} }
@ -2001,10 +2054,12 @@ int cleanup_conditionals(cstack_T *cstack, int searched_cond, int inclusive)
*/ */
static char_u *get_end_emsg(cstack_T *cstack) static char_u *get_end_emsg(cstack_T *cstack)
{ {
if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) if (cstack->cs_flags[cstack->cs_idx] & CSF_WHILE) {
return e_endwhile; return e_endwhile;
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) }
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
return e_endfor; return e_endfor;
}
return e_endif; return e_endif;
} }
@ -2016,14 +2071,15 @@ static char_u *get_end_emsg(cstack_T *cstack)
* type. * type.
* Also free "for info" structures where needed. * Also free "for info" structures where needed.
*/ */
void rewind_conditionals(cstack_T *cstack, int idx, int cond_type, void rewind_conditionals(cstack_T *cstack, int idx, int cond_type, int *cond_level)
int *cond_level)
{ {
while (cstack->cs_idx > idx) { while (cstack->cs_idx > idx) {
if (cstack->cs_flags[cstack->cs_idx] & cond_type) if (cstack->cs_flags[cstack->cs_idx] & cond_type) {
--*cond_level; --*cond_level;
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) }
if (cstack->cs_flags[cstack->cs_idx] & CSF_FOR) {
free_for_info(cstack->cs_forinfo[cstack->cs_idx]); free_for_info(cstack->cs_forinfo[cstack->cs_idx]);
}
--cstack->cs_idx; --cstack->cs_idx;
} }
} }
@ -2043,18 +2099,21 @@ int has_loop_cmd(char_u *p)
{ {
int len; int len;
/* skip modifiers, white space and ':' */ // skip modifiers, white space and ':'
for (;; ) { for (;; ) {
while (*p == ' ' || *p == '\t' || *p == ':') while (*p == ' ' || *p == '\t' || *p == ':') {
++p; ++p;
}
len = modifier_len(p); len = modifier_len(p);
if (len == 0) if (len == 0) {
break; break;
}
p += len; p += len;
} }
if ((p[0] == 'w' && p[1] == 'h') if ((p[0] == 'w' && p[1] == 'h')
|| (p[0] == 'f' && p[1] == 'o' && p[2] == 'r')) || (p[0] == 'f' && p[1] == 'o' && p[2] == 'r')) {
return TRUE; return TRUE;
}
return FALSE; return FALSE;
} }

File diff suppressed because it is too large Load Diff

View File

@ -8,13 +8,11 @@
// :mksession // :mksession
#include <assert.h> #include <assert.h>
#include <string.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h> #include <string.h>
#include "nvim/vim.h"
#include "nvim/globals.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
@ -28,6 +26,7 @@
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/fold.h" #include "nvim/fold.h"
#include "nvim/getchar.h" #include "nvim/getchar.h"
#include "nvim/globals.h"
#include "nvim/keymap.h" #include "nvim/keymap.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/move.h" #include "nvim/move.h"
@ -36,6 +35,7 @@
#include "nvim/os/os.h" #include "nvim/os/os.h"
#include "nvim/os/time.h" #include "nvim/os/time.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/vim.h"
#include "nvim/window.h" #include "nvim/window.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
@ -200,8 +200,7 @@ static int ses_do_win(win_T *wp)
/// @param flagp /// @param flagp
/// ///
/// @returns FAIL if writing fails. /// @returns FAIL if writing fails.
static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp)
unsigned *flagp)
{ {
char_u *buf = NULL; char_u *buf = NULL;
char_u *s; char_u *s;
@ -297,15 +296,13 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp)
return retval; return retval;
} }
// Write commands to "fd" to restore the view of a window. /// Write commands to "fd" to restore the view of a window.
// Caller must make sure 'scrolloff' is zero. /// Caller must make sure 'scrolloff' is zero.
static int put_view( ///
FILE *fd, /// @param add_edit add ":edit" command to view
win_T *wp, /// @param flagp vop_flags or ssop_flags
int add_edit, // add ":edit" command to view /// @param current_arg_idx current argument index of the window, use -1 if unknown
unsigned *flagp, // vop_flags or ssop_flags static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int current_arg_idx)
int current_arg_idx // current argument index of the window, use
) // -1 if unknown
{ {
win_T *save_curwin; win_T *save_curwin;
int f; int f;
@ -348,8 +345,8 @@ static int put_view(
// Load the file. // Load the file.
// //
if (wp->w_buffer->b_ffname != NULL if (wp->w_buffer->b_ffname != NULL
&& (!bt_nofile(wp->w_buffer) || wp->w_buffer->terminal) && (!bt_nofile(wp->w_buffer) ||
) { wp->w_buffer->terminal)) {
// Editing a file in this buffer: use ":edit file". // Editing a file in this buffer: use ":edit file".
// This may have side effects! (e.g., compressed or network file). // This may have side effects! (e.g., compressed or network file).
// //
@ -434,8 +431,8 @@ static int put_view(
// //
if ((*flagp & SSOP_FOLDS) if ((*flagp & SSOP_FOLDS)
&& wp->w_buffer->b_ffname != NULL && wp->w_buffer->b_ffname != NULL
&& (bt_normal(wp->w_buffer) || bt_help(wp->w_buffer)) && (bt_normal(wp->w_buffer) ||
) { bt_help(wp->w_buffer))) {
if (put_folds(fd, wp) == FAIL) { if (put_folds(fd, wp) == FAIL) {
return FAIL; return FAIL;
} }
@ -658,8 +655,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
if (ses_do_win(wp) if (ses_do_win(wp)
&& wp->w_buffer->b_ffname != NULL && wp->w_buffer->b_ffname != NULL
&& !bt_help(wp->w_buffer) && !bt_help(wp->w_buffer)
&& !bt_nofile(wp->w_buffer) && !bt_nofile(wp->w_buffer)) {
) {
if (need_tabnext && put_line(fd, "tabnext") == FAIL) { if (need_tabnext && put_line(fd, "tabnext") == FAIL) {
return FAIL; return FAIL;
} }

View File

@ -29,19 +29,20 @@
// code for redrawing the line with the deleted decoration. // code for redrawing the line with the deleted decoration.
#include <assert.h> #include <assert.h>
#include "nvim/api/vim.h" #include "nvim/api/vim.h"
#include "nvim/vim.h" #include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/extmark.h"
#include "nvim/decoration.h"
#include "nvim/buffer_updates.h" #include "nvim/buffer_updates.h"
#include "nvim/charset.h"
#include "nvim/decoration.h"
#include "nvim/extmark.h"
#include "nvim/globals.h"
#include "nvim/lib/kbtree.h"
#include "nvim/map.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/pos.h" #include "nvim/pos.h"
#include "nvim/globals.h"
#include "nvim/map.h"
#include "nvim/lib/kbtree.h"
#include "nvim/undo.h" #include "nvim/undo.h"
#include "nvim/buffer.h" #include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "extmark.c.generated.h" # include "extmark.c.generated.h"
@ -56,10 +57,9 @@ static ExtmarkNs *buf_ns_ref(buf_T *buf, uint64_t ns_id, bool put) {
/// ///
/// must not be used during iteration! /// must not be used during iteration!
/// @returns the mark id /// @returns the mark id
uint64_t extmark_set(buf_T *buf, uint64_t ns_id, uint64_t id, uint64_t extmark_set(buf_T *buf, uint64_t ns_id, uint64_t id, int row, colnr_T col, int end_row,
int row, colnr_T col, int end_row, colnr_T end_col, colnr_T end_col, Decoration *decor, bool right_gravity, bool end_right_gravity,
Decoration *decor, bool right_gravity, ExtmarkOp op)
bool end_right_gravity, ExtmarkOp op)
{ {
ExtmarkNs *ns = buf_ns_ref(buf, ns_id, true); ExtmarkNs *ns = buf_ns_ref(buf, ns_id, true);
assert(ns != NULL); assert(ns != NULL);
@ -178,9 +178,7 @@ bool extmark_del(buf_T *buf, uint64_t ns_id, uint64_t id)
// Free extmarks in a ns between lines // Free extmarks in a ns between lines
// if ns = 0, it means clear all namespaces // if ns = 0, it means clear all namespaces
bool extmark_clear(buf_T *buf, uint64_t ns_id, bool extmark_clear(buf_T *buf, uint64_t ns_id, int l_row, colnr_T l_col, int u_row, colnr_T u_col)
int l_row, colnr_T l_col,
int u_row, colnr_T u_col)
{ {
if (!map_size(buf->b_extmark_ns)) { if (!map_size(buf->b_extmark_ns)) {
return false; return false;
@ -281,10 +279,8 @@ bool extmark_clear(buf_T *buf, uint64_t ns_id,
// will be searched to the start, or end // will be searched to the start, or end
// dir can be set to control the order of the array // dir can be set to control the order of the array
// amount = amount of marks to find or -1 for all // amount = amount of marks to find or -1 for all
ExtmarkInfoArray extmark_get(buf_T *buf, uint64_t ns_id, ExtmarkInfoArray extmark_get(buf_T *buf, uint64_t ns_id, int l_row, colnr_T l_col, int u_row,
int l_row, colnr_T l_col, colnr_T u_col, int64_t amount, bool reverse)
int u_row, colnr_T u_col,
int64_t amount, bool reverse)
{ {
ExtmarkInfoArray array = KV_INITIAL_VALUE; ExtmarkInfoArray array = KV_INITIAL_VALUE;
MarkTreeIter itr[1]; MarkTreeIter itr[1];
@ -394,8 +390,7 @@ void extmark_free_all(buf_T *buf)
// Save info for undo/redo of set marks // Save info for undo/redo of set marks
static void u_extmark_set(buf_T *buf, uint64_t mark, static void u_extmark_set(buf_T *buf, uint64_t mark, int row, colnr_T col)
int row, colnr_T col)
{ {
u_header_T *uhp = u_force_get_undo_header(buf); u_header_T *uhp = u_force_get_undo_header(buf);
if (!uhp) { if (!uhp) {
@ -419,9 +414,7 @@ static void u_extmark_set(buf_T *buf, uint64_t mark,
/// ///
/// useful when we cannot simply reverse the operation. This will do nothing on /// useful when we cannot simply reverse the operation. This will do nothing on
/// redo, enforces correct position when undo. /// redo, enforces correct position when undo.
void u_extmark_copy(buf_T *buf, void u_extmark_copy(buf_T *buf, int l_row, colnr_T l_col, int u_row, colnr_T u_col)
int l_row, colnr_T l_col,
int u_row, colnr_T u_col)
{ {
u_header_T *uhp = u_force_get_undo_header(buf); u_header_T *uhp = u_force_get_undo_header(buf);
if (!uhp) { if (!uhp) {
@ -467,7 +460,6 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
splice.new_row, splice.new_col, splice.new_byte, splice.new_row, splice.new_col, splice.new_byte,
splice.old_row, splice.old_col, splice.old_byte, splice.old_row, splice.old_col, splice.old_byte,
kExtmarkNoUndo); kExtmarkNoUndo);
} else { } else {
extmark_splice_impl(curbuf, extmark_splice_impl(curbuf,
splice.start_row, splice.start_col, splice.start_byte, splice.start_row, splice.start_col, splice.start_byte,
@ -508,11 +500,7 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
// Adjust extmark row for inserted/deleted rows (columns stay fixed). // Adjust extmark row for inserted/deleted rows (columns stay fixed).
void extmark_adjust(buf_T *buf, void extmark_adjust(buf_T *buf, linenr_T line1, linenr_T line2, long amount, long amount_after,
linenr_T line1,
linenr_T line2,
long amount,
long amount_after,
ExtmarkOp undo) ExtmarkOp undo)
{ {
if (curbuf_splice_pending) { if (curbuf_splice_pending) {
@ -562,10 +550,8 @@ void extmark_adjust(buf_T *buf,
// the end column of the new region. // the end column of the new region.
// @param new_byte Byte extent of the new region. // @param new_byte Byte extent of the new region.
// @param undo // @param undo
void extmark_splice(buf_T *buf, void extmark_splice(buf_T *buf, int start_row, colnr_T start_col, int old_row, colnr_T old_col,
int start_row, colnr_T start_col, bcount_t old_byte, int new_row, colnr_T new_col, bcount_t new_byte,
int old_row, colnr_T old_col, bcount_t old_byte,
int new_row, colnr_T new_col, bcount_t new_byte,
ExtmarkOp undo) ExtmarkOp undo)
{ {
long offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true); long offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true);
@ -584,11 +570,9 @@ void extmark_splice(buf_T *buf,
undo); undo);
} }
void extmark_splice_impl(buf_T *buf, void extmark_splice_impl(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
int start_row, colnr_T start_col, bcount_t start_byte, int old_row, colnr_T old_col, bcount_t old_byte, int new_row,
int old_row, colnr_T old_col, bcount_t old_byte, colnr_T new_col, bcount_t new_byte, ExtmarkOp undo)
int new_row, colnr_T new_col, bcount_t new_byte,
ExtmarkOp undo)
{ {
curbuf->deleted_bytes2 = 0; curbuf->deleted_bytes2 = 0;
buf_updates_send_splice(buf, start_row, start_col, start_byte, buf_updates_send_splice(buf, start_row, start_col, start_byte,
@ -669,22 +653,17 @@ void extmark_splice_impl(buf_T *buf,
} }
} }
void extmark_splice_cols(buf_T *buf, void extmark_splice_cols(buf_T *buf, int start_row, colnr_T start_col, colnr_T old_col,
int start_row, colnr_T start_col, colnr_T new_col, ExtmarkOp undo)
colnr_T old_col, colnr_T new_col,
ExtmarkOp undo)
{ {
extmark_splice(buf, start_row, start_col, extmark_splice(buf, start_row, start_col,
0, old_col, old_col, 0, old_col, old_col,
0, new_col, new_col, undo); 0, new_col, new_col, undo);
} }
void extmark_move_region( void extmark_move_region(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
buf_T *buf, int extent_row, colnr_T extent_col, bcount_t extent_byte, int new_row,
int start_row, colnr_T start_col, bcount_t start_byte, colnr_T new_col, bcount_t new_byte, ExtmarkOp undo)
int extent_row, colnr_T extent_col, bcount_t extent_byte,
int new_row, colnr_T new_col, bcount_t new_byte,
ExtmarkOp undo)
{ {
curbuf->deleted_bytes2 = 0; curbuf->deleted_bytes2 = 0;
// TODO(bfredl): this is not synced to the buffer state inside the callback. // TODO(bfredl): this is not synced to the buffer state inside the callback.