From 133c7a43d410a9036485539225ef3834a3a56567 Mon Sep 17 00:00:00 2001 From: edyfox Date: Tue, 16 Sep 2008 01:29:34 +0000 Subject: [PATCH] Merged from the latest developing branch. git-svn-id: https://vim.svn.sourceforge.net/svnroot/vim/trunk@1196 2a77ed30-b011-0410-a7ad-c7884a0aa172 --- src/ex_cmds.c | 1 + src/ex_getln.c | 32 +++++++++++++++++++++++++++++--- src/ui.c | 32 +++++++++++++++++--------------- src/version.c | 6 ++++++ 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/ex_cmds.c b/src/ex_cmds.c index c2dc2676..02d5b3eb 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -5059,6 +5059,7 @@ skip: if (did_sub) ++sub_nlines; + vim_free(new_start); /* for when substitute was cancelled */ vim_free(sub_firstline); /* free the copy of the original line */ sub_firstline = NULL; } diff --git a/src/ex_getln.c b/src/ex_getln.c index 994fe2aa..8855f868 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -31,6 +31,8 @@ struct cmdline_info int cmdattr; /* attributes for prompt */ int overstrike; /* Typing mode on the command line. Shared by getcmdline() and put_on_cmdline(). */ + expand_T *xpc; /* struct being used for expansion, xp_pattern + may point into cmdbuff */ int xp_context; /* type of expansion */ # ifdef FEAT_EVAL char_u *xp_arg; /* user-defined expansion arg */ @@ -38,7 +40,11 @@ struct cmdline_info # endif }; -static struct cmdline_info ccline; /* current cmdline_info */ +/* The current cmdline_info. It is initialized in getcmdline() and after that + * used by other functions. When invoking getcmdline() recursively it needs + * to be saved with save_cmdline() and restored with restore_cmdline(). + * TODO: make it local to getcmdline() and pass it around. */ +static struct cmdline_info ccline; static int cmd_showtail; /* Only show path tail in lists ? */ @@ -238,6 +244,7 @@ getcmdline(firstc, count, indent) } ExpandInit(&xpc); + ccline.xpc = &xpc; #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl && *curwin->w_p_rlc == 's' @@ -408,9 +415,10 @@ getcmdline(firstc, count, indent) #endif /* - * works like CTRL-P (unless 'wc' is ). + * When there are matching completions to select works like + * CTRL-P (unless 'wc' is ). */ - if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles != -1) + if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) c = Ctrl_P; #ifdef FEAT_WILDMENU @@ -1513,6 +1521,7 @@ getcmdline(firstc, count, indent) int old_firstc; vim_free(ccline.cmdbuff); + xpc.xp_context = EXPAND_NOTHING; if (hiscnt == hislen) p = lookfor; /* back to the old one */ else @@ -1839,6 +1848,7 @@ returncmd: #endif ExpandCleanup(&xpc); + ccline.xpc = NULL; #ifdef FEAT_SEARCH_EXTRA if (did_incsearch) @@ -2508,6 +2518,20 @@ realloc_cmdbuff(len) } mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen + 1); vim_free(p); + + if (ccline.xpc != NULL + && ccline.xpc->xp_pattern != NULL + && ccline.xpc->xp_context != EXPAND_NOTHING + && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) + { + int i = ccline.xpc->xp_pattern - p; + + /* If xp_pattern points inside the old cmdbuff it needs to be adjusted + * to point into the newly allocated memory. */ + if (i >= 0 && i <= ccline.cmdlen) + ccline.xpc->xp_pattern = ccline.cmdbuff + i; + } + return OK; } @@ -2875,6 +2899,7 @@ save_cmdline(ccp) prev_ccline = ccline; ccline.cmdbuff = NULL; ccline.cmdprompt = NULL; + ccline.xpc = NULL; } /* @@ -3582,6 +3607,7 @@ ExpandOne(xp, str, orig, options, mode) ExpandInit(xp) expand_T *xp; { + xp->xp_pattern = NULL; xp->xp_backslash = XP_BS_NONE; #ifndef BACKSLASH_IN_FILENAME xp->xp_shell = FALSE; diff --git a/src/ui.c b/src/ui.c index db8f04c1..6d408b0c 100644 --- a/src/ui.c +++ b/src/ui.c @@ -2020,7 +2020,7 @@ clip_x11_request_selection_cb(w, success, sel_atom, type, value, length, if (value == NULL || *length == 0) { - clip_free_selection(cbd); /* ??? [what's the query?] */ + clip_free_selection(cbd); /* nothing received, clear register */ *(int *)success = FALSE; return; } @@ -2076,7 +2076,7 @@ clip_x11_request_selection_cb(w, success, sel_atom, type, value, length, text_prop.value = (unsigned char *)value; text_prop.encoding = *type; text_prop.format = *format; - text_prop.nitems = STRLEN(value); + text_prop.nitems = len; status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop, &text_list, &n_text); if (status != Success || n_text < 1) @@ -2131,7 +2131,7 @@ clip_x11_request_selection(myShell, dpy, cbd) case 3: type = text_atom; break; default: type = XA_STRING; } - success = FALSE; + success = MAYBE; XtGetSelectionValue(myShell, cbd->sel_atom, type, clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); @@ -2145,25 +2145,27 @@ clip_x11_request_selection(myShell, dpy, cbd) * paste! Don't worry, we will catch up with any other events later. */ start_time = time(NULL); - for (;;) + while (success == MAYBE) { - if (XCheckTypedEvent(dpy, SelectionNotify, &event)) + if (XCheckTypedEvent(dpy, SelectionNotify, &event) + || XCheckTypedEvent(dpy, SelectionRequest, &event) + || XCheckTypedEvent(dpy, PropertyNotify, &event)) { - /* this is where clip_x11_request_selection_cb() is actually - * called */ + /* This is where clip_x11_request_selection_cb() should be + * called. It may actually happen a bit later, so we loop + * until "success" changes. + * We may get a SelectionRequest here and if we don't handle + * it we hang. KDE klipper does this, for example. + * We need to handle a PropertyNotify for large selections. */ XtDispatchEvent(&event); - break; + continue; } - if (XCheckTypedEvent(dpy, SelectionRequest, &event)) - /* We may get a SelectionRequest here and if we don't handle - * it we hang. KDE klipper does this, for example. */ - XtDispatchEvent(&event); /* Time out after 2 to 3 seconds to avoid that we hang when the * other process doesn't respond. Note that the SelectionNotify * event may still come later when the selection owner comes back - * to life and the text gets inserted unexpectedly (by xterm). - * Don't know how to avoid that :-(. */ + * to life and the text gets inserted unexpectedly. Don't know + * why that happens or how to avoid that :-(. */ if (time(NULL) > start_time + 2) { timed_out = TRUE; @@ -2177,7 +2179,7 @@ clip_x11_request_selection(myShell, dpy, cbd) ui_delay(1L, TRUE); } - if (success) + if (success == TRUE) return; /* don't do a retry with another type after timing out, otherwise we diff --git a/src/version.c b/src/version.c index ac8ada80..ccc1c0ed 100644 --- a/src/version.c +++ b/src/version.c @@ -677,6 +677,12 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 18, +/**/ + 17, +/**/ + 16, +/**/ 15, /**/ 14, -- 2.11.4.GIT