To: vim-dev@vim.org Subject: Patch 6.1.349 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.349 Problem: "vim --serverlist" when no server was ever started gives an error message without "\n". "vim --serverlist" doesn't exit when the X server can't be contacted, it starts Vim unexpectedly. (Ricardo Signes) Solution: Don't give an error when no Vim server was ever started. Treat failing of opening the display equal to errors inside the remote*() functions. (Flemming Madsen) Files: src/if_xcmdsrv.c, src/main.c *** ../vim61.348/src/if_xcmdsrv.c Mon Feb 4 12:26:26 2002 --- src/if_xcmdsrv.c Mon Feb 17 21:18:32 2003 *************** *** 174,180 **** static int SendInit __ARGS((Display *dpy)); static int DoRegisterName __ARGS((Display *dpy, char_u *name)); static void DeleteAnyLingerer __ARGS((Display *dpy, Window w)); ! static int GetRegProp __ARGS((Display *dpy, char_u **regPropp, long_u *numItemsp, long_u *bytesAfterp, int msg)); static int WaitForPend __ARGS((void *p)); static int WaitForReply __ARGS((void *p)); static int WindowValid __ARGS((Display *dpy, Window w)); --- 174,180 ---- static int SendInit __ARGS((Display *dpy)); static int DoRegisterName __ARGS((Display *dpy, char_u *name)); static void DeleteAnyLingerer __ARGS((Display *dpy, Window w)); ! static int GetRegProp __ARGS((Display *dpy, char_u **regPropp, long_u *numItemsp, int domsg)); static int WaitForPend __ARGS((void *p)); static int WaitForReply __ARGS((void *p)); static int WindowValid __ARGS((Display *dpy, Window w)); *************** *** 628,634 **** char_u *regProp; char_u *entry; char_u *p; ! long_u numItems, bytesAfter; int_u w; garray_T ga; --- 628,634 ---- char_u *regProp; char_u *entry; char_u *p; ! long_u numItems; int_u w; garray_T ga; *************** *** 642,648 **** /* * Read the registry property. */ ! if (GetRegProp(dpy, ®Prop, &numItems, &bytesAfter, TRUE) == FAIL) return NULL; /* --- 642,648 ---- /* * Read the registry property. */ ! if (GetRegProp(dpy, ®Prop, &numItems, TRUE) == FAIL) return NULL; /* *************** *** 913,925 **** { char_u *regProp, *entry; char_u *p; ! long_u numItems, bytesAfter; int_u returnValue; /* * Read the registry property. */ ! if (GetRegProp(dpy, ®Prop, &numItems, &bytesAfter, FALSE) == FAIL) return 0; /* --- 913,925 ---- { char_u *regProp, *entry; char_u *p; ! long_u numItems; int_u returnValue; /* * Read the registry property. */ ! if (GetRegProp(dpy, ®Prop, &numItems, FALSE) == FAIL) return 0; /* *************** *** 1003,1015 **** { char_u *regProp, *entry = NULL; char_u *p; ! long_u numItems, bytesAfter; Window wwin; /* * Read the registry property. */ ! if (GetRegProp(dpy, ®Prop, &numItems, &bytesAfter, FALSE) == FAIL) return; /* Scan the property for the window id. */ --- 1003,1015 ---- { char_u *regProp, *entry = NULL; char_u *p; ! long_u numItems; Window wwin; /* * Read the registry property. */ ! if (GetRegProp(dpy, ®Prop, &numItems, FALSE) == FAIL) return; /* Scan the property for the window id. */ *************** *** 1056,1083 **** * Return OK when successful. */ static int ! GetRegProp(dpy, regPropp, numItemsp, bytesAfterp, msg) Display *dpy; char_u **regPropp; long_u *numItemsp; ! long_u *bytesAfterp; ! int msg; /* When TRUE give error message. */ { int result, actualFormat; Atom actualType; *regPropp = NULL; result = XGetWindowProperty(dpy, RootWindow(dpy, 0), registryProperty, 0L, (long)MAX_PROP_WORDS, False, XA_STRING, &actualType, ! &actualFormat, numItemsp, bytesAfterp, regPropp); if (actualType == None) { ! if (msg) ! EMSG(_("E249: couldn't read VIM instance registry property")); ! return FAIL; } /* If the property is improperly formed, then delete it. */ --- 1056,1084 ---- * Return OK when successful. */ static int ! GetRegProp(dpy, regPropp, numItemsp, domsg) Display *dpy; char_u **regPropp; long_u *numItemsp; ! int domsg; /* When TRUE give error message. */ { int result, actualFormat; + long_u bytesAfter; Atom actualType; *regPropp = NULL; result = XGetWindowProperty(dpy, RootWindow(dpy, 0), registryProperty, 0L, (long)MAX_PROP_WORDS, False, XA_STRING, &actualType, ! &actualFormat, numItemsp, &bytesAfter, regPropp); if (actualType == None) { ! /* No prop yet. Logically equal to the empty list */ ! *numItemsp = 0; ! *regPropp = (char_u *)""; ! return OK; } /* If the property is improperly formed, then delete it. */ *************** *** 1086,1092 **** if (*regPropp != NULL) XFree(*regPropp); XDeleteProperty(dpy, RootWindow(dpy, 0), registryProperty); ! if (msg) EMSG(_("E251: VIM instance registry property is badly formed. Deleted!")); return FAIL; } --- 1087,1093 ---- if (*regPropp != NULL) XFree(*regPropp); XDeleteProperty(dpy, RootWindow(dpy, 0), registryProperty); ! if (domsg) EMSG(_("E251: VIM instance registry property is badly formed. Deleted!")); return FAIL; } *** ../vim61.348/src/main.c Tue Feb 4 20:07:52 2003 --- src/main.c Mon Feb 17 21:13:53 2003 *************** *** 2380,2387 **** # endif #endif #ifdef FEAT_CLIENTSERVER ! main_msg(_("--remote \tEdit in a Vim server and exit")); main_msg(_("--remote-wait As --remote but wait for files to have been edited")); main_msg(_("--remote-send \tSend to a Vim server and exit")); main_msg(_("--remote-expr \tEvaluate in a Vim server and print result")); main_msg(_("--serverlist\t\tList available Vim server names and exit")); --- 2395,2404 ---- # endif #endif #ifdef FEAT_CLIENTSERVER ! main_msg(_("--remote \tEdit in a Vim server if possible")); ! main_msg(_("--remote-silent Same, don't complain if there is no server")); main_msg(_("--remote-wait As --remote but wait for files to have been edited")); + main_msg(_("--remote-wait-silent Same, don't complain if there is no server")); main_msg(_("--remote-send \tSend to a Vim server and exit")); main_msg(_("--remote-expr \tEvaluate in a Vim server and print result")); main_msg(_("--serverlist\t\tList available Vim server names and exit")); *************** *** 2606,2804 **** if (sname == NULL) return; ! # ifdef FEAT_X11 ! if (xterm_dpy != NULL) /* Win32 always works? */ ! # endif { ! /* ! * Execute the command server related arguments and remove them ! * from the argc/argv array; We may have to return into main() ! */ ! for (i = 1; i < Argc; i++) { ! res = NULL; ! if (STRCMP(argv[i], "--") == 0) /* end of options */ { ! for (; i < *argc; i++) ! { ! *newArgV++ = argv[i]; ! newArgC++; ! } ! break; } ! if (STRICMP(argv[i], "--remote") == 0) ! argtype = ARGTYPE_EDIT; ! else if (STRICMP(argv[i], "--remote-silent") == 0) ! { ! argtype = ARGTYPE_EDIT; ! silent = TRUE; ! } ! else if (STRICMP(argv[i], "--remote-wait") == 0) ! argtype = ARGTYPE_EDIT_WAIT; ! else if (STRICMP(argv[i], "--remote-wait-silent") == 0) { ! argtype = ARGTYPE_EDIT_WAIT; ! silent = TRUE; } - else if (STRICMP(argv[i], "--remote-send") == 0) - argtype = ARGTYPE_SEND; else - argtype = ARGTYPE_OTHER; - if (argtype != ARGTYPE_OTHER) { ! if (i == *argc - 1) ! mainerr_arg_missing((char_u *)argv[i]); ! if (argtype == ARGTYPE_SEND) ! { ! *serverStr = (char_u *)argv[i + 1]; ! i++; ! } ! else ! { ! *serverStr = build_drop_cmd(*argc - i - 1, argv + i + 1, argtype == ARGTYPE_EDIT_WAIT); ! if (*serverStr == NULL) ! { ! /* Probably out of memory, exit. */ ! didone = TRUE; ! exiterr = 1; ! break; ! } ! Argc = i; } # ifdef FEAT_X11 ret = serverSendToVim(xterm_dpy, sname, *serverStr, NULL, &srv, 0, 0, silent); # else ! ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, silent); # endif ! if (ret < 0) { ! if (argtype == ARGTYPE_SEND) ! { ! /* Failed to send, abort. */ ! mch_errmsg(_("\nSend failed.\n")); ! didone = TRUE; ! exiterr = 1; ! } ! else if (!silent) ! /* Let vim start normally. */ ! mch_errmsg(_("\nSend failed. Trying to execute locally\n")); ! break; } # ifdef FEAT_GUI_W32 ! /* Guess that when the server name starts with "g" it's a GUI ! * server, which we can bring to the foreground here. ! * Foreground() in the server doesn't work very well. */ ! if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G') ! SetForegroundWindow(srv); # endif ! /* ! * For --remote-wait: Wait until the server did edit each ! * file. Also detect that the server no longer runs. ! */ ! if (ret >= 0 && argtype == ARGTYPE_EDIT_WAIT) ! { ! int numFiles = *argc - i - 1; ! int j; ! char_u *done = alloc(numFiles); ! char_u *p; # ifdef FEAT_GUI_W32 ! NOTIFYICONDATA ni; ! int count = 0; ! extern HWND message_window; ! ! ni.cbSize = sizeof(ni); ! ni.hWnd = message_window; ! ni.uID = 0; ! ni.uFlags = NIF_ICON|NIF_TIP; ! ni.hIcon = LoadIcon((HINSTANCE)GetModuleHandle(0), ! "IDR_VIM"); ! sprintf(ni.szTip, _("%d of %d edited"), count, numFiles); ! Shell_NotifyIcon(NIM_ADD, &ni); ! # endif ! ! /* Wait for all files to unload in remote */ ! memset(done, 0, numFiles); ! while (memchr(done, 0, numFiles) != NULL) ! { # ifdef WIN32 ! p = serverGetReply(srv, NULL, TRUE, TRUE); ! if (p == NULL) ! break; # else ! if (serverReadReply(xterm_dpy, srv, &p, TRUE) < 0) ! break; # endif ! j = atoi((char *)p); ! if (j >= 0 && j < numFiles) ! { # ifdef FEAT_GUI_W32 ! ++count; ! sprintf(ni.szTip, _("%d of %d edited"), count, numFiles); ! Shell_NotifyIcon(NIM_MODIFY, &ni); # endif ! done[j] = 1; ! } } # ifdef FEAT_GUI_W32 ! Shell_NotifyIcon(NIM_DELETE, &ni); # endif - } } ! else if (STRICMP(argv[i], "--remote-expr") == 0) ! { ! if (i == *argc - 1) ! mainerr_arg_missing((char_u *)argv[i]); # ifdef WIN32 ! if (serverSendToVim(sname, (char_u *)argv[i + 1], &res, NULL, 1, FALSE) < 0) # else ! if (serverSendToVim(xterm_dpy, sname, (char_u *)argv[i + 1], &res, NULL, 1, 1, FALSE) < 0) # endif - mch_errmsg(_("Send expression failed.\n")); - } - else if (STRICMP(argv[i], "--serverlist") == 0) { # ifdef WIN32 ! res = serverGetVimNames(); ! #else res = serverGetVimNames(xterm_dpy); ! #endif ! } ! else if (STRICMP(argv[i], "--servername") == 0) ! { ! /* Alredy processed. Take it out of the command line */ ! i++; ! continue; ! } ! else ! { ! *newArgV++ = argv[i]; ! newArgC++; ! continue; ! } ! didone = TRUE; ! if (res != NULL && *res != NUL) ! { ! mch_msg((char *)res); ! if (res[STRLEN(res) - 1] != '\n') ! mch_msg("\n"); ! } ! vim_free(res); } ! ! if (didone) { ! display_errors(); /* display any collected messages */ ! exit(exiterr); /* Mission accomplished - get out */ } } /* Return back into main() */ *argc = newArgC; vim_free(sname); --- 2623,2839 ---- if (sname == NULL) return; ! /* ! * Execute the command server related arguments and remove them ! * from the argc/argv array; We may have to return into main() ! */ ! for (i = 1; i < Argc; i++) { ! res = NULL; ! if (STRCMP(argv[i], "--") == 0) /* end of options */ { ! for (; i < *argc; i++) { ! *newArgV++ = argv[i]; ! newArgC++; } + break; + } ! if (STRICMP(argv[i], "--remote") == 0) ! argtype = ARGTYPE_EDIT; ! else if (STRICMP(argv[i], "--remote-silent") == 0) ! { ! argtype = ARGTYPE_EDIT; ! silent = TRUE; ! } ! else if (STRICMP(argv[i], "--remote-wait") == 0) ! argtype = ARGTYPE_EDIT_WAIT; ! else if (STRICMP(argv[i], "--remote-wait-silent") == 0) ! { ! argtype = ARGTYPE_EDIT_WAIT; ! silent = TRUE; ! } ! else if (STRICMP(argv[i], "--remote-send") == 0) ! argtype = ARGTYPE_SEND; ! else ! argtype = ARGTYPE_OTHER; ! if (argtype != ARGTYPE_OTHER) ! { ! if (i == *argc - 1) ! mainerr_arg_missing((char_u *)argv[i]); ! if (argtype == ARGTYPE_SEND) { ! *serverStr = (char_u *)argv[i + 1]; ! i++; } else { ! *serverStr = build_drop_cmd(*argc - i - 1, argv + i + 1, argtype == ARGTYPE_EDIT_WAIT); ! if (*serverStr == NULL) ! { ! /* Probably out of memory, exit. */ ! didone = TRUE; ! exiterr = 1; ! break; } + Argc = i; + } # ifdef FEAT_X11 + if (xterm_dpy == NULL) + { + mch_errmsg(_("No display")); + ret = -1; + } + else ret = serverSendToVim(xterm_dpy, sname, *serverStr, NULL, &srv, 0, 0, silent); # else ! /* Win32 always works? */ ! ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, silent); # endif ! if (ret < 0) ! { ! if (argtype == ARGTYPE_SEND) { ! /* Failed to send, abort. */ ! mch_errmsg(_(": Send failed.\n")); ! didone = TRUE; ! exiterr = 1; } + else if (!silent) + /* Let vim start normally. */ + mch_errmsg(_(": Send failed. Trying to execute locally\n")); + break; + } # ifdef FEAT_GUI_W32 ! /* Guess that when the server name starts with "g" it's a GUI ! * server, which we can bring to the foreground here. ! * Foreground() in the server doesn't work very well. */ ! if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G') ! SetForegroundWindow(srv); # endif ! /* ! * For --remote-wait: Wait until the server did edit each ! * file. Also detect that the server no longer runs. ! */ ! if (ret >= 0 && argtype == ARGTYPE_EDIT_WAIT) ! { ! int numFiles = *argc - i - 1; ! int j; ! char_u *done = alloc(numFiles); ! char_u *p; # ifdef FEAT_GUI_W32 ! NOTIFYICONDATA ni; ! int count = 0; ! extern HWND message_window; ! ! ni.cbSize = sizeof(ni); ! ni.hWnd = message_window; ! ni.uID = 0; ! ni.uFlags = NIF_ICON|NIF_TIP; ! ni.hIcon = LoadIcon((HINSTANCE)GetModuleHandle(0), "IDR_VIM"); ! sprintf(ni.szTip, _("%d of %d edited"), count, numFiles); ! Shell_NotifyIcon(NIM_ADD, &ni); ! # endif ! ! /* Wait for all files to unload in remote */ ! memset(done, 0, numFiles); ! while (memchr(done, 0, numFiles) != NULL) ! { # ifdef WIN32 ! p = serverGetReply(srv, NULL, TRUE, TRUE); ! if (p == NULL) ! break; # else ! if (serverReadReply(xterm_dpy, srv, &p, TRUE) < 0) ! break; # endif ! j = atoi((char *)p); ! if (j >= 0 && j < numFiles) ! { # ifdef FEAT_GUI_W32 ! ++count; ! sprintf(ni.szTip, _("%d of %d edited"), count, numFiles); ! Shell_NotifyIcon(NIM_MODIFY, &ni); # endif ! done[j] = 1; } + } # ifdef FEAT_GUI_W32 ! Shell_NotifyIcon(NIM_DELETE, &ni); # endif } ! } ! else if (STRICMP(argv[i], "--remote-expr") == 0) ! { ! if (i == *argc - 1) ! mainerr_arg_missing((char_u *)argv[i]); # ifdef WIN32 ! /* Win32 always works? */ ! if (serverSendToVim(sname, (char_u *)argv[i + 1], &res, NULL, 1, FALSE) < 0) # else ! if (xterm_dpy == NULL) ! mch_errmsg(_("No display: Send expression failed.\n")); ! else if (serverSendToVim(xterm_dpy, sname, (char_u *)argv[i + 1], &res, NULL, 1, 1, FALSE) < 0) # endif { + if (res != NULL && *res != NUL) + { + /* Output error from remote */ + mch_errmsg((char *)res); + vim_free(res); + res = NULL; + } + mch_errmsg(_(": Send expression failed.\n")); + } + } + else if (STRICMP(argv[i], "--serverlist") == 0) + { # ifdef WIN32 ! /* Win32 always works? */ ! res = serverGetVimNames(); ! # else ! if (xterm_dpy != NULL) res = serverGetVimNames(xterm_dpy); ! # endif ! if (called_emsg) ! mch_errmsg("\n"); } ! else if (STRICMP(argv[i], "--servername") == 0) ! { ! /* Alredy processed. Take it out of the command line */ ! i++; ! continue; ! } ! else { ! *newArgV++ = argv[i]; ! newArgC++; ! continue; } + didone = TRUE; + if (res != NULL && *res != NUL) + { + mch_msg((char *)res); + if (res[STRLEN(res) - 1] != '\n') + mch_msg("\n"); + } + vim_free(res); + } + + if (didone) + { + display_errors(); /* display any collected messages */ + exit(exiterr); /* Mission accomplished - get out */ } + /* Return back into main() */ *argc = newArgC; vim_free(sname); *************** *** 2890,2899 **** /* Set 'cpoptions' the way we want it. * B set - backslashes are *not* treated specially * k set - keycodes are *not* reverse-engineered ! * < unset - sequenecs *are* interpreted ! * last parameter of replace_termcodes() is TRUE so that ! * the sequence is recognised - needed as backslash ! * is not special... */ p_cpo = (char_u *)"Bk"; str = replace_termcodes((char_u *)str, &ptr, FALSE, TRUE); --- 2925,2933 ---- /* Set 'cpoptions' the way we want it. * B set - backslashes are *not* treated specially * k set - keycodes are *not* reverse-engineered ! * < unset - sequences *are* interpreted ! * The last parameter of replace_termcodes() is TRUE so that the ! * sequence is recognised - needed for a real backslash. */ p_cpo = (char_u *)"Bk"; str = replace_termcodes((char_u *)str, &ptr, FALSE, TRUE); *** ../vim61.348/src/version.c Thu Feb 20 21:44:37 2003 --- src/version.c Thu Feb 20 21:50:42 2003 *************** *** 608,609 **** --- 612,615 ---- { /* Add new patch number below this line */ + /**/ + 349, /**/ -- [clop clop] GUARD #1: Halt! Who goes there? ARTHUR: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot. King of the Britons, defeator of the Saxons, sovereign of all England! GUARD #1: Pull the other one! The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///