aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/buffer.c1
-rw-r--r--src/nvim/ascii.h7
-rw-r--r--src/nvim/auevents.lua1
-rw-r--r--src/nvim/buffer.c15
-rw-r--r--src/nvim/buffer_defs.h1
-rw-r--r--src/nvim/diff.c1
-rw-r--r--src/nvim/edit.c16
-rw-r--r--src/nvim/eval.c39
-rw-r--r--src/nvim/eval.h3
-rw-r--r--src/nvim/eval_defs.h2
-rw-r--r--src/nvim/event/socket.c2
-rw-r--r--src/nvim/event/stream.c2
-rw-r--r--src/nvim/ex_cmds.c9
-rw-r--r--src/nvim/ex_cmds2.c9
-rw-r--r--src/nvim/ex_cmds_defs.h6
-rw-r--r--src/nvim/ex_docmd.c18
-rw-r--r--src/nvim/ex_eval.c8
-rw-r--r--src/nvim/ex_getln.c19
-rw-r--r--src/nvim/file_search.c1
-rw-r--r--src/nvim/fileio.c48
-rw-r--r--src/nvim/fold.c9
-rw-r--r--src/nvim/getchar.c8
-rw-r--r--src/nvim/globals.h60
-rw-r--r--src/nvim/hardcopy.c9
-rw-r--r--src/nvim/if_cscope.c3
-rw-r--r--src/nvim/keymap.c2
-rw-r--r--src/nvim/keymap.h7
-rw-r--r--src/nvim/log.c2
-rw-r--r--src/nvim/macros.h11
-rw-r--r--src/nvim/main.c11
-rw-r--r--src/nvim/mark.c9
-rw-r--r--src/nvim/mbyte.c10
-rw-r--r--src/nvim/memfile.c9
-rw-r--r--src/nvim/memline.c14
-rw-r--r--src/nvim/memline_defs.h2
-rw-r--r--src/nvim/memory.c1
-rw-r--r--src/nvim/menu.c10
-rw-r--r--src/nvim/message.c9
-rw-r--r--src/nvim/misc1.c9
-rw-r--r--src/nvim/misc2.c11
-rw-r--r--src/nvim/move.c7
-rw-r--r--src/nvim/normal.c8
-rw-r--r--src/nvim/ops.c12
-rw-r--r--src/nvim/option.c126
-rw-r--r--src/nvim/option_defs.h1
-rw-r--r--src/nvim/options.lua17
-rw-r--r--src/nvim/os/env.c33
-rw-r--r--src/nvim/os/fs.c29
-rw-r--r--src/nvim/os/fs_defs.h4
-rw-r--r--src/nvim/os/os_defs.h30
-rw-r--r--src/nvim/os/shell.c3
-rw-r--r--src/nvim/os/signal.c12
-rw-r--r--src/nvim/os/unix_defs.h18
-rw-r--r--src/nvim/os/win_defs.h13
-rw-r--r--src/nvim/os_unix.c8
-rw-r--r--src/nvim/path.c5
-rw-r--r--src/nvim/popupmnu.c2
-rw-r--r--src/nvim/quickfix.c9
-rw-r--r--src/nvim/regexp_nfa.c7
-rw-r--r--src/nvim/screen.c9
-rw-r--r--src/nvim/search.c9
-rw-r--r--src/nvim/shada.c334
-rw-r--r--src/nvim/spell.c7
-rw-r--r--src/nvim/strings.c2
-rw-r--r--src/nvim/syntax.c9
-rw-r--r--src/nvim/tag.c9
-rw-r--r--src/nvim/terminal.c8
-rw-r--r--src/nvim/types.h7
-rw-r--r--src/nvim/undo.c75
-rw-r--r--src/nvim/version.c24
-rw-r--r--src/nvim/vim.h7
-rw-r--r--src/nvim/window.c9
72 files changed, 550 insertions, 717 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index a8446265d0..b7a86af134 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1,6 +1,5 @@
// Much of this code was adapted from 'if_py_both.h' from the original
// vim source
-#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
diff --git a/src/nvim/ascii.h b/src/nvim/ascii.h
index cce52c5250..2b3e94d5a0 100644
--- a/src/nvim/ascii.h
+++ b/src/nvim/ascii.h
@@ -1,10 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
-
#ifndef NVIM_ASCII_H
#define NVIM_ASCII_H
diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua
index 7624dd2303..aa4a8d8332 100644
--- a/src/nvim/auevents.lua
+++ b/src/nvim/auevents.lua
@@ -57,6 +57,7 @@ return {
'InsertLeave', -- when leaving Insert mode
'JobActivity', -- when job sent some data
'MenuPopup', -- just before popup menu is displayed
+ 'OptionSet', -- after setting any option
'QuickFixCmdPost', -- after :make, :grep etc.
'QuickFixCmdPre', -- before :make, :grep etc.
'QuitPre', -- before :quit
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 6fc08643af..fae8e9ecd0 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* buffer.c: functions for dealing with the buffer structure
*/
@@ -25,7 +17,6 @@
*/
#include <stdbool.h>
-#include <errno.h>
#include <string.h>
#include <inttypes.h>
@@ -3754,8 +3745,10 @@ int build_stl_str_hl(
// Put a `<` to mark where we truncated at
*trunc_p = '<';
- // Advance the pointer to the end of the string
- trunc_p = trunc_p + STRLEN(trunc_p);
+ if (width + 1 < maxwidth) {
+ // Advance the pointer to the end of the string
+ trunc_p = trunc_p + STRLEN(trunc_p);
+ }
// Fill up for half a double-wide character.
while (++width < maxwidth) {
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 3eabb7ee43..6b5bbe3b00 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -612,6 +612,7 @@ struct file_buffer {
char_u *b_p_cfu; /* 'completefunc' */
char_u *b_p_ofu; /* 'omnifunc' */
int b_p_eol; /* 'endofline' */
+ int b_p_fixeol; /* 'fixendofline' */
int b_p_et; /* 'expandtab' */
int b_p_et_nobin; /* b_p_et saved for binary mode */
char_u *b_p_fenc; /* 'fileencoding' */
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 6e2b3056e4..d311588ab4 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -2,7 +2,6 @@
///
/// Code for diff'ing two, three or four buffers.
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 208e41946b..e820ea3d2b 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* edit.c: functions for Insert mode
*/
#include <assert.h>
-#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <stdbool.h>
@@ -7436,15 +7427,14 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
* delete newline!
*/
if (curwin->w_cursor.col == 0) {
- lnum = Insstart_orig.lnum;
+ lnum = Insstart.lnum;
if (curwin->w_cursor.lnum == lnum || revins_on) {
if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
(linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL) {
return FALSE;
}
- --Insstart_orig.lnum;
- Insstart_orig.col = MAXCOL;
- Insstart = Insstart_orig;
+ --Insstart.lnum;
+ Insstart.col = MAXCOL;
}
/*
* In replace mode:
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 9581b81456..b60886704e 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1,18 +1,8 @@
/*
- *
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* eval.c: Expression evaluation.
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdarg.h>
#include <string.h>
@@ -383,6 +373,9 @@ static struct vimvar {
{VV_NAME("progpath", VAR_STRING), VV_RO},
{VV_NAME("command_output", VAR_STRING), 0},
{VV_NAME("completed_item", VAR_DICT), VV_RO},
+ {VV_NAME("option_new", VAR_STRING), VV_RO},
+ {VV_NAME("option_old", VAR_STRING), VV_RO},
+ {VV_NAME("option_type", VAR_STRING), VV_RO},
{VV_NAME("msgpack_types", VAR_DICT), VV_RO},
};
@@ -5658,6 +5651,14 @@ bool garbage_collect(void)
ABORTING(set_ref_in_ht)(&fc->l_avars.dv_hashtab, copyID, NULL);
}
+ // Jobs
+ {
+ TerminalJobData *data;
+ map_foreach_value(jobs, data, {
+ ABORTING(set_ref_dict)(data->self, copyID);
+ })
+ }
+
// v: vars
ABORTING(set_ref_in_ht)(&vimvarht, copyID, NULL);
@@ -5735,8 +5736,7 @@ static int free_unref_items(int copyID)
// Go through the list of dicts and free items without the copyID.
// Don't free dicts that are referenced internally.
for (dict_T *dd = first_dict; dd != NULL; ) {
- if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)
- && !dd->internal_refcount) {
+ if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) {
// Free the Dictionary and ordinary items it contains, but don't
// recurse into Lists and Dictionaries, they will be in the list
// of dicts or list of lists. */
@@ -5977,7 +5977,6 @@ dict_T *dict_alloc(void) FUNC_ATTR_NONNULL_RET
d->dv_scope = 0;
d->dv_refcount = 0;
d->dv_copyID = 0;
- d->internal_refcount = 0;
QUEUE_INIT(&d->watchers);
return d;
@@ -21248,9 +21247,13 @@ void ex_oldfiles(exarg_T *eap)
}
}
-
-
-
+// reset v:option_new, v:option_old and v:option_type
+void reset_v_option_vars(void)
+{
+ set_vim_var_string(VV_OPTION_NEW, NULL, -1);
+ set_vim_var_string(VV_OPTION_OLD, NULL, -1);
+ set_vim_var_string(VV_OPTION_TYPE, NULL, -1);
+}
/*
* Adjust a filename, according to a string of modifiers.
@@ -21623,7 +21626,6 @@ static inline bool common_job_callbacks(dict_T *vopts, ufunc_T **on_stdout,
if (get_dict_callback(vopts, "on_stdout", on_stdout)
&& get_dict_callback(vopts, "on_stderr", on_stderr)
&& get_dict_callback(vopts, "on_exit", on_exit)) {
- vopts->internal_refcount++;
vopts->dv_refcount++;
return true;
}
@@ -21685,7 +21687,6 @@ static inline void free_term_job_data_event(void **argv)
}
if (data->self) {
- data->self->internal_refcount--;
dict_unref(data->self);
}
queue_free(data->events);
@@ -21936,7 +21937,7 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments)
true,
NULL);
- arguments->lv_refcount--;
+ list_unref(arguments);
// Restore caller scope information
restore_funccal(provider_caller_scope.funccalp);
provider_caller_scope = saved_provider_caller_scope;
diff --git a/src/nvim/eval.h b/src/nvim/eval.h
index 8ccf71068c..19a1bbb083 100644
--- a/src/nvim/eval.h
+++ b/src/nvim/eval.h
@@ -108,6 +108,9 @@ enum {
VV_PROGPATH,
VV_COMMAND_OUTPUT,
VV_COMPLETED_ITEM,
+ VV_OPTION_NEW,
+ VV_OPTION_OLD,
+ VV_OPTION_TYPE,
VV_MSGPACK_TYPES,
VV_LEN, /* number of v: vars */
};
diff --git a/src/nvim/eval_defs.h b/src/nvim/eval_defs.h
index bd50d6b829..ed419268d2 100644
--- a/src/nvim/eval_defs.h
+++ b/src/nvim/eval_defs.h
@@ -118,8 +118,6 @@ struct dictvar_S {
dict_T *dv_copydict; /* copied dict used by deepcopy() */
dict_T *dv_used_next; /* next dict in used dicts list */
dict_T *dv_used_prev; /* previous dict in used dicts list */
- int internal_refcount; // number of internal references to
- // prevent garbage collection
QUEUE watchers; // dictionary key watchers set by user code
};
diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c
index 347e464d25..93cc592683 100644
--- a/src/nvim/event/socket.c
+++ b/src/nvim/event/socket.c
@@ -97,7 +97,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb)
result = uv_listen(watcher->stream, backlog, connection_cb);
}
- assert(result <= 0); // libuv should have returned -errno or zero.
+ assert(result <= 0); // libuv should return negative error code or zero.
if (result < 0) {
if (result == -EACCES) {
// Libuv converts ENOENT to EACCES for Windows compatibility, but if
diff --git a/src/nvim/event/stream.c b/src/nvim/event/stream.c
index 376eb9fce7..71582ab357 100644
--- a/src/nvim/event/stream.c
+++ b/src/nvim/event/stream.c
@@ -13,7 +13,7 @@
/// Sets the stream associated with `fd` to "blocking" mode.
///
-/// @return `0` on success, or `-errno` on failure.
+/// @return `0` on success, or libuv error code on failure.
int stream_set_blocking(int fd, bool blocking)
{
// Private loop to avoid conflict with existing watcher(s):
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index c4fffcda71..3f19421a75 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* ex_cmds.c: some functions for command line commands
*/
#include <assert.h>
-#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index a632a3cce4..87a6283310 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* ex_cmds2.c: some more functions for command line commands
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h
index 4065cc2fdc..10d2eb688e 100644
--- a/src/nvim/ex_cmds_defs.h
+++ b/src/nvim/ex_cmds_defs.h
@@ -1,9 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
#ifndef NVIM_EX_CMDS_DEFS_H
#define NVIM_EX_CMDS_DEFS_H
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 4d9f8b5769..59bda9345e 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* ex_docmd.c: functions for executing an Ex command line.
*/
@@ -14,7 +6,6 @@
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
-#include <errno.h>
#include <inttypes.h>
#include "nvim/vim.h"
@@ -3455,6 +3446,7 @@ static linenr_T get_address(char_u **ptr,
}
if (addr_type != ADDR_LINES) {
EMSG(_(e_invaddr));
+ cmd = NULL;
goto error;
}
if (skip)
@@ -3482,6 +3474,7 @@ static linenr_T get_address(char_u **ptr,
c = *cmd++;
if (addr_type != ADDR_LINES) {
EMSG(_(e_invaddr));
+ cmd = NULL;
goto error;
}
if (skip) { /* skip "/pat/" */
@@ -3525,6 +3518,7 @@ static linenr_T get_address(char_u **ptr,
++cmd;
if (addr_type != ADDR_LINES) {
EMSG(_(e_invaddr));
+ cmd = NULL;
goto error;
}
if (*cmd == '&')
@@ -3596,7 +3590,8 @@ static linenr_T get_address(char_u **ptr,
else
n = getdigits(&cmd);
if (addr_type == ADDR_LOADED_BUFFERS || addr_type == ADDR_BUFFERS)
- lnum = compute_buffer_local_count(addr_type, lnum, (i == '-') ? -1 * n : n);
+ lnum = compute_buffer_local_count(
+ addr_type, lnum, (i == '-') ? -1 * n : n);
else if (i == '-')
lnum -= n;
else
@@ -3664,7 +3659,8 @@ static char_u *invalid_range(exarg_T *eap)
}
break;
case ADDR_ARGUMENTS:
- if (eap->line2 > ARGCOUNT + (!ARGCOUNT)) { // add 1 if ARGCOUNT is 0
+ // add 1 if ARGCOUNT is 0
+ if (eap->line2 > ARGCOUNT + (!ARGCOUNT)) {
return (char_u *)_(e_invrange);
}
break;
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index bea1aecb58..bf67047ae8 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* ex_eval.c: functions for Ex command line for the +eval feature.
*/
#include <assert.h>
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 52292128d8..6d81f3680a 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* ex_getln.c: Functions for entering and editing an Ex command line.
*/
#include <assert.h>
-#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
@@ -580,7 +571,7 @@ static int command_line_execute(VimState *state, int key)
}
if (vim_ispathsep(ccline.cmdbuff[s->j])
#ifdef BACKSLASH_IN_FILENAME
- && vim_strchr(" *?[{`$%#", ccline.cmdbuff[j + 1])
+ && vim_strchr(" *?[{`$%#", ccline.cmdbuff[s->j + 1])
== NULL
#endif
) {
@@ -1448,6 +1439,14 @@ static int command_line_handle_key(CommandLineState *s)
}
return command_line_not_changed(s);
+ case K_FOCUSGAINED: // Neovim has been given focus
+ apply_autocmds(EVENT_FOCUSGAINED, NULL, NULL, false, curbuf);
+ return command_line_not_changed(s);
+
+ case K_FOCUSLOST: // Neovim has lost focus
+ apply_autocmds(EVENT_FOCUSLOST, NULL, NULL, false, curbuf);
+ return command_line_not_changed(s);
+
default:
// Normal character with no special meaning. Just set mod_mask
// to 0x0 so that typing Shift-Space in the GUI doesn't enter
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index fbff7d2417..4f345158cf 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -45,7 +45,6 @@
*/
#include <assert.h>
-#include <errno.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index a7472b40e2..87fcddd3e9 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* fileio.c: read from and write to a file
*/
@@ -535,11 +527,7 @@ readfile (
if (!newfile) {
return FAIL;
}
- if (perm < 0
-#ifdef ENOENT
- && errno == ENOENT
-#endif
- ) {
+ if (perm == UV_ENOENT) {
/*
* Set the 'new-file' flag, so that when the file has
* been created by someone else, a ":w" will complain.
@@ -582,11 +570,11 @@ readfile (
return OK; /* a new file is not an error */
} else {
filemess(curbuf, sfname, (char_u *)(
-# ifdef EFBIG
- (errno == EFBIG) ? _("[File too big]") :
-# endif
-# ifdef EOVERFLOW
- (errno == EOVERFLOW) ? _("[File too big]") :
+ (fd == UV_EFBIG) ? _("[File too big]") :
+# if defined(UNIX) && defined(EOVERFLOW)
+ // libuv only returns -errno in Unix and in Windows open() does not
+ // set EOVERFLOW
+ (fd == -EOVERFLOW) ? _("[File too big]") :
# endif
_("[Permission Denied]")), 0);
curbuf->b_p_ro = TRUE; /* must use "w!" now */
@@ -1934,10 +1922,10 @@ failed:
check_marks_read();
/*
- * Trick: We remember if the last line of the read didn't have
- * an eol even when 'binary' is off, for when writing it again with
- * 'binary' on. This is required for
- * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
+ * We remember if the last line of the read didn't have
+ * an eol even when 'binary' is off, to support turning 'fixeol' off,
+ * or writing the read again with 'binary' on. The latter is required
+ * for ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
*/
curbuf->b_no_eol_lnum = read_no_eol_lnum;
@@ -3322,7 +3310,7 @@ restore_backup:
/* write failed or last line has no EOL: stop here */
if (end == 0
|| (lnum == end
- && write_bin
+ && (write_bin || !buf->b_p_fixeol)
&& (lnum == buf->b_no_eol_lnum
|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol)))) {
++lnum; /* written the line, count it */
@@ -4343,8 +4331,6 @@ void shorten_fnames(int force)
/// @return [allocated] - A new filename, made up from:
/// * fname + ext, if fname not NULL.
/// * current dir + ext, if fname is NULL.
-/// On Windows, and if ext starts with ".", a "_" is
-/// preprended to ext (for filename to be valid).
/// Result is guaranteed to:
/// * be ended by <ext>.
/// * have a basename with at most BASENAMELEN chars:
@@ -4398,15 +4384,6 @@ char *modname(const char *fname, const char *ext, bool prepend_dot)
char *s;
s = ptr + strlen(ptr);
-#if defined(WIN3264)
- // If there is no file name, and the extension starts with '.', put a
- // '_' before the dot, because just ".ext" may be invalid if it's on a
- // FAT partition, and on HPFS it doesn't matter.
- else if ((fname == NULL || *fname == NUL) && *ext == '.') {
- *s++ = '_';
- }
-#endif
-
// Append the extension.
// ext can start with '.' and cannot exceed 3 more characters.
strcpy(s, ext);
@@ -6430,7 +6407,7 @@ apply_autocmds_group (
* invalid.
*/
if (fname_io == NULL) {
- if (event == EVENT_COLORSCHEME)
+ if (event == EVENT_COLORSCHEME || event == EVENT_OPTIONSET)
autocmd_fname = NULL;
else if (fname != NULL && *fname != NUL)
autocmd_fname = fname;
@@ -6480,6 +6457,7 @@ apply_autocmds_group (
if (event == EVENT_COLORSCHEME
|| event == EVENT_FILETYPE
|| event == EVENT_FUNCUNDEFINED
+ || event == EVENT_OPTIONSET
|| event == EVENT_QUICKFIXCMDPOST
|| event == EVENT_QUICKFIXCMDPRE
|| event == EVENT_REMOTEREPLY
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index b52938075c..2e32e78062 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -1,11 +1,4 @@
-/* vim: set fdm=marker fdl=1 fdc=3
- *
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
+// vim: set fdm=marker fdl=1 fdc=3
/*
* fold.c: code for folding
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index b77a030158..44d6c086e7 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* getchar.c
*
* functions related with getting a character from the user/mapping/redo/...
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 7c42238d20..52eebebf41 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -1,10 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
-
#ifndef NVIM_GLOBALS_H
#define NVIM_GLOBALS_H
@@ -55,6 +48,57 @@
# endif
#endif
+#ifdef WIN32
+# define _PATHSEPSTR "\\"
+#else
+# define _PATHSEPSTR "/"
+#endif
+
+#ifndef FILETYPE_FILE
+# define FILETYPE_FILE "filetype.vim"
+#endif
+
+#ifndef FTPLUGIN_FILE
+# define FTPLUGIN_FILE "ftplugin.vim"
+#endif
+
+#ifndef INDENT_FILE
+# define INDENT_FILE "indent.vim"
+#endif
+
+#ifndef FTOFF_FILE
+# define FTOFF_FILE "ftoff.vim"
+#endif
+
+#ifndef FTPLUGOF_FILE
+# define FTPLUGOF_FILE "ftplugof.vim"
+#endif
+
+#ifndef INDOFF_FILE
+# define INDOFF_FILE "indoff.vim"
+#endif
+
+#define DFLT_ERRORFILE "errors.err"
+
+#ifndef SYS_VIMRC_FILE
+# define SYS_VIMRC_FILE "$VIM" _PATHSEPSTR "sysinit.vim"
+#endif
+
+#ifndef DFLT_HELPFILE
+# define DFLT_HELPFILE "$VIMRUNTIME" _PATHSEPSTR "doc" _PATHSEPSTR "help.txt"
+#endif
+
+#ifndef SYNTAX_FNAME
+# define SYNTAX_FNAME "$VIMRUNTIME" _PATHSEPSTR "syntax" _PATHSEPSTR "%s.vim"
+#endif
+
+#ifndef EXRC_FILE
+# define EXRC_FILE ".exrc"
+#endif
+
+#ifndef VIMRC_FILE
+# define VIMRC_FILE ".nvimrc"
+#endif
/* Values for "starting" */
#define NO_SCREEN 2 /* no screen updating yet */
@@ -998,7 +1042,7 @@ EXTERN int lcs_space INIT(= NUL);
EXTERN int lcs_tab1 INIT(= NUL);
EXTERN int lcs_tab2 INIT(= NUL);
EXTERN int lcs_trail INIT(= NUL);
-EXTERN int lcs_conceal INIT(= '-');
+EXTERN int lcs_conceal INIT(= ' ');
/* Characters from 'fillchars' option */
EXTERN int fill_stl INIT(= ' ');
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index 819015a85d..ab8959239b 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* hardcopy.c: printing to paper
*/
#include <assert.h>
-#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <stdint.h>
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index e5cbb58608..3585c26ca2 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -4,9 +4,8 @@
*
* The basic idea/structure of cscope for Vim was borrowed from Nvi. There
* might be a few lines of code that look similar to what Nvi has.
- *
- * See README.txt for an overview of the Vim source code.
*/
+
#include <stdbool.h>
#include <assert.h>
diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c
index 85380ba173..04d6cbf5e3 100644
--- a/src/nvim/keymap.c
+++ b/src/nvim/keymap.c
@@ -1,4 +1,4 @@
-/************************************************************************
+/*
* functions that use lookup tables for various things, generally to do with
* special key codes.
*/
diff --git a/src/nvim/keymap.h b/src/nvim/keymap.h
index d2d96c6149..766362d145 100644
--- a/src/nvim/keymap.h
+++ b/src/nvim/keymap.h
@@ -1,10 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
-
#ifndef NVIM_KEYMAP_H
#define NVIM_KEYMAP_H
diff --git a/src/nvim/log.c b/src/nvim/log.c
index 08b6d0483e..5767da03af 100644
--- a/src/nvim/log.c
+++ b/src/nvim/log.c
@@ -14,7 +14,7 @@
# include <unistd.h>
#endif
-#define USR_LOG_FILE "$HOME/.nvimlog"
+#define USR_LOG_FILE "$HOME" _PATHSEPSTR ".nvimlog"
static uv_mutex_t mutex;
diff --git a/src/nvim/macros.h b/src/nvim/macros.h
index d42997650c..26ab5a7de7 100644
--- a/src/nvim/macros.h
+++ b/src/nvim/macros.h
@@ -1,17 +1,6 @@
#ifndef NVIM_MACROS_H
#define NVIM_MACROS_H
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
-
-/*
- * macros.h: macro definitions for often used code
- */
-
#ifndef MIN
# define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#endif
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 83fe32cccb..cef10d12d5 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1,14 +1,5 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
#define EXTERN
#include <assert.h>
-#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
@@ -1865,5 +1856,3 @@ static void check_swap_exists_action(void)
getout(1);
handle_swap_exists(NULL);
}
-
-
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index 0432ec5cef..e2f212340c 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* mark.c: functions for setting marks and jumping to them
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <limits.h>
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 087d2e677c..b02c18c53b 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1,13 +1,6 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- * Multibyte extensions partly by Sung-Hoon Baek
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-/*
* mbyte.c: Code specifically for handling multi-byte characters.
+ * Multibyte extensions partly by Sung-Hoon Baek
*
* The encoding used in the core is set with 'encoding'. When 'encoding' is
* changed, the following four variables are set (for speed).
@@ -71,7 +64,6 @@
* some commands, like ":menutrans"
*/
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index b6a341d5e8..3df4cbc4a3 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -1,11 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
/// An abstraction to handle blocks of memory which can be stored in a file.
/// This is the implementation of a sort of virtual memory.
///
@@ -44,7 +36,6 @@
/// mf_fullname() make file name full path (use before first :cd)
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <string.h>
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 85f545f960..c91a25df6e 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1,11 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
/* for debugging */
/* #define CHECK(c, s) if (c) EMSG(s) */
#define CHECK(c, s)
@@ -3962,8 +3954,10 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
if (ffdos)
size += lnum - 1;
- /* Don't count the last line break if 'bin' and 'noeol'. */
- if (buf->b_p_bin && !buf->b_p_eol && buf->b_ml.ml_line_count == lnum) {
+ /* Don't count the last line break if 'noeol' and ('bin' or
+ * 'nofixeol'). */
+ if ((!buf->b_p_fixeol || buf->b_p_bin) && !buf->b_p_eol
+ && buf->b_ml.ml_line_count == lnum) {
size -= ffdos + 1;
}
}
diff --git a/src/nvim/memline_defs.h b/src/nvim/memline_defs.h
index bcc1c673d2..34a002af5d 100644
--- a/src/nvim/memline_defs.h
+++ b/src/nvim/memline_defs.h
@@ -41,7 +41,7 @@ typedef struct memline {
int ml_flags;
infoptr_T *ml_stack; /* stack of pointer blocks (array of IPTRs) */
- int ml_stack_top; /* current top if ml_stack */
+ int ml_stack_top; /* current top of ml_stack */
int ml_stack_size; /* total number of entries in ml_stack */
linenr_T ml_line_lnum; /* line number of cached line, 0 if not valid */
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index 6d386f3599..8db47b79c1 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -1,7 +1,6 @@
// Various routines dealing with allocation and deallocation of memory.
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 9857b8a778..91a72abfc5 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -1,14 +1,6 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- * GUI/Motif support by Robert Webb
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* Code for menus. Used for the GUI and 'wildmenu'.
+ * GUI/Motif support by Robert Webb
*/
#include <assert.h>
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 5f06506a31..66b8b9b5d2 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* message.c: functions for displaying messages on the command line
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdarg.h>
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 5097255880..96ef6cbaef 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* misc1.c: functions that didn't seem to fit elsewhere
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
index d9bc35470f..3c0a1414a6 100644
--- a/src/nvim/misc2.c
+++ b/src/nvim/misc2.c
@@ -1,16 +1,7 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* misc2.c: Various functions.
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <string.h>
@@ -479,7 +470,7 @@ void put_time(FILE *fd, time_t time_)
{
uint8_t buf[8];
time_to_bytes(time_, buf);
- fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd);
+ (void)fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd);
}
/// Writes time_t to "buf[8]".
diff --git a/src/nvim/move.c b/src/nvim/move.c
index 3831004703..eb55397511 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -1,11 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-/*
* move.c: Functions for moving the cursor and scrolling text.
*
* There are two ways to move the cursor:
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 1f0fe287bf..a2e473fcb8 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -1,18 +1,10 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-/*
* normal.c: Contains the main routine for processing characters in command
* mode. Communicates closely with the code in ops.c to handle
* the operators.
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 3fd2c0b773..bef0ebaeed 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* ops.c: implementation of various operators: op_shift, op_delete, op_tilde,
* op_change, op_yank, do_put, do_join
*/
@@ -4972,7 +4964,7 @@ void cursor_pos_info(void)
&char_count_cursor, len, eol_size);
if (lnum == curbuf->b_ml.ml_line_count
&& !curbuf->b_p_eol
- && curbuf->b_p_bin
+ && (curbuf->b_p_bin || !curbuf->b_p_fixeol)
&& (long)STRLEN(s) < len)
byte_count_cursor -= eol_size;
}
@@ -4993,7 +4985,7 @@ void cursor_pos_info(void)
}
/* Correction for when last line doesn't have an EOL. */
- if (!curbuf->b_p_eol && curbuf->b_p_bin)
+ if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol))
byte_count -= eol_size;
if (l_VIsual_active) {
diff --git a/src/nvim/option.c b/src/nvim/option.c
index cc4df28837..486f2083a6 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* Code to handle user-settable options. This is all pretty much table-
* driven. Checklist for adding a new option:
* - Put it in the options array below (copy an existing entry).
@@ -30,7 +22,6 @@
#define IN_OPTION_C
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
@@ -131,6 +122,7 @@ static char_u *p_cpt;
static char_u *p_cfu;
static char_u *p_ofu;
static int p_eol;
+static int p_fixeol;
static int p_et;
static char_u *p_fenc;
static char_u *p_ff;
@@ -1027,12 +1019,9 @@ void set_init_2(void)
*/
void set_init_3(void)
{
-#if defined(UNIX) || defined(WIN3264)
- /*
- * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
- * This is done after other initializations, where 'shell' might have been
- * set, but only if they have not been set before.
- */
+ // Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
+ // This is done after other initializations, where 'shell' might have been
+ // set, but only if they have not been set before.
int idx_srr;
int do_srr;
int idx_sp;
@@ -1089,8 +1078,6 @@ void set_init_3(void)
}
xfree(p);
}
-#endif
-
set_title_defaults();
}
@@ -1512,9 +1499,10 @@ do_set (
} else if (opt_idx >= 0) { /* string */
char_u *save_arg = NULL;
char_u *s = NULL;
- char_u *oldval; /* previous value if *varp */
+ char_u *oldval = NULL; // previous value if *varp
char_u *newval;
- char_u *origval;
+ char_u *origval = NULL;
+ char_u *saved_origval = NULL;
unsigned newlen;
int comma;
int bs;
@@ -1781,14 +1769,37 @@ do_set (
/* Set the new value. */
*(char_u **)(varp) = newval;
+ if (!starting && origval != NULL) {
+ // origval may be freed by
+ // did_set_string_option(), make a copy.
+ saved_origval = vim_strsave(origval);
+ }
+
/* Handle side effects, and set the global value for
* ":set" on local options. */
errmsg = did_set_string_option(opt_idx, (char_u **)varp,
new_value_alloced, oldval, errbuf, opt_flags);
- /* If error detected, print the error message. */
- if (errmsg != NULL)
+ // If error detected, print the error message.
+ if (errmsg != NULL) {
+ xfree(saved_origval);
goto skip;
+ }
+
+ if (saved_origval != NULL) {
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW,
+ *(char_u **)varp, -1);
+ set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *)options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ xfree(saved_origval);
+ }
} else {
// key code option(FIXME(tarruda): Show a warning or something
// similar)
@@ -2338,6 +2349,7 @@ set_string_option (
char_u *s;
char_u **varp;
char_u *oldval;
+ char_u *saved_oldval = NULL;
char_u *r = NULL;
if (options[opt_idx].var == NULL) /* don't set hidden option */
@@ -2351,10 +2363,30 @@ set_string_option (
: opt_flags);
oldval = *varp;
*varp = s;
- if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
+
+ if (!starting) {
+ saved_oldval = vim_strsave(oldval);
+ }
+
+ if ((r = did_set_string_option(opt_idx, varp, (int)true, oldval, NULL,
opt_flags)) == NULL)
did_set_option(opt_idx, opt_flags, TRUE);
+ // call autocommand after handling side effects
+ if (saved_oldval != NULL) {
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW, *varp, -1);
+ set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *)options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ xfree(saved_oldval);
+ }
+
return r;
}
@@ -3556,6 +3588,9 @@ set_bool_option (
/* when 'endofline' is changed, redraw the window title */
else if ((int *)varp == &curbuf->b_p_eol) {
redraw_titles();
+ } else if ((int *)varp == &curbuf->b_p_fixeol) {
+ // when 'fixeol' is changed, redraw the window title
+ redraw_titles();
}
/* when 'bomb' is changed, redraw the window title and tab page text */
else if ((int *)varp == &curbuf->b_p_bomb) {
@@ -3823,8 +3858,29 @@ set_bool_option (
* End of handling side effects for bool options.
*/
+ // after handling side effects, call autocommand
+
options[opt_idx].flags |= P_WAS_SET;
+ if (!starting) {
+ char_u buf_old[2];
+ char_u buf_new[2];
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_old, ARRAY_SIZE(buf_old), "%d",
+ old_value ? true: false);
+ vim_snprintf((char *)buf_new, ARRAY_SIZE(buf_new), "%d",
+ value ? true: false);
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
+ set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *) options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ }
+
comp_col(); /* in case 'ruler' or 'showcmd' changed */
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
@@ -4196,6 +4252,23 @@ set_num_option (
options[opt_idx].flags |= P_WAS_SET;
+ if (!starting && errmsg == NULL) {
+ char_u buf_old[NUMBUFLEN];
+ char_u buf_new[NUMBUFLEN];
+ char_u buf_type[7];
+ vim_snprintf((char *)buf_old, ARRAY_SIZE(buf_old), "%ld", old_value);
+ vim_snprintf((char *)buf_new, ARRAY_SIZE(buf_new), "%ld", value);
+ vim_snprintf((char *)buf_type, ARRAY_SIZE(buf_type), "%s",
+ (opt_flags & OPT_LOCAL) ? "local" : "global");
+ set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
+ set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
+ set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
+ apply_autocmds(EVENT_OPTIONSET,
+ (char_u *) options[opt_idx].fullname,
+ NULL, false, NULL);
+ reset_v_option_vars();
+ }
+
comp_col(); /* in case 'columns' or 'ls' changed */
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
@@ -5230,6 +5303,7 @@ static char_u *get_varp(vimoption_T *p)
case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
+ case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
case PV_ET: return (char_u *)&(curbuf->b_p_et);
case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
case PV_FF: return (char_u *)&(curbuf->b_p_ff);
@@ -5474,6 +5548,7 @@ void buf_copy_options(buf_T *buf, int flags)
buf->b_p_bin = p_bin;
buf->b_p_bomb = p_bomb;
buf->b_p_et = p_et;
+ buf->b_p_fixeol = p_fixeol;
buf->b_p_et_nobin = p_et_nobin;
buf->b_p_ml = p_ml;
buf->b_p_ml_nobin = p_ml_nobin;
@@ -6409,6 +6484,7 @@ void save_file_ff(buf_T *buf)
* from when editing started (save_file_ff() called).
* Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
* changed and 'binary' is not set.
+ * Also when 'endofline' was changed and 'fixeol' is not set.
* When "ignore_empty" is true don't consider a new, empty buffer to be
* changed.
*/
@@ -6423,9 +6499,9 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty)
&& *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
return FALSE;
if (buf->b_start_ffc != *buf->b_p_ff)
- return TRUE;
- if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
- return TRUE;
+ return true;
+ if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
+ return true;
if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
return TRUE;
if (buf->b_start_fenc == NULL)
diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h
index d4d3410d5c..c72e1cf0bb 100644
--- a/src/nvim/option_defs.h
+++ b/src/nvim/option_defs.h
@@ -665,6 +665,7 @@ enum {
, BV_DEF
, BV_INC
, BV_EOL
+ , BV_FIXEOL
, BV_EP
, BV_ET
, BV_FENC
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 633eabab60..5187340629 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -51,15 +51,6 @@ return {
defaults={if_true={vi=224}}
},
{
- full_name='antialias', abbreviation='anti',
- type='bool', scope={'global'},
- vi_def=true,
- vim=true,
- redraw={'everything'},
- enable_if=false,
- defaults={if_true={vi=false, vim=false}}
- },
- {
full_name='arabic', abbreviation='arab',
type='bool', scope={'window'},
vi_def=true,
@@ -808,6 +799,14 @@ return {
defaults={if_true={vi="vert:|,fold:-"}}
},
{
+ full_name='fixendofline', abbreviation='fixeol',
+ type='bool', scope={'buffer'},
+ vi_def=true,
+ redraw={'statuslines'},
+ varname='p_fixeol',
+ defaults={if_true={vi=true}}
+ },
+ {
full_name='fkmap', abbreviation='fk',
type='bool', scope={'global'},
vi_def=true,
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index bf6db97fcf..a791dca39c 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -46,7 +46,19 @@ bool os_env_exists(const char *name)
int os_setenv(const char *name, const char *value, int overwrite)
FUNC_ATTR_NONNULL_ALL
{
+#ifdef HAVE_SETENV
return setenv(name, value, overwrite);
+#elif defined(HAVE_PUTENV_S)
+ if (!overwrite && os_getenv(name) != NULL) {
+ return 0;
+ }
+ if (_putenv_s(name, value) == 0) {
+ return 0;
+ }
+ return -1;
+#else
+# error "This system has no implementation available for os_setenv()"
+#endif
}
/// Unset environment variable
@@ -141,6 +153,27 @@ void init_homedir(void)
char_u *var = (char_u *)os_getenv("HOME");
+#ifdef WIN32
+ // Typically, $HOME is not defined on Windows, unless the user has
+ // specifically defined it for Vim's sake. However, on Windows NT
+ // platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for
+ // each user. Try constructing $HOME from these.
+ if (var == NULL) {
+ const char *homedrive = os_getenv("HOMEDRIVE");
+ const char *homepath = os_getenv("HOMEPATH");
+ if (homepath == NULL) {
+ homepath = "\\";
+ }
+ if (homedrive != NULL && strlen(homedrive) + strlen(homepath) < MAXPATHL) {
+ snprintf((char *)NameBuff, MAXPATHL, "%s%s", homedrive, homepath);
+ if (NameBuff[0] != NUL) {
+ var = NameBuff;
+ vim_setenv("HOME", (char *)NameBuff);
+ }
+ }
+ }
+#endif
+
if (var != NULL) {
#ifdef UNIX
/*
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 3fb00eb24e..d59b66e773 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -185,13 +185,13 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath)
/// Opens or creates a file and returns a non-negative integer representing
/// the lowest-numbered unused file descriptor, for use in subsequent system
-/// calls (read, write, lseek, fcntl, etc.). If the operation fails, `-errno`
-/// is returned, and no file is created or modified.
+/// calls (read, write, lseek, fcntl, etc.). If the operation fails, a libuv
+/// error code is returned, and no file is created or modified.
///
/// @param flags Bitwise OR of flags defined in <fcntl.h>
/// @param mode Permissions for the newly-created file (IGNORED if 'flags' is
/// not `O_CREAT` or `O_TMPFILE`), subject to the current umask
-/// @return file descriptor, or negative `errno` on failure
+/// @return file descriptor, or libuv error code on failure
int os_open(const char* path, int flags, int mode)
FUNC_ATTR_NONNULL_ALL
{
@@ -204,28 +204,29 @@ int os_open(const char* path, int flags, int mode)
/// Get stat information for a file.
///
-/// @return OK on success, FAIL if a failure occurred.
-static bool os_stat(const char *name, uv_stat_t *statbuf)
+/// @return libuv return code.
+static int os_stat(const char *name, uv_stat_t *statbuf)
FUNC_ATTR_NONNULL_ALL
{
uv_fs_t request;
int result = uv_fs_stat(&fs_loop, &request, name, NULL);
*statbuf = request.statbuf;
uv_fs_req_cleanup(&request);
- return (result == kLibuvSuccess);
+ return result;
}
/// Get the file permissions for a given file.
///
-/// @return `-1` when `name` doesn't exist.
+/// @return libuv error code on error.
int32_t os_getperm(const char_u *name)
FUNC_ATTR_NONNULL_ALL
{
uv_stat_t statbuf;
- if (os_stat((char *)name, &statbuf)) {
+ int stat_result = os_stat((char *)name, &statbuf);
+ if (stat_result == kLibuvSuccess) {
return (int32_t)statbuf.st_mode;
} else {
- return -1;
+ return stat_result;
}
}
@@ -270,7 +271,7 @@ bool os_file_exists(const char_u *name)
FUNC_ATTR_NONNULL_ALL
{
uv_stat_t statbuf;
- return os_stat((char *)name, &statbuf);
+ return os_stat((char *)name, &statbuf) == kLibuvSuccess;
}
/// Check if a file is readable.
@@ -322,7 +323,7 @@ int os_rename(const char_u *path, const char_u *new_path)
/// Make a directory.
///
-/// @return `0` for success, -errno for failure.
+/// @return `0` for success, libuv error code for failure.
int os_mkdir(const char *path, int32_t mode)
FUNC_ATTR_NONNULL_ALL
{
@@ -342,7 +343,7 @@ int os_mkdir(const char *path, int32_t mode)
/// failed to create. I.e. it will contain dir or any
/// of the higher level directories.
///
-/// @return `0` for success, -errno for failure.
+/// @return `0` for success, libuv error code for failure.
int os_mkdir_recurse(const char *const dir, int32_t mode,
char **const failed_dir)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
@@ -470,7 +471,7 @@ int os_remove(const char *path)
bool os_fileinfo(const char *path, FileInfo *file_info)
FUNC_ATTR_NONNULL_ALL
{
- return os_stat(path, &(file_info->stat));
+ return os_stat(path, &(file_info->stat)) == kLibuvSuccess;
}
/// Get the file information for a given path without following links
@@ -572,7 +573,7 @@ bool os_fileid(const char *path, FileID *file_id)
FUNC_ATTR_NONNULL_ALL
{
uv_stat_t statbuf;
- if (os_stat(path, &statbuf)) {
+ if (os_stat(path, &statbuf) == kLibuvSuccess) {
file_id->inode = statbuf.st_ino;
file_id->device_id = statbuf.st_dev;
return true;
diff --git a/src/nvim/os/fs_defs.h b/src/nvim/os/fs_defs.h
index df1031b721..52b2841514 100644
--- a/src/nvim/os/fs_defs.h
+++ b/src/nvim/os/fs_defs.h
@@ -21,9 +21,9 @@ typedef struct {
uv_dirent_t ent; ///< @private The entry information.
} Directory;
-/// Function to convert -errno error to char * error description
+/// Function to convert libuv error to char * error description
///
-/// -errno errors are returned by a number of os functions.
+/// negative libuv error codes are returned by a number of os functions.
#define os_strerror uv_strerror
#endif // NVIM_OS_FS_DEFS_H
diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h
index 3d56115401..7d77899287 100644
--- a/src/nvim/os/os_defs.h
+++ b/src/nvim/os/os_defs.h
@@ -39,32 +39,6 @@
# define MAXPATHL 1024
#endif
-#ifndef FILETYPE_FILE
-# define FILETYPE_FILE "filetype.vim"
-#endif
-
-#ifndef FTPLUGIN_FILE
-# define FTPLUGIN_FILE "ftplugin.vim"
-#endif
-
-#ifndef INDENT_FILE
-# define INDENT_FILE "indent.vim"
-#endif
-
-#ifndef FTOFF_FILE
-# define FTOFF_FILE "ftoff.vim"
-#endif
-
-#ifndef FTPLUGOF_FILE
-# define FTPLUGOF_FILE "ftplugof.vim"
-#endif
-
-#ifndef INDOFF_FILE
-# define INDOFF_FILE "indoff.vim"
-#endif
-
-#define DFLT_ERRORFILE "errors.err"
-
// Command-processing buffer. Use large buffers for all platforms.
#define CMDBUFFSIZE 1024
@@ -103,9 +77,9 @@
# include <strings.h>
#endif
-/// Function to convert -errno error to char * error description
+/// Function to convert libuv error to char * error description
///
-/// -errno errors are returned by a number of os functions.
+/// negative libuv error codes are returned by a number of os functions.
#define os_strerror uv_strerror
#endif // NVIM_OS_OS_DEFS_H
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index 57e25560de..3813c45726 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -418,7 +418,8 @@ static void read_input(DynamicBuffer *buf)
// Finished a line, add a NL, unless this line should not have one.
// FIXME need to make this more readable
if (lnum != curbuf->b_op_end.lnum
- || !curbuf->b_p_bin
+ || (!curbuf->b_p_bin
+ && curbuf->b_p_fixeol)
|| (lnum != curbuf->b_no_eol_lnum
&& (lnum !=
curbuf->b_ml.ml_line_count
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index 7158721433..0ff6016e32 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -32,9 +32,13 @@ void signal_init(void)
signal_watcher_init(&loop, &shup, NULL);
signal_watcher_init(&loop, &squit, NULL);
signal_watcher_init(&loop, &sterm, NULL);
+#ifdef SIGPIPE
signal_watcher_start(&spipe, on_signal, SIGPIPE);
+#endif
signal_watcher_start(&shup, on_signal, SIGHUP);
+#ifdef SIGQUIT
signal_watcher_start(&squit, on_signal, SIGQUIT);
+#endif
signal_watcher_start(&sterm, on_signal, SIGTERM);
#ifdef SIGPWR
signal_watcher_init(&loop, &spwr, NULL);
@@ -82,12 +86,16 @@ static char * signal_name(int signum)
case SIGPWR:
return "SIGPWR";
#endif
+#ifdef SIGPIPE
case SIGPIPE:
return "SIGPIPE";
+#endif
case SIGTERM:
return "SIGTERM";
+#ifdef SIGQUIT
case SIGQUIT:
return "SIGQUIT";
+#endif
case SIGHUP:
return "SIGHUP";
default:
@@ -123,11 +131,15 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
ml_sync_all(false, false);
break;
#endif
+#ifdef SIGPIPE
case SIGPIPE:
// Ignore
break;
+#endif
case SIGTERM:
+#ifdef SIGQUIT
case SIGQUIT:
+#endif
case SIGHUP:
if (!rejecting_deadly) {
deadly_signal(signum);
diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h
index b1511d4b56..e3ba3262f4 100644
--- a/src/nvim/os/unix_defs.h
+++ b/src/nvim/os/unix_defs.h
@@ -9,7 +9,6 @@
# include <sys/param.h>
#endif
-
#define TEMP_DIR_NAMES {"$TMPDIR", "/tmp", ".", "~"}
#define TEMP_FILE_PATH_MAXLEN 256
@@ -18,21 +17,4 @@
// Special wildcards that need to be handled by the shell.
#define SPECIAL_WILDCHAR "`'{"
-// Unix system-dependent file names
-#ifndef SYS_VIMRC_FILE
-# define SYS_VIMRC_FILE "$VIM/sysinit.vim"
-#endif
-#ifndef DFLT_HELPFILE
-# define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
-#endif
-#ifndef SYNTAX_FNAME
-# define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
-#endif
-#ifndef EXRC_FILE
-# define EXRC_FILE ".exrc"
-#endif
-#ifndef VIMRC_FILE
-# define VIMRC_FILE ".nvimrc"
-#endif
-
#endif // NVIM_OS_UNIX_DEFS_H
diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h
index d614582250..32960dfbe9 100644
--- a/src/nvim/os/win_defs.h
+++ b/src/nvim/os/win_defs.h
@@ -6,17 +6,6 @@
#define TEMP_DIR_NAMES {"$TMP", "$TEMP", "$USERPROFILE", ""}
#define TEMP_FILE_PATH_MAXLEN _MAX_PATH
-// Defines needed to fix the build on Windows:
-// - DFLT_DIR
-// - DFLT_BDIR
-// - DFLT_VDIR
-// - EXRC_FILE
-// - VIMRC_FILE
-// - SYNTAX_FNAME
-// - DFLT_HELPFILE
-// - SYS_VIMRC_FILE
-// - SPECIAL_WILDCHAR
-
#define USE_CRNL
#ifdef _MSC_VER
@@ -28,7 +17,9 @@
# endif
#endif
+#ifdef _MSC_VER
typedef SSIZE_T ssize_t;
+#endif
#ifndef SSIZE_MAX
# ifdef _WIN64
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index 828ccd556d..62b264046c 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* os_unix.c -- code for all flavors of Unix (BSD, SYSV, SVR4, POSIX, ...)
*
* A lot of this file was originally written by Juergen Weigert and later
diff --git a/src/nvim/path.c b/src/nvim/path.c
index eaca85ed40..253035ed99 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1,6 +1,4 @@
-
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -469,16 +467,13 @@ bool path_has_wildcard(const char_u *p)
return false;
}
-#if defined(UNIX)
/*
* Unix style wildcard expansion code.
- * It's here because it's used both for Unix and Mac.
*/
static int pstrcmp(const void *a, const void *b)
{
return pathcmp(*(char **)a, *(char **)b, -1);
}
-#endif
/// Checks if a path has a character path_expand can expand.
/// @param p The path to expand.
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c
index 10012a9775..001740943f 100644
--- a/src/nvim/popupmnu.c
+++ b/src/nvim/popupmnu.c
@@ -1,7 +1,7 @@
/// @file popupmnu.c
///
/// Popup menu (PUM)
-//
+
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 4d53238381..8e6ae46a3b 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* quickfix.c: functions for quickfix mode, using a file with error messages
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c
index fa356da5b9..b96dcc66b3 100644
--- a/src/nvim/regexp_nfa.c
+++ b/src/nvim/regexp_nfa.c
@@ -1897,9 +1897,10 @@ static int nfa_regpiece(void)
return OK;
}
- // The engine is very inefficient (uses too many states) when the maximum is
- // much larger than the minimum. Bail out if we can use the other engine.
- if ((nfa_re_flags & RE_AUTO) && maxval > minval + 200) {
+ // The engine is very inefficient (uses too many states) when the maximum
+ // is much larger than the minimum and when the maximum is large. Bail out
+ // if we can use the other engine.
+ if ((nfa_re_flags & RE_AUTO) && (maxval > minval + 200 || maxval > 500)) {
return FAIL;
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 0c4cf30602..9fdb476748 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* screen.c: code for displaying on the screen
*
* Output to the screen (console, terminal emulator or GUI window) is minimized
@@ -87,7 +79,6 @@
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/search.c b/src/nvim/search.c
index d742a7a341..fb7dfa350b 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1,16 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-/*
* search.c: code for normal mode searching commands
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
@@ -4632,6 +4624,7 @@ void set_search_pattern(const SearchPattern pat)
{
free_spat(&spats[0]);
memcpy(&(spats[0]), &pat, sizeof(spats[0]));
+ set_vv_searchforward();
}
/// Set last substitute pattern
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index f8643fe655..340c14066a 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -10,7 +10,9 @@
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <assert.h>
#include <msgpack.h>
@@ -43,6 +45,7 @@
#include "nvim/path.h"
#include "nvim/fileio.h"
#include "nvim/strings.h"
+#include "nvim/quickfix.h"
#include "nvim/lib/khash.h"
#include "nvim/lib/kvec.h"
@@ -98,6 +101,7 @@ KHASH_SET_INIT_STR(strset)
#define SEARCH_KEY_HIGHLIGHTED "sh"
#define SEARCH_KEY_OFFSET "so"
#define SEARCH_KEY_PAT "sp"
+#define SEARCH_KEY_BACKWARD "sb"
#define REG_KEY_TYPE "rt"
#define REG_KEY_WIDTH "rw"
@@ -201,11 +205,11 @@ enum SRNIFlags {
kSDReadHeader = (1 << kSDItemHeader), ///< Determines whether header should
///< be read (it is usually ignored).
kSDReadUndisableableData = (
- (1 << kSDItemSearchPattern)
- | (1 << kSDItemSubString)
- | (1 << kSDItemJump)), ///< Data reading which cannot be disabled by &shada
- ///< or other options except for disabling reading
- ///< ShaDa as a whole.
+ (1 << kSDItemSearchPattern)
+ | (1 << kSDItemSubString)
+ | (1 << kSDItemJump)), ///< Data reading which cannot be disabled by
+ ///< &shada or other options except for disabling
+ ///< reading ShaDa as a whole.
kSDReadRegisters = (1 << kSDItemRegister), ///< Determines whether registers
///< should be read (may only be
///< disabled when writing, but
@@ -263,6 +267,7 @@ typedef struct {
bool is_last_used;
bool is_substitute_pattern;
bool highlighted;
+ bool search_backward;
char *pat;
dict_T *additional_data;
} search_pattern;
@@ -441,7 +446,7 @@ typedef struct sd_write_def {
.attr = { __VA_ARGS__ } \
} \
}
-#define DEFAULT_POS {1, 0, 0}
+#define DEFAULT_POS { 1, 0, 0 }
static const pos_T default_pos = DEFAULT_POS;
static const ShadaEntry sd_default_values[] = {
[kSDItemMissing] = { .type = kSDItemMissing, .timestamp = 0 },
@@ -455,6 +460,7 @@ static const ShadaEntry sd_default_values[] = {
.is_last_used = true,
.is_substitute_pattern = false,
.highlighted = false,
+ .search_backward = false,
.pat = NULL,
.additional_data = NULL),
DEF_SDE(SubString, sub_string, .sub = NULL, .additional_elements = NULL),
@@ -527,11 +533,14 @@ static inline void hmll_init(HMLList *const hmll, const size_t size)
///
/// @param hmll Pointer to the list.
/// @param cur_entry Name of the variable to iterate over.
+/// @param code Code to execute on each iteration.
///
/// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`).
-#define HMLL_FORALL(hmll, cur_entry) \
+#define HMLL_FORALL(hmll, cur_entry, code) \
for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \
- cur_entry = cur_entry->next)
+ cur_entry = cur_entry->next) { \
+ code \
+ } \
/// Remove entry from the linked list
///
@@ -627,11 +636,14 @@ static inline void hmll_insert(HMLList *const hmll,
/// @param hmll Pointer to the list.
/// @param cur_entry Name of the variable to iterate over, must be already
/// defined.
+/// @param code Code to execute on each iteration.
///
/// @return `for` cycle header (use `HMLL_FORALL(hmll, cur_entry) {body}`).
-#define HMLL_ITER_BACK(hmll, cur_entry) \
+#define HMLL_ITER_BACK(hmll, cur_entry, code) \
for (cur_entry = (hmll)->last; cur_entry != NULL; \
- cur_entry = cur_entry->prev)
+ cur_entry = cur_entry->prev) { \
+ code \
+ }
/// Free linked list
///
@@ -812,7 +824,7 @@ static ShaDaReadResult sd_reader_skip(ShaDaReadDef *const sd_reader,
///
/// All arguments are passed to os_open().
///
-/// @return file descriptor or -errno on failure.
+/// @return file descriptor or libuv error on failure.
static int open_file(const char *const fname, const int flags, const int mode)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
@@ -822,15 +834,15 @@ open_file_start:
fd = os_open(fname, flags, mode);
if (fd < 0) {
- if (-fd == ENOENT) {
+ if (fd == UV_ENOENT) {
return fd;
}
- if (-fd == ENOMEM && !did_try_to_free) {
+ if (fd == UV_ENOMEM && !did_try_to_free) {
try_to_free_memory();
did_try_to_free = true;
goto open_file_start;
}
- if (-fd != EEXIST) {
+ if (fd != UV_EEXIST) {
emsg3(_(SERR "System error while opening ShaDa file %s: %s"),
fname, os_strerror(fd));
}
@@ -844,7 +856,7 @@ open_file_start:
/// @param[in] fname File name to open.
/// @param[out] sd_reader Location where reader structure will be saved.
///
-/// @return -errno in case of error, 0 otherwise.
+/// @return libuv error in case of error, 0 otherwise.
static int open_shada_file_for_reading(const char *const fname,
ShaDaReadDef *sd_reader)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
@@ -953,16 +965,16 @@ static int shada_read_file(const char *const file, const int flags)
if (p_verbose > 0) {
verbose_enter();
smsg(_("Reading ShaDa file \"%s\"%s%s%s"),
- fname,
- (flags & kShaDaWantInfo) ? _(" info") : "",
- (flags & kShaDaWantMarks) ? _(" marks") : "",
- (flags & kShaDaGetOldfiles) ? _(" oldfiles") : "",
- of_ret != 0 ? _(" FAILED") : "");
+ fname,
+ (flags & kShaDaWantInfo) ? _(" info") : "",
+ (flags & kShaDaWantMarks) ? _(" marks") : "",
+ (flags & kShaDaGetOldfiles) ? _(" oldfiles") : "",
+ of_ret != 0 ? _(" FAILED") : "");
verbose_leave();
}
if (of_ret != 0) {
- if (-of_ret == ENOENT && (flags & kShaDaMissingError)) {
+ if (of_ret == UV_ENOENT && (flags & kShaDaMissingError)) {
emsg3(_(SERR "System error while opening ShaDa file %s for reading: %s"),
fname, os_strerror(of_ret));
}
@@ -1005,8 +1017,8 @@ static const void *shada_hist_iter(const void *const iter,
.histtype = history_type,
.string = (char *) hist_he.hisstr,
.sep = (char) (history_type == HIST_SEARCH
- ? (char) hist_he.hisstr[STRLEN(hist_he.hisstr) + 1]
- : 0),
+ ? (char) hist_he.hisstr[STRLEN(hist_he.hisstr) + 1]
+ : 0),
.additional_elements = hist_he.additional_elements,
}
}
@@ -1068,11 +1080,11 @@ static void hms_insert(HistoryMergerState *const hms_p, const ShadaEntry entry,
}
}
HMLListEntry *insert_after;
- HMLL_ITER_BACK(hmll, insert_after) {
+ HMLL_ITER_BACK(hmll, insert_after, {
if (insert_after->data.timestamp <= entry.timestamp) {
break;
}
- }
+ })
hmll_insert(hmll, insert_after, entry, can_free_entry);
}
@@ -1130,14 +1142,14 @@ static inline void hms_to_he_array(const HistoryMergerState *const hms_p,
FUNC_ATTR_NONNULL_ALL
{
histentry_T *hist = hist_array;
- HMLL_FORALL(&hms_p->hmll, cur_entry) {
+ HMLL_FORALL(&hms_p->hmll, cur_entry, {
hist->timestamp = cur_entry->data.timestamp;
hist->hisnum = (int) (hist - hist_array) + 1;
hist->hisstr = (char_u *) cur_entry->data.data.history_item.string;
hist->additional_elements =
cur_entry->data.data.history_item.additional_elements;
hist++;
- }
+ })
*new_hisnum = (int) (hist - hist_array);
*new_hisidx = *new_hisnum - 1;
}
@@ -1155,10 +1167,11 @@ static inline void hms_dealloc(HistoryMergerState *const hms_p)
///
/// @param[in] hms_p Merger structure to iterate over.
/// @param[out] cur_entry Name of the iterator variable.
+/// @param code Code to execute on each iteration.
///
/// @return for cycle header. Use `HMS_ITER(hms_p, cur_entry) {body}`.
-#define HMS_ITER(hms_p, cur_entry) \
- HMLL_FORALL(&((hms_p)->hmll), cur_entry)
+#define HMS_ITER(hms_p, cur_entry, code) \
+ HMLL_FORALL(&((hms_p)->hmll), cur_entry, code)
/// Find buffer for given buffer name (cached)
///
@@ -1335,17 +1348,18 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
(cur_entry.data.search_pattern.is_substitute_pattern
? &set_substitute_pattern
: &set_search_pattern)((SearchPattern) {
- .magic = cur_entry.data.search_pattern.magic,
- .no_scs = !cur_entry.data.search_pattern.smartcase,
- .off = {
- .line = cur_entry.data.search_pattern.has_line_offset,
- .end = cur_entry.data.search_pattern.place_cursor_at_end,
- .off = cur_entry.data.search_pattern.offset,
- },
- .pat = (char_u *) cur_entry.data.search_pattern.pat,
- .additional_data = cur_entry.data.search_pattern.additional_data,
- .timestamp = cur_entry.timestamp,
- });
+ .magic = cur_entry.data.search_pattern.magic,
+ .no_scs = !cur_entry.data.search_pattern.smartcase,
+ .off = {
+ .dir = cur_entry.data.search_pattern.search_backward ? '?' : '/',
+ .line = cur_entry.data.search_pattern.has_line_offset,
+ .end = cur_entry.data.search_pattern.place_cursor_at_end,
+ .off = cur_entry.data.search_pattern.offset,
+ },
+ .pat = (char_u *) cur_entry.data.search_pattern.pat,
+ .additional_data = cur_entry.data.search_pattern.additional_data,
+ .timestamp = cur_entry.timestamp,
+ });
if (cur_entry.data.search_pattern.is_last_used) {
set_last_used_pattern(
cur_entry.data.search_pattern.is_substitute_pattern);
@@ -1754,6 +1768,7 @@ static bool shada_pack_entry(msgpack_packer *const packer,
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.is_substitute_pattern)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.offset)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward)
// finally, additional data:
+ (size_t) (
entry.data.search_pattern.additional_data
@@ -1780,6 +1795,7 @@ static bool shada_pack_entry(msgpack_packer *const packer,
PACK_BOOL(entry, SEARCH_KEY_PLACE_CURSOR_AT_END, place_cursor_at_end);
PACK_BOOL(entry, SEARCH_KEY_IS_SUBSTITUTE_PATTERN, is_substitute_pattern);
PACK_BOOL(entry, SEARCH_KEY_HIGHLIGHTED, highlighted);
+ PACK_BOOL(entry, SEARCH_KEY_BACKWARD, search_backward);
if (!CHECK_DEFAULT(entry, search_pattern.offset)) {
PACK_STATIC_STR(SEARCH_KEY_OFFSET);
msgpack_pack_int64(spacker, entry.data.search_pattern.offset);
@@ -2421,13 +2437,13 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
}
const unsigned srni_flags = (unsigned) (
- kSDReadUndisableableData
- | kSDReadUnknown
- | (dump_history ? kSDReadHistory : 0)
- | (dump_registers ? kSDReadRegisters : 0)
- | (dump_global_vars ? kSDReadVariables : 0)
- | (dump_global_marks ? kSDReadGlobalMarks : 0)
- | (num_marked_files ? kSDReadLocalMarks | kSDReadChanges : 0));
+ kSDReadUndisableableData
+ | kSDReadUnknown
+ | (dump_history ? kSDReadHistory : 0)
+ | (dump_registers ? kSDReadRegisters : 0)
+ | (dump_global_vars ? kSDReadVariables : 0)
+ | (dump_global_marks ? kSDReadGlobalMarks : 0)
+ | (num_marked_files ? kSDReadLocalMarks | kSDReadChanges : 0));
msgpack_packer *const packer = msgpack_packer_new(sd_writer,
&msgpack_sd_writer_write);
@@ -2478,8 +2494,11 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
// Write buffer list
if (find_shada_parameter('%') != NULL) {
size_t buf_count = 0;
+#define IGNORE_BUF(buf)\
+ (buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
+ || in_bufset(&removable_bufs, buf))
FOR_ALL_BUFFERS(buf) {
- if (buf->b_ffname != NULL && !in_bufset(&removable_bufs, buf)) {
+ if (!IGNORE_BUF(buf)) {
buf_count++;
}
}
@@ -2497,7 +2516,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
};
size_t i = 0;
FOR_ALL_BUFFERS(buf) {
- if (buf->b_ffname == NULL || in_bufset(&removable_bufs, buf)) {
+ if (IGNORE_BUF(buf)) {
continue;
}
buflist_entry.data.buffer_list.buffers[i] = (struct buffer_list_buffer) {
@@ -2513,6 +2532,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
goto shada_write_exit;
}
xfree(buflist_entry.data.buffer_list.buffers);
+#undef IGNORE_BUF
}
// Write some of the variables
@@ -2581,6 +2601,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
&& search_highlighted), \
.pat = (char *) pat.pat, \
.additional_data = pat.additional_data, \
+ .search_backward = (!is_sub && pat.off.dir == '?'), \
} \
} \
} \
@@ -2881,16 +2902,16 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
for (size_t i = 0; i < HIST_COUNT; i++) {
if (dump_one_history[i]) {
hms_insert_whole_neovim_history(&wms->hms[i]);
- HMS_ITER(&wms->hms[i], cur_entry) {
+ HMS_ITER(&wms->hms[i], cur_entry, {
if (!shada_pack_encoded_entry(
- packer, &sd_writer->sd_conv, (PossiblyFreedShadaEntry) {
- .data = cur_entry->data,
- .can_free_entry = cur_entry->can_free_entry,
- }, max_kbyte)) {
+ packer, &sd_writer->sd_conv, (PossiblyFreedShadaEntry) {
+ .data = cur_entry->data,
+ .can_free_entry = cur_entry->can_free_entry,
+ }, max_kbyte)) {
ret = kSDWriteFailed;
break;
}
- }
+ })
hms_dealloc(&wms->hms[i]);
if (ret == kSDWriteFailed) {
goto shada_write_exit;
@@ -2957,9 +2978,9 @@ shada_write_file_open:
fd = (intptr_t) open_file(tempname, O_CREAT|O_WRONLY|O_NOFOLLOW|O_EXCL,
perm);
if (fd < 0) {
- if (-fd == EEXIST
+ if (fd == UV_EEXIST
#ifdef ELOOP
- || -fd == ELOOP
+ || fd == UV_ELOOP
#endif
) {
// File already exists, try another name
@@ -3341,8 +3362,8 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv,
entry_name " entry at position %" PRIu64 " " \
error_desc
#define CHECK_KEY(key, expected) ( \
- key.via.str.size == sizeof(expected) - 1 \
- && STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0)
+ key.via.str.size == sizeof(expected) - 1 \
+ && STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0)
#define CLEAR_GA_AND_ERROR_OUT(ga) \
do { \
ga_clear(&ga); \
@@ -3365,18 +3386,17 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv,
tgt = proc(obj.via.attr); \
} while (0)
#define CHECK_KEY_IS_STR(entry_name) \
- do { \
- if (unpacked.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \
- emsgu(_(READERR(entry_name, "has key which is not a string")), \
- initial_fpos); \
- CLEAR_GA_AND_ERROR_OUT(ad_ga); \
- } else if (unpacked.data.via.map.ptr[i].key.via.str.size == 0) { \
- emsgu(_(READERR(entry_name, "has empty key")), initial_fpos); \
- CLEAR_GA_AND_ERROR_OUT(ad_ga); \
- } \
- } while (0)
+ if (unpacked.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \
+ emsgu(_(READERR(entry_name, "has key which is not a string")), \
+ initial_fpos); \
+ CLEAR_GA_AND_ERROR_OUT(ad_ga); \
+ } else if (unpacked.data.via.map.ptr[i].key.via.str.size == 0) { \
+ emsgu(_(READERR(entry_name, "has empty key")), initial_fpos); \
+ CLEAR_GA_AND_ERROR_OUT(ad_ga); \
+ }
#define CHECKED_KEY(entry_name, name, error_desc, tgt, condition, attr, proc) \
- if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, name)) { \
+ else if (CHECK_KEY( /* NOLINT(readability/braces) */ \
+ unpacked.data.via.map.ptr[i].key, name)) { \
CHECKED_ENTRY( \
condition, "has " name " key value " error_desc, \
entry_name, unpacked.data.via.map.ptr[i].val, \
@@ -3396,17 +3416,17 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv,
#define INT_KEY(entry_name, name, tgt, proc) \
CHECKED_KEY( \
entry_name, name, "which is not an integer", tgt, \
- (unpacked.data.via.map.ptr[i].val.type \
- == MSGPACK_OBJECT_POSITIVE_INTEGER \
- || unpacked.data.via.map.ptr[i].val.type \
- == MSGPACK_OBJECT_NEGATIVE_INTEGER), \
+ ((unpacked.data.via.map.ptr[i].val.type \
+ == MSGPACK_OBJECT_POSITIVE_INTEGER) \
+ || (unpacked.data.via.map.ptr[i].val.type \
+ == MSGPACK_OBJECT_NEGATIVE_INTEGER)), \
i64, proc)
#define INTEGER_KEY(entry_name, name, tgt) \
INT_KEY(entry_name, name, tgt, TOINT)
#define LONG_KEY(entry_name, name, tgt) \
INT_KEY(entry_name, name, tgt, TOLONG)
#define ADDITIONAL_KEY \
- { \
+ else { /* NOLINT(readability/braces) */ \
ga_grow(&ad_ga, 1); \
memcpy(((char *)ad_ga.ga_data) + ((size_t) ad_ga.ga_len \
* sizeof(*unpacked.data.via.map.ptr)), \
@@ -3415,9 +3435,9 @@ static inline char *get_converted_string(const vimconv_T *const sd_conv,
ad_ga.ga_len++; \
}
#define CONVERTED(str, len) ( \
- sd_reader->sd_conv.vc_type != CONV_NONE \
- ? get_converted_string(&sd_reader->sd_conv, (str), (len)) \
- : xmemdupz((str), (len)))
+ sd_reader->sd_conv.vc_type != CONV_NONE \
+ ? get_converted_string(&sd_reader->sd_conv, (str), (len)) \
+ : xmemdupz((str), (len)))
#define BIN_CONVERTED(b) CONVERTED(b.ptr, b.size)
#define SET_ADDITIONAL_DATA(tgt, name) \
do { \
@@ -3611,35 +3631,28 @@ shada_read_next_item_start:
garray_T ad_ga;
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
- CHECK_KEY_IS_STR("search pattern");
+ CHECK_KEY_IS_STR("search pattern")
BOOLEAN_KEY("search pattern", SEARCH_KEY_MAGIC,
entry->data.search_pattern.magic)
- else
- BOOLEAN_KEY("search pattern", SEARCH_KEY_SMARTCASE,
- entry->data.search_pattern.smartcase)
- else
- BOOLEAN_KEY("search pattern", SEARCH_KEY_HAS_LINE_OFFSET,
- entry->data.search_pattern.has_line_offset)
- else
- BOOLEAN_KEY("search pattern", SEARCH_KEY_PLACE_CURSOR_AT_END,
- entry->data.search_pattern.place_cursor_at_end)
- else
- BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_LAST_USED,
- entry->data.search_pattern.is_last_used)
- else
- BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_SUBSTITUTE_PATTERN,
- entry->data.search_pattern.is_substitute_pattern)
- else
- BOOLEAN_KEY("search pattern", SEARCH_KEY_HIGHLIGHTED,
- entry->data.search_pattern.highlighted)
- else
- INTEGER_KEY("search pattern", SEARCH_KEY_OFFSET,
- entry->data.search_pattern.offset)
- else
- CONVERTED_STRING_KEY("search pattern", SEARCH_KEY_PAT,
- entry->data.search_pattern.pat)
- else
- ADDITIONAL_KEY
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_SMARTCASE,
+ entry->data.search_pattern.smartcase)
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_HAS_LINE_OFFSET,
+ entry->data.search_pattern.has_line_offset)
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_PLACE_CURSOR_AT_END,
+ entry->data.search_pattern.place_cursor_at_end)
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_LAST_USED,
+ entry->data.search_pattern.is_last_used)
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_IS_SUBSTITUTE_PATTERN,
+ entry->data.search_pattern.is_substitute_pattern)
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_HIGHLIGHTED,
+ entry->data.search_pattern.highlighted)
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_BACKWARD,
+ entry->data.search_pattern.search_backward)
+ INTEGER_KEY("search pattern", SEARCH_KEY_OFFSET,
+ entry->data.search_pattern.offset)
+ CONVERTED_STRING_KEY("search pattern", SEARCH_KEY_PAT,
+ entry->data.search_pattern.pat)
+ ADDITIONAL_KEY
}
if (entry->data.search_pattern.pat == NULL) {
emsgu(_(READERR("search pattern", "has no pattern")), initial_fpos);
@@ -3660,7 +3673,7 @@ shada_read_next_item_start:
garray_T ad_ga;
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
- CHECK_KEY_IS_STR("mark");
+ CHECK_KEY_IS_STR("mark")
if (CHECK_KEY(unpacked.data.via.map.ptr[i].key, KEY_NAME_CHAR)) {
if (type_u64 == kSDItemJump || type_u64 == kSDItemChange) {
emsgu(_(READERR("mark", "has n key which is only valid for "
@@ -3673,15 +3686,11 @@ shada_read_next_item_start:
"has n key value which is not an unsigned integer",
"mark", unpacked.data.via.map.ptr[i].val,
entry->data.filemark.name, u64, TOCHAR);
- } else {
- LONG_KEY("mark", KEY_LNUM, entry->data.filemark.mark.lnum)
- else
- INTEGER_KEY("mark", KEY_COL, entry->data.filemark.mark.col)
- else
- STRING_KEY("mark", KEY_FILE, entry->data.filemark.fname)
- else
- ADDITIONAL_KEY
}
+ LONG_KEY("mark", KEY_LNUM, entry->data.filemark.mark.lnum)
+ INTEGER_KEY("mark", KEY_COL, entry->data.filemark.mark.col)
+ STRING_KEY("mark", KEY_FILE, entry->data.filemark.fname)
+ ADDITIONAL_KEY
}
if (entry->data.filemark.fname == NULL) {
emsgu(_(READERR("mark", "is missing file name")), initial_fpos);
@@ -3706,48 +3715,44 @@ shada_read_next_item_start:
garray_T ad_ga;
ga_init(&ad_ga, sizeof(*(unpacked.data.via.map.ptr)), 1);
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
- CHECK_KEY_IS_STR("register");
- TYPED_KEY("register", REG_KEY_TYPE, "an unsigned integer",
- entry->data.reg.type, POSITIVE_INTEGER, u64, TOU8)
- else
- TYPED_KEY("register", KEY_NAME_CHAR, "an unsigned integer",
- entry->data.reg.name, POSITIVE_INTEGER, u64, TOCHAR)
- else
- TYPED_KEY("register", REG_KEY_WIDTH, "an unsigned integer",
- entry->data.reg.width, POSITIVE_INTEGER, u64, TOSIZE)
- else
- if (CHECK_KEY(unpacked.data.via.map.ptr[i].key,
- REG_KEY_CONTENTS)) {
- if (unpacked.data.via.map.ptr[i].val.type != MSGPACK_OBJECT_ARRAY) {
- emsgu(_(READERR(
- "register",
- "has " REG_KEY_CONTENTS " key with non-array value")),
- initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- if (unpacked.data.via.map.ptr[i].val.via.array.size == 0) {
- emsgu(_(READERR("register",
- "has " REG_KEY_CONTENTS " key with empty array")),
- initial_fpos);
+ CHECK_KEY_IS_STR("register")
+ if (CHECK_KEY(unpacked.data.via.map.ptr[i].key,
+ REG_KEY_CONTENTS)) {
+ if (unpacked.data.via.map.ptr[i].val.type != MSGPACK_OBJECT_ARRAY) {
+ emsgu(_(READERR("register",
+ "has " REG_KEY_CONTENTS
+ " key with non-array value")),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ if (unpacked.data.via.map.ptr[i].val.via.array.size == 0) {
+ emsgu(_(READERR("register",
+ "has " REG_KEY_CONTENTS " key with empty array")),
+ initial_fpos);
+ CLEAR_GA_AND_ERROR_OUT(ad_ga);
+ }
+ const msgpack_object_array arr =
+ unpacked.data.via.map.ptr[i].val.via.array;
+ for (size_t i = 0; i < arr.size; i++) {
+ if (arr.ptr[i].type != MSGPACK_OBJECT_BIN) {
+ emsgu(_(READERR("register", "has " REG_KEY_CONTENTS " array "
+ "with non-binary value")), initial_fpos);
CLEAR_GA_AND_ERROR_OUT(ad_ga);
}
- const msgpack_object_array arr =
- unpacked.data.via.map.ptr[i].val.via.array;
- for (size_t i = 0; i < arr.size; i++) {
- if (arr.ptr[i].type != MSGPACK_OBJECT_BIN) {
- emsgu(_(READERR("register", "has " REG_KEY_CONTENTS " array "
- "with non-binary value")), initial_fpos);
- CLEAR_GA_AND_ERROR_OUT(ad_ga);
- }
- }
- entry->data.reg.contents_size = arr.size;
- entry->data.reg.contents = xmalloc(arr.size * sizeof(char *));
- for (size_t i = 0; i < arr.size; i++) {
- entry->data.reg.contents[i] = BIN_CONVERTED(arr.ptr[i].via.bin);
- }
- } else {
- ADDITIONAL_KEY
}
+ entry->data.reg.contents_size = arr.size;
+ entry->data.reg.contents = xmalloc(arr.size * sizeof(char *));
+ for (size_t i = 0; i < arr.size; i++) {
+ entry->data.reg.contents[i] = BIN_CONVERTED(arr.ptr[i].via.bin);
+ }
+ }
+ TYPED_KEY("register", REG_KEY_TYPE, "an unsigned integer",
+ entry->data.reg.type, POSITIVE_INTEGER, u64, TOU8)
+ TYPED_KEY("register", KEY_NAME_CHAR, "an unsigned integer",
+ entry->data.reg.name, POSITIVE_INTEGER, u64, TOCHAR)
+ TYPED_KEY("register", REG_KEY_WIDTH, "an unsigned integer",
+ entry->data.reg.width, POSITIVE_INTEGER, u64, TOSIZE)
+ ADDITIONAL_KEY
}
if (entry->data.reg.contents == NULL) {
emsgu(_(READERR("register", "has missing " REG_KEY_CONTENTS " array")),
@@ -3815,8 +3820,8 @@ shada_read_next_item_hist_no_conv:
+ 1); // Separator character
entry->data.history_item.string = xmalloc(strsize);
memcpy(entry->data.history_item.string,
- unpacked.data.via.array.ptr[1].via.bin.ptr,
- unpacked.data.via.array.ptr[1].via.bin.size);
+ unpacked.data.via.array.ptr[1].via.bin.ptr,
+ unpacked.data.via.array.ptr[1].via.bin.size);
} else {
size_t len = unpacked.data.via.array.ptr[1].via.bin.size;
char *const converted = string_convert(
@@ -3936,17 +3941,14 @@ shada_read_next_item_hist_no_conv:
const size_t j = i;
{
for (size_t i = 0; i < unpacked.data.via.map.size; i++) {
- CHECK_KEY_IS_STR("buffer list entry");
+ CHECK_KEY_IS_STR("buffer list entry")
LONG_KEY("buffer list entry", KEY_LNUM,
- entry->data.buffer_list.buffers[j].pos.lnum)
- else
- INTEGER_KEY("buffer list entry", KEY_COL,
- entry->data.buffer_list.buffers[j].pos.col)
- else
- STRING_KEY("buffer list entry", KEY_FILE,
- entry->data.buffer_list.buffers[j].fname)
- else
- ADDITIONAL_KEY
+ entry->data.buffer_list.buffers[j].pos.lnum)
+ INTEGER_KEY("buffer list entry", KEY_COL,
+ entry->data.buffer_list.buffers[j].pos.col)
+ STRING_KEY("buffer list entry", KEY_FILE,
+ entry->data.buffer_list.buffers[j].fname)
+ ADDITIONAL_KEY
}
}
}
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 7d9257141a..420e8e2b70 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -1,9 +1,3 @@
-// VIM - Vi IMproved by Bram Moolenaar
-//
-// Do ":help uganda" in Vim to read copying and usage conditions.
-// Do ":help credits" in Vim to see a list of people who contributed.
-// See README.txt for an overview of the Vim source code.
-
// spell.c: code for spell checking
//
// The spell checking mechanism uses a tree (aka trie). Each node in the tree
@@ -285,7 +279,6 @@
// few bytes as possible, see offset2bytes())
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 9ffa5c6a76..00dcf3cf46 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -1,5 +1,3 @@
-
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index d0491ab42b..24422c71fb 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -1,18 +1,9 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* syntax.c: code for syntax highlighting
*/
#include <assert.h>
#include <ctype.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index b0d1a17c89..d832924efd 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -1,17 +1,8 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* Code to handle tags and the tag stack
*/
#include <assert.h>
-#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 119ee2c5b3..adf3f725a2 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -402,6 +402,14 @@ static int terminal_execute(VimState *state, int key)
TerminalState *s = (TerminalState *)state;
switch (key) {
+ case K_FOCUSGAINED: // Neovim has been given focus
+ apply_autocmds(EVENT_FOCUSGAINED, NULL, NULL, false, curbuf);
+ break;
+
+ case K_FOCUSLOST: // Neovim has lost focus
+ apply_autocmds(EVENT_FOCUSLOST, NULL, NULL, false, curbuf);
+ break;
+
case K_LEFTMOUSE:
case K_LEFTDRAG:
case K_LEFTRELEASE:
diff --git a/src/nvim/types.h b/src/nvim/types.h
index afd684925a..bfe8be2091 100644
--- a/src/nvim/types.h
+++ b/src/nvim/types.h
@@ -1,10 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
-
#ifndef NVIM_TYPES_H
#define NVIM_TYPES_H
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index b0c49cbf8e..69ac18ad54 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -1,12 +1,4 @@
/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
* undo.c: multi level undo facility
*
* The saved lines are stored in a list of lists (one for each buffer):
@@ -83,7 +75,6 @@
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
-#include <errno.h>
#include <stdbool.h>
#include <string.h>
@@ -284,32 +275,32 @@ int u_savedel(linenr_T lnum, long nlines)
nlines == curbuf->b_ml.ml_line_count ? 2 : lnum, FALSE);
}
-/*
- * Return TRUE when undo is allowed. Otherwise give an error message and
- * return FALSE.
- */
-int undo_allowed(void)
+/// Return true when undo is allowed. Otherwise print an error message and
+/// return false.
+///
+/// @return true if undo is allowed.
+bool undo_allowed(void)
{
/* Don't allow changes when 'modifiable' is off. */
if (!MODIFIABLE(curbuf)) {
EMSG(_(e_modifiable));
- return FALSE;
+ return false;
}
// In the sandbox it's not allowed to change the text.
if (sandbox != 0) {
EMSG(_(e_sandbox));
- return FALSE;
+ return false;
}
/* Don't allow changes in the buffer while editing the cmdline. The
* caller of getcmdline() may get confused. */
if (textlock != 0) {
EMSG(_(e_secure));
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
/*
@@ -756,7 +747,11 @@ static void u_free_uhp(u_header_T *uhp)
xfree(uhp);
}
-/// Writes the header.
+/// Writes the undofile header.
+///
+/// @param bi The buffer information
+/// @param hash The hash of the buffer contents
+//
/// @returns false in case of an error.
static bool serialize_header(bufinfo_T *bi, char_u *hash)
FUNC_ATTR_NONNULL_ALL
@@ -810,6 +805,12 @@ static bool serialize_header(bufinfo_T *bi, char_u *hash)
return true;
}
+/// Writes an undo header.
+///
+/// @param bi The buffer information
+/// @param uhp The undo header to write
+//
+/// @returns false in case of an error.
static bool serialize_uhp(bufinfo_T *bi, u_header_T *uhp)
{
if (!undo_write_bytes(bi, (uintmax_t)UF_HEADER_MAGIC, 2)) {
@@ -930,6 +931,9 @@ static u_header_T *unserialize_uhp(bufinfo_T *bi,
/// Serializes "uep".
///
+/// @param bi The buffer information
+/// @param uep The undo entry to write
+//
/// @returns false in case of an error.
static bool serialize_uep(bufinfo_T *bi, u_entry_T *uep)
{
@@ -1554,6 +1558,10 @@ theend:
/// Writes a sequence of bytes to the undo file.
///
+/// @param bi The buffer info
+/// @param ptr The byte buffer to write
+/// @param len The number of bytes to write
+///
/// @returns false in case of an error.
static bool undo_write(bufinfo_T *bi, uint8_t *ptr, size_t len)
FUNC_ATTR_NONNULL_ARG(1)
@@ -1565,6 +1573,10 @@ static bool undo_write(bufinfo_T *bi, uint8_t *ptr, size_t len)
///
/// Must match with undo_read_?c() functions.
///
+/// @param bi The buffer info
+/// @param nr The number to write
+/// @param len The number of bytes to use when writing the number.
+///
/// @returns false in case of an error.
static bool undo_write_bytes(bufinfo_T *bi, uintmax_t nr, size_t len)
{
@@ -1609,6 +1621,10 @@ static time_t undo_read_time(bufinfo_T *bi)
/// Reads "buffer[size]" from the undo file.
///
+/// @param bi The buffer info
+/// @param buffer Character buffer to read data into
+/// @param size The size of the character buffer
+///
/// @returns false in case of an error.
static bool undo_read(bufinfo_T *bi, uint8_t *buffer, size_t size)
FUNC_ATTR_NONNULL_ARG(1)
@@ -2839,19 +2855,26 @@ static char_u *u_save_line(linenr_T lnum)
return vim_strsave(ml_get(lnum));
}
-/*
- * Check if the 'modified' flag is set, or 'ff' has changed (only need to
- * check the first character, because it can only be "dos", "unix" or "mac").
- * "nofile" and "scratch" type buffers are considered to always be unchanged.
- */
-int bufIsChanged(buf_T *buf)
+/// Check if the 'modified' flag is set, or 'ff' has changed (only need to
+/// check the first character, because it can only be "dos", "unix" or "mac").
+/// "nofile" and "scratch" type buffers are considered to always be unchanged.
+///
+/// @param buf The buffer to check
+///
+/// @return true if the buffer has changed
+bool bufIsChanged(buf_T *buf)
{
return
!bt_dontwrite(buf) &&
(buf->b_changed || file_ff_differs(buf, true));
}
-int curbufIsChanged(void)
+/// Check if the 'modified' flag is set, or 'ff' has changed (only need to
+/// check the first character, because it can only be "dos", "unix" or "mac").
+/// "nofile" and "scratch" type buffers are considered to always be unchanged.
+///
+/// @return true if the current buffer has changed
+bool curbufIsChanged(void)
{
return
!bt_dontwrite(curbuf) &&
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 65a8f81fa5..75c21d4b37 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -98,7 +98,7 @@ static int included_patches[] = {
// 901,
// 900 NA
// 899 NA
- // 898,
+ 898,
// 897,
// 896,
// 895,
@@ -201,17 +201,17 @@ static int included_patches[] = {
// 798,
// 797,
// 796 NA
- // 795,
+ 795,
// 794 NA
793,
// 792,
791,
- // 790,
- // 789,
+ 790,
+ 789,
// 788 NA
- // 787,
- // 786,
- // 785,
+ 787,
+ 786,
+ 785,
784,
// 783 NA
// 782,
@@ -347,7 +347,7 @@ static int included_patches[] = {
// 652 NA
651,
// 650 NA
- // 649,
+ 649,
// 648 NA
// 647 NA
646,
@@ -356,7 +356,7 @@ static int included_patches[] = {
// 643,
// 642,
// 641,
- // 640,
+ 640,
// 639,
// 638 NA
637,
@@ -365,7 +365,7 @@ static int included_patches[] = {
// 634,
633,
// 632 NA
- // 631,
+ 631,
630,
629,
// 628,
@@ -373,13 +373,13 @@ static int included_patches[] = {
// 626 NA
// 625 NA
// 624,
- // 623,
+ 623,
// 622 NA
// 621 NA
// 620,
// 619 NA
// 618 NA
- // 617,
+ 617,
// 616,
615,
// 614,
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index 48d53369de..fa00d9efcf 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -1,10 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- */
-
#ifndef NVIM_VIM_H
#define NVIM_VIM_H
diff --git a/src/nvim/window.c b/src/nvim/window.c
index b71b2cb603..16ff7dfb14 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -1,12 +1,3 @@
-/*
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda" in Vim to read a list of people who contributed.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-#include <errno.h>
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>