diff options
Diffstat (limited to 'src')
45 files changed, 1083 insertions, 545 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 5ae4416052..22ca0fb0cc 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -43,20 +43,29 @@ static bool chartab_initialized = false; #define GET_CHARTAB(buf, c) \ ((buf)->b_chartab[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f))) -/// Fill chartab[]. Also fills curbuf->b_chartab[] with flags for keyword +// Table used below, see init_chartab() for an explanation +static char_u g_chartab[256]; + +// Flags for g_chartab[]. +#define CT_CELL_MASK 0x07 ///< mask: nr of display cells (1, 2 or 4) +#define CT_PRINT_CHAR 0x10 ///< flag: set for printable chars +#define CT_ID_CHAR 0x20 ///< flag: set for ID chars +#define CT_FNAME_CHAR 0x40 ///< flag: set for file name chars + +/// Fill g_chartab[]. Also fills curbuf->b_chartab[] with flags for keyword /// characters for current buffer. /// /// Depends on the option settings 'iskeyword', 'isident', 'isfname', /// 'isprint' and 'encoding'. /// -/// The index in chartab[] depends on 'encoding': +/// The index in g_chartab[] depends on 'encoding': /// - For non-multi-byte index with the byte (same as the character). /// - For DBCS index with the first byte. /// - For UTF-8 index with the character (when first byte is up to 0x80 it is /// the same as the character, if the first byte is 0x80 and above it depends /// on further bytes). /// -/// The contents of chartab[]: +/// The contents of g_chartab[]: /// - The lower two bits, masked by CT_CELL_MASK, give the number of display /// cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80. /// - CT_PRINT_CHAR bit is set when the character is printable (no need to @@ -94,32 +103,32 @@ int buf_init_chartab(buf_T *buf, int global) c = 0; while (c < ' ') { - chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; + g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; } while (c <= '~') { - chartab[c++] = 1 + CT_PRINT_CHAR; + g_chartab[c++] = 1 + CT_PRINT_CHAR; } if (p_altkeymap) { while (c < YE) { - chartab[c++] = 1 + CT_PRINT_CHAR; + g_chartab[c++] = 1 + CT_PRINT_CHAR; } } while (c < 256) { if (enc_utf8 && (c >= 0xa0)) { // UTF-8: bytes 0xa0 - 0xff are printable (latin1) - chartab[c++] = CT_PRINT_CHAR + 1; + g_chartab[c++] = CT_PRINT_CHAR + 1; } else if ((enc_dbcs == DBCS_JPNU) && (c == 0x8e)) { // euc-jp characters starting with 0x8e are single width - chartab[c++] = CT_PRINT_CHAR + 1; + g_chartab[c++] = CT_PRINT_CHAR + 1; } else if ((enc_dbcs != 0) && (MB_BYTE2LEN(c) == 2)) { // other double-byte chars can be printable AND double-width - chartab[c++] = CT_PRINT_CHAR + 2; + g_chartab[c++] = CT_PRINT_CHAR + 2; } else { // the rest is unprintable by default - chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; + g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; } } @@ -128,7 +137,7 @@ int buf_init_chartab(buf_T *buf, int global) if (((enc_dbcs != 0) && (MB_BYTE2LEN(c) > 1)) || ((enc_dbcs == DBCS_JPNU) && (c == 0x8e)) || (enc_utf8 && (c >= 0xa0))) { - chartab[c] |= CT_FNAME_CHAR; + g_chartab[c] |= CT_FNAME_CHAR; } } } @@ -231,9 +240,9 @@ int buf_init_chartab(buf_T *buf, int global) if (i == 0) { // (re)set ID flag if (tilde) { - chartab[c] &= (uint8_t)~CT_ID_CHAR; + g_chartab[c] &= (uint8_t)~CT_ID_CHAR; } else { - chartab[c] |= CT_ID_CHAR; + g_chartab[c] |= CT_ID_CHAR; } } else if (i == 1) { // (re)set printable @@ -244,20 +253,20 @@ int buf_init_chartab(buf_T *buf, int global) || (p_altkeymap && (F_isalpha(c) || F_isdigit(c)))) && !(enc_dbcs && (MB_BYTE2LEN(c) == 2))) { if (tilde) { - chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK) - + ((dy_flags & DY_UHEX) ? 4 : 2)); - chartab[c] &= (uint8_t)~CT_PRINT_CHAR; + g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK) + + ((dy_flags & DY_UHEX) ? 4 : 2)); + g_chartab[c] &= (uint8_t)~CT_PRINT_CHAR; } else { - chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK) + 1); - chartab[c] |= CT_PRINT_CHAR; + g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK) + 1); + g_chartab[c] |= CT_PRINT_CHAR; } } } else if (i == 2) { // (re)set fname flag if (tilde) { - chartab[c] &= (uint8_t)~CT_FNAME_CHAR; + g_chartab[c] &= (uint8_t)~CT_FNAME_CHAR; } else { - chartab[c] |= CT_FNAME_CHAR; + g_chartab[c] |= CT_FNAME_CHAR; } } else { // i == 3 // (re)set keyword flag @@ -492,9 +501,9 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) return buf; } -// Catch 22: chartab[] can't be initialized before the options are +// Catch 22: g_chartab[] can't be initialized before the options are // initialized, and initializing options may cause transchar() to be called! -// When chartab_initialized == false don't use chartab[]. +// When chartab_initialized == false don't use g_chartab[]. // Does NOT work for multi-byte characters, c must be <= 255. // Also doesn't work for the first byte of a multi-byte, "c" must be a // character! @@ -633,7 +642,7 @@ int byte2cells(int b) if (enc_utf8 && (b >= 0x80)) { return 0; } - return chartab[b] & CT_CELL_MASK; + return g_chartab[b] & CT_CELL_MASK; } /// Return number of display cells occupied by character "c". @@ -665,7 +674,7 @@ int char2cells(int c) return 2; } } - return chartab[c & 0xff] & CT_CELL_MASK; + return g_chartab[c & 0xff] & CT_CELL_MASK; } /// Return number of display cells occupied by character at "*p". @@ -682,7 +691,7 @@ int ptr2cells(char_u *p) } // For DBCS we can tell the cell count from the first byte. - return chartab[*p] & CT_CELL_MASK; + return g_chartab[*p] & CT_CELL_MASK; } /// Return the number of character cells string "s" will take on the screen, @@ -806,7 +815,7 @@ unsigned int win_linetabsize(win_T *wp, char_u *line, colnr_T len) bool vim_isIDc(int c) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - return c > 0 && c < 0x100 && (chartab[c] & CT_ID_CHAR); + return c > 0 && c < 0x100 && (g_chartab[c] & CT_ID_CHAR); } /// Check that "c" is a keyword character: @@ -878,7 +887,7 @@ bool vim_iswordp_buf(char_u *p, buf_T *buf) bool vim_isfilec(int c) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - return c >= 0x100 || (c > 0 && (chartab[c] & CT_FNAME_CHAR)); + return c >= 0x100 || (c > 0 && (g_chartab[c] & CT_FNAME_CHAR)); } /// Check that "c" is a valid file-name character or a wildcard character @@ -906,7 +915,7 @@ bool vim_isprintc(int c) if (enc_utf8 && (c >= 0x100)) { return utf_printable(c); } - return c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR)); + return c >= 0x100 || (c > 0 && (g_chartab[c] & CT_PRINT_CHAR)); } /// Strict version of vim_isprintc(c), don't return true if "c" is the head @@ -925,7 +934,7 @@ bool vim_isprintc_strict(int c) if (enc_utf8 && (c >= 0x100)) { return utf_printable(c); } - return c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR)); + return c >= 0x100 || (c > 0 && (g_chartab[c] & CT_PRINT_CHAR)); } /// like chartabsize(), but also check for line breaks on the screen @@ -1247,7 +1256,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, if (enc_utf8 && (c >= 0x80)) { incr = utf_ptr2cells(ptr); } else { - incr = CHARSIZE(c); + incr = g_chartab[c] & CT_CELL_MASK; } // If a double-cell char doesn't fit at the end of a line @@ -1261,7 +1270,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, head = 1; } } else { - incr = CHARSIZE(c); + incr = g_chartab[c] & CT_CELL_MASK; } } diff --git a/src/nvim/charset.h b/src/nvim/charset.h index 995ad123ae..78d6f2a76c 100644 --- a/src/nvim/charset.h +++ b/src/nvim/charset.h @@ -1,14 +1,6 @@ #ifndef NVIM_CHARSET_H #define NVIM_CHARSET_H -/* - * Flags for chartab[]. - */ -#define CT_CELL_MASK 0x07 /* mask: nr of display cells (1, 2 or 4) */ -#define CT_PRINT_CHAR 0x10 /* flag: set for printable chars */ -#define CT_ID_CHAR 0x20 /* flag: set for ID chars */ -#define CT_FNAME_CHAR 0x40 /* flag: set for file name chars */ - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "charset.h.generated.h" #endif diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 9525024c1b..aad145b3e5 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1757,12 +1757,12 @@ char_u* keymap_init(void) vim_snprintf(buf, buflen, "keymap/%s_%s.vim", curbuf->b_p_keymap, p_enc); - if (source_runtime((char_u *)buf, FALSE) == FAIL) { + if (source_runtime((char_u *)buf, 0) == FAIL) { // try finding "keymap/'keymap'.vim" in 'runtimepath' vim_snprintf(buf, buflen, "keymap/%s.vim", curbuf->b_p_keymap); - if (source_runtime((char_u *)buf, FALSE) == FAIL) { + if (source_runtime((char_u *)buf, 0) == FAIL) { xfree(buf); return (char_u *)N_("E544: Keymap file not found"); } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f5cffbc3e1..47d44b148a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -435,6 +435,7 @@ typedef struct { TimeWatcher tw; int timer_id; int repeat_count; + long timeout; bool stopped; ufunc_T *callback; } timer_T; @@ -7667,7 +7668,8 @@ static void f_assert_exception(typval_T *argvars, typval_T *rettv) ga_concat(&ga, (char_u *)"v:exception is not set"); assert_error(&ga); ga_clear(&ga); - } else if (strstr((char *)vimvars[VV_EXCEPTION].vv_str, error) == NULL) { + } else if (error != NULL + && strstr((char *)vimvars[VV_EXCEPTION].vv_str, error) == NULL) { prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[1], NULL, &argvars[0], &vimvars[VV_EXCEPTION].vv_tv); @@ -10780,6 +10782,7 @@ static void f_has(typval_T *argvars, typval_T *rettv) "mouse", "multi_byte", "multi_lang", + "packages", "path_extra", "persistent_undo", "postscript", @@ -16638,6 +16641,9 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv) } if (dict_find(dict, (char_u *)"repeat", -1) != NULL) { repeat = get_dict_number(dict, (char_u *)"repeat"); + if (repeat == 0) { + repeat = 1; + } } } @@ -16655,6 +16661,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv) timer = xmalloc(sizeof *timer); timer->stopped = false; timer->repeat_count = repeat; + timer->timeout = timeout; timer->timer_id = last_timer_id++; timer->callback = func; @@ -16709,6 +16716,14 @@ static void timer_due_cb(TimeWatcher *tw, void *data) call_user_func(timer->callback, ARRAY_SIZE(argv), argv, &rettv, curwin->w_cursor.lnum, curwin->w_cursor.lnum, NULL); clear_tv(&rettv); + + if (!timer->stopped && timer->timeout == 0) { + // special case: timeout=0 means the callback will be + // invoked again on the next event loop tick. + // we don't use uv_idle_t to not spin the event loop + // when the main loop is blocked. + time_watcher_start(&timer->tw, timer_due_cb, 0, 0); + } } static void timer_stop(timer_T *timer) @@ -20154,11 +20169,15 @@ theend: */ static int eval_fname_script(char_u *p) { - if (p[0] == '<' && (STRNICMP(p + 1, "SID>", 4) == 0 - || STRNICMP(p + 1, "SNR>", 4) == 0)) + // Use mb_stricmp() because in Turkish comparing the "I" may not work with + // the standard library function. + if (p[0] == '<' && (mb_strnicmp(p + 1, (char_u *)"SID>", 4) == 0 + || mb_strnicmp(p + 1, (char_u *)"SNR>", 4) == 0)) { return 5; - if (p[0] == 's' && p[1] == ':') + } + if (p[0] == 's' && p[1] == ':') { return 2; + } return 0; } @@ -20483,9 +20502,10 @@ script_autoload ( tofree = NULL; } - /* Try loading the package from $VIMRUNTIME/autoload/<name>.vim */ - if (source_runtime(scriptname, FALSE) == OK) - ret = TRUE; + // Try loading the package from $VIMRUNTIME/autoload/<name>.vim + if (source_runtime(scriptname, 0) == OK) { + ret = true; + } } xfree(tofree); @@ -22324,7 +22344,10 @@ bool eval_has_provider(char *name) } \ } - static int has_clipboard = -1, has_python = -1, has_python3 = -1; + static int has_clipboard = -1; + static int has_python = -1; + static int has_python3 = -1; + static int has_ruby = -1; if (!strcmp(name, "clipboard")) { check_provider(clipboard); @@ -22335,6 +22358,9 @@ bool eval_has_provider(char *name) } else if (!strcmp(name, "python")) { check_provider(python); return has_python; + } else if (!strcmp(name, "ruby")) { + check_provider(ruby); + return has_ruby; } return false; diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 1fffdbf957..1c4c9737c3 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -333,9 +333,61 @@ static void process_close(Process *proc) } } +/// Flush output stream. +/// +/// @param proc Process, for which an output stream should be flushed. +/// @param stream Stream to flush. +static void flush_stream(Process *proc, Stream *stream) + FUNC_ATTR_NONNULL_ARG(1) +{ + if (!stream || stream->closed) { + return; + } + + // Maximal remaining data size of terminated process is system + // buffer size. + // Also helps with a child process that keeps the output streams open. If it + // keeps sending data, we only accept as much data as the system buffer size. + // Otherwise this would block cleanup/teardown. + int system_buffer_size = 0; + int err = uv_recv_buffer_size((uv_handle_t *)&stream->uv.pipe, + &system_buffer_size); + if (err) { + system_buffer_size = (int)rbuffer_capacity(stream->buffer); + } + + size_t max_bytes = stream->num_bytes + (size_t)system_buffer_size; + + // Read remaining data. + while (!stream->closed && stream->num_bytes < max_bytes) { + // Remember number of bytes before polling + size_t num_bytes = stream->num_bytes; + + // Poll for data and process the generated events. + loop_poll_events(proc->loop, 0); + if (proc->events) { + queue_process_events(proc->events); + } + + // Stream can be closed if it is empty. + if (num_bytes == stream->num_bytes) { + if (stream->read_cb) { + // Stream callback could miss EOF handling if a child keeps the stream + // open. + stream->read_cb(stream, stream->buffer, 0, stream->data, true); + } + break; + } + } +} + static void process_close_handles(void **argv) { Process *proc = argv[0]; + + flush_stream(proc, proc->out); + flush_stream(proc, proc->err); + process_close_streams(proc); process_close(proc); } @@ -350,11 +402,12 @@ static void on_process_exit(Process *proc) uv_timer_stop(&loop->children_kill_timer); } - // Process handles are closed in the next event loop tick. This is done to - // give libuv more time to read data from the OS after the process exits(If - // process_close_streams is called with data still in the OS buffer, we lose - // it) - CREATE_EVENT(proc->events, process_close_handles, 1, proc); + // Process has terminated, but there could still be data to be read from the + // OS. We are still in the libuv loop, so we cannot call code that polls for + // more data directly. Instead delay the reading after the libuv loop by + // queueing process_close_handles() as an event. + Queue *queue = proc->events ? proc->events : loop->events; + CREATE_EVENT(queue, process_close_handles, 1, proc); } static void on_process_stream_close(Stream *stream, void *data) diff --git a/src/nvim/event/rstream.c b/src/nvim/event/rstream.c index 9f3fbc25ff..a520143064 100644 --- a/src/nvim/event/rstream.c +++ b/src/nvim/event/rstream.c @@ -100,6 +100,10 @@ static void read_cb(uv_stream_t *uvstream, ssize_t cnt, const uv_buf_t *buf) { Stream *stream = uvstream->data; + if (cnt > 0) { + stream->num_bytes += (size_t)cnt; + } + if (cnt <= 0) { if (cnt != UV_ENOBUFS // cnt == 0 means libuv asked for a buffer and decided it wasn't needed: @@ -185,10 +189,6 @@ static void read_event(void **argv) static void invoke_read_cb(Stream *stream, size_t count, bool eof) { - if (stream->closed) { - return; - } - // Don't let the stream be closed before the event is processed. stream->pending_reqs++; diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index 93cc592683..cdaf40849b 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -103,7 +103,7 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb) // Libuv converts ENOENT to EACCES for Windows compatibility, but if // the parent directory does not exist, ENOENT would be more accurate. *path_tail((char_u *)watcher->addr) = NUL; - if (!os_file_exists((char_u *)watcher->addr)) { + if (!os_path_exists((char_u *)watcher->addr)) { result = -ENOENT; } } diff --git a/src/nvim/event/stream.c b/src/nvim/event/stream.c index 71582ab357..33404158cf 100644 --- a/src/nvim/event/stream.c +++ b/src/nvim/event/stream.c @@ -71,6 +71,7 @@ void stream_init(Loop *loop, Stream *stream, int fd, uv_stream_t *uvstream, stream->closed = false; stream->buffer = NULL; stream->events = NULL; + stream->num_bytes = 0; } void stream_close(Stream *stream, stream_close_cb on_stream_close) diff --git a/src/nvim/event/stream.h b/src/nvim/event/stream.h index c6baac0db7..ad4e24775b 100644 --- a/src/nvim/event/stream.h +++ b/src/nvim/event/stream.h @@ -49,6 +49,7 @@ struct stream { size_t curmem; size_t maxmem; size_t pending_reqs; + size_t num_bytes; void *data, *internal_data; bool closed; Queue *events; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 86f1a16216..da64533708 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1745,14 +1745,14 @@ check_overwrite ( * write to other file or b_flags set or not writing the whole file: * overwriting only allowed with '!' */ - if ( (other - || (buf->b_flags & BF_NOTEDITED) - || ((buf->b_flags & BF_NEW) - && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) - || (buf->b_flags & BF_READERR)) - && !p_wa - && !bt_nofile(buf) - && os_file_exists(ffname)) { + if ((other + || (buf->b_flags & BF_NOTEDITED) + || ((buf->b_flags & BF_NEW) + && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) + || (buf->b_flags & BF_READERR)) + && !p_wa + && !bt_nofile(buf) + && os_path_exists(ffname)) { if (!eap->forceit && !eap->append) { #ifdef UNIX // It is possible to open a directory on Unix. @@ -1795,7 +1795,7 @@ check_overwrite ( } swapname = makeswapname(fname, ffname, curbuf, dir); xfree(dir); - if (os_file_exists(swapname)) { + if (os_path_exists(swapname)) { if (p_confirm || cmdmod.confirm) { char_u buff[DIALOG_MSG_SIZE]; @@ -1909,7 +1909,7 @@ static int check_readonly(int *forceit, buf_T *buf) /* Handle a file being readonly when the 'readonly' option is set or when * the file exists and permissions are read-only. */ if (!*forceit && (buf->b_p_ro - || (os_file_exists(buf->b_ffname) + || (os_path_exists(buf->b_ffname) && !os_file_is_writable((char *)buf->b_ffname)))) { if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL) { char_u buff[DIALOG_MSG_SIZE]; @@ -4796,122 +4796,15 @@ void ex_viusage(exarg_T *eap) } -/* - * ":helptags" - */ -void ex_helptags(exarg_T *eap) -{ - garray_T ga; - int len; - char_u lang[2]; - expand_T xpc; - char_u *dirname; - char_u ext[5]; - char_u fname[8]; - int filecount; - char_u **files; - int add_help_tags = FALSE; - - /* Check for ":helptags ++t {dir}". */ - if (STRNCMP(eap->arg, "++t", 3) == 0 && ascii_iswhite(eap->arg[3])) { - add_help_tags = TRUE; - eap->arg = skipwhite(eap->arg + 3); - } - - ExpandInit(&xpc); - xpc.xp_context = EXPAND_DIRECTORIES; - dirname = ExpandOne(&xpc, eap->arg, NULL, - WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); - if (dirname == NULL || !os_isdir(dirname)) { - EMSG2(_("E150: Not a directory: %s"), eap->arg); - xfree(dirname); - return; - } - - /* Get a list of all files in the help directory and in subdirectories. */ - STRCPY(NameBuff, dirname); - add_pathsep((char *)NameBuff); - STRCAT(NameBuff, "**"); - - // Note: We cannot just do `&NameBuff` because it is a statically sized array - // so `NameBuff == &NameBuff` according to C semantics. - char_u *buff_list[1] = {NameBuff}; - if (gen_expand_wildcards(1, buff_list, &filecount, &files, - EW_FILE|EW_SILENT) == FAIL - || filecount == 0) { - EMSG2("E151: No match: %s", NameBuff); - xfree(dirname); - return; - } - - /* Go over all files in the directory to find out what languages are - * present. */ - ga_init(&ga, 1, 10); - for (int i = 0; i < filecount; ++i) { - len = (int)STRLEN(files[i]); - if (len <= 4) { - continue; - } - if (STRICMP(files[i] + len - 4, ".txt") == 0) { - /* ".txt" -> language "en" */ - lang[0] = 'e'; - lang[1] = 'n'; - } else if (files[i][len - 4] == '.' - && ASCII_ISALPHA(files[i][len - 3]) - && ASCII_ISALPHA(files[i][len - 2]) - && TOLOWER_ASC(files[i][len - 1]) == 'x') { - /* ".abx" -> language "ab" */ - lang[0] = TOLOWER_ASC(files[i][len - 3]); - lang[1] = TOLOWER_ASC(files[i][len - 2]); - } else - continue; - - int j; - /* Did we find this language already? */ - for (j = 0; j < ga.ga_len; j += 2) - if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) - break; - if (j == ga.ga_len) { - /* New language, add it. */ - ga_grow(&ga, 2); - ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; - ((char_u *)ga.ga_data)[ga.ga_len++] = lang[1]; - } - } - - /* - * Loop over the found languages to generate a tags file for each one. - */ - for (int j = 0; j < ga.ga_len; j += 2) { - STRCPY(fname, "tags-xx"); - fname[5] = ((char_u *)ga.ga_data)[j]; - fname[6] = ((char_u *)ga.ga_data)[j + 1]; - if (fname[5] == 'e' && fname[6] == 'n') { - /* English is an exception: use ".txt" and "tags". */ - fname[4] = NUL; - STRCPY(ext, ".txt"); - } else { - /* Language "ab" uses ".abx" and "tags-ab". */ - STRCPY(ext, ".xxx"); - ext[1] = fname[5]; - ext[2] = fname[6]; - } - helptags_one(dirname, ext, fname, add_help_tags); - } - - ga_clear(&ga); - FreeWild(filecount, files); - - xfree(dirname); -} - -static void -helptags_one ( - char_u *dir, /* doc directory */ - char_u *ext, /* suffix, ".txt", ".itx", ".frx", etc. */ - char_u *tagfname, /* "tags" for English, "tags-fr" for French. */ - int add_help_tags /* add "help-tags" tag */ -) +/// Generate tags in one help directory +/// +/// @param dir Path to the doc directory +/// @param ext Suffix of the help files (".txt", ".itx", ".frx", etc.) +/// @param tagname Name of the tags file ("tags" for English, "tags-fr" for +/// French) +/// @param add_help_tags Whether to add the "help-tags" tag +static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname, + bool add_help_tags) { FILE *fd_tags; FILE *fd; @@ -5111,6 +5004,132 @@ helptags_one ( fclose(fd_tags); /* there is no check for an error... */ } +/// Generate tags in one help directory, taking care of translations. +static void do_helptags(char_u *dirname, bool add_help_tags) +{ + int len; + garray_T ga; + char_u lang[2]; + char_u ext[5]; + char_u fname[8]; + int filecount; + char_u **files; + + // Get a list of all files in the help directory and in subdirectories. + STRCPY(NameBuff, dirname); + add_pathsep((char *)NameBuff); + STRCAT(NameBuff, "**"); + + // Note: We cannot just do `&NameBuff` because it is a statically sized array + // so `NameBuff == &NameBuff` according to C semantics. + char_u *buff_list[1] = {NameBuff}; + if (gen_expand_wildcards(1, buff_list, &filecount, &files, + EW_FILE|EW_SILENT) == FAIL + || filecount == 0) { + EMSG2("E151: No match: %s", NameBuff); + xfree(dirname); + return; + } + + /* Go over all files in the directory to find out what languages are + * present. */ + int j; + ga_init(&ga, 1, 10); + for (int i = 0; i < filecount; i++) { + len = (int)STRLEN(files[i]); + if (len <= 4) { + continue; + } + if (STRICMP(files[i] + len - 4, ".txt") == 0) { + /* ".txt" -> language "en" */ + lang[0] = 'e'; + lang[1] = 'n'; + } else if (files[i][len - 4] == '.' + && ASCII_ISALPHA(files[i][len - 3]) + && ASCII_ISALPHA(files[i][len - 2]) + && TOLOWER_ASC(files[i][len - 1]) == 'x') { + /* ".abx" -> language "ab" */ + lang[0] = TOLOWER_ASC(files[i][len - 3]); + lang[1] = TOLOWER_ASC(files[i][len - 2]); + } else + continue; + + // Did we find this language already? + for (j = 0; j < ga.ga_len; j += 2) { + if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) { + break; + } + } + if (j == ga.ga_len) { + // New language, add it. + ga_grow(&ga, 2); + ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; + ((char_u *)ga.ga_data)[ga.ga_len++] = lang[1]; + } + } + + /* + * Loop over the found languages to generate a tags file for each one. + */ + for (j = 0; j < ga.ga_len; j += 2) { + STRCPY(fname, "tags-xx"); + fname[5] = ((char_u *)ga.ga_data)[j]; + fname[6] = ((char_u *)ga.ga_data)[j + 1]; + if (fname[5] == 'e' && fname[6] == 'n') { + /* English is an exception: use ".txt" and "tags". */ + fname[4] = NUL; + STRCPY(ext, ".txt"); + } else { + /* Language "ab" uses ".abx" and "tags-ab". */ + STRCPY(ext, ".xxx"); + ext[1] = fname[5]; + ext[2] = fname[6]; + } + helptags_one(dirname, ext, fname, add_help_tags); + } + + ga_clear(&ga); + FreeWild(filecount, files); +} + + static void +helptags_cb(char_u *fname, void *cookie) +{ + do_helptags(fname, *(bool *)cookie); +} + +/* + * ":helptags" + */ +void ex_helptags(exarg_T *eap) +{ + expand_T xpc; + char_u *dirname; + bool add_help_tags = false; + + /* Check for ":helptags ++t {dir}". */ + if (STRNCMP(eap->arg, "++t", 3) == 0 && ascii_iswhite(eap->arg[3])) { + add_help_tags = true; + eap->arg = skipwhite(eap->arg + 3); + } + + if (STRCMP(eap->arg, "ALL") == 0) { + do_in_path(p_rtp, (char_u *)"doc", DIP_ALL + DIP_DIR, + helptags_cb, &add_help_tags); + } else { + ExpandInit(&xpc); + xpc.xp_context = EXPAND_DIRECTORIES; + dirname = ExpandOne(&xpc, eap->arg, NULL, + WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); + if (dirname == NULL || !os_isdir(dirname)) { + EMSG2(_("E150: Not a directory: %s"), eap->arg); + } else { + do_helptags(dirname, add_help_tags); + } + xfree(dirname); + } +} + struct sign { sign_T *sn_next; /* next sign in list */ diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 6c58879d58..3f5d9b3244 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -1849,6 +1849,18 @@ return { func='ex_print', }, { + command='packadd', + flags=bit.bor(BANG, FILE1, NEEDARG, TRLBAR, SBOXOK, CMDWIN), + addr_type=ADDR_LINES, + func='ex_packadd', + }, + { + command='packloadall', + flags=bit.bor(BANG, TRLBAR, SBOXOK, CMDWIN), + addr_type=ADDR_LINES, + func='ex_packloadall', + }, + { command='pclose', flags=bit.bor(BANG, TRLBAR), addr_type=ADDR_LINES, @@ -2158,19 +2170,19 @@ return { command='ruby', flags=bit.bor(RANGE, EXTRA, NEEDARG, CMDWIN), addr_type=ADDR_LINES, - func='ex_script_ni', + func='ex_ruby', }, { command='rubydo', flags=bit.bor(RANGE, DFLALL, EXTRA, NEEDARG, CMDWIN), addr_type=ADDR_LINES, - func='ex_ni', + func='ex_rubydo', }, { command='rubyfile', flags=bit.bor(RANGE, FILE1, NEEDARG, CMDWIN), addr_type=ADDR_LINES, - func='ex_ni', + func='ex_rubyfile', }, { command='rviminfo', diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index e7f51326c4..6d24ba91f2 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -897,6 +897,21 @@ void ex_pydo(exarg_T *eap) script_host_do_range("python", eap); } +void ex_ruby(exarg_T *eap) +{ + script_host_execute("ruby", eap); +} + +void ex_rubyfile(exarg_T *eap) +{ + script_host_execute_file("ruby", eap); +} + +void ex_rubydo(exarg_T *eap) +{ + script_host_do_range("ruby", eap); +} + void ex_python3(exarg_T *eap) { script_host_execute("python3", eap); @@ -2237,7 +2252,7 @@ void ex_compiler(exarg_T *eap) do_unlet((char_u *)"b:current_compiler", true); snprintf((char *)buf, bufsize, "compiler/%s.vim", eap->arg); - if (source_runtime(buf, true) == FAIL) { + if (source_runtime(buf, DIP_ALL) == FAIL) { EMSG2(_("E666: compiler not supported: %s"), eap->arg); } xfree(buf); @@ -2263,10 +2278,29 @@ void ex_compiler(exarg_T *eap) } } -/// ":runtime {name}" +/// ":runtime [what] {name}" void ex_runtime(exarg_T *eap) { - source_runtime(eap->arg, eap->forceit); + char_u *arg = eap->arg; + char_u *p = skiptowhite(arg); + ptrdiff_t len = p - arg; + int flags = eap->forceit ? DIP_ALL : 0; + + if (STRNCMP(arg, "START", len) == 0) { + flags += DIP_START + DIP_NORTP; + arg = skipwhite(arg + len); + } else if (STRNCMP(arg, "OPT", len) == 0) { + flags += DIP_OPT + DIP_NORTP; + arg = skipwhite(arg + len); + } else if (STRNCMP(arg, "PACK", len) == 0) { + flags += DIP_START + DIP_OPT + DIP_NORTP; + arg = skipwhite(arg + len); + } else if (STRNCMP(arg, "ALL", len) == 0) { + flags += DIP_START + DIP_OPT; + arg = skipwhite(arg + len); + } + + source_runtime(arg, flags); } @@ -2277,28 +2311,25 @@ static void source_callback(char_u *fname, void *cookie) /// Source the file "name" from all directories in 'runtimepath'. /// "name" can contain wildcards. -/// When "all" is true, source all files, otherwise only the first one. +/// When "flags" has DIP_ALL: source all files, otherwise only the first one. +/// /// return FAIL when no file could be sourced, OK otherwise. -int source_runtime(char_u *name, int all) +int source_runtime(char_u *name, int flags) { - return do_in_runtimepath(name, all, source_callback, NULL); + return do_in_runtimepath(name, flags, source_callback, NULL); } -/// Find "name" in 'runtimepath'. When found, invoke the callback function for -/// it: callback(fname, "cookie") -/// When "all" is true repeat for all matches, otherwise only the first one is -/// used. -/// Returns OK when at least one match found, FAIL otherwise. -/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is -/// passed by reference in this case, setting it to NULL indicates that callback -/// has done its job. -int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, - void *cookie) +/// Find the file "name" in all directories in "path" and invoke +/// "callback(fname, cookie)". +/// "name" can contain wildcards. +/// When "flags" has DIP_ALL: source all files, otherwise only the first one. +/// When "flags" has DIP_DIR: find directories instead of files. +/// When "flags" has DIP_ERR: give an error message if there is no match. +/// +/// return FAIL when no file could be sourced, OK otherwise. +int do_in_path(char_u *path, char_u *name, int flags, + DoInRuntimepathCB callback, void *cookie) { - char_u *rtp; - char_u *np; - char_u *buf; - char_u *rtp_copy; char_u *tail; int num_files; char_u **files; @@ -2307,19 +2338,19 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, // Make a copy of 'runtimepath'. Invoking the callback may change the // value. - rtp_copy = vim_strsave(p_rtp); - buf = xmallocz(MAXPATHL); + char_u *rtp_copy = vim_strsave(path); + char_u *buf = xmallocz(MAXPATHL); { if (p_verbose > 1 && name != NULL) { verbose_enter(); smsg(_("Searching for \"%s\" in \"%s\""), - (char *)name, (char *)p_rtp); + (char *)name, (char *)path); verbose_leave(); } // Loop over all entries in 'runtimepath'. - rtp = rtp_copy; - while (*rtp != NUL && (all || !did_one)) { + char_u *rtp = rtp_copy; + while (*rtp != NUL && ((flags & DIP_ALL) || !did_one)) { // Copy the path from 'runtimepath' to buf[]. copy_option_part(&rtp, buf, MAXPATHL, ","); if (name == NULL) { @@ -2332,8 +2363,8 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, tail = buf + STRLEN(buf); // Loop over all patterns in "name" - np = name; - while (*np != NUL && (all || !did_one)) { + char_u *np = name; + while (*np != NUL && ((flags & DIP_ALL) || !did_one)) { // Append the pattern from "name" to buf[]. assert(MAXPATHL >= (tail - buf)); copy_option_part(&np, tail, (size_t)(MAXPATHL - (tail - buf)), @@ -2347,11 +2378,12 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, // Expand wildcards, invoke the callback for each match. if (gen_expand_wildcards(1, &buf, &num_files, &files, - EW_FILE) == OK) { + (flags & DIP_DIR) ? EW_DIR + : EW_FILE) == OK) { for (i = 0; i < num_files; i++) { (*callback)(files[i], cookie); did_one = true; - if (!all) { + if (!(flags & DIP_ALL)) { break; } } @@ -2363,16 +2395,228 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, } xfree(buf); xfree(rtp_copy); - if (p_verbose > 0 && !did_one && name != NULL) { - verbose_enter(); - smsg(_("not found in 'runtimepath': \"%s\""), name); - verbose_leave(); + if (!did_one && name != NULL) { + char *basepath = path == p_rtp ? "runtimepath" : "packpath"; + + if (flags & DIP_ERR) { + EMSG3(_(e_dirnotf), basepath, name); + } else if (p_verbose > 0) { + verbose_enter(); + smsg(_("not found in '%s': \"%s\""), basepath, name); + verbose_leave(); + } } return did_one ? OK : FAIL; } +/// Find "name" in 'runtimepath'. When found, invoke the callback function for +/// it: callback(fname, "cookie") +/// When "flags" has DIP_ALL repeat for all matches, otherwise only the first +/// one is used. +/// Returns OK when at least one match found, FAIL otherwise. +/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is +/// passed by reference in this case, setting it to NULL indicates that callback +/// has done its job. +int do_in_runtimepath(char_u *name, int flags, DoInRuntimepathCB callback, + void *cookie) +{ + int done = FAIL; + + if ((flags & DIP_NORTP) == 0) { + done = do_in_path(p_rtp, name, flags, callback, cookie); + } + + if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) { + char *start_dir = "pack/*/start/*/%s"; // NOLINT + size_t len = STRLEN(start_dir) + STRLEN(name); + char_u *s = xmallocz(len); + + vim_snprintf((char *)s, len, start_dir, name); + done = do_in_path(p_pp, s, flags, callback, cookie); + + xfree(s); + } + + if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT)) { + char *opt_dir = "pack/*/opt/*/%s"; // NOLINT + size_t len = STRLEN(opt_dir) + STRLEN(name); + char_u *s = xmallocz(len); + + vim_snprintf((char *)s, len, opt_dir, name); + done = do_in_path(p_pp, s, flags, callback, cookie); + + xfree(s); + } + + return done; +} + +// Expand wildcards in "pat" and invoke do_source() for each match. +static void source_all_matches(char_u *pat) +{ + int num_files; + char_u **files; + + if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) { + for (int i = 0; i < num_files; i++) { + (void)do_source(files[i], false, DOSO_NONE); + } + FreeWild(num_files, files); + } +} + +// used for "cookie" of add_pack_plugin() +static int APP_ADD_DIR; +static int APP_LOAD; +static int APP_BOTH; + +static void add_pack_plugin(char_u *fname, void *cookie) +{ + char_u *p4, *p3, *p2, *p1, *p; + char_u *new_rtp; + char_u *ffname = (char_u *)fix_fname((char *)fname); + + if (ffname == NULL) { + return; + } + + if (cookie != &APP_LOAD && strstr((char *)p_rtp, (char *)ffname) == NULL) { + // directory is not yet in 'runtimepath', add it + p4 = p3 = p2 = p1 = get_past_head(ffname); + for (p = p1; *p; mb_ptr_adv(p)) { + if (vim_ispathsep_nocolon(*p)) { + p4 = p3; p3 = p2; p2 = p1; p1 = p; + } + } + + // now we have: + // rtp/pack/name/start/name + // p4 p3 p2 p1 + // + // find the part up to "pack" in 'runtimepath' + char_u c = *p4; + *p4 = NUL; + + // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences + size_t fname_len = STRLEN(ffname); + char_u *insp = p_rtp; + for (;;) { + if (vim_fnamencmp(insp, ffname, fname_len) == 0) { + break; + } + insp = vim_strchr(insp, ','); + if (insp == NULL) { + break; + } + insp++; + } + + if (insp == NULL) { + // not found, append at the end + insp = p_rtp + STRLEN(p_rtp); + } else { + // append after the matching directory. + insp += STRLEN(ffname); + while (*insp != NUL && *insp != ',') { + insp++; + } + } + *p4 = c; + + // check if rtp/pack/name/start/name/after exists + char *afterdir = concat_fnames((char *)ffname, "after", true); + size_t afterlen = 0; + if (os_isdir((char_u *)afterdir)) { + afterlen = STRLEN(afterdir) + 1; // add one for comma + } + + size_t oldlen = STRLEN(p_rtp); + size_t addlen = STRLEN(ffname) + 1; // add one for comma + new_rtp = try_malloc(oldlen + addlen + afterlen + 1); // add one for NUL + if (new_rtp == NULL) { + goto theend; + } + uintptr_t keep = (uintptr_t)(insp - p_rtp); + memmove(new_rtp, p_rtp, keep); + new_rtp[keep] = ','; + memmove(new_rtp + keep + 1, ffname, addlen); + if (p_rtp[keep] != NUL) { + memmove(new_rtp + keep + addlen, p_rtp + keep, + oldlen - keep + 1); + } + if (afterlen > 0) { + STRCAT(new_rtp, ","); + STRCAT(new_rtp, afterdir); + } + set_option_value((char_u *)"rtp", 0L, new_rtp, 0); + xfree(new_rtp); + xfree(afterdir); + } + + if (cookie != &APP_ADD_DIR) { + static const char *plugpat = "%s/plugin/*.vim"; // NOLINT + static const char *ftpat = "%s/ftdetect/*.vim"; // NOLINT + + size_t len = STRLEN(ffname) + STRLEN(ftpat); + char_u *pat = try_malloc(len + 1); + if (pat == NULL) { + goto theend; + } + vim_snprintf((char *)pat, len, plugpat, ffname); + source_all_matches(pat); + + char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); + + // If runtime/filetype.vim wasn't loaded yet, the scripts will be + // found when it loads. + if (eval_to_number(cmd) > 0) { + do_cmdline_cmd("augroup filetypedetect"); + vim_snprintf((char *)pat, len, ftpat, ffname); + source_all_matches(pat); + do_cmdline_cmd("augroup END"); + } + xfree(cmd); + xfree(pat); + } + +theend: + xfree(ffname); +} + +static bool did_source_packages = false; + +// ":packloadall" +// Find plugins in the package directories and source them. +void ex_packloadall(exarg_T *eap) +{ + if (!did_source_packages || (eap != NULL && eap->forceit)) { + did_source_packages = true; + + // First do a round to add all directories to 'runtimepath', then load + // the plugins. This allows for plugins to use an autoload directory + // of another plugin. + do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT + add_pack_plugin, &APP_ADD_DIR); + do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT + add_pack_plugin, &APP_LOAD); + } +} + +/// ":packadd[!] {name}" +void ex_packadd(exarg_T *eap) +{ + static const char *plugpat = "pack/*/opt/%s"; // NOLINT + + size_t len = STRLEN(plugpat) + STRLEN(eap->arg); + char *pat = (char *)xmallocz(len); + vim_snprintf(pat, len, plugpat, eap->arg); + do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR, add_pack_plugin, + eap->forceit ? &APP_ADD_DIR : &APP_BOTH); + xfree(pat); +} + /// ":options" void ex_options(exarg_T *eap) { @@ -3533,5 +3777,6 @@ void ex_drop(exarg_T *eap) } else { eap->cmdidx = CMD_first; } + ex_rewind(eap); } } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 6864e2b914..9bc7ec39da 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3316,6 +3316,11 @@ set_one_cmd_context ( xp->xp_pattern = arg; break; + case CMD_packadd: + xp->xp_context = EXPAND_PACKADD; + xp->xp_pattern = arg; + break; + #ifdef HAVE_WORKING_LIBINTL case CMD_language: p = skiptowhite(arg); @@ -4660,41 +4665,42 @@ static struct { char *name; } command_complete[] = { - {EXPAND_AUGROUP, "augroup"}, - {EXPAND_BEHAVE, "behave"}, - {EXPAND_BUFFERS, "buffer"}, - {EXPAND_COLORS, "color"}, - {EXPAND_COMMANDS, "command"}, - {EXPAND_COMPILER, "compiler"}, - {EXPAND_CSCOPE, "cscope"}, - {EXPAND_USER_DEFINED, "custom"}, - {EXPAND_USER_LIST, "customlist"}, - {EXPAND_DIRECTORIES, "dir"}, - {EXPAND_ENV_VARS, "environment"}, - {EXPAND_EVENTS, "event"}, - {EXPAND_EXPRESSION, "expression"}, - {EXPAND_FILES, "file"}, - {EXPAND_FILES_IN_PATH, "file_in_path"}, - {EXPAND_FILETYPE, "filetype"}, - {EXPAND_FUNCTIONS, "function"}, - {EXPAND_HELP, "help"}, - {EXPAND_HIGHLIGHT, "highlight"}, - {EXPAND_HISTORY, "history"}, + { EXPAND_AUGROUP, "augroup" }, + { EXPAND_BEHAVE, "behave" }, + { EXPAND_BUFFERS, "buffer" }, + { EXPAND_COLORS, "color" }, + { EXPAND_COMMANDS, "command" }, + { EXPAND_COMPILER, "compiler" }, + { EXPAND_CSCOPE, "cscope" }, + { EXPAND_USER_DEFINED, "custom" }, + { EXPAND_USER_LIST, "customlist" }, + { EXPAND_DIRECTORIES, "dir" }, + { EXPAND_ENV_VARS, "environment" }, + { EXPAND_EVENTS, "event" }, + { EXPAND_EXPRESSION, "expression" }, + { EXPAND_FILES, "file" }, + { EXPAND_FILES_IN_PATH, "file_in_path" }, + { EXPAND_FILETYPE, "filetype" }, + { EXPAND_FUNCTIONS, "function" }, + { EXPAND_HELP, "help" }, + { EXPAND_HIGHLIGHT, "highlight" }, + { EXPAND_HISTORY, "history" }, #ifdef HAVE_WORKING_LIBINTL - {EXPAND_LOCALES, "locale"}, + { EXPAND_LOCALES, "locale" }, #endif - {EXPAND_MAPPINGS, "mapping"}, - {EXPAND_MENUS, "menu"}, - {EXPAND_OWNSYNTAX, "syntax"}, - {EXPAND_SYNTIME, "syntime"}, - {EXPAND_SETTINGS, "option"}, - {EXPAND_SHELLCMD, "shellcmd"}, - {EXPAND_SIGN, "sign"}, - {EXPAND_TAGS, "tag"}, - {EXPAND_TAGS_LISTFILES, "tag_listfiles"}, - {EXPAND_USER, "user"}, - {EXPAND_USER_VARS, "var"}, - {0, NULL} + { EXPAND_MAPPINGS, "mapping" }, + { EXPAND_MENUS, "menu" }, + { EXPAND_OWNSYNTAX, "syntax" }, + { EXPAND_SYNTIME, "syntime" }, + { EXPAND_SETTINGS, "option" }, + { EXPAND_PACKADD, "packadd" }, + { EXPAND_SHELLCMD, "shellcmd" }, + { EXPAND_SIGN, "sign" }, + { EXPAND_TAGS, "tag" }, + { EXPAND_TAGS_LISTFILES, "tag_listfiles" }, + { EXPAND_USER, "user" }, + { EXPAND_USER_VARS, "var" }, + { 0, NULL } }; static void uc_list(char_u *name, size_t name_len) @@ -7650,7 +7656,7 @@ open_exfile ( return NULL; } #endif - if (!forceit && *mode != 'a' && os_file_exists(fname)) { + if (!forceit && *mode != 'a' && os_path_exists(fname)) { EMSG2(_("E189: \"%s\" exists (add ! to override)"), fname); return NULL; } @@ -9330,14 +9336,14 @@ static void ex_filetype(exarg_T *eap) } if (STRCMP(arg, "on") == 0 || STRCMP(arg, "detect") == 0) { if (*arg == 'o' || !filetype_detect) { - source_runtime((char_u *)FILETYPE_FILE, true); + source_runtime((char_u *)FILETYPE_FILE, DIP_ALL); filetype_detect = kTrue; if (plugin) { - source_runtime((char_u *)FTPLUGIN_FILE, true); + source_runtime((char_u *)FTPLUGIN_FILE, DIP_ALL); filetype_plugin = kTrue; } if (indent) { - source_runtime((char_u *)INDENT_FILE, true); + source_runtime((char_u *)INDENT_FILE, DIP_ALL); filetype_indent = kTrue; } } @@ -9348,15 +9354,15 @@ static void ex_filetype(exarg_T *eap) } else if (STRCMP(arg, "off") == 0) { if (plugin || indent) { if (plugin) { - source_runtime((char_u *)FTPLUGOF_FILE, true); + source_runtime((char_u *)FTPLUGOF_FILE, DIP_ALL); filetype_plugin = kFalse; } if (indent) { - source_runtime((char_u *)INDOFF_FILE, true); + source_runtime((char_u *)INDOFF_FILE, DIP_ALL); filetype_indent = kFalse; } } else { - source_runtime((char_u *)FTOFF_FILE, true); + source_runtime((char_u *)FTOFF_FILE, DIP_ALL); filetype_detect = kFalse; } } else diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 65144dace8..cd28554970 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3440,6 +3440,7 @@ addstar ( || context == EXPAND_COMPILER || context == EXPAND_OWNSYNTAX || context == EXPAND_FILETYPE + || context == EXPAND_PACKADD || (context == EXPAND_TAGS && fname[0] == '/')) retval = vim_strnsave(fname, len); else { @@ -3794,23 +3795,27 @@ ExpandFromContext ( || xp->xp_context == EXPAND_TAGS_LISTFILES) return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file); if (xp->xp_context == EXPAND_COLORS) { - char *directories[] = {"colors", NULL}; - return ExpandRTDir(pat, num_file, file, directories); + char *directories[] = { "colors", NULL }; + return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file, directories); } if (xp->xp_context == EXPAND_COMPILER) { - char *directories[] = {"compiler", NULL}; - return ExpandRTDir(pat, num_file, file, directories); + char *directories[] = { "compiler", NULL }; + return ExpandRTDir(pat, 0, num_file, file, directories); } if (xp->xp_context == EXPAND_OWNSYNTAX) { - char *directories[] = {"syntax", NULL}; - return ExpandRTDir(pat, num_file, file, directories); + char *directories[] = { "syntax", NULL }; + return ExpandRTDir(pat, 0, num_file, file, directories); } if (xp->xp_context == EXPAND_FILETYPE) { - char *directories[] = {"syntax", "indent", "ftplugin", NULL}; - return ExpandRTDir(pat, num_file, file, directories); + char *directories[] = { "syntax", "indent", "ftplugin", NULL }; + return ExpandRTDir(pat, 0, num_file, file, directories); } - if (xp->xp_context == EXPAND_USER_LIST) + if (xp->xp_context == EXPAND_USER_LIST) { return ExpandUserList(xp, num_file, file); + } + if (xp->xp_context == EXPAND_PACKADD) { + return ExpandPackAddDir(pat, num_file, file); + } regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) @@ -4190,12 +4195,16 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file) return OK; } -/* - * Expand color scheme, compiler or filetype names: - * 'runtimepath'/{dirnames}/{pat}.vim - * "dirnames" is an array with one or more directory names. - */ -static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirnames[]) +/// Expand color scheme, compiler or filetype names. +/// Search from 'runtimepath': +/// 'runtimepath'/{dirnames}/{pat}.vim +/// When "flags" has DIP_START: search also from 'start' of 'packpath': +/// 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim +/// When "flags" has DIP_OPT: search also from 'opt' of 'packpath': +/// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim +/// "dirnames" is an array with one or more directory names. +static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, + char *dirnames[]) { *num_file = 0; *file = NULL; @@ -4212,6 +4221,26 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname xfree(s); } + if (flags & DIP_START) { + for (int i = 0; dirnames[i] != NULL; i++) { + size_t size = STRLEN(dirnames[i]) + pat_len + 22; + char_u *s = xmalloc(size); + snprintf((char *)s, size, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); + xfree(s); + } + } + + if (flags & DIP_OPT) { + for (int i = 0; dirnames[i] != NULL; i++) { + size_t size = STRLEN(dirnames[i]) + pat_len + 20; + char_u *s = xmalloc(size); + snprintf((char *)s, size, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT + globpath(p_pp, s, &ga, 0); + xfree(s); + } + } + for (int i = 0; i < ga.ga_len; i++) { char_u *match = ((char_u **)ga.ga_data)[i]; char_u *s = match; @@ -4241,6 +4270,43 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname return OK; } +/// Expand loadplugin names: +/// 'packpath'/pack/ * /opt/{pat} +static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file) +{ + garray_T ga; + + *num_file = 0; + *file = NULL; + size_t pat_len = STRLEN(pat); + ga_init(&ga, (int)sizeof(char *), 10); + + size_t buflen = pat_len + 26; + char_u *s = xmalloc(buflen); + snprintf((char *)s, buflen, "pack/*/opt/%s*", pat); // NOLINT + globpath(p_pp, s, &ga, 0); + xfree(s); + + for (int i = 0; i < ga.ga_len; i++) { + char_u *match = ((char_u **)ga.ga_data)[i]; + s = path_tail(match); + char_u *e = s + STRLEN(s); + memmove(match, s, e - s + 1); + } + + if (GA_EMPTY(&ga)) { + return FAIL; + } + + // Sort and remove duplicates which can happen when specifying multiple + // directories in dirnames. + ga_remove_duplicate_strings(&ga); + + *file = ga.ga_data; + *num_file = ga.ga_len; + return OK; +} + /// Expand `file` for all comma-separated directories in `path`. /// Adds matches to `ga`. diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index f7555c99fa..78b224f04c 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -791,7 +791,7 @@ char_u *vim_findfile(void *search_ctx_arg) for (;; ) { /* if file exists and we didn't already find it */ if ((path_with_url((char *)file_path) - || (os_file_exists(file_path) + || (os_path_exists(file_path) && (search_ctx->ffsc_find_what == FINDFILE_BOTH || ((search_ctx->ffsc_find_what @@ -1442,12 +1442,12 @@ find_file_in_path_option ( buf = suffixes; for (;; ) { if ( - (os_file_exists(NameBuff) - && (find_what == FINDFILE_BOTH - || ((find_what == FINDFILE_DIR) - == os_isdir(NameBuff))))) { - file_name = vim_strsave(NameBuff); - goto theend; + (os_path_exists(NameBuff) + && (find_what == FINDFILE_BOTH + || ((find_what == FINDFILE_DIR) + == os_isdir(NameBuff))))) { + file_name = vim_strsave(NameBuff); + goto theend; } if (*buf == NUL) break; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 4d9e10fb85..154558b332 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2990,14 +2990,15 @@ nobackup: * delete an existing one, try to use another name. * Change one character, just before the extension. */ - if (!p_bk && os_file_exists(backup)) { + if (!p_bk && os_path_exists(backup)) { p = backup + STRLEN(backup) - 1 - STRLEN(backup_ext); if (p < backup) /* empty file name ??? */ p = backup; *p = 'z'; - while (*p > 'a' && os_file_exists(backup)) - --*p; - /* They all exist??? Must be something wrong! */ + while (*p > 'a' && os_path_exists(backup)) { + (*p)--; + } + // They all exist??? Must be something wrong! if (*p == 'a') { xfree(backup); backup = NULL; @@ -3224,12 +3225,12 @@ restore_backup: * This may not work if the vim_rename() fails. * In that case we leave the copy around. */ - /* If file does not exist, put the copy in its place */ - if (!os_file_exists(fname)) { + // If file does not exist, put the copy in its place + if (!os_path_exists(fname)) { vim_rename(backup, fname); } - /* if original file does exist throw away the copy */ - if (os_file_exists(fname)) { + // if original file does exist throw away the copy + if (os_path_exists(fname)) { os_remove((char *)backup); } } else { @@ -3238,8 +3239,8 @@ restore_backup: } } - /* if original file no longer exists give an extra warning */ - if (!newfile && !os_file_exists(fname)) { + // if original file no longer exists give an extra warning + if (!newfile && !os_path_exists(fname)) { end = 0; } } @@ -3597,9 +3598,9 @@ restore_backup: * If the original file does not exist yet * the current backup file becomes the original file */ - if (org == NULL) + if (org == NULL) { EMSG(_("E205: Patchmode: can't save original file")); - else if (!os_file_exists((char_u *)org)) { + } else if (!os_path_exists((char_u *)org)) { vim_rename(backup, (char_u *)org); xfree(backup); /* don't delete the file */ backup = NULL; @@ -4514,9 +4515,11 @@ int vim_rename(char_u *from, char_u *to) if (STRLEN(from) >= MAXPATHL - 5) return -1; STRCPY(tempname, from); - for (n = 123; n < 99999; ++n) { - sprintf((char *)path_tail(tempname), "%d", n); - if (!os_file_exists(tempname)) { + for (n = 123; n < 99999; n++) { + char * tail = (char *)path_tail(tempname); + snprintf(tail, (MAXPATHL + 1) - (tail - (char *)tempname - 1), "%d", n); + + if (!os_path_exists(tempname)) { if (os_rename(from, tempname) == OK) { if (os_rename(tempname, to) == OK) return 0; @@ -4863,7 +4866,7 @@ buf_check_timestamp ( } } else if ((buf->b_flags & BF_NEW) && !(buf->b_flags & BF_NEW_W) - && os_file_exists(buf->b_ffname)) { + && os_path_exists(buf->b_ffname)) { retval = 1; mesg = _("W13: Warning: File \"%s\" has been created after editing started"); buf->b_flags |= BF_NEW_W; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 42fde50bee..f2610ac868 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -414,7 +414,7 @@ EXTERN int provider_call_nesting INIT(= 0); EXTERN char_u hash_removed; -EXTERN int t_colors INIT(= 0); /* int value of T_CCO */ +EXTERN int t_colors INIT(= 256); // int value of T_CCO /* * When highlight_match is TRUE, highlight a match, starting at the cursor @@ -914,9 +914,6 @@ EXTERN int KeyTyped; // TRUE if user typed current char EXTERN int KeyStuffed; // TRUE if current char from stuffbuf EXTERN int maptick INIT(= 0); // tick for each non-mapped char -EXTERN uint8_t chartab[256]; // table used in charset.c; See - // init_chartab() for explanation - EXTERN int must_redraw INIT(= 0); /* type of redraw necessary */ EXTERN int skip_redraw INIT(= FALSE); /* skip redraw once */ EXTERN int do_redraw INIT(= FALSE); /* extra redraw once */ @@ -1223,6 +1220,8 @@ EXTERN char_u e_invalpat[] INIT(= N_( EXTERN char_u e_bufloaded[] INIT(= N_("E139: File is loaded in another buffer")); EXTERN char_u e_notset[] INIT(= N_("E764: Option '%s' is not set")); EXTERN char_u e_invalidreg[] INIT(= N_("E850: Invalid register name")); +EXTERN char_u e_dirnotf[] INIT(= N_( + "E919: Directory not found in '%s': \"%s\"")); EXTERN char_u e_unsupportedoption[] INIT(= N_("E519: Option not supported")); diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index 916d27a964..1c9b8e18ef 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -1526,8 +1526,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) vim_strcat(buffer, (char_u *)name, MAXPATHL); vim_strcat(buffer, (char_u *)".ps", MAXPATHL); resource->filename[0] = NUL; - retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name, - resource->filename) + retval = (do_in_runtimepath(buffer, 0, prt_resource_name, resource->filename) && resource->filename[0] != NUL); xfree(buffer); return retval; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index 2f9ec0b3ff..f2432dd71d 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -480,8 +480,9 @@ staterr: if (arg2 != NULL) { ppath = xmalloc(MAXPATHL + 1); expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL); - if (!os_file_exists((char_u *)ppath)) + if (!os_path_exists((char_u *)ppath)) { goto staterr; + } } int i; diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 5f69fa2f6a..503daa9648 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -73,11 +73,6 @@ /* Returns empty string if it is NULL. */ #define EMPTY_IF_NULL(x) ((x) ? (x) : (char_u *)"") -/* macro version of chartab(). - * Only works with values 0-255! - * Doesn't work for UTF-8 mode with chars >= 0x80. */ -#define CHARSIZE(c) (chartab[c] & CT_CELL_MASK) - /* * Adjust chars in a language according to 'langmap' option. * NOTE that there is no noticeable overhead if 'langmap' is not set. diff --git a/src/nvim/main.c b/src/nvim/main.c index ba545c0815..e052d0d315 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -276,7 +276,6 @@ int main(int argc, char **argv) printf(_("%d files to edit\n"), GARGCOUNT); full_screen = true; - t_colors = 256; check_tty(¶ms); /* @@ -507,6 +506,9 @@ int main(int argc, char **argv) no_wait_return = FALSE; starting = 0; + // 'autochdir' has been postponed. + do_autochdir(); + /* start in insert mode */ if (p_im) need_start_insertmode = TRUE; @@ -668,8 +670,8 @@ static void init_locale(void) { char_u *p; - /* expand_env() doesn't work yet, because chartab[] is not initialized - * yet, call vim_getenv() directly */ + // expand_env() doesn't work yet, because g_chartab[] is not + // initialized yet, call vim_getenv() directly p = (char_u *)vim_getenv("VIMRUNTIME"); if (p != NULL && *p != NUL) { vim_snprintf((char *)NameBuff, MAXPATHL, "%s/lang", p); @@ -1239,8 +1241,11 @@ static void set_window_layout(mparm_T *paramp) static void load_plugins(void) { if (p_lpl) { - source_runtime((char_u *)"plugin/**/*.vim", TRUE); + source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL); // NOLINT TIME_MSG("loading plugins"); + + ex_packloadall(NULL); + TIME_MSG("loading packages"); } } @@ -1668,8 +1673,6 @@ static bool do_user_initialization(void) } /// Source startup scripts -/// -/// @param[in] static void source_startup_scripts(const mparm_T *const parmp) FUNC_ATTR_NONNULL_ALL { diff --git a/src/nvim/map.c b/src/nvim/map.c index 03439e7a9c..398e74268f 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -129,7 +129,10 @@ static inline khint_t String_hash(String s) static inline bool String_eq(String a, String b) { - return strncmp(a.data, b.data, MIN(a.size, b.size)) == 0; + if (a.size != b.size) { + return false; + } + return memcmp(a.data, b.data, a.size) == 0; } diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 9c20f15727..673205f08f 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1359,7 +1359,7 @@ recover_names ( if (*dirp == NUL && file_count + num_files == 0 && fname != NULL) { char_u *swapname = (char_u *)modname((char *)fname_res, ".swp", TRUE); if (swapname != NULL) { - if (os_file_exists(swapname)) { + if (os_path_exists(swapname)) { files = xmalloc(sizeof(char_u *)); files[0] = swapname; swapname = NULL; @@ -3426,11 +3426,11 @@ static char *findswapname(buf_T *buf, char **dirp, char *old_fname, break; } - /* If the file was deleted this fname can be used. */ - if (!os_file_exists((char_u *) fname)) + // If the file was deleted this fname can be used. + if (!os_path_exists((char_u *)fname)) { break; - } else - { + } + } else { MSG_PUTS("\n"); if (msg_silent == 0) /* call wait_return() later */ diff --git a/src/nvim/ops.c b/src/nvim/ops.c index cb068aa37f..25b3b85497 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1613,7 +1613,7 @@ int op_replace(oparg_T *oap, int c) int n, numc; int num_chars; char_u *newp, *oldp; - size_t oldlen; + colnr_T oldlen; struct block_def bd; char_u *after_p = NULL; int had_ctrl_v_cr = (c == -1 || c == -2); @@ -1681,14 +1681,19 @@ int op_replace(oparg_T *oap, int c) /* Compute bytes needed, move character count to num_chars. */ num_chars = numc; numc *= (*mb_char2len)(c); - /* oldlen includes textlen, so don't double count */ - n += numc - bd.textlen; oldp = get_cursor_line_ptr(); - oldlen = STRLEN(oldp); - assert(n >= 0); - newp = (char_u *)xmalloc(oldlen + 1 + (size_t)n); - memset(newp, NUL, oldlen + 1 + (size_t)n); + oldlen = (int)STRLEN(oldp); + + size_t newp_size = (size_t)(bd.textcol + bd.startspaces); + if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { + newp_size += (size_t)numc; + if (!bd.is_short) { + newp_size += (size_t)(bd.endspaces + oldlen + - bd.textcol - bd.textlen); + } + } + newp = xmallocz(newp_size); // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); oldp += bd.textcol + bd.textlen; @@ -1696,28 +1701,36 @@ int op_replace(oparg_T *oap, int c) memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); // insert replacement chars CHECK FOR ALLOCATED SPACE // -1/-2 is used for entering CR literally. + size_t after_p_len = 0; if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { - if (has_mbyte) { - n = (int)STRLEN(newp); - while (--num_chars >= 0) - n += (*mb_char2bytes)(c, newp + n); - } else - memset(newp + STRLEN(newp), c, (size_t)numc); - if (!bd.is_short) { - /* insert post-spaces */ - memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); - /* copy the part after the changed part */ - STRMOVE(newp + STRLEN(newp), oldp); + // strlen(newp) at this point + int newp_len = bd.textcol + bd.startspaces; + if (has_mbyte) { + while (--num_chars >= 0) { + newp_len += (*mb_char2bytes)(c, newp + newp_len); + } + } else { + memset(newp + newp_len, c, (size_t)numc); + newp_len += numc; + } + if (!bd.is_short) { + // insert post-spaces + memset(newp + newp_len, ' ', (size_t)bd.endspaces); + newp_len += bd.endspaces; + // copy the part after the changed part + memmove(newp + newp_len, oldp, + (size_t)(oldlen - bd.textcol - bd.textlen + 1)); } } else { // Replacing with \r or \n means splitting the line. - after_p = (char_u *)xmalloc(oldlen + 1 + (size_t)n - STRLEN(newp)); - STRMOVE(after_p, oldp); + after_p_len = (size_t)(oldlen - bd.textcol - bd.textlen + 1); + after_p = (char_u *)xmalloc(after_p_len); + memmove(after_p, oldp, after_p_len); } /* replace the line */ ml_replace(curwin->w_cursor.lnum, newp, FALSE); if (after_p != NULL) { - ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); + ml_append(curwin->w_cursor.lnum++, after_p, (int)after_p_len, false); appended_lines_mark(curwin->w_cursor.lnum, 1L); oap->end.lnum++; xfree(after_p); @@ -5439,7 +5452,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing) yankreg_T *target; if (cb_flags & CB_UNNAMEDPLUS) { - *name = cb_flags & CB_UNNAMED ? '"': '+'; + *name = (cb_flags & CB_UNNAMED && writing) ? '"': '+'; target = &y_regs[PLUS_REGISTER]; } else { *name = '*'; diff --git a/src/nvim/option.c b/src/nvim/option.c index 020a119fd3..de53b0b1f4 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2439,16 +2439,13 @@ did_set_string_option ( else if (varp == &curwin->w_p_briopt) { if (briopt_check(curwin) == FAIL) errmsg = e_invarg; - } - /* - * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[] - * If the new option is invalid, use old value. 'lisp' option: refill - * chartab[] for '-' char - */ - else if ( varp == &p_isi + } else if (varp == &p_isi || varp == &(curbuf->b_p_isk) || varp == &p_isp || varp == &p_isf) { + // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] + // If the new option is invalid, use old value. 'lisp' option: refill + // g_chartab[] for '-' char if (init_chartab() == FAIL) { did_chartab = TRUE; /* need to restore it below */ errmsg = e_invarg; /* error in value */ @@ -3187,8 +3184,9 @@ did_set_string_option ( for (p = q; *p != NUL; ++p) if (vim_strchr((char_u *)"_.,", *p) != NULL) break; - vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q); - source_runtime(fname, TRUE); + vim_snprintf((char *)fname, sizeof(fname), "spell/%.*s.vim", + (int)(p - q), q); + source_runtime(fname, DIP_ALL); } } @@ -4404,6 +4402,7 @@ bool get_tty_option(char *name, char **value) if (is_tty_option(name)) { if (value) { + // XXX: All other t_* options were removed in 3baba1e7. *value = xstrdup(""); } return true; @@ -5838,6 +5837,7 @@ set_context_in_set_cmd ( if (p == (char_u *)&p_bdir || p == (char_u *)&p_dir || p == (char_u *)&p_path + || p == (char_u *)&p_pp || p == (char_u *)&p_rtp || p == (char_u *)&p_cdpath || p == (char_u *)&p_vdir diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index b1a2b00bdb..8d6f42e088 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -456,80 +456,81 @@ EXTERN int p_hid; // 'hidden' // Use P_HID to check if a buffer is to be hidden when it is no longer // visible in a window. # define P_HID(buf) (buf_hide(buf)) -EXTERN char_u *p_hl; /* 'highlight' */ -EXTERN int p_hls; /* 'hlsearch' */ -EXTERN long p_hi; /* 'history' */ -EXTERN int p_hkmap; /* 'hkmap' */ -EXTERN int p_hkmapp; /* 'hkmapp' */ -EXTERN int p_fkmap; /* 'fkmap' */ -EXTERN int p_altkeymap; /* 'altkeymap' */ -EXTERN int p_arshape; /* 'arabicshape' */ -EXTERN int p_icon; /* 'icon' */ -EXTERN char_u *p_iconstring; /* 'iconstring' */ -EXTERN int p_ic; /* 'ignorecase' */ -EXTERN int p_is; /* 'incsearch' */ -EXTERN int p_im; /* 'insertmode' */ -EXTERN char_u *p_isf; /* 'isfname' */ -EXTERN char_u *p_isi; /* 'isident' */ -EXTERN char_u *p_isp; /* 'isprint' */ -EXTERN int p_js; /* 'joinspaces' */ -EXTERN char_u *p_kp; /* 'keywordprg' */ -EXTERN char_u *p_km; /* 'keymodel' */ -EXTERN char_u *p_langmap; /* 'langmap'*/ -EXTERN int p_lnr; /* 'langnoremap'*/ -EXTERN char_u *p_lm; /* 'langmenu' */ -EXTERN char_u *p_lispwords; /* 'lispwords' */ -EXTERN long p_ls; /* 'laststatus' */ -EXTERN long p_stal; /* 'showtabline' */ -EXTERN char_u *p_lcs; /* 'listchars' */ - -EXTERN int p_lz; /* 'lazyredraw' */ -EXTERN int p_lpl; /* 'loadplugins' */ -EXTERN int p_magic; /* 'magic' */ -EXTERN char_u *p_mef; /* 'makeef' */ -EXTERN char_u *p_mp; /* 'makeprg' */ -EXTERN char_u *p_cc; /* 'colorcolumn' */ -EXTERN int p_cc_cols[256]; /* array for 'colorcolumn' columns */ -EXTERN long p_mat; /* 'matchtime' */ -EXTERN long p_mco; /* 'maxcombine' */ -EXTERN long p_mfd; /* 'maxfuncdepth' */ -EXTERN long p_mmd; /* 'maxmapdepth' */ -EXTERN long p_mm; /* 'maxmem' */ -EXTERN long p_mmp; /* 'maxmempattern' */ -EXTERN long p_mmt; /* 'maxmemtot' */ -EXTERN long p_mis; /* 'menuitems' */ -EXTERN char_u *p_msm; /* 'mkspellmem' */ -EXTERN long p_mls; /* 'modelines' */ -EXTERN char_u *p_mouse; /* 'mouse' */ -EXTERN char_u *p_mousem; /* 'mousemodel' */ -EXTERN long p_mouset; /* 'mousetime' */ -EXTERN int p_more; /* 'more' */ -EXTERN char_u *p_opfunc; /* 'operatorfunc' */ -EXTERN char_u *p_para; /* 'paragraphs' */ -EXTERN int p_paste; /* 'paste' */ -EXTERN char_u *p_pt; /* 'pastetoggle' */ -EXTERN char_u *p_pex; /* 'patchexpr' */ -EXTERN char_u *p_pm; /* 'patchmode' */ -EXTERN char_u *p_path; /* 'path' */ -EXTERN char_u *p_cdpath; /* 'cdpath' */ -EXTERN long p_rdt; /* 'redrawtime' */ -EXTERN int p_remap; /* 'remap' */ -EXTERN long p_re; /* 'regexpengine' */ -EXTERN long p_report; /* 'report' */ -EXTERN long p_pvh; /* 'previewheight' */ -EXTERN int p_ari; /* 'allowrevins' */ -EXTERN int p_ri; /* 'revins' */ -EXTERN int p_ru; /* 'ruler' */ -EXTERN char_u *p_ruf; /* 'rulerformat' */ -EXTERN char_u *p_rtp; /* 'runtimepath' */ -EXTERN long p_sj; /* 'scrolljump' */ -EXTERN long p_so; /* 'scrolloff' */ -EXTERN char_u *p_sbo; /* 'scrollopt' */ -EXTERN char_u *p_sections; /* 'sections' */ -EXTERN int p_secure; /* 'secure' */ -EXTERN char_u *p_sel; /* 'selection' */ -EXTERN char_u *p_slm; /* 'selectmode' */ -EXTERN char_u *p_ssop; /* 'sessionoptions' */ +EXTERN char_u *p_hl; // 'highlight' +EXTERN int p_hls; // 'hlsearch' +EXTERN long p_hi; // 'history' +EXTERN int p_hkmap; // 'hkmap' +EXTERN int p_hkmapp; // 'hkmapp' +EXTERN int p_fkmap; // 'fkmap' +EXTERN int p_altkeymap; // 'altkeymap' +EXTERN int p_arshape; // 'arabicshape' +EXTERN int p_icon; // 'icon' +EXTERN char_u *p_iconstring; // 'iconstring' +EXTERN int p_ic; // 'ignorecase' +EXTERN int p_is; // 'incsearch' +EXTERN int p_im; // 'insertmode' +EXTERN char_u *p_isf; // 'isfname' +EXTERN char_u *p_isi; // 'isident' +EXTERN char_u *p_isp; // 'isprint' +EXTERN int p_js; // 'joinspaces' +EXTERN char_u *p_kp; // 'keywordprg' +EXTERN char_u *p_km; // 'keymodel' +EXTERN char_u *p_langmap; // 'langmap'*/ +EXTERN int p_lnr; // 'langnoremap'*/ +EXTERN char_u *p_lm; // 'langmenu' +EXTERN char_u *p_lispwords; // 'lispwords' +EXTERN long p_ls; // 'laststatus' +EXTERN long p_stal; // 'showtabline' +EXTERN char_u *p_lcs; // 'listchars' + +EXTERN int p_lz; // 'lazyredraw' +EXTERN int p_lpl; // 'loadplugins' +EXTERN int p_magic; // 'magic' +EXTERN char_u *p_mef; // 'makeef' +EXTERN char_u *p_mp; // 'makeprg' +EXTERN char_u *p_cc; // 'colorcolumn' +EXTERN int p_cc_cols[256]; // array for 'colorcolumn' columns +EXTERN long p_mat; // 'matchtime' +EXTERN long p_mco; // 'maxcombine' +EXTERN long p_mfd; // 'maxfuncdepth' +EXTERN long p_mmd; // 'maxmapdepth' +EXTERN long p_mm; // 'maxmem' +EXTERN long p_mmp; // 'maxmempattern' +EXTERN long p_mmt; // 'maxmemtot' +EXTERN long p_mis; // 'menuitems' +EXTERN char_u *p_msm; // 'mkspellmem' +EXTERN long p_mls; // 'modelines' +EXTERN char_u *p_mouse; // 'mouse' +EXTERN char_u *p_mousem; // 'mousemodel' +EXTERN long p_mouset; // 'mousetime' +EXTERN int p_more; // 'more' +EXTERN char_u *p_opfunc; // 'operatorfunc' +EXTERN char_u *p_para; // 'paragraphs' +EXTERN int p_paste; // 'paste' +EXTERN char_u *p_pt; // 'pastetoggle' +EXTERN char_u *p_pex; // 'patchexpr' +EXTERN char_u *p_pm; // 'patchmode' +EXTERN char_u *p_path; // 'path' +EXTERN char_u *p_cdpath; // 'cdpath' +EXTERN long p_rdt; // 'redrawtime' +EXTERN int p_remap; // 'remap' +EXTERN long p_re; // 'regexpengine' +EXTERN long p_report; // 'report' +EXTERN long p_pvh; // 'previewheight' +EXTERN int p_ari; // 'allowrevins' +EXTERN int p_ri; // 'revins' +EXTERN int p_ru; // 'ruler' +EXTERN char_u *p_ruf; // 'rulerformat' +EXTERN char_u *p_pp; // 'packpath' +EXTERN char_u *p_rtp; // 'runtimepath' +EXTERN long p_sj; // 'scrolljump' +EXTERN long p_so; // 'scrolloff' +EXTERN char_u *p_sbo; // 'scrollopt' +EXTERN char_u *p_sections; // 'sections' +EXTERN int p_secure; // 'secure' +EXTERN char_u *p_sel; // 'selection' +EXTERN char_u *p_slm; // 'selectmode' +EXTERN char_u *p_ssop; // 'sessionoptions' EXTERN unsigned ssop_flags; # ifdef IN_OPTION_C /* Also used for 'viewoptions'! */ diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 218e34f595..d19af4f73f 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1640,6 +1640,16 @@ return { defaults={if_true={vi=""}} }, { + full_name='packpath', abbreviation='pp', + type='string', list='onecomma', scope={'global'}, + deny_duplicates=true, + secure=true, + vi_def=true, + expand=true, + varname='p_pp', + defaults={if_true={vi=''}} + }, + { full_name='paragraphs', abbreviation='para', type='string', scope={'global'}, vi_def=true, diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 49c42cb63d..d12d34d595 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -599,14 +599,14 @@ int os_fchown(int fd, uv_uid_t owner, uv_gid_t group) return r; } -/// Check if a file exists. +/// Check if a path exists. /// -/// @return `true` if `name` exists. -bool os_file_exists(const char_u *name) +/// @return `true` if `path` exists +bool os_path_exists(const char_u *path) FUNC_ATTR_NONNULL_ALL { uv_stat_t statbuf; - return os_stat((char *)name, &statbuf) == kLibuvSuccess; + return os_stat((char *)path, &statbuf) == kLibuvSuccess; } /// Check if a file is readable. diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 988620b145..64c673930a 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -310,25 +310,70 @@ static void system_data_cb(Stream *stream, RBuffer *buf, size_t count, dbuf->len += nread; } +/// Continue to append data to last screen line. +/// +/// @param output Data to append to screen lines. +/// @param remaining Size of data. +/// @param new_line If true, next data output will be on a new line. +static void append_to_screen_end(char *output, size_t remaining, bool new_line) +{ + // Column of last row to start appending data to. + static colnr_T last_col = 0; + + size_t off = 0; + int last_row = (int)Rows - 1; + + while (off < remaining) { + // Found end of line? + if (output[off] == NL) { + // Can we start a new line or do we need to continue the last one? + if (last_col == 0) { + screen_del_lines(0, 0, 1, (int)Rows, NULL); + } + screen_puts_len((char_u *)output, (int)off, last_row, last_col, 0); + last_col = 0; + + size_t skip = off + 1; + output += skip; + remaining -= skip; + off = 0; + continue; + } + + // Translate NUL to SOH + if (output[off] == NUL) { + output[off] = 1; + } + + off++; + } + + if (remaining) { + if (last_col == 0) { + screen_del_lines(0, 0, 1, (int)Rows, NULL); + } + screen_puts_len((char_u *)output, (int)remaining, last_row, last_col, 0); + last_col += (colnr_T)remaining; + } + + if (new_line) { + last_col = 0; + } + + ui_flush(); +} + static void out_data_cb(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof) { + // We always output the whole buffer, so the buffer can never + // wrap around. size_t cnt; char *ptr = rbuffer_read_ptr(buf, &cnt); - if (!cnt) { - return; - } - - size_t written = write_output(ptr, cnt, false, eof); - // No output written, force emptying the Rbuffer if it is full. - if (!written && rbuffer_size(buf) == rbuffer_capacity(buf)) { - screen_del_lines(0, 0, 1, (int)Rows, NULL); - screen_puts_len((char_u *)ptr, (int)cnt, (int)Rows - 1, 0, 0); - written = cnt; - } - if (written) { - rbuffer_consumed(buf, written); + append_to_screen_end(ptr, cnt, eof); + if (cnt) { + rbuffer_consumed(buf, cnt); } } diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 2ed0c2c856..def7e3b0e5 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -566,10 +566,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, /* * Move the file names to allocated memory. */ - for (j = 0, i = 0; i < *num_file; ++i) { - /* Require the files to exist. Helps when using /bin/sh */ - if (!(flags & EW_NOTFOUND) && !os_file_exists((*file)[i])) + for (j = 0, i = 0; i < *num_file; i++) { + // Require the files to exist. Helps when using /bin/sh + if (!(flags & EW_NOTFOUND) && !os_path_exists((*file)[i])) { continue; + } /* check if this entry should be included */ dir = (os_isdir((*file)[i])); diff --git a/src/nvim/path.c b/src/nvim/path.c index 41fd69f238..57499429ec 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -684,7 +684,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, } // add existing file or symbolic link if ((flags & EW_ALLLINKS) ? os_fileinfo_link((char *)buf, &file_info) - : os_file_exists(buf)) { + : os_path_exists(buf)) { addfile(gap, buf, flags); } } @@ -1205,10 +1205,11 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, /* When EW_NOTFOUND is used, always add files and dirs. Makes * "vim c:/" work. */ - if (flags & EW_NOTFOUND) + if (flags & EW_NOTFOUND) { addfile(&ga, t, flags | EW_DIR | EW_FILE); - else if (os_file_exists(t)) + } else if (os_path_exists(t)) { addfile(&ga, t, flags); + } xfree(t); } @@ -1327,7 +1328,7 @@ void addfile( if (!(flags & EW_NOTFOUND) && ((flags & EW_ALLLINKS) ? !os_fileinfo_link((char *)f, &file_info) - : !os_file_exists(f))) { + : !os_path_exists(f))) { return; } diff --git a/src/nvim/po/ja.po b/src/nvim/po/ja.po index 8a3fcb8f78..0326f33bb5 100644 --- a/src/nvim/po/ja.po +++ b/src/nvim/po/ja.po @@ -5653,7 +5653,7 @@ msgstr "単語 '%.*s' が %s から削除されました" #: ../spell.c:8117 #, c-format msgid "Word '%.*s' added to %s" -msgstr "%s に単語が追加されました" +msgstr "単語 '%.*s' が %s へ追加されました" #: ../spell.c:8381 msgid "E763: Word characters differ between spell files" diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 629e7858b3..dfd795b0ba 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -571,8 +571,9 @@ restofline: *regmatch.endp[i] = c; if (vim_strchr((char_u *)"OPQ", idx) != NULL - && !os_file_exists(namebuf)) + && !os_path_exists(namebuf)) { continue; + } } if ((i = (int)fmt_ptr->addr[1]) > 0) { /* %n */ if (regmatch.startp[i] == NULL) @@ -706,11 +707,12 @@ restofline: } else if (vim_strchr((char_u *)"OPQ", idx) != NULL) { // global file names valid = false; - if (*namebuf == NUL || os_file_exists(namebuf)) { - if (*namebuf && idx == 'P') + if (*namebuf == NUL || os_path_exists(namebuf)) { + if (*namebuf && idx == 'P') { currfile = qf_push_dir(namebuf, &file_stack); - else if (idx == 'Q') + } else if (idx == 'Q') { currfile = qf_pop_dir(&file_stack); + } *namebuf = NUL; if (tail && *tail) { STRMOVE(IObuff, skipwhite(tail)); @@ -1080,7 +1082,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname) * "leaving directory"-messages we might have missed a * directory change. */ - if (!os_file_exists(ptr)) { + if (!os_path_exists(ptr)) { xfree(ptr); directory = qf_guess_filepath(fname); if (directory) @@ -1232,8 +1234,9 @@ static char_u *qf_guess_filepath(char_u *filename) xfree(fullname); fullname = (char_u *)concat_fnames((char *)ds_ptr->dirname, (char *)filename, TRUE); - if (os_file_exists(fullname)) + if (os_path_exists(fullname)) { break; + } ds_ptr = ds_ptr->next; } diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c index d4cc8c0d5d..a2cc432eca 100644 --- a/src/nvim/rbuffer.c +++ b/src/nvim/rbuffer.c @@ -15,7 +15,7 @@ RBuffer *rbuffer_new(size_t capacity) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET { if (!capacity) { - capacity = 0xffff; + capacity = 0x10000; } RBuffer *rv = xmalloc(sizeof(RBuffer) + capacity); diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 34eef83164..d67142822f 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3416,12 +3416,10 @@ win_line ( /* * Handling of non-printable characters. */ - if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) { - /* - * when getting a character from the file, we may have to - * turn it into something else on the way to putting it - * into "ScreenLines". - */ + if (!vim_isprintc(c)) { + // when getting a character from the file, we may have to + // turn it into something else on the way to putting it + // into "ScreenLines". if (c == TAB && (!wp->w_p_list || lcs_tab1)) { int tab_len = 0; long vcol_adjusted = vcol; // removed showbreak length diff --git a/src/nvim/spell.c b/src/nvim/spell.c index d2401b6776..610fb660e7 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2317,16 +2317,14 @@ static void spell_load_lang(char_u *lang) for (round = 1; round <= 2; ++round) { // Find the first spell file for "lang" in 'runtimepath' and load it. vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, - "spell/%s.%s.spl", - lang, spell_enc()); - r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl); + "spell/%s.%s.spl", lang, spell_enc()); + r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); if (r == FAIL && *sl.sl_lang != NUL) { // Try loading the ASCII version. vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, - "spell/%s.ascii.spl", - lang); - r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl); + "spell/%s.ascii.spl", lang); + r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); if (r == FAIL && *sl.sl_lang != NUL && round == 1 && apply_autocmds(EVENT_SPELLFILEMISSING, lang, @@ -2354,7 +2352,7 @@ static void spell_load_lang(char_u *lang) } else if (sl.sl_slang != NULL) { // At least one file was loaded, now load ALL the additions. STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl"); - do_in_runtimepath(fname_enc, TRUE, spell_load_cb, &sl); + do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl); } } @@ -7630,7 +7628,7 @@ mkspell ( else { // Check for overwriting before doing things that may take a lot of // time. - if (!over_write && os_file_exists(wfname)) { + if (!over_write && os_path_exists(wfname)) { EMSG(_(e_exists)); goto theend; } @@ -7686,7 +7684,7 @@ mkspell ( spin.si_region = 1 << i; vim_snprintf((char *)fname, MAXPATHL, "%s.aff", innames[i]); - if (os_file_exists(fname)) { + if (os_path_exists(fname)) { // Read the .aff file. Will init "spin->si_conv" based on the // "SET" line. afile[i] = spell_read_aff(&spin, fname); diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 05141eaf1e..27855184df 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4207,9 +4207,10 @@ static void syn_cmd_include(exarg_T *eap, int syncing) current_syn_inc_tag = ++running_syn_inc_tag; prev_toplvl_grp = curwin->w_s->b_syn_topgrp; curwin->w_s->b_syn_topgrp = sgl_id; - if (source ? do_source(eap->arg, FALSE, DOSO_NONE) == FAIL - : source_runtime(eap->arg, TRUE) == FAIL) + if (source ? do_source(eap->arg, false, DOSO_NONE) == FAIL + : source_runtime(eap->arg, DIP_ALL) == FAIL) { EMSG2(_(e_notopen), eap->arg); + } curwin->w_s->b_syn_topgrp = prev_toplvl_grp; current_syn_inc_tag = prev_syn_inc_tag; } @@ -6023,12 +6024,12 @@ init_highlight ( if (get_var_value((char_u *)"g:syntax_on") != NULL) { static int recursive = 0; - if (recursive >= 5) + if (recursive >= 5) { EMSG(_("E679: recursive loop loading syncolor.vim")); - else { - ++recursive; - (void)source_runtime((char_u *)"syntax/syncolor.vim", TRUE); - --recursive; + } else { + recursive++; + (void)source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL); + recursive--; } } } @@ -6041,22 +6042,24 @@ int load_colors(char_u *name) { char_u *buf; int retval = FAIL; - static int recursive = FALSE; + static int recursive = false; - /* When being called recursively, this is probably because setting - * 'background' caused the highlighting to be reloaded. This means it is - * working, thus we should return OK. */ - if (recursive) + // When being called recursively, this is probably because setting + // 'background' caused the highlighting to be reloaded. This means it is + // working, thus we should return OK. + if (recursive) { return OK; + } - recursive = TRUE; - buf = xmalloc(STRLEN(name) + 12); - sprintf((char *)buf, "colors/%s.vim", name); - retval = source_runtime(buf, FALSE); + recursive = true; + size_t buflen = STRLEN(name) + 12; + buf = xmalloc(buflen); + snprintf((char *)buf, buflen, "colors/%s.vim", name); + retval = source_runtime(buf, DIP_START + DIP_OPT); xfree(buf); apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); - recursive = FALSE; + recursive = false; ui_refresh(); return retval; diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 7885d467d8..dfecfb776d 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2023,9 +2023,8 @@ get_tagfname ( if (first) { ga_clear_strings(&tag_fnames); ga_init(&tag_fnames, (int)sizeof(char_u *), 10); - do_in_runtimepath((char_u *) - "doc/tags doc/tags-??" - , TRUE, found_tagfile_cb, NULL); + do_in_runtimepath((char_u *)"doc/tags doc/tags-??", DIP_ALL, + found_tagfile_cb, NULL); } if (tnp->tn_hf_idx >= tag_fnames.ga_len) { @@ -2353,7 +2352,7 @@ jumpto_tag ( * file. Also accept a file name for which there is a matching BufReadCmd * autocommand event (e.g., http://sys/file). */ - if (!os_file_exists(fname) + if (!os_path_exists(fname) && !has_autocmd(EVENT_BUFREADCMD, fname, NULL) ) { retval = NOTAGFILE; diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index fd416b3dcc..6f50c03be9 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -241,6 +241,7 @@ Terminal *terminal_open(TerminalOptions opts) set_option_value((uint8_t *)"wrap", false, NULL, OPT_LOCAL); set_option_value((uint8_t *)"number", false, NULL, OPT_LOCAL); set_option_value((uint8_t *)"relativenumber", false, NULL, OPT_LOCAL); + buf_set_term_title(curbuf, (char *)curbuf->b_ffname); RESET_BINDING(curwin); // Apply TermOpen autocmds so the user can configure the terminal apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf); @@ -618,6 +619,17 @@ static int term_movecursor(VTermPos new, VTermPos old, int visible, return 1; } +static void buf_set_term_title(buf_T *buf, char *title) + FUNC_ATTR_NONNULL_ALL +{ + Error err; + api_free_object(dict_set_value(buf->b_vars, + cstr_as_string("term_title"), + STRING_OBJ(cstr_as_string(title)), + false, + &err)); +} + static int term_settermprop(VTermProp prop, VTermValue *val, void *data) { Terminal *term = data; @@ -633,12 +645,7 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data) case VTERM_PROP_TITLE: { buf_T *buf = handle_get_buffer(term->buf_handle); - Error err; - api_free_object(dict_set_value(buf->b_vars, - cstr_as_string("term_title"), - STRING_OBJ(cstr_as_string(val->string)), - false, - &err)); + buf_set_term_title(buf, val->string); break; } diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 578d64efde..1b1f5d7688 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -39,6 +39,9 @@ set nomore " Output all messages in English. lang mess C +" Always use forward slashes. +set shellslash + " Source the test script. First grab the file name, in case the script " navigates away. let testname = expand('%') diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 50558e644a..d220df508a 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -135,6 +135,8 @@ static void terminfo_start(UI *ui) data->ut = unibi_dummy(); } fix_terminfo(data); + // Set 't_Co' from the result of unibilium & fix_terminfo. + t_colors = unibi_get_num(data->ut, unibi_max_colors); // Enter alternate screen and clear unibi_out(ui, unibi_enter_ca_mode); unibi_out(ui, unibi_clear_screen); @@ -786,6 +788,7 @@ static void fix_terminfo(TUIData *data) unibi_term *ut = data->ut; const char *term = os_getenv("TERM"); + const char *colorterm = os_getenv("COLORTERM"); if (!term) { goto end; } @@ -831,10 +834,10 @@ static void fix_terminfo(TUIData *data) #define XTERM_SETAB \ "\x1b[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m" - if (os_getenv("COLORTERM") != NULL - && (!strcmp(term, "xterm") || !strcmp(term, "screen"))) { - // probably every modern terminal that sets TERM=xterm supports 256 - // colors(eg: gnome-terminal). Also do it when TERM=screen. + if ((colorterm && strstr(colorterm, "256")) + || strstr(term, "256") + || strstr(term, "xterm")) { + // Assume TERM~=xterm or COLORTERM~=256 supports 256 colors. unibi_set_num(ut, unibi_max_colors, 256); unibi_set_str(ut, unibi_set_a_foreground, XTERM_SETAF); unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB); diff --git a/src/nvim/undo.c b/src/nvim/undo.c index f16b4264d7..fc5d6acaa4 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -712,7 +712,7 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) // When reading check if the file exists. if (undo_file_name != NULL - && (!reading || os_file_exists((char_u *)undo_file_name))) { + && (!reading || os_path_exists((char_u *)undo_file_name))) { break; } xfree(undo_file_name); @@ -1094,7 +1094,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf, /* If the undo file already exists, verify that it actually is an undo * file, and delete it. */ - if (os_file_exists((char_u *)file_name)) { + if (os_path_exists((char_u *)file_name)) { if (name == NULL || !forceit) { /* Check we can read it and it's an undo file. */ fd = os_open(file_name, O_RDONLY, 0); diff --git a/src/nvim/version.c b/src/nvim/version.c index 50205f4b2b..966e4f9b4f 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -75,7 +75,9 @@ static char *features[] = { // clang-format off static int included_patches[] = { + 1973, 1960, + 1840, 1832, 1831, 1809, @@ -86,9 +88,12 @@ static int included_patches[] = { 1755, 1753, 1728, + 1716, + 1712, 1695, 1654, 1652, + 1649, 1643, 1641, // 1624 NA @@ -97,7 +102,7 @@ static int included_patches[] = { // 1599 NA // 1598 NA // 1597 NA - // 1596, + 1596, // 1595 NA // 1594 NA // 1593 NA @@ -115,13 +120,13 @@ static int included_patches[] = { // 1581, // 1580, - // 1579, + // 1579 NA 1578, // 1577, 1576, // 1575 NA 1574, - // 1573, + // 1573 NA // 1572 NA 1571, 1570, @@ -134,17 +139,17 @@ static int included_patches[] = { // 1563, // 1562 NA // 1561 NA - // 1560, + // 1560 NA // 1559, // 1558, // 1557, - // 1556, - // 1555, - // 1554, - // 1553, - // 1552, - // 1551, - // 1550, + // 1556 NA + // 1555 NA + 1554, + 1553, + 1552, + 1551, + 1550, // 1549, // 1548, // 1547, @@ -166,7 +171,7 @@ static int included_patches[] = { // 1531 NA // 1530 NA // 1529 NA - // 1528, + 1528, // 1527 NA // 1526 NA // 1525 NA @@ -195,28 +200,28 @@ static int included_patches[] = { // 1502 NA // 1501 NA 1500, - // 1499, + 1499, // 1498 NA // 1497 NA // 1496 NA // 1495 NA // 1494, // 1493 NA - // 1492, + 1492, // 1491, // 1490 NA // 1489 NA // 1488 NA // 1487 NA - // 1486, + 1486, // 1485 NA // 1484 NA // 1483 NA // 1482 NA // 1481 NA - // 1480, - // 1479, - // 1478, + 1480, + 1479, + 1478, // 1477, // 1476 NA // 1475 NA @@ -298,7 +303,7 @@ static int included_patches[] = { // 1399 NA // 1398 NA 1397, - // 1396, + 1396, // 1395 NA 1394, // 1393 NA @@ -306,11 +311,11 @@ static int included_patches[] = { // 1391 NA // 1390 NA // 1389 NA - // 1388, + 1388, // 1387 NA // 1386 NA // 1385 NA - // 1384, + 1384, // 1383 NA // 1382 NA // 1381 NA @@ -547,18 +552,18 @@ static int included_patches[] = { 1150, 1149, // 1148 NA - // 1147, + 1147, // 1146 NA // 1145 NA 1144, 1143, 1142, 1141, - // 1140, + 1140, // 1139 NA // 1138 NA 1137, - // 1136, + 1136, // 1135 NA // 1134 NA // 1133 NA @@ -573,7 +578,7 @@ static int included_patches[] = { // 1124 NA 1123, // 1122 NA - // 1121, + 1121, 1120, 1119, 1118, @@ -583,7 +588,7 @@ static int included_patches[] = { 1114, 1113, 1112, - // 1111, + 1111, 1110, // 1109 NA 1108, @@ -597,7 +602,7 @@ static int included_patches[] = { // 1100 NA // 1099 NA // 1098 NA - // 1097, + // 1097 NA 1096, // 1095 NA 1094, @@ -615,13 +620,13 @@ static int included_patches[] = { // 1082 NA 1081, // 1080 NA - // 1079, + // 1079 NA // 1078 NA // 1077 NA 1076, 1075, // 1074 NA, - // 1073, + // 1073 NA 1072, 1071, // 1070 NA @@ -636,7 +641,7 @@ static int included_patches[] = { 1061, // 1060 NA 1059, - // 1058, + // 1058 NA 1057, 1056, 1055, @@ -655,7 +660,7 @@ static int included_patches[] = { 1042, 1041, // 1040 NA - // 1039, + // 1039 NA // 1038 NA 1037, 1036, diff --git a/src/nvim/vim.h b/src/nvim/vim.h index 165a44a148..09e9e850a7 100644 --- a/src/nvim/vim.h +++ b/src/nvim/vim.h @@ -174,6 +174,7 @@ enum { EXPAND_USER, EXPAND_SYNTIME, EXPAND_USER_ADDR_TYPE, + EXPAND_PACKADD, }; @@ -307,4 +308,12 @@ enum { # define SET_NO_HLSEARCH(flag) no_hlsearch = (flag); set_vim_var_nr( \ VV_HLSEARCH, !no_hlsearch && p_hls) +// Used for flags in do_in_path() +#define DIP_ALL 0x01 // all matches, not just the first one +#define DIP_DIR 0x02 // find directories instead of files +#define DIP_ERR 0x04 // give an error message when none found +#define DIP_START 0x08 // also use "start" directory in 'packpath' +#define DIP_OPT 0x10 // also use "opt" directory in 'packpath' +#define DIP_NORTP 0x20 // do not use 'runtimepath' + #endif /* NVIM_VIM_H */ diff --git a/src/nvim/window.c b/src/nvim/window.c index 4eaba3a3df..e267d493bf 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -251,11 +251,14 @@ newwindow: if (win_new_tabpage((int)Prenum, NULL) == OK && valid_tabpage(oldtab)) { newtab = curtab; - goto_tabpage_tp(oldtab, TRUE, TRUE); - if (curwin == wp) - win_close(curwin, FALSE); - if (valid_tabpage(newtab)) - goto_tabpage_tp(newtab, TRUE, TRUE); + goto_tabpage_tp(oldtab, true, true); + if (curwin == wp) { + win_close(curwin, false); + } + if (valid_tabpage(newtab)) { + goto_tabpage_tp(newtab, true, true); + apply_autocmds(EVENT_TABNEWENTERED, NULL, NULL, false, curbuf); + } } } break; @@ -3293,8 +3296,11 @@ void tabpage_move(int nr) tabpage_T *tp; tabpage_T *tp_dst; - if (first_tabpage->tp_next == NULL) + assert(curtab != NULL); + + if (first_tabpage->tp_next == NULL) { return; + } for (tp = first_tabpage; tp->tp_next != NULL && n < nr; tp = tp->tp_next) { ++n; |