From 481049e0c91995dd48b7cc10f8fbb157258a5e26 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 19 Sep 2015 14:26:04 -0400 Subject: build: remove USEMAN_S --- src/nvim/options.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 14f912f9e8..723736d376 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1329,9 +1329,7 @@ return { expand=true, varname='p_kp', defaults={ - condition='USEMAN_S', if_true={vi="man -s"}, - if_false={vi="man"}, } }, { -- cgit From 998d0ffc09d5c7358db62dc88c2e2b87622f60b5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 23 Jan 2015 20:03:05 -0500 Subject: 'keywordprg': support ex commands - new feature: if the first character of 'keywordprg' is ":", the command is invoked as a Vim ex-command prefixed with [count]. - change default 'keywordprg' to :Man --- src/nvim/normal.c | 46 ++++++++++++++++++++++------------------------ src/nvim/options.lua | 2 +- 2 files changed, 23 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 5b35af9209..8ce2065336 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4213,18 +4213,12 @@ void do_nv_ident(int c1, int c2) static void nv_ident(cmdarg_T *cap) { char_u *ptr = NULL; - char_u *buf; - char_u *newbuf; char_u *p; - char_u *kp; /* value of 'keywordprg' */ - bool kp_help; /* 'keywordprg' is ":help" */ size_t n = 0; /* init for GCC */ int cmdchar; bool g_cmd; /* "g" command */ bool tag_cmd = false; char_u *aux_ptr; - bool isman; - bool isman_s; if (cap->cmdchar == 'g') { /* "g*", "g#", "g]" and "gCTRL-]" */ cmdchar = cap->nchar; @@ -4259,10 +4253,10 @@ static void nv_ident(cmdarg_T *cap) /* Allocate buffer to put the command in. Inserting backslashes can * double the length of the word. p_kp / curbuf->b_p_kp could be added * and some numbers. */ - kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); - kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 - || STRCMP(kp, ":help") == 0); - buf = xmalloc(n * 2 + 30 + STRLEN(kp)); + char_u *kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); //'keywordprg' + assert(*kp != NUL); //option.c::do_set() should default to ":help" if empty. + bool kp_ex = (*kp == ':'); //'keywordprg' is an ex command + char *buf = xmalloc(n * 2 + 30 + STRLEN(kp)); buf[0] = NUL; switch (cmdchar) { @@ -4283,9 +4277,13 @@ static void nv_ident(cmdarg_T *cap) break; case 'K': - if (kp_help) - STRCPY(buf, "he! "); - else { + if (kp_ex) { + if (cap->count0 != 0) { // Send the count to the ex command. + sprintf(buf, "%" PRId64, (int64_t)(cap->count0)); + } + STRCAT(buf, kp); + STRCAT(buf, " "); + } else { /* An external command will probably use an argument starting * with "-" as an option. To avoid trouble we skip the "-". */ while (*ptr == '-' && n > 0) { @@ -4300,10 +4298,10 @@ static void nv_ident(cmdarg_T *cap) /* When a count is given, turn it into a range. Is this * really what we want? */ - isman = (STRCMP(kp, "man") == 0); - isman_s = (STRCMP(kp, "man -s") == 0); + bool isman = (STRCMP(kp, "man") == 0); + bool isman_s = (STRCMP(kp, "man -s") == 0); if (cap->count0 != 0 && !(isman || isman_s)) - sprintf((char *)buf, ".,.+%" PRId64, (int64_t)(cap->count0 - 1)); + sprintf(buf, ".,.+%" PRId64, (int64_t)(cap->count0 - 1)); STRCAT(buf, "! "); if (cap->count0 == 0 && isman_s) @@ -4312,7 +4310,7 @@ static void nv_ident(cmdarg_T *cap) STRCAT(buf, kp); STRCAT(buf, " "); if (cap->count0 != 0 && (isman || isman_s)) { - sprintf((char *)buf + STRLEN(buf), "%" PRId64, (int64_t)cap->count0); + sprintf(buf + STRLEN(buf), "%" PRId64, (int64_t)cap->count0); STRCAT(buf, " "); } } @@ -4334,19 +4332,19 @@ static void nv_ident(cmdarg_T *cap) if (g_cmd) STRCPY(buf, "tj "); else - sprintf((char *)buf, "%" PRId64 "ta ", (int64_t)cap->count0); + sprintf(buf, "%" PRId64 "ta ", (int64_t)cap->count0); } } /* * Now grab the chars in the identifier */ - if (cmdchar == 'K' && !kp_help) { + if (cmdchar == 'K' && !kp_ex) { /* Escape the argument properly for a shell command */ ptr = vim_strnsave(ptr, n); p = vim_strsave_shellescape(ptr, true, true); xfree(ptr); - newbuf = (char_u *)xrealloc(buf, STRLEN(buf) + STRLEN(p) + 1); + char *newbuf = xrealloc(buf, STRLEN(buf) + STRLEN(p) + 1); buf = newbuf; STRCAT(buf, p); xfree(p); @@ -4364,7 +4362,7 @@ static void nv_ident(cmdarg_T *cap) } else aux_ptr = (char_u *)"\\|\"\n*?["; - p = buf + STRLEN(buf); + p = (char_u *)buf + STRLEN(buf); while (n-- > 0) { /* put a backslash before \ and some others */ if (vim_strchr(aux_ptr, *ptr) != NULL) @@ -4391,10 +4389,10 @@ static void nv_ident(cmdarg_T *cap) STRCAT(buf, "\\>"); /* put pattern in search history */ init_history(); - add_to_history(HIST_SEARCH, buf, true, NUL); - (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); + add_to_history(HIST_SEARCH, (char_u *)buf, true, NUL); + (void)normal_search(cap, cmdchar == '*' ? '/' : '?', (char_u *)buf, 0); } else - do_cmdline_cmd((char *)buf); + do_cmdline_cmd(buf); xfree(buf); } diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 723736d376..e02326be78 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1329,7 +1329,7 @@ return { expand=true, varname='p_kp', defaults={ - if_true={vi="man -s"}, + if_true={vi=":Man"}, } }, { -- cgit From 6eb78dcaaa6af509e7dce221e88047b5869ced20 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 20 Sep 2015 10:11:24 -0400 Subject: nv_ident: sprintf => snprintf Also fix some other clint errors. --- src/nvim/normal.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 8ce2065336..467b74f9e6 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4253,10 +4253,11 @@ static void nv_ident(cmdarg_T *cap) /* Allocate buffer to put the command in. Inserting backslashes can * double the length of the word. p_kp / curbuf->b_p_kp could be added * and some numbers. */ - char_u *kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); //'keywordprg' - assert(*kp != NUL); //option.c::do_set() should default to ":help" if empty. - bool kp_ex = (*kp == ':'); //'keywordprg' is an ex command - char *buf = xmalloc(n * 2 + 30 + STRLEN(kp)); + char_u *kp = *curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp; // 'keywordprg' + assert(*kp != NUL); // option.c:do_set() should default to ":help" if empty. + bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command + size_t buf_size = n * 2 + 30 + STRLEN(kp); + char *buf = xmalloc(buf_size); buf[0] = NUL; switch (cmdchar) { @@ -4279,7 +4280,7 @@ static void nv_ident(cmdarg_T *cap) case 'K': if (kp_ex) { if (cap->count0 != 0) { // Send the count to the ex command. - sprintf(buf, "%" PRId64, (int64_t)(cap->count0)); + snprintf(buf, buf_size, "%" PRId64, (int64_t)(cap->count0)); } STRCAT(buf, kp); STRCAT(buf, " "); @@ -4300,17 +4301,20 @@ static void nv_ident(cmdarg_T *cap) * really what we want? */ bool isman = (STRCMP(kp, "man") == 0); bool isman_s = (STRCMP(kp, "man -s") == 0); - if (cap->count0 != 0 && !(isman || isman_s)) - sprintf(buf, ".,.+%" PRId64, (int64_t)(cap->count0 - 1)); + if (cap->count0 != 0 && !(isman || isman_s)) { + snprintf(buf, buf_size, ".,.+%" PRId64, (int64_t)(cap->count0 - 1)); + } STRCAT(buf, "! "); - if (cap->count0 == 0 && isman_s) + if (cap->count0 == 0 && isman_s) { STRCAT(buf, "man"); - else + } else { STRCAT(buf, kp); + } STRCAT(buf, " "); if (cap->count0 != 0 && (isman || isman_s)) { - sprintf(buf + STRLEN(buf), "%" PRId64, (int64_t)cap->count0); + snprintf(buf + STRLEN(buf), buf_size - STRLEN(buf), "%" PRId64, + (int64_t)cap->count0); STRCAT(buf, " "); } } @@ -4332,7 +4336,7 @@ static void nv_ident(cmdarg_T *cap) if (g_cmd) STRCPY(buf, "tj "); else - sprintf(buf, "%" PRId64 "ta ", (int64_t)cap->count0); + snprintf(buf, buf_size, "%" PRId64 "ta ", (int64_t)cap->count0); } } @@ -4391,8 +4395,9 @@ static void nv_ident(cmdarg_T *cap) init_history(); add_to_history(HIST_SEARCH, (char_u *)buf, true, NUL); (void)normal_search(cap, cmdchar == '*' ? '/' : '?', (char_u *)buf, 0); - } else + } else { do_cmdline_cmd(buf); + } xfree(buf); } -- cgit