summaryrefslogtreecommitdiffstats
path: root/src/ex_cmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r--src/ex_cmds.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index d8e891c..864f89d 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -323,7 +323,7 @@ sort_compare(const void *s1, const void *s2)
if (sort_nr)
{
if (l1.st_u.num.is_number != l2.st_u.num.is_number)
- result = l1.st_u.num.is_number - l2.st_u.num.is_number;
+ result = l1.st_u.num.is_number > l2.st_u.num.is_number ? 1 : -1;
else
result = l1.st_u.num.value == l2.st_u.num.value ? 0
: l1.st_u.num.value > l2.st_u.num.value ? 1 : -1;
@@ -489,7 +489,7 @@ ex_sort(exarg_T *eap)
for (lnum = eap->line1; lnum <= eap->line2; ++lnum)
{
s = ml_get(lnum);
- len = (int)STRLEN(s);
+ len = ml_get_len(lnum);
if (maxlen < len)
maxlen = len;
@@ -691,7 +691,7 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
return FAIL;
for (extra = 0, l = line1; l <= line2; l++)
{
- str = vim_strsave(ml_get(l + extra));
+ str = vim_strnsave(ml_get(l + extra), ml_get_len(l + extra));
if (str != NULL)
{
ml_append(dest + l - line1, str, (colnr_T)0, FALSE);
@@ -824,9 +824,9 @@ ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
curwin->w_cursor.lnum = n;
while (line1 <= line2)
{
- // need to use vim_strsave() because the line will be unlocked within
+ // need to make a copy because the line will be unlocked within
// ml_append()
- p = vim_strsave(ml_get(line1));
+ p = vim_strnsave(ml_get(line1), ml_get_len(line1));
if (p != NULL)
{
ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE);
@@ -2428,6 +2428,9 @@ getfile(
int retval;
char_u *free_me = NULL;
+ if (!check_can_set_curbuf_forceit(forceit))
+ return GETFILE_ERROR;
+
if (text_locked())
return GETFILE_ERROR;
if (curbuf_locked())
@@ -2782,9 +2785,16 @@ do_ecmd(
{
bufref_T save_au_new_curbuf;
int save_cmdwin_type = cmdwin_type;
+ win_T *save_cmdwin_win = cmdwin_win;
+
+ // Should only be possible to get here if the cmdwin is closed, or
+ // if it's opening and its buffer hasn't been set yet (the new
+ // buffer is for it).
+ assert(cmdwin_buf == NULL);
// BufLeave applies to the old buffer.
cmdwin_type = 0;
+ cmdwin_win = NULL;
/*
* Be careful: The autocommands may delete any buffer and change
@@ -2801,7 +2811,10 @@ do_ecmd(
save_au_new_curbuf = au_new_curbuf;
set_bufref(&au_new_curbuf, buf);
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
+
cmdwin_type = save_cmdwin_type;
+ cmdwin_win = save_cmdwin_win;
+
if (!bufref_valid(&au_new_curbuf))
{
// new buffer has been deleted
@@ -4212,7 +4225,8 @@ ex_substitute(exarg_T *eap)
if (sub_firstline == NULL)
{
- sub_firstline = vim_strsave(ml_get(sub_firstlnum));
+ sub_firstline = vim_strnsave(ml_get(sub_firstlnum),
+ ml_get_len(sub_firstlnum));
if (sub_firstline == NULL)
{
vim_free(new_start);
@@ -4366,7 +4380,8 @@ ex_substitute(exarg_T *eap)
// really update the line, it would change
// what matches. Temporarily replace the line
// and change it back afterwards.
- orig_line = vim_strsave(ml_get(lnum));
+ orig_line = vim_strnsave(ml_get(lnum),
+ ml_get_len(lnum));
if (orig_line != NULL)
{
char_u *new_line = concat_str(new_start,
@@ -4712,7 +4727,8 @@ ex_substitute(exarg_T *eap)
{
sub_firstlnum += nmatch - 1;
vim_free(sub_firstline);
- sub_firstline = vim_strsave(ml_get(sub_firstlnum));
+ sub_firstline = vim_strnsave(ml_get(sub_firstlnum),
+ ml_get_len(sub_firstlnum));
// When going beyond the last line, stop substituting.
if (sub_firstlnum <= line2)
do_again = TRUE;
@@ -5425,8 +5441,7 @@ ex_smile(exarg_T *eap UNUSED)
/*
* ":drop"
- * Opens the first argument in a window. When there are two or more arguments
- * the argument list is redefined.
+ * Opens the first argument in a window, and the argument list is redefined.
*/
void
ex_drop(exarg_T *eap)
@@ -5463,6 +5478,8 @@ ex_drop(exarg_T *eap)
// edited in a window yet. It's like ":tab all" but without closing
// windows or tabs.
ex_all(eap);
+ cmdmod.cmod_tab = 0;
+ ex_rewind(eap);
return;
}
@@ -5486,6 +5503,8 @@ ex_drop(exarg_T *eap)
buf_check_timestamp(curbuf, FALSE);
curbuf->b_p_ar = save_ar;
}
+ if (curbuf->b_ml.ml_flags & ML_EMPTY)
+ ex_rewind(eap);
return;
}
}