aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c14
-rw-r--r--src/nvim/ex_cmds.lua8
-rw-r--r--src/nvim/ex_cmds2.c14
-rw-r--r--src/nvim/ex_getln.c98
-rw-r--r--src/nvim/ops.c1
5 files changed, 81 insertions, 54 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 7c576c9238..b9768978e5 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -6577,6 +6577,7 @@ static struct fst {
{"prevnonblank", 1, 1, f_prevnonblank},
{"printf", 2, 19, f_printf},
{"pumvisible", 0, 0, f_pumvisible},
+ {"py3eval", 1, 1, f_py3eval},
{"pyeval", 1, 1, f_pyeval},
{"range", 1, 3, f_range},
{"readfile", 1, 3, f_readfile},
@@ -11946,6 +11947,14 @@ static void f_pyeval(typval_T *argvars, typval_T *rettv)
}
/*
+ * "py3eval()" function
+ */
+static void f_py3eval(typval_T *argvars, typval_T *rettv)
+{
+ script_host_eval("python3", argvars, rettv);
+}
+
+/*
* "range()" function
*/
static void f_range(typval_T *argvars, typval_T *rettv)
@@ -20458,11 +20467,14 @@ bool eval_has_provider(char *name)
} \
}
- static int has_clipboard = -1, has_python = -1;
+ static int has_clipboard = -1, has_python = -1, has_python3 = -1;
if (!strcmp(name, "clipboard")) {
check_provider(clipboard);
return has_clipboard;
+ } else if (!strcmp(name, "python3")) {
+ check_provider(python3);
+ return has_python3;
} else if (!strcmp(name, "python")) {
check_provider(python);
return has_python;
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index e1951e88f8..52dc0d6212 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -1668,22 +1668,22 @@ return {
{
command='py3',
flags=bit.bor(RANGE, EXTRA, NEEDARG, CMDWIN),
- func='ex_script_ni',
+ func='ex_python3',
},
{
command='py3do',
flags=bit.bor(RANGE, DFLALL, EXTRA, NEEDARG, CMDWIN),
- func='ex_ni',
+ func='ex_pydo3',
},
{
command='python3',
flags=bit.bor(RANGE, EXTRA, NEEDARG, CMDWIN),
- func='ex_script_ni',
+ func='ex_python3',
},
{
command='py3file',
flags=bit.bor(RANGE, FILE1, NEEDARG, CMDWIN),
- func='ex_ni',
+ func='ex_py3file',
},
{
command='quit',
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index b9f2d1f0d2..dc04835774 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -797,6 +797,20 @@ void ex_pydo(exarg_T *eap)
script_host_do_range("python", eap);
}
+void ex_python3(exarg_T *eap)
+{
+ script_host_execute("python3", eap);
+}
+
+void ex_py3file(exarg_T *eap)
+{
+ script_host_execute_file("python3", eap);
+}
+
+void ex_pydo3(exarg_T *eap)
+{
+ script_host_do_range("python3", eap);
+}
/* Command line expansion for :profile. */
static enum {
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 5fd5c2a345..9a5da761a5 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -10,6 +10,7 @@
* ex_getln.c: Functions for entering and editing an Ex command line.
*/
+#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
@@ -4169,58 +4170,59 @@ static char_u *get_history_arg(expand_T *xp, int idx)
return NULL;
}
-/*
- * init_history() - Initialize the command line history.
- * Also used to re-allocate the history when the size changes.
- */
+/// Initialize command line history.
+/// Also used to re-allocate history tables when size changes.
void init_history(void)
{
- /*
- * If size of history table changed, reallocate it
- */
- ssize_t newlen = p_hi;
- if (newlen != hislen) {
- histentry_T *temp;
- ssize_t i;
- ssize_t j;
-
- // adjust the tables
- for (int type = 0; type < HIST_COUNT; ++type) {
- if (newlen) {
- temp = xmalloc(newlen * sizeof(*temp));
- } else
- temp = NULL;
- if (newlen == 0 || temp != NULL) {
- if (hisidx[type] < 0) { /* there are no entries yet */
- for (i = 0; i < newlen; ++i)
- clear_hist_entry(&temp[i]);
- } else if (newlen > hislen) { /* array becomes bigger */
- for (i = 0; i <= hisidx[type]; ++i)
- temp[i] = history[type][i];
- j = i;
- for (; i <= newlen - (hislen - hisidx[type]); ++i)
- clear_hist_entry(&temp[i]);
- for (; j < hislen; ++i, ++j)
- temp[i] = history[type][j];
- } else { /* array becomes smaller or 0 */
- j = hisidx[type];
- for (i = newlen - 1;; --i) {
- if (i >= 0) /* copy newest entries */
- temp[i] = history[type][j];
- else { /* remove older entries */
- xfree(history[type][j].hisstr);
- history[type][j].hisstr = NULL;
- }
- if (--j < 0)
- j = hislen - 1;
- if (j == hisidx[type])
- break;
- }
- hisidx[type] = newlen - 1;
+ assert(p_hi >= 0 && p_hi <= INT_MAX);
+ int newlen = (int)p_hi;
+ int oldlen = hislen;
+
+ // If history tables size changed, reallocate them.
+ // Tables are circular arrays (current position marked by hisidx[type]).
+ // On copying them to the new arrays, we take the chance to reorder them.
+ if (newlen != oldlen) {
+ for (int type = 0; type < HIST_COUNT; type++) {
+ histentry_T *temp = newlen ? xmalloc(newlen * sizeof(*temp)) : NULL;
+
+ int j = hisidx[type];
+ if (j >= 0) {
+ // old array gets partitioned this way:
+ // [0 , i1 ) --> newest entries to be deleted
+ // [i1 , i1 + l1) --> newest entries to be copied
+ // [i1 + l1 , i2 ) --> oldest entries to be deleted
+ // [i2 , i2 + l2) --> oldest entries to be copied
+ int l1 = MIN(j + 1, newlen); // how many newest to copy
+ int l2 = MIN(newlen, oldlen) - l1; // how many oldest to copy
+ int i1 = j + 1 - l1; // copy newest from here
+ int i2 = MAX(l1, oldlen - newlen + l1); // copy oldest from here
+
+ // copy as much entries as they fit to new table, reordering them
+ if (newlen) {
+ // copy oldest entries
+ memcpy(&temp[0], &history[type][i2], (size_t)l2 * sizeof(*temp));
+ // copy newest entries
+ memcpy(&temp[l2], &history[type][i1], (size_t)l1 * sizeof(*temp));
+ }
+
+ // delete entries that don't fit in newlen, if any
+ for (int i = 0; i < i1; i++) {
+ xfree(history[type][i].hisstr);
+ history[type][i].hisstr = NULL;
+ }
+ for (int i = i1 + l1; i < i2; i++) {
+ xfree(history[type][i].hisstr);
+ history[type][i].hisstr = NULL;
}
- xfree(history[type]);
- history[type] = temp;
}
+
+ // clear remaining space, if any
+ int l3 = j < 0 ? 0 : MIN(newlen, oldlen); // number of copied entries
+ memset(temp + l3, 0, (size_t)(newlen - l3) * sizeof(*temp));
+
+ hisidx[type] = l3 - 1;
+ xfree(history[type]);
+ history[type] = temp;
}
hislen = newlen;
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 595f025d63..66ba9943d3 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -2477,7 +2477,6 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
curr->y_array[j++] = reg->y_array[y_idx++];
curr->y_size = j;
xfree(reg->y_array);
- reg = curr;
}
if (curwin->w_p_rnu) {
redraw_later(SOME_VALID); // cursor moved to start