Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * Netbeans integration by David Weatherford |
| 5 | * Adopted for Win32 by Sergey Khorev |
| 6 | * |
| 7 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 8 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * Implements client side of org.netbeans.modules.emacs editor |
| 13 | * integration protocol. Be careful! The protocol uses offsets |
| 14 | * which are *between* characters, whereas vim uses line number |
| 15 | * and column number which are *on* characters. |
| 16 | * See ":help netbeans-protocol" for explanation. |
| 17 | */ |
| 18 | |
| 19 | #include "vim.h" |
| 20 | |
| 21 | #if defined(FEAT_NETBEANS_INTG) || defined(PROTO) |
| 22 | |
| 23 | /* Note: when making changes here also adjust configure.in. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | # include <fcntl.h> |
| 25 | #ifdef WIN32 |
| 26 | # ifdef DEBUG |
| 27 | # include <tchar.h> /* for _T definition for TRACEn macros */ |
| 28 | # endif |
| 29 | # include <io.h> |
| 30 | /* WinSock API is separated from C API, thus we can't use read(), write(), |
| 31 | * errno... */ |
| 32 | # define sock_errno WSAGetLastError() |
| 33 | # define ECONNREFUSED WSAECONNREFUSED |
| 34 | # ifdef EINTR |
| 35 | # undef EINTR |
| 36 | # endif |
| 37 | # define EINTR WSAEINTR |
| 38 | # define sock_write(sd, buf, len) send(sd, buf, len, 0) |
| 39 | # define sock_read(sd, buf, len) recv(sd, buf, len, 0) |
| 40 | # define sock_close(sd) closesocket(sd) |
| 41 | # define sleep(t) Sleep(t*1000) /* WinAPI Sleep() accepts milliseconds */ |
| 42 | #else |
| 43 | # include <netdb.h> |
| 44 | # include <netinet/in.h> |
| 45 | # include <sys/socket.h> |
| 46 | # ifdef HAVE_LIBGEN_H |
| 47 | # include <libgen.h> |
| 48 | # endif |
| 49 | # define sock_errno errno |
| 50 | # define sock_write(sd, buf, len) write(sd, buf, len) |
| 51 | # define sock_read(sd, buf, len) read(sd, buf, len) |
| 52 | # define sock_close(sd) close(sd) |
| 53 | #endif |
| 54 | |
| 55 | #include "version.h" |
| 56 | |
| 57 | #define INET_SOCKETS |
| 58 | |
| 59 | #define GUARDED 10000 /* typenr for "guarded" annotation */ |
| 60 | #define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */ |
| 61 | |
| 62 | /* The first implementation (working only with Netbeans) returned "1.1". The |
| 63 | * protocol implemented here also supports A-A-P. */ |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 64 | static char *ExtEdProtocolVersion = "2.3"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 65 | |
| 66 | static long pos2off __ARGS((buf_T *, pos_T *)); |
| 67 | static pos_T *off2pos __ARGS((buf_T *, long)); |
| 68 | static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp)); |
| 69 | static long get_buf_size __ARGS((buf_T *)); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 70 | static void netbeans_keystring __ARGS((int key, char *keystr)); |
| 71 | static void special_keys __ARGS((char_u *args)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 72 | |
| 73 | static void netbeans_connect __ARGS((void)); |
| 74 | static int getConnInfo __ARGS((char *file, char **host, char **port, char **password)); |
| 75 | |
| 76 | static void nb_init_graphics __ARGS((void)); |
| 77 | static void coloncmd __ARGS((char *cmd, ...)); |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 78 | static void nb_set_curbuf __ARGS((buf_T *buf)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | #ifdef FEAT_GUI_MOTIF |
| 80 | static void messageFromNetbeans __ARGS((XtPointer, int *, XtInputId *)); |
| 81 | #endif |
| 82 | #ifdef FEAT_GUI_GTK |
| 83 | static void messageFromNetbeans __ARGS((gpointer, gint, GdkInputCondition)); |
| 84 | #endif |
| 85 | static void nb_parse_cmd __ARGS((char_u *)); |
| 86 | static int nb_do_cmd __ARGS((int, char_u *, int, int, char_u *)); |
| 87 | static void nb_send __ARGS((char *buf, char *fun)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 88 | |
| 89 | static int sd = -1; /* socket fd for Netbeans connection */ |
| 90 | #ifdef FEAT_GUI_MOTIF |
| 91 | static XtInputId inputHandler; /* Cookie for input */ |
| 92 | #endif |
| 93 | #ifdef FEAT_GUI_GTK |
| 94 | static gint inputHandler; /* Cookie for input */ |
| 95 | #endif |
| 96 | #ifdef FEAT_GUI_W32 |
| 97 | static int inputHandler = -1; /* simply ret.value of WSAAsyncSelect() */ |
| 98 | extern HWND s_hwnd; /* Gvim's Window handle */ |
| 99 | #endif |
| 100 | static int cmdno; /* current command number for reply */ |
| 101 | static int haveConnection = FALSE; /* socket is connected and |
| 102 | initialization is done */ |
| 103 | static int oldFire = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 104 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 105 | #ifdef FEAT_GUI_MOTIF |
| 106 | static void netbeans_Xt_connect __ARGS((void *context)); |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 107 | #endif |
| 108 | #ifdef FEAT_GUI_GTK |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 109 | static void netbeans_gtk_connect __ARGS((void)); |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 110 | #endif |
| 111 | #ifdef FEAT_GUI_W32 |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 112 | static void netbeans_w32_connect __ARGS((void)); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | static int dosetvisible = FALSE; |
| 116 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 117 | /* |
| 118 | * Include the debugging code if wanted. |
| 119 | */ |
| 120 | #ifdef NBDEBUG |
| 121 | # include "nbdebug.c" |
| 122 | #endif |
| 123 | |
| 124 | /* Connect back to Netbeans process */ |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 125 | #ifdef FEAT_GUI_MOTIF |
| 126 | static void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 127 | netbeans_Xt_connect(void *context) |
| 128 | { |
| 129 | netbeans_connect(); |
| 130 | if (sd > 0) |
| 131 | { |
| 132 | /* tell notifier we are interested in being called |
| 133 | * when there is input on the editor connection socket |
| 134 | */ |
| 135 | inputHandler = XtAppAddInput((XtAppContext)context, sd, |
| 136 | (XtPointer)(XtInputReadMask + XtInputExceptMask), |
| 137 | messageFromNetbeans, NULL); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | static void |
| 142 | netbeans_disconnect(void) |
| 143 | { |
| 144 | if (inputHandler != (XtInputId)NULL) |
| 145 | { |
| 146 | XtRemoveInput(inputHandler); |
| 147 | inputHandler = (XtInputId)NULL; |
| 148 | } |
| 149 | sd = -1; |
| 150 | haveConnection = FALSE; |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 151 | # ifdef FEAT_BEVAL |
| 152 | bevalServers &= ~BEVAL_NETBEANS; |
| 153 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 154 | } |
| 155 | #endif /* FEAT_MOTIF_GUI */ |
| 156 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 157 | #ifdef FEAT_GUI_GTK |
| 158 | static void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 159 | netbeans_gtk_connect(void) |
| 160 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 161 | netbeans_connect(); |
| 162 | if (sd > 0) |
| 163 | { |
| 164 | /* |
| 165 | * Tell gdk we are interested in being called when there |
| 166 | * is input on the editor connection socket |
| 167 | */ |
| 168 | inputHandler = gdk_input_add(sd, (GdkInputCondition) |
| 169 | ((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION), |
| 170 | messageFromNetbeans, NULL); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static void |
| 175 | netbeans_disconnect(void) |
| 176 | { |
| 177 | if (inputHandler != 0) |
| 178 | { |
| 179 | gdk_input_remove(inputHandler); |
| 180 | inputHandler = 0; |
| 181 | } |
| 182 | sd = -1; |
| 183 | haveConnection = FALSE; |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 184 | # ifdef FEAT_BEVAL |
| 185 | bevalServers &= ~BEVAL_NETBEANS; |
| 186 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 187 | } |
| 188 | #endif /* FEAT_GUI_GTK */ |
| 189 | |
Bram Moolenaar | 5b625c5 | 2005-01-31 18:55:55 +0000 | [diff] [blame] | 190 | #if defined(FEAT_GUI_W32) || defined(PROTO) |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 191 | static void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 192 | netbeans_w32_connect(void) |
| 193 | { |
| 194 | netbeans_connect(); |
| 195 | if (sd > 0) |
| 196 | { |
| 197 | /* |
| 198 | * Tell Windows we are interested in receiving message when there |
| 199 | * is input on the editor connection socket |
| 200 | */ |
| 201 | inputHandler = WSAAsyncSelect(sd, s_hwnd, WM_NETBEANS, FD_READ); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | netbeans_disconnect(void) |
| 207 | { |
| 208 | if (inputHandler == 0) |
| 209 | { |
| 210 | WSAAsyncSelect(sd, s_hwnd, 0, 0); |
| 211 | inputHandler = -1; |
| 212 | } |
| 213 | sd = -1; |
| 214 | haveConnection = FALSE; |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 215 | # ifdef FEAT_BEVAL |
| 216 | bevalServers &= ~BEVAL_NETBEANS; |
| 217 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 218 | } |
| 219 | #endif /* FEAT_GUI_W32 */ |
| 220 | |
| 221 | #define NB_DEF_HOST "localhost" |
| 222 | #define NB_DEF_ADDR "3219" |
| 223 | #define NB_DEF_PASS "changeme" |
| 224 | |
| 225 | static void |
| 226 | netbeans_connect(void) |
| 227 | { |
| 228 | #ifdef INET_SOCKETS |
| 229 | struct sockaddr_in server; |
| 230 | struct hostent * host; |
| 231 | # ifdef FEAT_GUI_W32 |
| 232 | u_short port; |
| 233 | # else |
| 234 | int port; |
| 235 | #endif |
| 236 | #else |
| 237 | struct sockaddr_un server; |
| 238 | #endif |
| 239 | char buf[32]; |
| 240 | char *hostname = NULL; |
| 241 | char *address = NULL; |
| 242 | char *password = NULL; |
| 243 | char *fname; |
| 244 | char *arg = NULL; |
| 245 | |
| 246 | if (netbeansArg[3] == '=') |
| 247 | { |
| 248 | /* "-nb=fname": Read info from specified file. */ |
| 249 | if (getConnInfo(netbeansArg + 4, &hostname, &address, &password) |
| 250 | == FAIL) |
| 251 | return; |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | if (netbeansArg[3] == ':') |
| 256 | /* "-nb:<host>:<addr>:<password>": get info from argument */ |
| 257 | arg = netbeansArg + 4; |
| 258 | if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL) |
| 259 | { |
| 260 | /* "-nb": get info from file specified in environment */ |
| 261 | if (getConnInfo(fname, &hostname, &address, &password) == FAIL) |
| 262 | return; |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | if (arg != NULL) |
| 267 | { |
| 268 | /* "-nb:<host>:<addr>:<password>": get info from argument */ |
| 269 | hostname = arg; |
| 270 | address = strchr(hostname, ':'); |
| 271 | if (address != NULL) |
| 272 | { |
| 273 | *address++ = '\0'; |
| 274 | password = strchr(address, ':'); |
| 275 | if (password != NULL) |
| 276 | *password++ = '\0'; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | /* Get the missing values from the environment. */ |
| 281 | if (hostname == NULL || *hostname == '\0') |
| 282 | hostname = getenv("__NETBEANS_HOST"); |
| 283 | if (address == NULL) |
| 284 | address = getenv("__NETBEANS_SOCKET"); |
| 285 | if (password == NULL) |
| 286 | password = getenv("__NETBEANS_VIM_PASSWORD"); |
| 287 | |
| 288 | /* Move values to allocated memory. */ |
| 289 | if (hostname != NULL) |
| 290 | hostname = (char *)vim_strsave((char_u *)hostname); |
| 291 | if (address != NULL) |
| 292 | address = (char *)vim_strsave((char_u *)address); |
| 293 | if (password != NULL) |
| 294 | password = (char *)vim_strsave((char_u *)password); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /* Use the default when a value is missing. */ |
| 299 | if (hostname == NULL || *hostname == '\0') |
| 300 | { |
| 301 | vim_free(hostname); |
| 302 | hostname = (char *)vim_strsave((char_u *)NB_DEF_HOST); |
| 303 | } |
| 304 | if (address == NULL || *address == '\0') |
| 305 | { |
| 306 | vim_free(address); |
| 307 | address = (char *)vim_strsave((char_u *)NB_DEF_ADDR); |
| 308 | } |
| 309 | if (password == NULL || *password == '\0') |
| 310 | { |
| 311 | vim_free(password); |
| 312 | password = (char *)vim_strsave((char_u *)NB_DEF_PASS); |
| 313 | } |
| 314 | if (hostname == NULL || address == NULL || password == NULL) |
| 315 | goto theend; /* out of memory */ |
| 316 | |
| 317 | #ifdef INET_SOCKETS |
| 318 | port = atoi(address); |
| 319 | |
| 320 | if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) |
| 321 | { |
| 322 | PERROR("socket() in netbeans_connect()"); |
| 323 | goto theend; |
| 324 | } |
| 325 | |
| 326 | /* Get the server internet address and put into addr structure */ |
| 327 | /* fill in the socket address structure and connect to server */ |
| 328 | memset((char *)&server, '\0', sizeof(server)); |
| 329 | server.sin_family = AF_INET; |
| 330 | server.sin_port = htons(port); |
| 331 | if ((host = gethostbyname(hostname)) == NULL) |
| 332 | { |
| 333 | if (mch_access(hostname, R_OK) >= 0) |
| 334 | { |
| 335 | /* DEBUG: input file */ |
| 336 | sd = mch_open(hostname, O_RDONLY, 0); |
| 337 | goto theend; |
| 338 | } |
| 339 | PERROR("gethostbyname() in netbeans_connect()"); |
| 340 | sd = -1; |
| 341 | goto theend; |
| 342 | } |
| 343 | memcpy((char *)&server.sin_addr, host->h_addr, host->h_length); |
| 344 | #else |
| 345 | if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) |
| 346 | { |
| 347 | PERROR("socket()"); |
| 348 | goto theend; |
| 349 | } |
| 350 | |
| 351 | server.sun_family = AF_UNIX; |
| 352 | strcpy(server.sun_path, address); |
| 353 | #endif |
| 354 | /* Connect to server */ |
| 355 | if (connect(sd, (struct sockaddr *)&server, sizeof(server))) |
| 356 | { |
| 357 | nbdebug(("netbeans_connect: Connect failed with errno %d\n", sock_errno)); |
| 358 | if (sock_errno == ECONNREFUSED) |
| 359 | { |
| 360 | sock_close(sd); |
| 361 | #ifdef INET_SOCKETS |
| 362 | if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) |
| 363 | { |
| 364 | PERROR("socket()#2 in netbeans_connect()"); |
| 365 | goto theend; |
| 366 | } |
| 367 | #else |
| 368 | if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) |
| 369 | { |
| 370 | PERROR("socket()#2 in netbeans_connect()"); |
| 371 | goto theend; |
| 372 | } |
| 373 | #endif |
| 374 | if (connect(sd, (struct sockaddr *)&server, sizeof(server))) |
| 375 | { |
| 376 | int retries = 36; |
| 377 | int success = FALSE; |
| 378 | while (retries-- |
| 379 | && ((sock_errno == ECONNREFUSED) || (sock_errno == EINTR))) |
| 380 | { |
| 381 | nbdebug(("retrying...\n")); |
| 382 | sleep(5); |
| 383 | if (connect(sd, (struct sockaddr *)&server, |
| 384 | sizeof(server)) == 0) |
| 385 | { |
| 386 | success = TRUE; |
| 387 | break; |
| 388 | } |
| 389 | } |
| 390 | if (!success) |
| 391 | { |
| 392 | /* Get here when the server can't be found. */ |
| 393 | PERROR(_("Cannot connect to Netbeans #2")); |
| 394 | getout(1); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | PERROR(_("Cannot connect to Netbeans")); |
| 402 | getout(1); |
| 403 | } |
| 404 | } |
| 405 | |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 406 | vim_snprintf(buf, sizeof(buf), "AUTH %s\n", password); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 407 | nb_send(buf, "netbeans_connect"); |
| 408 | |
| 409 | sprintf(buf, "0:version=0 \"%s\"\n", ExtEdProtocolVersion); |
| 410 | nb_send(buf, "externaleditor_version"); |
| 411 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 412 | /* nb_init_graphics(); delay until needed */ |
| 413 | |
| 414 | haveConnection = TRUE; |
| 415 | |
| 416 | theend: |
| 417 | vim_free(hostname); |
| 418 | vim_free(address); |
| 419 | vim_free(password); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | /* |
| 424 | * Obtain the NetBeans hostname, port address and password from a file. |
| 425 | * Return the strings in allocated memory. |
| 426 | * Return FAIL if the file could not be read, OK otherwise (no matter what it |
| 427 | * contains). |
| 428 | */ |
| 429 | static int |
| 430 | getConnInfo(char *file, char **host, char **port, char **auth) |
| 431 | { |
| 432 | FILE *fp; |
| 433 | char_u buf[BUFSIZ]; |
| 434 | char_u *lp; |
| 435 | char_u *nl; |
| 436 | #ifdef UNIX |
| 437 | struct stat st; |
| 438 | |
| 439 | /* |
| 440 | * For Unix only accept the file when it's not accessible by others. |
| 441 | * The open will then fail if we don't own the file. |
| 442 | */ |
| 443 | if (mch_stat(file, &st) == 0 && (st.st_mode & 0077) != 0) |
| 444 | { |
| 445 | EMSG2(_("E668: Wrong access mode for NetBeans connection info file: \"%s\""), |
| 446 | file); |
| 447 | return FAIL; |
| 448 | } |
| 449 | #endif |
| 450 | |
| 451 | fp = mch_fopen(file, "r"); |
| 452 | if (fp == NULL) |
| 453 | { |
| 454 | PERROR("E660: Cannot open NetBeans connection info file"); |
| 455 | return FAIL; |
| 456 | } |
| 457 | |
| 458 | /* Read the file. There should be one of each parameter */ |
| 459 | while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL) |
| 460 | { |
| 461 | if ((nl = vim_strchr(lp, '\n')) != NULL) |
| 462 | *nl = 0; /* strip off the trailing newline */ |
| 463 | |
| 464 | if (STRNCMP(lp, "host=", 5) == 0) |
| 465 | { |
| 466 | vim_free(*host); |
| 467 | *host = (char *)vim_strsave(&buf[5]); |
| 468 | } |
| 469 | else if (STRNCMP(lp, "port=", 5) == 0) |
| 470 | { |
| 471 | vim_free(*port); |
| 472 | *port = (char *)vim_strsave(&buf[5]); |
| 473 | } |
| 474 | else if (STRNCMP(lp, "auth=", 5) == 0) |
| 475 | { |
| 476 | vim_free(*auth); |
| 477 | *auth = (char *)vim_strsave(&buf[5]); |
| 478 | } |
| 479 | } |
| 480 | fclose(fp); |
| 481 | |
| 482 | return OK; |
| 483 | } |
| 484 | |
| 485 | |
| 486 | struct keyqueue |
| 487 | { |
| 488 | int key; |
| 489 | struct keyqueue *next; |
| 490 | struct keyqueue *prev; |
| 491 | }; |
| 492 | |
| 493 | typedef struct keyqueue keyQ_T; |
| 494 | |
| 495 | static keyQ_T keyHead; /* dummy node, header for circular queue */ |
| 496 | |
| 497 | |
| 498 | /* |
| 499 | * Queue up key commands sent from netbeans. |
| 500 | */ |
| 501 | static void |
| 502 | postpone_keycommand(int key) |
| 503 | { |
| 504 | keyQ_T *node; |
| 505 | |
| 506 | node = (keyQ_T *)alloc(sizeof(keyQ_T)); |
| 507 | |
| 508 | if (keyHead.next == NULL) /* initialize circular queue */ |
| 509 | { |
| 510 | keyHead.next = &keyHead; |
| 511 | keyHead.prev = &keyHead; |
| 512 | } |
| 513 | |
| 514 | /* insert node at tail of queue */ |
| 515 | node->next = &keyHead; |
| 516 | node->prev = keyHead.prev; |
| 517 | keyHead.prev->next = node; |
| 518 | keyHead.prev = node; |
| 519 | |
| 520 | node->key = key; |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Handle any queued-up NetBeans keycommands to be send. |
| 525 | */ |
| 526 | static void |
| 527 | handle_key_queue(void) |
| 528 | { |
| 529 | while (keyHead.next && keyHead.next != &keyHead) |
| 530 | { |
| 531 | /* first, unlink the node */ |
| 532 | keyQ_T *node = keyHead.next; |
| 533 | keyHead.next = node->next; |
| 534 | node->next->prev = node->prev; |
| 535 | |
| 536 | /* now, send the keycommand */ |
| 537 | netbeans_keycommand(node->key); |
| 538 | |
| 539 | /* Finally, dispose of the node */ |
| 540 | vim_free(node); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | |
| 545 | struct cmdqueue |
| 546 | { |
| 547 | char_u *buffer; |
| 548 | struct cmdqueue *next; |
| 549 | struct cmdqueue *prev; |
| 550 | }; |
| 551 | |
| 552 | typedef struct cmdqueue queue_T; |
| 553 | |
| 554 | static queue_T head; /* dummy node, header for circular queue */ |
| 555 | |
| 556 | |
| 557 | /* |
| 558 | * Put the buffer on the work queue; possibly save it to a file as well. |
| 559 | */ |
| 560 | static void |
| 561 | save(char_u *buf, int len) |
| 562 | { |
| 563 | queue_T *node; |
| 564 | |
| 565 | node = (queue_T *)alloc(sizeof(queue_T)); |
| 566 | if (node == NULL) |
| 567 | return; /* out of memory */ |
| 568 | node->buffer = alloc(len + 1); |
| 569 | if (node->buffer == NULL) |
| 570 | { |
| 571 | vim_free(node); |
| 572 | return; /* out of memory */ |
| 573 | } |
| 574 | mch_memmove(node->buffer, buf, (size_t)len); |
| 575 | node->buffer[len] = NUL; |
| 576 | |
| 577 | if (head.next == NULL) /* initialize circular queue */ |
| 578 | { |
| 579 | head.next = &head; |
| 580 | head.prev = &head; |
| 581 | } |
| 582 | |
| 583 | /* insert node at tail of queue */ |
| 584 | node->next = &head; |
| 585 | node->prev = head.prev; |
| 586 | head.prev->next = node; |
| 587 | head.prev = node; |
| 588 | |
| 589 | #ifdef NBDEBUG |
| 590 | { |
| 591 | static int outfd = -2; |
| 592 | |
| 593 | /* possibly write buffer out to a file */ |
| 594 | if (outfd == -3) |
| 595 | return; |
| 596 | |
| 597 | if (outfd == -2) |
| 598 | { |
| 599 | char *file = getenv("__NETBEANS_SAVE"); |
| 600 | if (file == NULL) |
| 601 | outfd = -3; |
| 602 | else |
| 603 | outfd = mch_open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
| 604 | } |
| 605 | |
| 606 | if (outfd >= 0) |
| 607 | write(outfd, buf, len); |
| 608 | } |
| 609 | #endif |
| 610 | } |
| 611 | |
| 612 | |
| 613 | /* |
| 614 | * While there's still a command in the work queue, parse and execute it. |
| 615 | */ |
| 616 | static void |
| 617 | nb_parse_messages(void) |
| 618 | { |
| 619 | char_u *p; |
| 620 | queue_T *node; |
| 621 | |
| 622 | while (head.next != &head) |
| 623 | { |
| 624 | node = head.next; |
| 625 | |
| 626 | /* Locate the first line in the first buffer. */ |
| 627 | p = vim_strchr(node->buffer, '\n'); |
| 628 | if (p == NULL) |
| 629 | { |
| 630 | /* Command isn't complete. If there is no following buffer, |
| 631 | * return (wait for more). If there is another buffer following, |
| 632 | * prepend the text to that buffer and delete this one. */ |
| 633 | if (node->next == &head) |
| 634 | return; |
| 635 | p = alloc(STRLEN(node->buffer) + STRLEN(node->next->buffer) + 1); |
| 636 | if (p == NULL) |
| 637 | return; /* out of memory */ |
| 638 | STRCPY(p, node->buffer); |
| 639 | STRCAT(p, node->next->buffer); |
| 640 | vim_free(node->next->buffer); |
| 641 | node->next->buffer = p; |
| 642 | |
| 643 | /* dispose of the node and buffer */ |
| 644 | head.next = node->next; |
| 645 | node->next->prev = node->prev; |
| 646 | vim_free(node->buffer); |
| 647 | vim_free(node); |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | /* There is a complete command at the start of the buffer. |
| 652 | * Terminate it with a NUL. When no more text is following unlink |
| 653 | * the buffer. Do this before executing, because new buffers can |
| 654 | * be added while busy handling the command. */ |
| 655 | *p++ = NUL; |
| 656 | if (*p == NUL) |
| 657 | { |
| 658 | head.next = node->next; |
| 659 | node->next->prev = node->prev; |
| 660 | } |
| 661 | |
| 662 | /* now, parse and execute the commands */ |
| 663 | nb_parse_cmd(node->buffer); |
| 664 | |
| 665 | if (*p == NUL) |
| 666 | { |
| 667 | /* buffer finished, dispose of the node and buffer */ |
| 668 | vim_free(node->buffer); |
| 669 | vim_free(node); |
| 670 | } |
| 671 | else |
| 672 | { |
| 673 | /* more follows, move to the start */ |
| 674 | mch_memmove(node->buffer, p, STRLEN(p) + 1); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /* Buffer size for reading incoming messages. */ |
| 681 | #define MAXMSGSIZE 4096 |
| 682 | |
| 683 | /* |
| 684 | * Read and process a command from netbeans. |
| 685 | */ |
| 686 | /*ARGSUSED*/ |
| 687 | #if defined(FEAT_GUI_W32) || defined(PROTO) |
| 688 | /* Use this one when generating prototypes, the others are static. */ |
| 689 | void |
| 690 | messageFromNetbeansW32() |
| 691 | #else |
| 692 | # ifdef FEAT_GUI_MOTIF |
| 693 | static void |
| 694 | messageFromNetbeans(XtPointer clientData, int *unused1, XtInputId *unused2) |
| 695 | # endif |
| 696 | # ifdef FEAT_GUI_GTK |
| 697 | static void |
| 698 | messageFromNetbeans(gpointer clientData, gint unused1, |
| 699 | GdkInputCondition unused2) |
| 700 | # endif |
| 701 | #endif |
| 702 | { |
| 703 | static char_u *buf = NULL; |
| 704 | int len; |
| 705 | int readlen = 0; |
| 706 | static int level = 0; |
| 707 | |
| 708 | if (sd < 0) |
| 709 | { |
| 710 | nbdebug(("messageFromNetbeans() called without a socket\n")); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | ++level; /* recursion guard; this will be called from the X event loop */ |
| 715 | |
| 716 | /* Allocate a buffer to read into. */ |
| 717 | if (buf == NULL) |
| 718 | { |
| 719 | buf = alloc(MAXMSGSIZE); |
| 720 | if (buf == NULL) |
| 721 | return; /* out of memory! */ |
| 722 | } |
| 723 | |
| 724 | /* Keep on reading for as long as there is something to read. */ |
| 725 | for (;;) |
| 726 | { |
| 727 | len = sock_read(sd, buf, MAXMSGSIZE); |
| 728 | if (len <= 0) |
| 729 | break; /* error or nothing more to read */ |
| 730 | |
| 731 | /* Store the read message in the queue. */ |
| 732 | save(buf, len); |
| 733 | readlen += len; |
| 734 | if (len < MAXMSGSIZE) |
| 735 | break; /* did read everything that's available */ |
| 736 | } |
| 737 | |
| 738 | if (readlen <= 0) |
| 739 | { |
| 740 | /* read error or didn't read anything */ |
| 741 | netbeans_disconnect(); |
| 742 | nbdebug(("messageFromNetbeans: Error in read() from socket\n")); |
| 743 | if (len < 0) |
| 744 | PERROR(_("read from Netbeans socket")); |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 745 | return; /* don't try to parse it */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /* Parse the messages, but avoid recursion. */ |
| 749 | if (level == 1) |
| 750 | nb_parse_messages(); |
| 751 | |
| 752 | --level; |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * Handle one NUL terminated command. |
| 757 | * |
| 758 | * format of a command from netbeans: |
| 759 | * |
| 760 | * 6:setTitle!84 "a.c" |
| 761 | * |
| 762 | * bufno |
| 763 | * colon |
| 764 | * cmd |
| 765 | * ! |
| 766 | * cmdno |
| 767 | * args |
| 768 | * |
| 769 | * for function calls, the ! is replaced by a / |
| 770 | */ |
| 771 | static void |
| 772 | nb_parse_cmd(char_u *cmd) |
| 773 | { |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 774 | char *verb; |
| 775 | char *q; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 776 | int bufno; |
| 777 | int isfunc = -1; |
| 778 | |
| 779 | if (STRCMP(cmd, "DISCONNECT") == 0) |
| 780 | { |
| 781 | /* We assume the server knows that we can safely exit! */ |
| 782 | if (sd >= 0) |
| 783 | sock_close(sd); |
| 784 | /* Disconnect before exiting, Motif hangs in a Select error |
| 785 | * message otherwise. */ |
| 786 | netbeans_disconnect(); |
| 787 | getout(0); |
| 788 | /* NOTREACHED */ |
| 789 | } |
| 790 | |
| 791 | if (STRCMP(cmd, "DETACH") == 0) |
| 792 | { |
| 793 | /* The IDE is breaking the connection. */ |
| 794 | if (sd >= 0) |
| 795 | sock_close(sd); |
| 796 | netbeans_disconnect(); |
| 797 | return; |
| 798 | } |
| 799 | |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 800 | bufno = strtol((char *)cmd, &verb, 10); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 801 | |
| 802 | if (*verb != ':') |
| 803 | { |
| 804 | EMSG2("E627: missing colon: %s", cmd); |
| 805 | return; |
| 806 | } |
| 807 | ++verb; /* skip colon */ |
| 808 | |
| 809 | for (q = verb; *q; q++) |
| 810 | { |
| 811 | if (*q == '!') |
| 812 | { |
| 813 | *q++ = NUL; |
| 814 | isfunc = 0; |
| 815 | break; |
| 816 | } |
| 817 | else if (*q == '/') |
| 818 | { |
| 819 | *q++ = NUL; |
| 820 | isfunc = 1; |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | if (isfunc < 0) |
| 826 | { |
| 827 | EMSG2("E628: missing ! or / in: %s", cmd); |
| 828 | return; |
| 829 | } |
| 830 | |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 831 | cmdno = strtol(q, &q, 10); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 832 | |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 833 | q = (char *)skipwhite((char_u *)q); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 834 | |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 835 | if (nb_do_cmd(bufno, (char_u *)verb, isfunc, cmdno, (char_u *)q) == FAIL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 836 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 837 | #ifdef NBDEBUG |
| 838 | /* |
| 839 | * This happens because the ExtEd can send a cammand or 2 after |
| 840 | * doing a stopDocumentListen command. It doesn't harm anything |
| 841 | * so I'm disabling it except for debugging. |
| 842 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 843 | nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd)); |
| 844 | EMSG("E629: bad return from nb_do_cmd"); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 845 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
| 849 | struct nbbuf_struct |
| 850 | { |
| 851 | buf_T *bufp; |
| 852 | unsigned int fireChanges:1; |
| 853 | unsigned int initDone:1; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 854 | unsigned int insertDone:1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 855 | unsigned int modified:1; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 856 | int nbbuf_number; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 857 | char *displayname; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 858 | int *signmap; |
| 859 | short_u signmaplen; |
| 860 | short_u signmapused; |
| 861 | }; |
| 862 | |
| 863 | typedef struct nbbuf_struct nbbuf_T; |
| 864 | |
| 865 | static nbbuf_T *buf_list = 0; |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 866 | static int buf_list_size = 0; /* size of buf_list */ |
| 867 | static int buf_list_used = 0; /* nr of entries in buf_list actually in use */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 868 | |
| 869 | static char **globalsignmap; |
| 870 | static int globalsignmaplen; |
| 871 | static int globalsignmapused; |
| 872 | |
| 873 | static int mapsigntype __ARGS((nbbuf_T *, int localsigntype)); |
| 874 | static void addsigntype __ARGS((nbbuf_T *, int localsigntype, char_u *typeName, |
| 875 | char_u *tooltip, char_u *glyphfile, |
| 876 | int usefg, int fg, int usebg, int bg)); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 877 | static void print_read_msg __ARGS((nbbuf_T *buf)); |
| 878 | static void print_save_msg __ARGS((nbbuf_T *buf, long nchars)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 879 | |
| 880 | static int curPCtype = -1; |
| 881 | |
| 882 | /* |
| 883 | * Get the Netbeans buffer number for the specified buffer. |
| 884 | */ |
| 885 | static int |
| 886 | nb_getbufno(buf_T *bufp) |
| 887 | { |
| 888 | int i; |
| 889 | |
| 890 | for (i = 0; i < buf_list_used; i++) |
| 891 | if (buf_list[i].bufp == bufp) |
| 892 | return i; |
| 893 | return -1; |
| 894 | } |
| 895 | |
| 896 | /* |
| 897 | * Is this a NetBeans-owned buffer? |
| 898 | */ |
| 899 | int |
| 900 | isNetbeansBuffer(buf_T *bufp) |
| 901 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 902 | return usingNetbeans && bufp->b_netbeans_file; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /* |
| 906 | * NetBeans and Vim have different undo models. In Vim, the file isn't |
| 907 | * changed if changes are undone via the undo command. In NetBeans, once |
| 908 | * a change has been made the file is marked as modified until saved. It |
| 909 | * doesn't matter if the change was undone. |
| 910 | * |
| 911 | * So this function is for the corner case where Vim thinks a buffer is |
| 912 | * unmodified but NetBeans thinks it IS modified. |
| 913 | */ |
| 914 | int |
| 915 | isNetbeansModified(buf_T *bufp) |
| 916 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 917 | if (usingNetbeans && bufp->b_netbeans_file) |
| 918 | { |
| 919 | int bufno = nb_getbufno(bufp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 920 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 921 | if (bufno > 0) |
| 922 | return buf_list[bufno].modified; |
| 923 | else |
| 924 | return FALSE; |
| 925 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 926 | else |
| 927 | return FALSE; |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | * Given a Netbeans buffer number, return the netbeans buffer. |
| 932 | * Returns NULL for 0 or a negative number. A 0 bufno means a |
| 933 | * non-buffer related command has been sent. |
| 934 | */ |
| 935 | static nbbuf_T * |
| 936 | nb_get_buf(int bufno) |
| 937 | { |
| 938 | /* find or create a buffer with the given number */ |
| 939 | int incr; |
| 940 | |
| 941 | if (bufno <= 0) |
| 942 | return NULL; |
| 943 | |
| 944 | if (!buf_list) |
| 945 | { |
| 946 | /* initialize */ |
| 947 | buf_list = (nbbuf_T *)alloc_clear(100 * sizeof(nbbuf_T)); |
| 948 | buf_list_size = 100; |
| 949 | } |
| 950 | if (bufno >= buf_list_used) /* new */ |
| 951 | { |
| 952 | if (bufno >= buf_list_size) /* grow list */ |
| 953 | { |
| 954 | incr = bufno - buf_list_size + 90; |
| 955 | buf_list_size += incr; |
| 956 | buf_list = (nbbuf_T *)vim_realloc( |
| 957 | buf_list, buf_list_size * sizeof(nbbuf_T)); |
| 958 | memset(buf_list + buf_list_size - incr, 0, incr * sizeof(nbbuf_T)); |
| 959 | } |
| 960 | |
| 961 | while (buf_list_used <= bufno) |
| 962 | { |
| 963 | /* Default is to fire text changes. */ |
| 964 | buf_list[buf_list_used].fireChanges = 1; |
| 965 | ++buf_list_used; |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | return buf_list + bufno; |
| 970 | } |
| 971 | |
| 972 | /* |
| 973 | * Return the number of buffers that are modified. |
| 974 | */ |
| 975 | static int |
| 976 | count_changed_buffers(void) |
| 977 | { |
| 978 | buf_T *bufp; |
| 979 | int n; |
| 980 | |
| 981 | n = 0; |
| 982 | for (bufp = firstbuf; bufp != NULL; bufp = bufp->b_next) |
| 983 | if (bufp->b_changed) |
| 984 | ++n; |
| 985 | return n; |
| 986 | } |
| 987 | |
| 988 | /* |
| 989 | * End the netbeans session. |
| 990 | */ |
| 991 | void |
| 992 | netbeans_end(void) |
| 993 | { |
| 994 | int i; |
| 995 | static char buf[128]; |
| 996 | |
| 997 | if (!haveConnection) |
| 998 | return; |
| 999 | |
| 1000 | for (i = 0; i < buf_list_used; i++) |
| 1001 | { |
| 1002 | if (!buf_list[i].bufp) |
| 1003 | continue; |
| 1004 | if (netbeansForcedQuit) |
| 1005 | { |
| 1006 | /* mark as unmodified so NetBeans won't put up dialog on "killed" */ |
| 1007 | sprintf(buf, "%d:unmodified=%d\n", i, cmdno); |
| 1008 | nbdebug(("EVT: %s", buf)); |
| 1009 | nb_send(buf, "netbeans_end"); |
| 1010 | } |
| 1011 | sprintf(buf, "%d:killed=%d\n", i, cmdno); |
| 1012 | nbdebug(("EVT: %s", buf)); |
| 1013 | /* nb_send(buf, "netbeans_end"); avoid "write failed" messages */ |
| 1014 | if (sd >= 0) |
| 1015 | sock_write(sd, buf, STRLEN(buf)); /* ignore errors */ |
| 1016 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /* |
| 1020 | * Send a message to netbeans. |
| 1021 | */ |
| 1022 | static void |
| 1023 | nb_send(char *buf, char *fun) |
| 1024 | { |
| 1025 | /* Avoid giving pages full of error messages when the other side has |
| 1026 | * exited, only mention the first error until the connection works again. */ |
| 1027 | static int did_error = FALSE; |
| 1028 | |
| 1029 | if (sd < 0) |
| 1030 | { |
| 1031 | if (!did_error) |
| 1032 | EMSG2("E630: %s(): write while not connected", fun); |
| 1033 | did_error = TRUE; |
| 1034 | } |
| 1035 | else if (sock_write(sd, buf, STRLEN(buf)) != (int)STRLEN(buf)) |
| 1036 | { |
| 1037 | if (!did_error) |
| 1038 | EMSG2("E631: %s(): write failed", fun); |
| 1039 | did_error = TRUE; |
| 1040 | } |
| 1041 | else |
| 1042 | did_error = FALSE; |
| 1043 | } |
| 1044 | |
| 1045 | /* |
| 1046 | * Some input received from netbeans requires a response. This function |
| 1047 | * handles a response with no information (except the command number). |
| 1048 | */ |
| 1049 | static void |
| 1050 | nb_reply_nil(int cmdno) |
| 1051 | { |
| 1052 | char reply[32]; |
| 1053 | |
| 1054 | if (!haveConnection) |
| 1055 | return; |
| 1056 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1057 | nbdebug(("REP %d: <none>\n", cmdno)); |
| 1058 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1059 | sprintf(reply, "%d\n", cmdno); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1060 | nb_send(reply, "nb_reply_nil"); |
| 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | /* |
| 1065 | * Send a response with text. |
| 1066 | * "result" must have been quoted already (using nb_quote()). |
| 1067 | */ |
| 1068 | static void |
| 1069 | nb_reply_text(int cmdno, char_u *result) |
| 1070 | { |
| 1071 | char_u *reply; |
| 1072 | |
| 1073 | if (!haveConnection) |
| 1074 | return; |
| 1075 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1076 | nbdebug(("REP %d: %s\n", cmdno, (char *)result)); |
| 1077 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1078 | reply = alloc(STRLEN(result) + 32); |
| 1079 | sprintf((char *)reply, "%d %s\n", cmdno, (char *)result); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1080 | nb_send((char *)reply, "nb_reply_text"); |
| 1081 | |
| 1082 | vim_free(reply); |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | /* |
| 1087 | * Send a response with a number result code. |
| 1088 | */ |
| 1089 | static void |
| 1090 | nb_reply_nr(int cmdno, long result) |
| 1091 | { |
| 1092 | char reply[32]; |
| 1093 | |
| 1094 | if (!haveConnection) |
| 1095 | return; |
| 1096 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1097 | nbdebug(("REP %d: %ld\n", cmdno, result)); |
| 1098 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1099 | sprintf(reply, "%d %ld\n", cmdno, result); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1100 | nb_send(reply, "nb_reply_nr"); |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | /* |
| 1105 | * Encode newline, ret, backslash, double quote for transmission to NetBeans. |
| 1106 | */ |
| 1107 | static char_u * |
| 1108 | nb_quote(char_u *txt) |
| 1109 | { |
| 1110 | char_u *buf = alloc(2 * STRLEN(txt) + 1); |
| 1111 | char_u *p = txt; |
| 1112 | char_u *q = buf; |
| 1113 | |
| 1114 | if (buf == NULL) |
| 1115 | return NULL; |
| 1116 | for (; *p; p++) |
| 1117 | { |
| 1118 | switch (*p) |
| 1119 | { |
| 1120 | case '\"': |
| 1121 | case '\\': |
| 1122 | *q++ = '\\'; *q++ = *p; break; |
| 1123 | /* case '\t': */ |
| 1124 | /* *q++ = '\\'; *q++ = 't'; break; */ |
| 1125 | case '\n': |
| 1126 | *q++ = '\\'; *q++ = 'n'; break; |
| 1127 | case '\r': |
| 1128 | *q++ = '\\'; *q++ = 'r'; break; |
| 1129 | default: |
| 1130 | *q++ = *p; |
| 1131 | break; |
| 1132 | } |
| 1133 | } |
| 1134 | *q++ = '\0'; |
| 1135 | |
| 1136 | return buf; |
| 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | /* |
| 1141 | * Remove top level double quotes; convert backslashed chars. |
| 1142 | * Returns an allocated string (NULL for failure). |
| 1143 | * If "endp" is not NULL it is set to the character after the terminating |
| 1144 | * quote. |
| 1145 | */ |
| 1146 | static char * |
| 1147 | nb_unquote(char_u *p, char_u **endp) |
| 1148 | { |
| 1149 | char *result = 0; |
| 1150 | char *q; |
| 1151 | int done = 0; |
| 1152 | |
| 1153 | /* result is never longer than input */ |
| 1154 | result = (char *)alloc_clear(STRLEN(p) + 1); |
| 1155 | if (result == NULL) |
| 1156 | return NULL; |
| 1157 | |
| 1158 | if (*p++ != '"') |
| 1159 | { |
| 1160 | nbdebug(("nb_unquote called with string that doesn't start with a quote!: %s\n", |
| 1161 | p)); |
| 1162 | result[0] = NUL; |
| 1163 | return result; |
| 1164 | } |
| 1165 | |
| 1166 | for (q = result; !done && *p != NUL;) |
| 1167 | { |
| 1168 | switch (*p) |
| 1169 | { |
| 1170 | case '"': |
| 1171 | /* |
| 1172 | * Unbackslashed dquote marks the end, if first char was dquote. |
| 1173 | */ |
| 1174 | done = 1; |
| 1175 | break; |
| 1176 | |
| 1177 | case '\\': |
| 1178 | ++p; |
| 1179 | switch (*p) |
| 1180 | { |
| 1181 | case '\\': *q++ = '\\'; break; |
| 1182 | case 'n': *q++ = '\n'; break; |
| 1183 | case 't': *q++ = '\t'; break; |
| 1184 | case 'r': *q++ = '\r'; break; |
| 1185 | case '"': *q++ = '"'; break; |
| 1186 | case NUL: --p; break; |
| 1187 | /* default: skip over illegal chars */ |
| 1188 | } |
| 1189 | ++p; |
| 1190 | break; |
| 1191 | |
| 1192 | default: |
| 1193 | *q++ = *p++; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | if (endp != NULL) |
| 1198 | *endp = p; |
| 1199 | |
| 1200 | return result; |
| 1201 | } |
| 1202 | |
| 1203 | #define SKIP_STOP 2 |
| 1204 | #define streq(a,b) (strcmp(a,b) == 0) |
| 1205 | static int needupdate = 0; |
| 1206 | static int inAtomic = 0; |
| 1207 | |
| 1208 | /* |
| 1209 | * Do the actual processing of a single netbeans command or function. |
| 1210 | * The differance between a command and function is that a function |
| 1211 | * gets a response (its required) but a command does not. |
| 1212 | * For arguments see comment for nb_parse_cmd(). |
| 1213 | */ |
| 1214 | static int |
| 1215 | nb_do_cmd( |
| 1216 | int bufno, |
| 1217 | char_u *cmd, |
| 1218 | int func, |
| 1219 | int cmdno, |
| 1220 | char_u *args) /* points to space before arguments or NUL */ |
| 1221 | { |
| 1222 | int doupdate = 0; |
| 1223 | long off = 0; |
| 1224 | nbbuf_T *buf = nb_get_buf(bufno); |
| 1225 | static int skip = 0; |
| 1226 | int retval = OK; |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 1227 | char *cp; /* for when a char pointer is needed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1228 | |
| 1229 | nbdebug(("%s %d: (%d) %s %s\n", (func) ? "FUN" : "CMD", cmdno, bufno, cmd, |
| 1230 | STRCMP(cmd, "insert") == 0 ? "<text>" : (char *)args)); |
| 1231 | |
| 1232 | if (func) |
| 1233 | { |
| 1234 | /* =====================================================================*/ |
| 1235 | if (streq((char *)cmd, "getModified")) |
| 1236 | { |
| 1237 | if (buf == NULL || buf->bufp == NULL) |
| 1238 | /* Return the number of buffers that are modified. */ |
| 1239 | nb_reply_nr(cmdno, (long)count_changed_buffers()); |
| 1240 | else |
| 1241 | /* Return whether the buffer is modified. */ |
| 1242 | nb_reply_nr(cmdno, (long)(buf->bufp->b_changed |
| 1243 | || isNetbeansModified(buf->bufp))); |
| 1244 | /* =====================================================================*/ |
| 1245 | } |
| 1246 | else if (streq((char *)cmd, "saveAndExit")) |
| 1247 | { |
| 1248 | /* Note: this will exit Vim if successful. */ |
| 1249 | coloncmd(":confirm qall"); |
| 1250 | |
| 1251 | /* We didn't exit: return the number of changed buffers. */ |
| 1252 | nb_reply_nr(cmdno, (long)count_changed_buffers()); |
| 1253 | /* =====================================================================*/ |
| 1254 | } |
| 1255 | else if (streq((char *)cmd, "getCursor")) |
| 1256 | { |
| 1257 | char_u text[200]; |
| 1258 | |
| 1259 | /* Note: nb_getbufno() may return -1. This indicates the IDE |
| 1260 | * didn't assign a number to the current buffer in response to a |
| 1261 | * fileOpened event. */ |
| 1262 | sprintf((char *)text, "%d %ld %d %ld", |
| 1263 | nb_getbufno(curbuf), |
| 1264 | (long)curwin->w_cursor.lnum, |
| 1265 | (int)curwin->w_cursor.col, |
| 1266 | pos2off(curbuf, &curwin->w_cursor)); |
| 1267 | nb_reply_text(cmdno, text); |
| 1268 | /* =====================================================================*/ |
| 1269 | } |
| 1270 | else if (streq((char *)cmd, "getLength")) |
| 1271 | { |
| 1272 | long len = 0; |
| 1273 | |
| 1274 | if (buf == NULL || buf->bufp == NULL) |
| 1275 | { |
| 1276 | nbdebug((" null bufp in getLength")); |
| 1277 | EMSG("E632: null bufp in getLength"); |
| 1278 | retval = FAIL; |
| 1279 | } |
| 1280 | else |
| 1281 | { |
| 1282 | len = get_buf_size(buf->bufp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1283 | } |
| 1284 | nb_reply_nr(cmdno, len); |
| 1285 | /* =====================================================================*/ |
| 1286 | } |
| 1287 | else if (streq((char *)cmd, "getText")) |
| 1288 | { |
| 1289 | long len; |
| 1290 | linenr_T nlines; |
| 1291 | char_u *text = NULL; |
| 1292 | linenr_T lno = 1; |
| 1293 | char_u *p; |
| 1294 | char_u *line; |
| 1295 | |
| 1296 | if (buf == NULL || buf->bufp == NULL) |
| 1297 | { |
| 1298 | nbdebug((" null bufp in getText")); |
| 1299 | EMSG("E633: null bufp in getText"); |
| 1300 | retval = FAIL; |
| 1301 | } |
| 1302 | else |
| 1303 | { |
| 1304 | len = get_buf_size(buf->bufp); |
| 1305 | nlines = buf->bufp->b_ml.ml_line_count; |
| 1306 | text = alloc((unsigned)((len > 0) |
| 1307 | ? ((len + nlines) * 2) : 4)); |
| 1308 | if (text == NULL) |
| 1309 | { |
| 1310 | nbdebug((" nb_do_cmd: getText has null text field\n")); |
| 1311 | retval = FAIL; |
| 1312 | } |
| 1313 | else |
| 1314 | { |
| 1315 | p = text; |
| 1316 | *p++ = '\"'; |
| 1317 | for (; lno <= nlines ; lno++) |
| 1318 | { |
| 1319 | line = nb_quote(ml_get_buf(buf->bufp, lno, FALSE)); |
| 1320 | if (line != NULL) |
| 1321 | { |
| 1322 | STRCPY(p, line); |
| 1323 | p += STRLEN(line); |
| 1324 | *p++ = '\\'; |
| 1325 | *p++ = 'n'; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1326 | vim_free(line); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1327 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1328 | } |
| 1329 | *p++ = '\"'; |
| 1330 | *p = '\0'; |
| 1331 | } |
| 1332 | } |
| 1333 | if (text == NULL) |
| 1334 | nb_reply_text(cmdno, (char_u *)""); |
| 1335 | else |
| 1336 | { |
| 1337 | nb_reply_text(cmdno, text); |
| 1338 | vim_free(text); |
| 1339 | } |
| 1340 | /* =====================================================================*/ |
| 1341 | } |
| 1342 | else if (streq((char *)cmd, "remove")) |
| 1343 | { |
| 1344 | long count; |
| 1345 | pos_T first, last; |
| 1346 | pos_T *pos; |
| 1347 | int oldFire = netbeansFireChanges; |
| 1348 | int oldSuppress = netbeansSuppressNoLines; |
| 1349 | int wasChanged; |
| 1350 | |
| 1351 | if (skip >= SKIP_STOP) |
| 1352 | { |
| 1353 | nbdebug((" Skipping %s command\n", (char *) cmd)); |
| 1354 | nb_reply_nil(cmdno); |
| 1355 | return OK; |
| 1356 | } |
| 1357 | |
| 1358 | if (buf == NULL || buf->bufp == NULL) |
| 1359 | { |
| 1360 | nbdebug((" null bufp in remove")); |
| 1361 | EMSG("E634: null bufp in remove"); |
| 1362 | retval = FAIL; |
| 1363 | } |
| 1364 | else |
| 1365 | { |
| 1366 | netbeansFireChanges = FALSE; |
| 1367 | netbeansSuppressNoLines = TRUE; |
| 1368 | |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 1369 | nb_set_curbuf(buf->bufp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1370 | wasChanged = buf->bufp->b_changed; |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 1371 | cp = (char *)args; |
| 1372 | off = strtol(cp, &cp, 10); |
| 1373 | count = strtol(cp, &cp, 10); |
| 1374 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1375 | /* delete "count" chars, starting at "off" */ |
| 1376 | pos = off2pos(buf->bufp, off); |
| 1377 | if (!pos) |
| 1378 | { |
| 1379 | nb_reply_text(cmdno, (char_u *)"!bad position"); |
| 1380 | netbeansFireChanges = oldFire; |
| 1381 | netbeansSuppressNoLines = oldSuppress; |
| 1382 | return FAIL; |
| 1383 | } |
| 1384 | first = *pos; |
| 1385 | nbdebug((" FIRST POS: line %d, col %d\n", first.lnum, first.col)); |
| 1386 | pos = off2pos(buf->bufp, off+count-1); |
| 1387 | if (!pos) |
| 1388 | { |
| 1389 | nb_reply_text(cmdno, (char_u *)"!bad count"); |
| 1390 | netbeansFireChanges = oldFire; |
| 1391 | netbeansSuppressNoLines = oldSuppress; |
| 1392 | return FAIL; |
| 1393 | } |
| 1394 | last = *pos; |
| 1395 | nbdebug((" LAST POS: line %d, col %d\n", last.lnum, last.col)); |
| 1396 | curwin->w_cursor = first; |
| 1397 | doupdate = 1; |
| 1398 | |
| 1399 | /* keep part of first line */ |
| 1400 | if (first.lnum == last.lnum && first.col != last.col) |
| 1401 | { |
| 1402 | /* deletion is within one line */ |
| 1403 | char_u *p = ml_get(first.lnum); |
| 1404 | mch_memmove(p + first.col, p + last.col + 1, STRLEN(p + last.col) + 1); |
| 1405 | nbdebug((" NEW LINE %d: %s\n", first.lnum, p)); |
| 1406 | ml_replace(first.lnum, p, TRUE); |
| 1407 | } |
| 1408 | |
| 1409 | if (first.lnum < last.lnum) |
| 1410 | { |
| 1411 | int i; |
| 1412 | |
| 1413 | /* delete signs from the lines being deleted */ |
| 1414 | for (i = first.lnum; i <= last.lnum; i++) |
| 1415 | { |
| 1416 | int id = buf_findsign_id(buf->bufp, (linenr_T)i); |
| 1417 | if (id > 0) |
| 1418 | { |
| 1419 | nbdebug((" Deleting sign %d on line %d\n", id, i)); |
| 1420 | buf_delsign(buf->bufp, id); |
| 1421 | } |
| 1422 | else |
| 1423 | nbdebug((" No sign on line %d\n", i)); |
| 1424 | } |
| 1425 | |
| 1426 | /* delete whole lines */ |
| 1427 | nbdebug((" Deleting lines %d through %d\n", first.lnum, last.lnum)); |
| 1428 | del_lines(last.lnum - first.lnum + 1, FALSE); |
| 1429 | } |
| 1430 | buf->bufp->b_changed = wasChanged; /* logically unchanged */ |
| 1431 | netbeansFireChanges = oldFire; |
| 1432 | netbeansSuppressNoLines = oldSuppress; |
| 1433 | |
| 1434 | u_blockfree(buf->bufp); |
| 1435 | u_clearall(buf->bufp); |
| 1436 | } |
| 1437 | nb_reply_nil(cmdno); |
| 1438 | /* =====================================================================*/ |
| 1439 | } |
| 1440 | else if (streq((char *)cmd, "insert")) |
| 1441 | { |
| 1442 | pos_T *pos; |
| 1443 | pos_T mypos; |
| 1444 | char_u *to_free; |
| 1445 | char_u *nl; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1446 | linenr_T lnum; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1447 | pos_T old_w_cursor; |
| 1448 | int old_b_changed; |
| 1449 | |
| 1450 | if (skip >= SKIP_STOP) |
| 1451 | { |
| 1452 | nbdebug((" Skipping %s command\n", (char *) cmd)); |
| 1453 | nb_reply_nil(cmdno); |
| 1454 | return OK; |
| 1455 | } |
| 1456 | |
| 1457 | /* get offset */ |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 1458 | cp = (char *)args; |
| 1459 | off = strtol(cp, &cp, 10); |
| 1460 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1461 | |
| 1462 | /* get text to be inserted */ |
| 1463 | args = skipwhite(args); |
| 1464 | args = to_free = (char_u *)nb_unquote(args, NULL); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1465 | /* |
| 1466 | nbdebug((" CHUNK[%d]: %d bytes at offset %d\n", |
| 1467 | buf->bufp->b_ml.ml_line_count, STRLEN(args), off)); |
| 1468 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1469 | |
| 1470 | if (buf == NULL || buf->bufp == NULL) |
| 1471 | { |
| 1472 | nbdebug((" null bufp in insert")); |
| 1473 | EMSG("E635: null bufp in insert"); |
| 1474 | retval = FAIL; |
| 1475 | } |
| 1476 | else if (args != NULL) |
| 1477 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1478 | /* |
| 1479 | * We need to detect EOL style |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1480 | * because addAnno passes char-offset |
| 1481 | */ |
| 1482 | int ff_detected = EOL_UNKNOWN; |
| 1483 | int buf_was_empty = (buf->bufp->b_ml.ml_flags & ML_EMPTY); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1484 | char_u lbuf[4096]; /* size of largest insert sent by exted */ |
| 1485 | int lbuf_len = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1486 | |
| 1487 | oldFire = netbeansFireChanges; |
| 1488 | netbeansFireChanges = 0; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1489 | lbuf[0] = '\0'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1490 | |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 1491 | nb_set_curbuf(buf->bufp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1492 | old_b_changed = buf->bufp->b_changed; |
| 1493 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1494 | pos = off2pos(buf->bufp, off); |
| 1495 | if (pos) |
| 1496 | { |
| 1497 | if (pos->lnum == 0) |
| 1498 | pos->lnum = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1499 | } |
| 1500 | else |
| 1501 | { |
| 1502 | /* if the given position is not found, assume we want |
| 1503 | * the end of the file. See setLocAndSize HACK. */ |
| 1504 | pos = &mypos; |
| 1505 | pos->col = 0; |
| 1506 | #ifdef FEAT_VIRTUALEDIT |
| 1507 | pos->coladd = 0; |
| 1508 | #endif |
| 1509 | pos->lnum = buf->bufp->b_ml.ml_line_count; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1510 | } |
| 1511 | lnum = pos->lnum; |
| 1512 | old_w_cursor = curwin->w_cursor; |
| 1513 | curwin->w_cursor = *pos; |
| 1514 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1515 | if (buf->bufp->b_start_eol == FALSE && lnum > 0) |
| 1516 | { |
| 1517 | /* Append to a partial line */ |
| 1518 | char_u *partial = ml_get(lnum); |
| 1519 | |
| 1520 | if (partial != IObuff) |
| 1521 | STRCPY(lbuf, partial); |
| 1522 | lbuf_len = STRLEN(partial); |
| 1523 | ml_delete(lnum, FALSE); |
| 1524 | } |
| 1525 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1526 | doupdate = 1; |
| 1527 | while (*args) |
| 1528 | { |
| 1529 | nl = (char_u *)strchr((char *)args, '\n'); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1530 | if (nl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1531 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1532 | STRNCAT(lbuf, args, nl - args); |
| 1533 | lbuf[lbuf_len + nl - args] = '\0'; |
| 1534 | args += nl - args + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1535 | } |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1536 | else |
| 1537 | { |
| 1538 | STRCPY(lbuf, args); |
| 1539 | args += STRLEN(lbuf); |
| 1540 | } |
| 1541 | |
| 1542 | /* |
| 1543 | * EOL detecting. Not sure how to deal with '\n' on Mac. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1544 | */ |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1545 | if (buf_was_empty && nl && *(nl - 1) != '\r') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1546 | ff_detected = EOL_UNIX; |
| 1547 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1548 | /* nbdebug((" INSERT[%d]: %s\n", lnum, lbuf)); */ |
| 1549 | ml_append((linenr_T)(lnum++ - 1), lbuf, |
| 1550 | STRLEN(lbuf) + 1, FALSE); |
| 1551 | lbuf[0] = '\0'; /* empty buffer */ |
| 1552 | lbuf_len = 0; |
| 1553 | } |
| 1554 | |
| 1555 | if (*(args - 1) == '\n') |
| 1556 | { |
| 1557 | buf->bufp->b_p_eol = TRUE; |
| 1558 | buf->bufp->b_start_eol = TRUE; |
| 1559 | } |
| 1560 | else |
| 1561 | { |
| 1562 | buf->bufp->b_p_eol = FALSE; |
| 1563 | buf->bufp->b_start_eol = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | appended_lines_mark(pos->lnum - 1, lnum - pos->lnum); |
| 1567 | |
| 1568 | /* We can change initial ff without consequences |
| 1569 | * Isn't it a kind of hacking? |
| 1570 | */ |
| 1571 | if (buf_was_empty) |
| 1572 | { |
| 1573 | if (ff_detected == EOL_UNKNOWN) |
| 1574 | ff_detected = EOL_DOS; |
| 1575 | set_fileformat(ff_detected, OPT_LOCAL); |
| 1576 | buf->bufp->b_start_ffc = *buf->bufp->b_p_ff; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1577 | ml_delete(curbuf->b_ml.ml_line_count, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1580 | curwin->w_cursor = old_w_cursor; |
| 1581 | |
| 1582 | /* |
| 1583 | * XXX - GRP - Is the next line right? If I've inserted |
| 1584 | * text the buffer has been updated but not written. Will |
| 1585 | * netbeans guarantee to write it? Even if I do a :q! ? |
| 1586 | */ |
| 1587 | buf->bufp->b_changed = old_b_changed; /* logically unchanged */ |
| 1588 | netbeansFireChanges = oldFire; |
| 1589 | |
| 1590 | u_blockfree(buf->bufp); |
| 1591 | u_clearall(buf->bufp); |
| 1592 | } |
| 1593 | vim_free(to_free); |
| 1594 | nb_reply_nil(cmdno); /* or !error */ |
| 1595 | } |
| 1596 | else |
| 1597 | { |
| 1598 | nbdebug(("UNIMPLEMENTED FUNCTION: %s\n", cmd)); |
| 1599 | nb_reply_nil(cmdno); |
| 1600 | retval = FAIL; |
| 1601 | } |
| 1602 | } |
| 1603 | else /* Not a function; no reply required. */ |
| 1604 | { |
| 1605 | /* =====================================================================*/ |
| 1606 | if (streq((char *)cmd, "create")) |
| 1607 | { |
| 1608 | /* Create a buffer without a name. */ |
| 1609 | if (buf == NULL) |
| 1610 | { |
| 1611 | EMSG("E636: null buf in create"); |
| 1612 | return FAIL; |
| 1613 | } |
| 1614 | vim_free(buf->displayname); |
| 1615 | buf->displayname = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1616 | |
| 1617 | netbeansReadFile = 0; /* don't try to open disk file */ |
| 1618 | do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF); |
| 1619 | netbeansReadFile = 1; |
| 1620 | buf->bufp = curbuf; |
| 1621 | maketitle(); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1622 | buf->insertDone = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1623 | gui_update_menus(0); |
| 1624 | /* =====================================================================*/ |
| 1625 | } |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1626 | else if (streq((char *)cmd, "insertDone")) |
| 1627 | { |
| 1628 | buf->bufp->b_start_eol = *args == 'T'; |
| 1629 | buf->insertDone = TRUE; |
| 1630 | args += 2; |
| 1631 | buf->bufp->b_p_ro = *args == 'T'; |
| 1632 | print_read_msg(buf); |
| 1633 | /* =====================================================================*/ |
| 1634 | } |
| 1635 | else if (streq((char *)cmd, "saveDone")) |
| 1636 | { |
| 1637 | long savedChars = atol((char *) args); |
| 1638 | print_save_msg(buf, savedChars); |
| 1639 | /* =====================================================================*/ |
| 1640 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1641 | else if (streq((char *)cmd, "startDocumentListen")) |
| 1642 | { |
| 1643 | if (buf == NULL) |
| 1644 | { |
| 1645 | EMSG("E637: null buf in startDocumentListen"); |
| 1646 | return FAIL; |
| 1647 | } |
| 1648 | buf->fireChanges = 1; |
| 1649 | /* =====================================================================*/ |
| 1650 | } |
| 1651 | else if (streq((char *)cmd, "stopDocumentListen")) |
| 1652 | { |
| 1653 | if (buf == NULL) |
| 1654 | { |
| 1655 | EMSG("E638: null buf in stopDocumentListen"); |
| 1656 | return FAIL; |
| 1657 | } |
| 1658 | buf->fireChanges = 0; |
Bram Moolenaar | 24c088a | 2005-02-02 22:55:47 +0000 | [diff] [blame] | 1659 | if (buf->bufp != NULL && buf->bufp->b_was_netbeans_file) |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1660 | { |
Bram Moolenaar | 24c088a | 2005-02-02 22:55:47 +0000 | [diff] [blame] | 1661 | if (!buf->bufp->b_netbeans_file) |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1662 | EMSGN(_("E658: NetBeans connection lost for buffer %ld"), |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1663 | buf->bufp->b_fnum); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1664 | else |
| 1665 | { |
Bram Moolenaar | 24c088a | 2005-02-02 22:55:47 +0000 | [diff] [blame] | 1666 | /* NetBeans uses stopDocumentListen when it stops editing |
| 1667 | * a file. It then expects the buffer in Vim to |
| 1668 | * disappear. */ |
| 1669 | do_bufdel(DOBUF_DEL, (char_u *)"", 1, |
| 1670 | buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1671 | vim_memset(buf, 0, sizeof(nbbuf_T)); |
| 1672 | } |
| 1673 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1674 | /* =====================================================================*/ |
| 1675 | } |
| 1676 | else if (streq((char *)cmd, "setTitle")) |
| 1677 | { |
| 1678 | if (buf == NULL) |
| 1679 | { |
| 1680 | EMSG("E639: null buf in setTitle"); |
| 1681 | return FAIL; |
| 1682 | } |
| 1683 | vim_free(buf->displayname); |
| 1684 | buf->displayname = nb_unquote(args, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1685 | /* =====================================================================*/ |
| 1686 | } |
| 1687 | else if (streq((char *)cmd, "initDone")) |
| 1688 | { |
| 1689 | if (buf == NULL || buf->bufp == NULL) |
| 1690 | { |
| 1691 | EMSG("E640: null buf in initDone"); |
| 1692 | return FAIL; |
| 1693 | } |
| 1694 | doupdate = 1; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1695 | buf->initDone = TRUE; |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 1696 | nb_set_curbuf(buf->bufp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1697 | #if defined(FEAT_AUTOCMD) |
| 1698 | apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp); |
| 1699 | #endif |
| 1700 | |
| 1701 | /* handle any postponed key commands */ |
| 1702 | handle_key_queue(); |
| 1703 | /* =====================================================================*/ |
| 1704 | } |
| 1705 | else if (streq((char *)cmd, "setBufferNumber") |
| 1706 | || streq((char *)cmd, "putBufferNumber")) |
| 1707 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1708 | char_u *path; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1709 | buf_T *bufp; |
| 1710 | |
| 1711 | if (buf == NULL) |
| 1712 | { |
| 1713 | EMSG("E641: null buf in setBufferNumber"); |
| 1714 | return FAIL; |
| 1715 | } |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1716 | path = (char_u *)nb_unquote(args, NULL); |
| 1717 | if (path == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1718 | return FAIL; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1719 | bufp = buflist_findname(path); |
| 1720 | vim_free(path); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1721 | if (bufp == NULL) |
| 1722 | { |
| 1723 | EMSG2("E642: File %s not found in setBufferNumber", args); |
| 1724 | return FAIL; |
| 1725 | } |
| 1726 | buf->bufp = bufp; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1727 | buf->nbbuf_number = bufp->b_fnum; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1728 | |
| 1729 | /* "setBufferNumber" has the side effect of jumping to the buffer |
| 1730 | * (don't know why!). Don't do that for "putBufferNumber". */ |
| 1731 | if (*cmd != 'p') |
| 1732 | coloncmd(":buffer %d", bufp->b_fnum); |
| 1733 | else |
| 1734 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1735 | buf->initDone = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1736 | |
| 1737 | /* handle any postponed key commands */ |
| 1738 | handle_key_queue(); |
| 1739 | } |
| 1740 | |
| 1741 | #if 0 /* never used */ |
| 1742 | buf->internalname = (char *)alloc_clear(8); |
| 1743 | sprintf(buf->internalname, "<%d>", bufno); |
| 1744 | buf->netbeansOwns = 0; |
| 1745 | #endif |
| 1746 | /* =====================================================================*/ |
| 1747 | } |
| 1748 | else if (streq((char *)cmd, "setFullName")) |
| 1749 | { |
| 1750 | if (buf == NULL) |
| 1751 | { |
| 1752 | EMSG("E643: null buf in setFullName"); |
| 1753 | return FAIL; |
| 1754 | } |
| 1755 | vim_free(buf->displayname); |
| 1756 | buf->displayname = nb_unquote(args, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1757 | |
| 1758 | netbeansReadFile = 0; /* don't try to open disk file */ |
| 1759 | do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE, |
| 1760 | ECMD_HIDE + ECMD_OLDBUF); |
| 1761 | netbeansReadFile = 1; |
| 1762 | buf->bufp = curbuf; |
| 1763 | maketitle(); |
| 1764 | gui_update_menus(0); |
| 1765 | /* =====================================================================*/ |
| 1766 | } |
| 1767 | else if (streq((char *)cmd, "editFile")) |
| 1768 | { |
| 1769 | if (buf == NULL) |
| 1770 | { |
| 1771 | EMSG("E644: null buf in editFile"); |
| 1772 | return FAIL; |
| 1773 | } |
| 1774 | /* Edit a file: like create + setFullName + read the file. */ |
| 1775 | vim_free(buf->displayname); |
| 1776 | buf->displayname = nb_unquote(args, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1777 | do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE, |
| 1778 | ECMD_HIDE + ECMD_OLDBUF); |
| 1779 | buf->bufp = curbuf; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1780 | buf->initDone = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1781 | doupdate = 1; |
| 1782 | #if defined(FEAT_TITLE) |
| 1783 | maketitle(); |
| 1784 | #endif |
| 1785 | gui_update_menus(0); |
| 1786 | /* =====================================================================*/ |
| 1787 | } |
| 1788 | else if (streq((char *)cmd, "setVisible")) |
| 1789 | { |
| 1790 | if (buf == NULL || buf->bufp == NULL) |
| 1791 | { |
| 1792 | /* EMSG("E645: null bufp in setVisible"); */ |
| 1793 | return FAIL; |
| 1794 | } |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1795 | if (streq((char *)args, "T") && buf->bufp != curbuf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1796 | { |
| 1797 | exarg_T exarg; |
| 1798 | exarg.cmd = (char_u *)"goto"; |
| 1799 | exarg.forceit = FALSE; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1800 | dosetvisible = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1801 | goto_buffer(&exarg, DOBUF_FIRST, FORWARD, buf->bufp->b_fnum); |
| 1802 | doupdate = 1; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1803 | dosetvisible = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1804 | |
| 1805 | /* Side effect!!!. */ |
| 1806 | if (!gui.starting) |
| 1807 | gui_mch_set_foreground(); |
| 1808 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1809 | /* =====================================================================*/ |
| 1810 | } |
| 1811 | else if (streq((char *)cmd, "raise")) |
| 1812 | { |
| 1813 | /* Bring gvim to the foreground. */ |
| 1814 | if (!gui.starting) |
| 1815 | gui_mch_set_foreground(); |
| 1816 | /* =====================================================================*/ |
| 1817 | } |
| 1818 | else if (streq((char *)cmd, "setModified")) |
| 1819 | { |
| 1820 | if (buf == NULL || buf->bufp == NULL) |
| 1821 | { |
| 1822 | /* EMSG("E646: null bufp in setModified"); */ |
| 1823 | return FAIL; |
| 1824 | } |
| 1825 | if (streq((char *)args, "T")) |
| 1826 | buf->bufp->b_changed = 1; |
| 1827 | else |
| 1828 | { |
| 1829 | struct stat st; |
| 1830 | |
| 1831 | /* Assume NetBeans stored the file. Reset the timestamp to |
| 1832 | * avoid "file changed" warnings. */ |
| 1833 | if (buf->bufp->b_ffname != NULL |
| 1834 | && mch_stat((char *)buf->bufp->b_ffname, &st) >= 0) |
| 1835 | buf_store_time(buf->bufp, &st, buf->bufp->b_ffname); |
| 1836 | buf->bufp->b_changed = 0; |
| 1837 | } |
| 1838 | buf->modified = buf->bufp->b_changed; |
| 1839 | /* =====================================================================*/ |
| 1840 | } |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1841 | else if (streq((char *)cmd, "setModtime")) |
| 1842 | { |
| 1843 | buf->bufp->b_mtime = atoi((char *) args); |
| 1844 | /* =====================================================================*/ |
| 1845 | } |
| 1846 | else if (streq((char *)cmd, "setReadOnly")) |
| 1847 | { |
| 1848 | if (streq((char *)args, "T")) |
| 1849 | buf->bufp->b_p_ro = TRUE; |
| 1850 | else |
| 1851 | buf->bufp->b_p_ro = FALSE; |
| 1852 | /* =====================================================================*/ |
| 1853 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1854 | else if (streq((char *)cmd, "setMark")) |
| 1855 | { |
| 1856 | /* not yet */ |
| 1857 | /* =====================================================================*/ |
| 1858 | } |
| 1859 | else if (streq((char *)cmd, "showBalloon")) |
| 1860 | { |
| 1861 | #if defined(FEAT_BEVAL) |
| 1862 | static char *text = NULL; |
| 1863 | |
| 1864 | /* |
| 1865 | * Set up the Balloon Expression Evaluation area. |
| 1866 | * Ignore 'ballooneval' here. |
| 1867 | * The text pointer must remain valid for a while. |
| 1868 | */ |
| 1869 | if (balloonEval != NULL) |
| 1870 | { |
| 1871 | vim_free(text); |
| 1872 | text = nb_unquote(args, NULL); |
| 1873 | if (text != NULL) |
| 1874 | gui_mch_post_balloon(balloonEval, (char_u *)text); |
| 1875 | } |
| 1876 | #endif |
| 1877 | /* =====================================================================*/ |
| 1878 | } |
| 1879 | else if (streq((char *)cmd, "setDot")) |
| 1880 | { |
| 1881 | pos_T *pos; |
| 1882 | #ifdef NBDEBUG |
| 1883 | char_u *s; |
| 1884 | #endif |
| 1885 | |
| 1886 | if (buf == NULL || buf->bufp == NULL) |
| 1887 | { |
| 1888 | EMSG("E647: null bufp in setDot"); |
| 1889 | return FAIL; |
| 1890 | } |
| 1891 | |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 1892 | nb_set_curbuf(buf->bufp); |
| 1893 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1894 | #ifdef FEAT_VISUAL |
| 1895 | /* Don't want Visual mode now. */ |
| 1896 | if (VIsual_active) |
| 1897 | end_visual_mode(); |
| 1898 | #endif |
| 1899 | #ifdef NBDEBUG |
| 1900 | s = args; |
| 1901 | #endif |
| 1902 | pos = get_off_or_lnum(buf->bufp, &args); |
| 1903 | if (pos) |
| 1904 | { |
| 1905 | curwin->w_cursor = *pos; |
| 1906 | check_cursor(); |
| 1907 | #ifdef FEAT_FOLDING |
| 1908 | foldOpenCursor(); |
| 1909 | #endif |
| 1910 | } |
| 1911 | else |
| 1912 | nbdebug((" BAD POSITION in setDot: %s\n", s)); |
| 1913 | |
| 1914 | /* gui_update_cursor(TRUE, FALSE); */ |
| 1915 | /* update_curbuf(NOT_VALID); */ |
| 1916 | update_topline(); /* scroll to show the line */ |
| 1917 | update_screen(VALID); |
| 1918 | setcursor(); |
| 1919 | out_flush(); |
| 1920 | gui_update_cursor(TRUE, FALSE); |
| 1921 | gui_mch_flush(); |
| 1922 | /* Quit a hit-return or more prompt. */ |
| 1923 | if (State == HITRETURN || State == ASKMORE) |
| 1924 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1925 | #ifdef FEAT_GUI_GTK |
| 1926 | if (gtk_main_level() > 0) |
| 1927 | gtk_main_quit(); |
| 1928 | #endif |
| 1929 | } |
| 1930 | /* =====================================================================*/ |
| 1931 | } |
| 1932 | else if (streq((char *)cmd, "close")) |
| 1933 | { |
| 1934 | #ifdef NBDEBUG |
| 1935 | char *name = "<NONE>"; |
| 1936 | #endif |
| 1937 | |
| 1938 | if (buf == NULL) |
| 1939 | { |
| 1940 | EMSG("E648: null buf in close"); |
| 1941 | return FAIL; |
| 1942 | } |
| 1943 | |
| 1944 | #ifdef NBDEBUG |
| 1945 | if (buf->displayname != NULL) |
| 1946 | name = buf->displayname; |
| 1947 | #endif |
| 1948 | /* if (buf->bufp == NULL) */ |
| 1949 | /* EMSG("E649: null bufp in close"); */ |
| 1950 | nbdebug((" CLOSE %d: %s\n", bufno, name)); |
| 1951 | need_mouse_correct = TRUE; |
| 1952 | if (buf->bufp != NULL) |
| 1953 | do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, |
| 1954 | buf->bufp->b_fnum, TRUE); |
| 1955 | doupdate = 1; |
| 1956 | /* =====================================================================*/ |
| 1957 | } |
| 1958 | else if (streq((char *)cmd, "setStyle")) /* obsolete... */ |
| 1959 | { |
| 1960 | nbdebug((" setStyle is obsolete!")); |
| 1961 | /* =====================================================================*/ |
| 1962 | } |
| 1963 | else if (streq((char *)cmd, "setExitDelay")) |
| 1964 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 1965 | /* Only used in version 2.1. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1966 | /* =====================================================================*/ |
| 1967 | } |
| 1968 | else if (streq((char *)cmd, "defineAnnoType")) |
| 1969 | { |
| 1970 | #ifdef FEAT_SIGNS |
| 1971 | int typeNum; |
| 1972 | char_u *typeName; |
| 1973 | char_u *tooltip; |
| 1974 | char_u *p; |
| 1975 | char_u *glyphFile; |
| 1976 | int use_fg = 0; |
| 1977 | int use_bg = 0; |
| 1978 | int fg = -1; |
| 1979 | int bg = -1; |
| 1980 | |
| 1981 | if (buf == NULL) |
| 1982 | { |
| 1983 | EMSG("E650: null buf in defineAnnoType"); |
| 1984 | return FAIL; |
| 1985 | } |
| 1986 | |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 1987 | cp = (char *)args; |
| 1988 | typeNum = strtol(cp, &cp, 10); |
| 1989 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1990 | args = skipwhite(args); |
| 1991 | typeName = (char_u *)nb_unquote(args, &args); |
| 1992 | args = skipwhite(args + 1); |
| 1993 | tooltip = (char_u *)nb_unquote(args, &args); |
| 1994 | args = skipwhite(args + 1); |
| 1995 | |
| 1996 | p = (char_u *)nb_unquote(args, &args); |
| 1997 | glyphFile = vim_strsave_escaped(p, escape_chars); |
| 1998 | vim_free(p); |
| 1999 | |
| 2000 | args = skipwhite(args + 1); |
| 2001 | if (STRNCMP(args, "none", 4) == 0) |
| 2002 | args += 5; |
| 2003 | else |
| 2004 | { |
| 2005 | use_fg = 1; |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2006 | cp = (char *)args; |
| 2007 | fg = strtol(cp, &cp, 10); |
| 2008 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2009 | } |
| 2010 | if (STRNCMP(args, "none", 4) == 0) |
| 2011 | args += 5; |
| 2012 | else |
| 2013 | { |
| 2014 | use_bg = 1; |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2015 | cp = (char *)args; |
| 2016 | bg = strtol(cp, &cp, 10); |
| 2017 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2018 | } |
| 2019 | if (typeName != NULL && tooltip != NULL && glyphFile != NULL) |
| 2020 | addsigntype(buf, typeNum, typeName, tooltip, glyphFile, |
| 2021 | use_fg, fg, use_bg, bg); |
| 2022 | else |
| 2023 | vim_free(typeName); |
| 2024 | |
| 2025 | /* don't free typeName; it's used directly in addsigntype() */ |
| 2026 | vim_free(tooltip); |
| 2027 | vim_free(glyphFile); |
| 2028 | |
| 2029 | #endif |
| 2030 | /* =====================================================================*/ |
| 2031 | } |
| 2032 | else if (streq((char *)cmd, "addAnno")) |
| 2033 | { |
| 2034 | #ifdef FEAT_SIGNS |
| 2035 | int serNum; |
| 2036 | int localTypeNum; |
| 2037 | int typeNum; |
| 2038 | # ifdef NBDEBUG |
| 2039 | int len; |
| 2040 | # endif |
| 2041 | pos_T *pos; |
| 2042 | |
| 2043 | if (buf == NULL || buf->bufp == NULL) |
| 2044 | { |
| 2045 | EMSG("E651: null bufp in addAnno"); |
| 2046 | return FAIL; |
| 2047 | } |
| 2048 | |
| 2049 | doupdate = 1; |
| 2050 | |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2051 | cp = (char *)args; |
| 2052 | serNum = strtol(cp, &cp, 10); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2053 | |
| 2054 | /* Get the typenr specific for this buffer and convert it to |
| 2055 | * the global typenumber, as used for the sign name. */ |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2056 | localTypeNum = strtol(cp, &cp, 10); |
| 2057 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2058 | typeNum = mapsigntype(buf, localTypeNum); |
| 2059 | |
| 2060 | pos = get_off_or_lnum(buf->bufp, &args); |
| 2061 | |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2062 | cp = (char *)args; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2063 | # ifdef NBDEBUG |
| 2064 | len = |
| 2065 | # endif |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2066 | strtol(cp, &cp, 10); |
| 2067 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2068 | # ifdef NBDEBUG |
| 2069 | if (len != -1) |
| 2070 | { |
| 2071 | nbdebug((" partial line annotation -- Not Yet Implemented!")); |
| 2072 | } |
| 2073 | # endif |
| 2074 | if (serNum >= GUARDEDOFFSET) |
| 2075 | { |
| 2076 | nbdebug((" too many annotations! ignoring...")); |
| 2077 | return FAIL; |
| 2078 | } |
| 2079 | if (pos) |
| 2080 | { |
| 2081 | coloncmd(":sign place %d line=%d name=%d buffer=%d", |
| 2082 | serNum, pos->lnum, typeNum, buf->bufp->b_fnum); |
| 2083 | if (typeNum == curPCtype) |
| 2084 | coloncmd(":sign jump %d buffer=%d", serNum, |
| 2085 | buf->bufp->b_fnum); |
| 2086 | } |
| 2087 | /* XXX only redraw what changed. */ |
| 2088 | redraw_later(CLEAR); |
| 2089 | #endif |
| 2090 | /* =====================================================================*/ |
| 2091 | } |
| 2092 | else if (streq((char *)cmd, "removeAnno")) |
| 2093 | { |
| 2094 | #ifdef FEAT_SIGNS |
| 2095 | int serNum; |
| 2096 | |
| 2097 | if (buf == NULL || buf->bufp == NULL) |
| 2098 | { |
| 2099 | nbdebug((" null bufp in removeAnno")); |
| 2100 | return FAIL; |
| 2101 | } |
| 2102 | doupdate = 1; |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2103 | cp = (char *)args; |
| 2104 | serNum = strtol(cp, &cp, 10); |
| 2105 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2106 | coloncmd(":sign unplace %d buffer=%d", |
| 2107 | serNum, buf->bufp->b_fnum); |
| 2108 | redraw_buf_later(buf->bufp, NOT_VALID); |
| 2109 | #endif |
| 2110 | /* =====================================================================*/ |
| 2111 | } |
| 2112 | else if (streq((char *)cmd, "moveAnnoToFront")) |
| 2113 | { |
| 2114 | #ifdef FEAT_SIGNS |
| 2115 | nbdebug((" moveAnnoToFront: Not Yet Implemented!")); |
| 2116 | #endif |
| 2117 | /* =====================================================================*/ |
| 2118 | } |
| 2119 | else if (streq((char *)cmd, "guard") || streq((char *)cmd, "unguard")) |
| 2120 | { |
| 2121 | int len; |
| 2122 | pos_T first; |
| 2123 | pos_T last; |
| 2124 | pos_T *pos; |
| 2125 | int un = (cmd[0] == 'u'); |
| 2126 | static int guardId = GUARDEDOFFSET; |
| 2127 | |
| 2128 | if (skip >= SKIP_STOP) |
| 2129 | { |
| 2130 | nbdebug((" Skipping %s command\n", (char *) cmd)); |
| 2131 | return OK; |
| 2132 | } |
| 2133 | |
| 2134 | nb_init_graphics(); |
| 2135 | |
| 2136 | if (buf == NULL || buf->bufp == NULL) |
| 2137 | { |
| 2138 | nbdebug((" null bufp in %s command", cmd)); |
| 2139 | return FAIL; |
| 2140 | } |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 2141 | nb_set_curbuf(buf->bufp); |
Bram Moolenaar | 349b2f6 | 2004-10-11 10:00:50 +0000 | [diff] [blame] | 2142 | cp = (char *)args; |
| 2143 | off = strtol(cp, &cp, 10); |
| 2144 | len = strtol(cp, NULL, 10); |
| 2145 | args = (char_u *)cp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2146 | pos = off2pos(buf->bufp, off); |
| 2147 | doupdate = 1; |
| 2148 | if (!pos) |
| 2149 | nbdebug((" no such start pos in %s, %ld\n", cmd, off)); |
| 2150 | else |
| 2151 | { |
| 2152 | first = *pos; |
| 2153 | pos = off2pos(buf->bufp, off + len - 1); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2154 | if (pos != NULL && pos->col == 0) |
| 2155 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2156 | /* |
| 2157 | * In Java Swing the offset is a position between 2 |
| 2158 | * characters. If col == 0 then we really want the |
| 2159 | * previous line as the end. |
| 2160 | */ |
| 2161 | pos = off2pos(buf->bufp, off + len - 2); |
| 2162 | } |
| 2163 | if (!pos) |
| 2164 | nbdebug((" no such end pos in %s, %ld\n", |
| 2165 | cmd, off + len - 1)); |
| 2166 | else |
| 2167 | { |
| 2168 | long lnum; |
| 2169 | last = *pos; |
| 2170 | /* set highlight for region */ |
| 2171 | nbdebug((" %sGUARD %ld,%d to %ld,%d\n", (un) ? "UN" : "", |
| 2172 | first.lnum, first.col, |
| 2173 | last.lnum, last.col)); |
| 2174 | #ifdef FEAT_SIGNS |
| 2175 | for (lnum = first.lnum; lnum <= last.lnum; lnum++) |
| 2176 | { |
| 2177 | if (un) |
| 2178 | { |
| 2179 | /* never used */ |
| 2180 | } |
| 2181 | else |
| 2182 | { |
| 2183 | if (buf_findsigntype_id(buf->bufp, lnum, |
| 2184 | GUARDED) == 0) |
| 2185 | { |
| 2186 | coloncmd( |
| 2187 | ":sign place %d line=%d name=%d buffer=%d", |
| 2188 | guardId++, lnum, GUARDED, |
| 2189 | buf->bufp->b_fnum); |
| 2190 | } |
| 2191 | } |
| 2192 | } |
| 2193 | #endif |
| 2194 | redraw_buf_later(buf->bufp, NOT_VALID); |
| 2195 | } |
| 2196 | } |
| 2197 | /* =====================================================================*/ |
| 2198 | } |
| 2199 | else if (streq((char *)cmd, "startAtomic")) |
| 2200 | { |
| 2201 | inAtomic = 1; |
| 2202 | /* =====================================================================*/ |
| 2203 | } |
| 2204 | else if (streq((char *)cmd, "endAtomic")) |
| 2205 | { |
| 2206 | inAtomic = 0; |
| 2207 | if (needupdate) |
| 2208 | { |
| 2209 | doupdate = 1; |
| 2210 | needupdate = 0; |
| 2211 | } |
| 2212 | /* =====================================================================*/ |
| 2213 | } |
| 2214 | else if (streq((char *)cmd, "save")) |
| 2215 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2216 | /* |
| 2217 | * NOTE - This command is obsolete wrt NetBeans. Its left in |
| 2218 | * only for historical reasons. |
| 2219 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2220 | if (buf == NULL || buf->bufp == NULL) |
| 2221 | { |
| 2222 | nbdebug((" null bufp in %s command", cmd)); |
| 2223 | return FAIL; |
| 2224 | } |
| 2225 | |
| 2226 | /* the following is taken from ex_cmds.c (do_wqall function) */ |
| 2227 | if (bufIsChanged(buf->bufp)) |
| 2228 | { |
| 2229 | /* Only write if the buffer can be written. */ |
| 2230 | if (p_write |
| 2231 | && !buf->bufp->b_p_ro |
| 2232 | && buf->bufp->b_ffname != NULL |
| 2233 | #ifdef FEAT_QUICKFIX |
| 2234 | && !bt_dontwrite(buf->bufp) |
| 2235 | #endif |
| 2236 | ) |
| 2237 | { |
| 2238 | buf_write_all(buf->bufp, FALSE); |
| 2239 | #ifdef FEAT_AUTOCMD |
| 2240 | /* an autocommand may have deleted the buffer */ |
| 2241 | if (!buf_valid(buf->bufp)) |
| 2242 | buf->bufp = NULL; |
| 2243 | #endif |
| 2244 | } |
| 2245 | } |
| 2246 | /* =====================================================================*/ |
| 2247 | } |
| 2248 | else if (streq((char *)cmd, "netbeansBuffer")) |
| 2249 | { |
| 2250 | if (buf == NULL || buf->bufp == NULL) |
| 2251 | { |
| 2252 | nbdebug((" null bufp in %s command", cmd)); |
| 2253 | return FAIL; |
| 2254 | } |
| 2255 | if (*args == 'T') |
| 2256 | { |
| 2257 | buf->bufp->b_netbeans_file = TRUE; |
| 2258 | buf->bufp->b_was_netbeans_file = TRUE; |
| 2259 | } |
| 2260 | else |
| 2261 | buf->bufp->b_netbeans_file = FALSE; |
| 2262 | /* =====================================================================*/ |
| 2263 | } |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2264 | else if (streq((char *)cmd, "specialKeys")) |
| 2265 | { |
| 2266 | special_keys(args); |
| 2267 | /* =====================================================================*/ |
| 2268 | } |
| 2269 | else if (streq((char *)cmd, "actionMenuItem")) |
| 2270 | { |
| 2271 | /* not used yet */ |
| 2272 | /* =====================================================================*/ |
| 2273 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2274 | else if (streq((char *)cmd, "version")) |
| 2275 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2276 | /* not used yet */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2277 | } |
| 2278 | /* |
| 2279 | * Unrecognized command is ignored. |
| 2280 | */ |
| 2281 | } |
| 2282 | if (inAtomic && doupdate) |
| 2283 | { |
| 2284 | needupdate = 1; |
| 2285 | doupdate = 0; |
| 2286 | } |
| 2287 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2288 | /* |
| 2289 | * Is this needed? I moved the netbeans_Xt_connect() later during startup |
| 2290 | * and it may no longer be necessary. If its not needed then needupdate |
| 2291 | * and doupdate can also be removed. |
| 2292 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2293 | if (buf != NULL && buf->initDone && doupdate) |
| 2294 | { |
| 2295 | update_screen(NOT_VALID); |
| 2296 | setcursor(); |
| 2297 | out_flush(); |
| 2298 | gui_update_cursor(TRUE, FALSE); |
| 2299 | gui_mch_flush(); |
| 2300 | /* Quit a hit-return or more prompt. */ |
| 2301 | if (State == HITRETURN || State == ASKMORE) |
| 2302 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2303 | #ifdef FEAT_GUI_GTK |
| 2304 | if (gtk_main_level() > 0) |
| 2305 | gtk_main_quit(); |
| 2306 | #endif |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | return retval; |
| 2311 | } |
| 2312 | |
| 2313 | |
| 2314 | /* |
Bram Moolenaar | 8b6144b | 2006-02-08 09:20:24 +0000 | [diff] [blame] | 2315 | * If "buf" is not the current buffer try changing to a window that edits this |
| 2316 | * buffer. If there is no such window then close the current buffer and set |
| 2317 | * the current buffer as "buf". |
| 2318 | */ |
| 2319 | static void |
| 2320 | nb_set_curbuf(buf) |
| 2321 | buf_T *buf; |
| 2322 | { |
| 2323 | if (curbuf != buf && buf_jump_open_win(buf) == NULL) |
| 2324 | set_curbuf(buf, DOBUF_GOTO); |
| 2325 | } |
| 2326 | |
| 2327 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2328 | * Process a vim colon command. |
| 2329 | */ |
| 2330 | static void |
| 2331 | coloncmd(char *cmd, ...) |
| 2332 | { |
| 2333 | char buf[1024]; |
| 2334 | va_list ap; |
| 2335 | |
| 2336 | va_start(ap, cmd); |
| 2337 | vsprintf(buf, cmd, ap); |
| 2338 | va_end(ap); |
| 2339 | |
| 2340 | nbdebug((" COLONCMD %s\n", buf)); |
| 2341 | |
| 2342 | /* ALT_INPUT_LOCK_ON; */ |
| 2343 | do_cmdline((char_u *)buf, NULL, NULL, DOCMD_NOWAIT | DOCMD_KEYTYPED); |
| 2344 | /* ALT_INPUT_LOCK_OFF; */ |
| 2345 | |
| 2346 | setcursor(); /* restore the cursor position */ |
| 2347 | out_flush(); /* make sure output has been written */ |
| 2348 | |
| 2349 | gui_update_cursor(TRUE, FALSE); |
| 2350 | gui_mch_flush(); |
| 2351 | } |
| 2352 | |
| 2353 | |
| 2354 | /* |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2355 | * Parse the specialKeys argument and issue the appropriate map commands. |
| 2356 | */ |
| 2357 | static void |
| 2358 | special_keys(char_u *args) |
| 2359 | { |
| 2360 | char *save_str = nb_unquote(args, NULL); |
| 2361 | char *tok = strtok(save_str, " "); |
| 2362 | char *sep; |
| 2363 | char keybuf[64]; |
| 2364 | char cmdbuf[256]; |
| 2365 | |
| 2366 | while (tok != NULL) |
| 2367 | { |
| 2368 | int i = 0; |
| 2369 | |
| 2370 | if ((sep = strchr(tok, '-')) != NULL) |
| 2371 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 2372 | *sep = NUL; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2373 | while (*tok) |
| 2374 | { |
| 2375 | switch (*tok) |
| 2376 | { |
| 2377 | case 'A': |
| 2378 | case 'M': |
| 2379 | case 'C': |
| 2380 | case 'S': |
| 2381 | keybuf[i++] = *tok; |
| 2382 | keybuf[i++] = '-'; |
| 2383 | break; |
| 2384 | } |
| 2385 | tok++; |
| 2386 | } |
| 2387 | tok++; |
| 2388 | } |
| 2389 | |
| 2390 | strcpy(&keybuf[i], tok); |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 2391 | vim_snprintf(cmdbuf, sizeof(cmdbuf), |
| 2392 | "<silent><%s> :nbkey %s<CR>", keybuf, keybuf); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2393 | do_map(0, (char_u *)cmdbuf, NORMAL, FALSE); |
| 2394 | tok = strtok(NULL, " "); |
| 2395 | } |
| 2396 | vim_free(save_str); |
| 2397 | } |
| 2398 | |
| 2399 | |
| 2400 | void |
| 2401 | ex_nbkey(eap) |
| 2402 | exarg_T *eap; |
| 2403 | { |
| 2404 | netbeans_keystring(0, (char *)eap->arg); |
| 2405 | } |
| 2406 | |
| 2407 | |
| 2408 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2409 | * Initialize highlights and signs for use by netbeans (mostly obsolete) |
| 2410 | */ |
| 2411 | static void |
| 2412 | nb_init_graphics(void) |
| 2413 | { |
| 2414 | static int did_init = FALSE; |
| 2415 | |
| 2416 | if (!did_init) |
| 2417 | { |
| 2418 | coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"); |
| 2419 | coloncmd(":sign define %d linehl=NBGuarded", GUARDED); |
| 2420 | |
| 2421 | did_init = TRUE; |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | /* |
| 2426 | * Convert key to netbeans name. |
| 2427 | */ |
| 2428 | static void |
| 2429 | netbeans_keyname(int key, char *buf) |
| 2430 | { |
| 2431 | char *name = 0; |
| 2432 | char namebuf[2]; |
| 2433 | int ctrl = 0; |
| 2434 | int shift = 0; |
| 2435 | int alt = 0; |
| 2436 | |
| 2437 | if (mod_mask & MOD_MASK_CTRL) |
| 2438 | ctrl = 1; |
| 2439 | if (mod_mask & MOD_MASK_SHIFT) |
| 2440 | shift = 1; |
| 2441 | if (mod_mask & MOD_MASK_ALT) |
| 2442 | alt = 1; |
| 2443 | |
| 2444 | |
| 2445 | switch (key) |
| 2446 | { |
| 2447 | case K_F1: name = "F1"; break; |
| 2448 | case K_S_F1: name = "F1"; shift = 1; break; |
| 2449 | case K_F2: name = "F2"; break; |
| 2450 | case K_S_F2: name = "F2"; shift = 1; break; |
| 2451 | case K_F3: name = "F3"; break; |
| 2452 | case K_S_F3: name = "F3"; shift = 1; break; |
| 2453 | case K_F4: name = "F4"; break; |
| 2454 | case K_S_F4: name = "F4"; shift = 1; break; |
| 2455 | case K_F5: name = "F5"; break; |
| 2456 | case K_S_F5: name = "F5"; shift = 1; break; |
| 2457 | case K_F6: name = "F6"; break; |
| 2458 | case K_S_F6: name = "F6"; shift = 1; break; |
| 2459 | case K_F7: name = "F7"; break; |
| 2460 | case K_S_F7: name = "F7"; shift = 1; break; |
| 2461 | case K_F8: name = "F8"; break; |
| 2462 | case K_S_F8: name = "F8"; shift = 1; break; |
| 2463 | case K_F9: name = "F9"; break; |
| 2464 | case K_S_F9: name = "F9"; shift = 1; break; |
| 2465 | case K_F10: name = "F10"; break; |
| 2466 | case K_S_F10: name = "F10"; shift = 1; break; |
| 2467 | case K_F11: name = "F11"; break; |
| 2468 | case K_S_F11: name = "F11"; shift = 1; break; |
| 2469 | case K_F12: name = "F12"; break; |
| 2470 | case K_S_F12: name = "F12"; shift = 1; break; |
| 2471 | default: |
| 2472 | if (key >= ' ' && key <= '~') |
| 2473 | { |
| 2474 | /* Allow ASCII characters. */ |
| 2475 | name = namebuf; |
| 2476 | namebuf[0] = key; |
| 2477 | namebuf[1] = NUL; |
| 2478 | } |
| 2479 | else |
| 2480 | name = "X"; |
| 2481 | break; |
| 2482 | } |
| 2483 | |
| 2484 | buf[0] = '\0'; |
| 2485 | if (ctrl) |
| 2486 | strcat(buf, "C"); |
| 2487 | if (shift) |
| 2488 | strcat(buf, "S"); |
| 2489 | if (alt) |
| 2490 | strcat(buf, "M"); /* META */ |
| 2491 | if (ctrl || shift || alt) |
| 2492 | strcat(buf, "-"); |
| 2493 | strcat(buf, name); |
| 2494 | } |
| 2495 | |
| 2496 | #ifdef FEAT_BEVAL |
| 2497 | /* |
| 2498 | * Function to be called for balloon evaluation. Grabs the text under the |
| 2499 | * cursor and sends it to the debugger for evaluation. The debugger should |
| 2500 | * respond with a showBalloon command when there is a useful result. |
| 2501 | */ |
| 2502 | /*ARGSUSED*/ |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 2503 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2504 | netbeans_beval_cb( |
| 2505 | BalloonEval *beval, |
| 2506 | int state) |
| 2507 | { |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 2508 | win_T *wp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2509 | char_u *text; |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 2510 | linenr_T lnum; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2511 | int col; |
| 2512 | char buf[MAXPATHL * 2 + 25]; |
| 2513 | char_u *p; |
| 2514 | |
| 2515 | /* Don't do anything when 'ballooneval' is off, messages scrolled the |
| 2516 | * windows up or we have no connection. */ |
| 2517 | if (!p_beval || msg_scrolled > 0 || !haveConnection) |
| 2518 | return; |
| 2519 | |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 2520 | if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2521 | { |
| 2522 | /* Send debugger request. Only when the text is of reasonable |
| 2523 | * length. */ |
| 2524 | if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL) |
| 2525 | { |
| 2526 | p = nb_quote(text); |
| 2527 | if (p != NULL) |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2528 | { |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 2529 | vim_snprintf(buf, sizeof(buf), |
| 2530 | "0:balloonText=%d \"%s\"\n", cmdno, p); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2531 | vim_free(p); |
| 2532 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2533 | nbdebug(("EVT: %s", buf)); |
| 2534 | nb_send(buf, "netbeans_beval_cb"); |
| 2535 | } |
| 2536 | vim_free(text); |
| 2537 | } |
| 2538 | } |
| 2539 | #endif |
| 2540 | |
| 2541 | /* |
| 2542 | * Tell netbeans that the window was opened, ready for commands. |
| 2543 | */ |
| 2544 | void |
| 2545 | netbeans_startup_done(void) |
| 2546 | { |
| 2547 | char *cmd = "0:startupDone=0\n"; |
| 2548 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2549 | if (usingNetbeans) |
| 2550 | #ifdef FEAT_GUI_MOTIF |
| 2551 | netbeans_Xt_connect(app_context); |
| 2552 | #else |
| 2553 | # ifdef FEAT_GUI_GTK |
| 2554 | netbeans_gtk_connect(); |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 2555 | # else |
| 2556 | # ifdef FEAT_GUI_W32 |
| 2557 | netbeans_w32_connect(); |
| 2558 | # endif |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2559 | # endif |
| 2560 | #endif |
| 2561 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2562 | if (!haveConnection) |
| 2563 | return; |
| 2564 | |
Bram Moolenaar | d62bec8 | 2005-03-07 22:56:57 +0000 | [diff] [blame] | 2565 | #ifdef FEAT_BEVAL |
| 2566 | bevalServers |= BEVAL_NETBEANS; |
| 2567 | #endif |
| 2568 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2569 | nbdebug(("EVT: %s", cmd)); |
| 2570 | nb_send(cmd, "netbeans_startup_done"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2573 | /* |
| 2574 | * Tell netbeans that we're exiting. This should be called right |
| 2575 | * before calling exit. |
| 2576 | */ |
| 2577 | void |
| 2578 | netbeans_send_disconnect() |
| 2579 | { |
| 2580 | char buf[128]; |
| 2581 | |
| 2582 | if (haveConnection) |
| 2583 | { |
| 2584 | sprintf(buf, "0:disconnect=%d\n", cmdno); |
| 2585 | nbdebug(("EVT: %s", buf)); |
| 2586 | nb_send(buf, "netbeans_disconnect"); |
| 2587 | } |
| 2588 | } |
| 2589 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2590 | #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_W32) || defined(PROTO) |
| 2591 | /* |
| 2592 | * Tell netbeans that the window was moved or resized. |
| 2593 | */ |
| 2594 | void |
| 2595 | netbeans_frame_moved(int new_x, int new_y) |
| 2596 | { |
| 2597 | char buf[128]; |
| 2598 | |
| 2599 | if (!haveConnection) |
| 2600 | return; |
| 2601 | |
| 2602 | sprintf(buf, "0:geometry=%d %d %d %d %d\n", |
| 2603 | cmdno, (int)Columns, (int)Rows, new_x, new_y); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2604 | /*nbdebug(("EVT: %s", buf)); happens too many times during a move */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2605 | nb_send(buf, "netbeans_frame_moved"); |
| 2606 | } |
| 2607 | #endif |
| 2608 | |
| 2609 | /* |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2610 | * Tell netbeans the user opened or activated a file. |
| 2611 | */ |
| 2612 | void |
| 2613 | netbeans_file_activated(buf_T *bufp) |
| 2614 | { |
| 2615 | int bufno = nb_getbufno(bufp); |
| 2616 | nbbuf_T *bp = nb_get_buf(bufno); |
| 2617 | char buffer[2*MAXPATHL]; |
| 2618 | char_u *q; |
| 2619 | |
| 2620 | if (!haveConnection || dosetvisible) |
| 2621 | return; |
| 2622 | |
| 2623 | q = nb_quote(bufp->b_ffname); |
| 2624 | if (q == NULL || bp == NULL || bufp == NULL) |
| 2625 | return; |
| 2626 | |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 2627 | vim_snprintf(buffer, sizeof(buffer), "%d:fileOpened=%d \"%s\" %s %s\n", |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2628 | bufno, |
| 2629 | bufno, |
| 2630 | (char *)q, |
| 2631 | "T", /* open in NetBeans */ |
| 2632 | "F"); /* modified */ |
| 2633 | |
| 2634 | vim_free(q); |
| 2635 | nbdebug(("EVT: %s", buffer)); |
| 2636 | |
| 2637 | nb_send(buffer, "netbeans_file_opened"); |
| 2638 | } |
| 2639 | |
| 2640 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2641 | * Tell netbeans the user opened a file. |
| 2642 | */ |
| 2643 | void |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2644 | netbeans_file_opened(buf_T *bufp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2645 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2646 | int bufno = nb_getbufno(bufp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2647 | char buffer[2*MAXPATHL]; |
| 2648 | char_u *q; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2649 | nbbuf_T *bp = nb_get_buf(nb_getbufno(bufp)); |
| 2650 | int bnum; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2651 | |
| 2652 | if (!haveConnection) |
| 2653 | return; |
| 2654 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2655 | q = nb_quote(bufp->b_ffname); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2656 | if (q == NULL) |
| 2657 | return; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2658 | if (bp != NULL) |
| 2659 | bnum = bufno; |
| 2660 | else |
| 2661 | bnum = 0; |
| 2662 | |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 2663 | vim_snprintf(buffer, sizeof(buffer), "%d:fileOpened=%d \"%s\" %s %s\n", |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2664 | bnum, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2665 | 0, |
| 2666 | (char *)q, |
| 2667 | "T", /* open in NetBeans */ |
| 2668 | "F"); /* modified */ |
| 2669 | |
| 2670 | vim_free(q); |
| 2671 | nbdebug(("EVT: %s", buffer)); |
| 2672 | |
| 2673 | nb_send(buffer, "netbeans_file_opened"); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2674 | if (p_acd && vim_chdirfile(bufp->b_ffname) == OK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2675 | shorten_fnames(TRUE); |
| 2676 | } |
| 2677 | |
| 2678 | /* |
| 2679 | * Tell netbeans a file was closed. |
| 2680 | */ |
| 2681 | void |
| 2682 | netbeans_file_closed(buf_T *bufp) |
| 2683 | { |
| 2684 | int bufno = nb_getbufno(bufp); |
| 2685 | nbbuf_T *nbbuf = nb_get_buf(bufno); |
| 2686 | char buffer[2*MAXPATHL]; |
| 2687 | |
| 2688 | if (!haveConnection || bufno < 0) |
| 2689 | return; |
| 2690 | |
| 2691 | if (!netbeansCloseFile) |
| 2692 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2693 | nbdebug(("Ignoring file_closed for %s. File was closed from IDE\n", |
| 2694 | bufp->b_ffname)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2695 | return; |
| 2696 | } |
| 2697 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2698 | nbdebug(("netbeans_file_closed:\n")); |
| 2699 | nbdebug((" Closing bufno: %d", bufno)); |
| 2700 | if (curbuf != NULL && curbuf != bufp) |
| 2701 | { |
| 2702 | nbdebug((" Curbuf bufno: %d\n", nb_getbufno(curbuf))); |
| 2703 | } |
| 2704 | else if (curbuf == bufp) |
| 2705 | { |
| 2706 | nbdebug((" curbuf == bufp\n")); |
| 2707 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2708 | |
| 2709 | if (bufno <= 0) |
| 2710 | return; |
| 2711 | |
| 2712 | sprintf(buffer, "%d:killed=%d\n", bufno, cmdno); |
| 2713 | |
| 2714 | nbdebug(("EVT: %s", buffer)); |
| 2715 | |
| 2716 | nb_send(buffer, "netbeans_file_closed"); |
| 2717 | |
| 2718 | if (nbbuf != NULL) |
| 2719 | nbbuf->bufp = NULL; |
| 2720 | } |
| 2721 | |
| 2722 | /* |
| 2723 | * Get a pointer to the Netbeans buffer for Vim buffer "bufp". |
| 2724 | * Return NULL if there is no such buffer or changes are not to be reported. |
| 2725 | * Otherwise store the buffer number in "*bufnop". |
| 2726 | */ |
| 2727 | static nbbuf_T * |
| 2728 | nb_bufp2nbbuf_fire(buf_T *bufp, int *bufnop) |
| 2729 | { |
| 2730 | int bufno; |
| 2731 | nbbuf_T *nbbuf; |
| 2732 | |
| 2733 | if (!haveConnection || !netbeansFireChanges) |
| 2734 | return NULL; /* changes are not reported at all */ |
| 2735 | |
| 2736 | bufno = nb_getbufno(bufp); |
| 2737 | if (bufno <= 0) |
| 2738 | return NULL; /* file is not known to NetBeans */ |
| 2739 | |
| 2740 | nbbuf = nb_get_buf(bufno); |
| 2741 | if (nbbuf != NULL && !nbbuf->fireChanges) |
| 2742 | return NULL; /* changes in this buffer are not reported */ |
| 2743 | |
| 2744 | *bufnop = bufno; |
| 2745 | return nbbuf; |
| 2746 | } |
| 2747 | |
| 2748 | /* |
| 2749 | * Tell netbeans the user inserted some text. |
| 2750 | */ |
| 2751 | void |
| 2752 | netbeans_inserted( |
| 2753 | buf_T *bufp, |
| 2754 | linenr_T linenr, |
| 2755 | colnr_T col, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2756 | char_u *txt, |
| 2757 | int newlen) |
| 2758 | { |
| 2759 | char_u *buf; |
| 2760 | int bufno; |
| 2761 | nbbuf_T *nbbuf; |
| 2762 | pos_T pos; |
| 2763 | long off; |
| 2764 | char_u *p; |
| 2765 | char_u *newtxt; |
| 2766 | |
| 2767 | nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno); |
| 2768 | if (nbbuf == NULL) |
| 2769 | return; |
| 2770 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2771 | /* Don't mark as modified for initial read */ |
| 2772 | if (nbbuf->insertDone) |
| 2773 | nbbuf->modified = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2774 | |
| 2775 | pos.lnum = linenr; |
| 2776 | pos.col = col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2777 | off = pos2off(bufp, &pos); |
| 2778 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2779 | /* send the "insert" EVT */ |
| 2780 | newtxt = alloc(newlen + 1); |
Bram Moolenaar | b635633 | 2005-07-18 21:40:44 +0000 | [diff] [blame] | 2781 | vim_strncpy(newtxt, txt, newlen); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2782 | p = nb_quote(newtxt); |
| 2783 | if (p != NULL) |
| 2784 | { |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2785 | buf = alloc(128 + 2*newlen); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2786 | sprintf((char *)buf, "%d:insert=%d %ld \"%s\"\n", bufno, cmdno, off, p); |
| 2787 | nbdebug(("EVT: %s", buf)); |
| 2788 | nb_send((char *)buf, "netbeans_inserted"); |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2789 | vim_free(p); |
| 2790 | vim_free(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2791 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2792 | vim_free(newtxt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | /* |
| 2796 | * Tell netbeans some bytes have been removed. |
| 2797 | */ |
| 2798 | void |
| 2799 | netbeans_removed( |
| 2800 | buf_T *bufp, |
| 2801 | linenr_T linenr, |
| 2802 | colnr_T col, |
| 2803 | long len) |
| 2804 | { |
| 2805 | char_u buf[128]; |
| 2806 | int bufno; |
| 2807 | nbbuf_T *nbbuf; |
| 2808 | pos_T pos; |
| 2809 | long off; |
| 2810 | |
| 2811 | nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno); |
| 2812 | if (nbbuf == NULL) |
| 2813 | return; |
| 2814 | |
| 2815 | if (len < 0) |
| 2816 | { |
| 2817 | nbdebug(("Negative len %ld in netbeans_removed()!", len)); |
| 2818 | return; |
| 2819 | } |
| 2820 | |
| 2821 | nbbuf->modified = 1; |
| 2822 | |
| 2823 | pos.lnum = linenr; |
| 2824 | pos.col = col; |
| 2825 | |
| 2826 | off = pos2off(bufp, &pos); |
| 2827 | |
| 2828 | sprintf((char *)buf, "%d:remove=%d %ld %ld\n", bufno, cmdno, off, len); |
| 2829 | nbdebug(("EVT: %s", buf)); |
| 2830 | nb_send((char *)buf, "netbeans_removed"); |
| 2831 | } |
| 2832 | |
| 2833 | /* |
| 2834 | * Send netbeans an unmodufied command. |
| 2835 | */ |
| 2836 | /*ARGSUSED*/ |
| 2837 | void |
| 2838 | netbeans_unmodified(buf_T *bufp) |
| 2839 | { |
| 2840 | #if 0 |
| 2841 | char_u buf[128]; |
| 2842 | int bufno; |
| 2843 | nbbuf_T *nbbuf; |
| 2844 | |
| 2845 | /* This has been disabled, because NetBeans considers a buffer modified |
| 2846 | * even when all changes have been undone. */ |
| 2847 | nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno); |
| 2848 | if (nbbuf == NULL) |
| 2849 | return; |
| 2850 | |
| 2851 | nbbuf->modified = 0; |
| 2852 | |
| 2853 | sprintf((char *)buf, "%d:unmodified=%d\n", bufno, cmdno); |
| 2854 | nbdebug(("EVT: %s", buf)); |
| 2855 | nb_send((char *)buf, "netbeans_unmodified"); |
| 2856 | #endif |
| 2857 | } |
| 2858 | |
| 2859 | /* |
| 2860 | * Send a button release event back to netbeans. Its up to netbeans |
| 2861 | * to decide what to do (if anything) with this event. |
| 2862 | */ |
| 2863 | void |
| 2864 | netbeans_button_release(int button) |
| 2865 | { |
| 2866 | char buf[128]; |
| 2867 | int bufno; |
| 2868 | |
| 2869 | bufno = nb_getbufno(curbuf); |
| 2870 | |
| 2871 | if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf) |
| 2872 | { |
Bram Moolenaar | c92ad2e | 2005-01-19 22:08:28 +0000 | [diff] [blame] | 2873 | int col = mouse_col - W_WINCOL(curwin) - (curwin->w_p_nu ? 9 : 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2874 | long off = pos2off(curbuf, &curwin->w_cursor); |
| 2875 | |
| 2876 | /* sync the cursor position */ |
| 2877 | sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, cmdno, off, off); |
| 2878 | nbdebug(("EVT: %s", buf)); |
| 2879 | nb_send(buf, "netbeans_button_release[newDotAndMark]"); |
| 2880 | |
| 2881 | sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, cmdno, |
| 2882 | button, (long)curwin->w_cursor.lnum, col); |
| 2883 | nbdebug(("EVT: %s", buf)); |
| 2884 | nb_send(buf, "netbeans_button_release"); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | |
| 2889 | /* |
| 2890 | * Send a keypress event back to netbeans. This usualy simulates some |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2891 | * kind of function key press. This function operates on a key code. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2892 | */ |
| 2893 | void |
| 2894 | netbeans_keycommand(int key) |
| 2895 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2896 | char keyName[60]; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2897 | |
| 2898 | netbeans_keyname(key, keyName); |
| 2899 | netbeans_keystring(key, keyName); |
| 2900 | } |
| 2901 | |
| 2902 | |
| 2903 | /* |
| 2904 | * Send a keypress event back to netbeans. This usualy simulates some |
| 2905 | * kind of function key press. This function operates on a key string. |
| 2906 | */ |
| 2907 | static void |
| 2908 | netbeans_keystring(int key, char *keyName) |
| 2909 | { |
| 2910 | char buf[2*MAXPATHL]; |
| 2911 | int bufno = nb_getbufno(curbuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2912 | long off; |
| 2913 | char_u *q; |
| 2914 | |
| 2915 | if (!haveConnection) |
| 2916 | return; |
| 2917 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2918 | |
| 2919 | if (bufno == -1) |
| 2920 | { |
| 2921 | nbdebug(("got keycommand for non-NetBeans buffer, opening...\n")); |
| 2922 | q = curbuf->b_ffname == NULL ? (char_u *)"" |
| 2923 | : nb_quote(curbuf->b_ffname); |
| 2924 | if (q == NULL) |
| 2925 | return; |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 2926 | vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2927 | q, |
| 2928 | "T", /* open in NetBeans */ |
| 2929 | "F"); /* modified */ |
| 2930 | if (curbuf->b_ffname != NULL) |
| 2931 | vim_free(q); |
| 2932 | nbdebug(("EVT: %s", buf)); |
| 2933 | nb_send(buf, "netbeans_keycommand"); |
| 2934 | |
Bram Moolenaar | 5b625c5 | 2005-01-31 18:55:55 +0000 | [diff] [blame] | 2935 | if (key > 0) |
| 2936 | postpone_keycommand(key); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2937 | return; |
| 2938 | } |
| 2939 | |
| 2940 | /* sync the cursor position */ |
| 2941 | off = pos2off(curbuf, &curwin->w_cursor); |
| 2942 | sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, cmdno, off, off); |
| 2943 | nbdebug(("EVT: %s", buf)); |
| 2944 | nb_send(buf, "netbeans_keycommand"); |
| 2945 | |
| 2946 | /* To work on Win32 you must apply patch to ExtEditor module |
| 2947 | * from ExtEdCaret.java.diff - make EVT_newDotAndMark handler |
| 2948 | * more synchronous |
| 2949 | */ |
| 2950 | |
| 2951 | /* now send keyCommand event */ |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 2952 | vim_snprintf(buf, sizeof(buf), "%d:keyCommand=%d \"%s\"\n", |
| 2953 | bufno, cmdno, keyName); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2954 | nbdebug(("EVT: %s", buf)); |
| 2955 | nb_send(buf, "netbeans_keycommand"); |
| 2956 | |
| 2957 | /* New: do both at once and include the lnum/col. */ |
Bram Moolenaar | 9c13b35 | 2005-05-19 20:53:52 +0000 | [diff] [blame] | 2958 | vim_snprintf(buf, sizeof(buf), "%d:keyAtPos=%d \"%s\" %ld %ld/%ld\n", |
| 2959 | bufno, cmdno, keyName, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2960 | off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col); |
| 2961 | nbdebug(("EVT: %s", buf)); |
| 2962 | nb_send(buf, "netbeans_keycommand"); |
| 2963 | } |
| 2964 | |
| 2965 | |
| 2966 | /* |
| 2967 | * Send a save event to netbeans. |
| 2968 | */ |
| 2969 | void |
| 2970 | netbeans_save_buffer(buf_T *bufp) |
| 2971 | { |
| 2972 | char_u buf[64]; |
| 2973 | int bufno; |
| 2974 | nbbuf_T *nbbuf; |
| 2975 | |
| 2976 | nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno); |
| 2977 | if (nbbuf == NULL) |
| 2978 | return; |
| 2979 | |
| 2980 | nbbuf->modified = 0; |
| 2981 | |
| 2982 | sprintf((char *)buf, "%d:save=%d\n", bufno, cmdno); |
| 2983 | nbdebug(("EVT: %s", buf)); |
| 2984 | nb_send((char *)buf, "netbeans_save_buffer"); |
| 2985 | } |
| 2986 | |
| 2987 | |
| 2988 | /* |
| 2989 | * Send remove command to netbeans (this command has been turned off). |
| 2990 | */ |
| 2991 | void |
| 2992 | netbeans_deleted_all_lines(buf_T *bufp) |
| 2993 | { |
| 2994 | char_u buf[64]; |
| 2995 | int bufno; |
| 2996 | nbbuf_T *nbbuf; |
| 2997 | |
| 2998 | nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno); |
| 2999 | if (nbbuf == NULL) |
| 3000 | return; |
| 3001 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 3002 | /* Don't mark as modified for initial read */ |
| 3003 | if (nbbuf->insertDone) |
| 3004 | nbbuf->modified = 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3005 | |
| 3006 | sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, cmdno); |
| 3007 | nbdebug(("EVT(suppressed): %s", buf)); |
| 3008 | /* nb_send(buf, "netbeans_deleted_all_lines"); */ |
| 3009 | } |
| 3010 | |
| 3011 | |
| 3012 | /* |
| 3013 | * See if the lines are guarded. The top and bot parameters are from |
| 3014 | * u_savecommon(), these are the line above the change and the line below the |
| 3015 | * change. |
| 3016 | */ |
| 3017 | int |
| 3018 | netbeans_is_guarded(linenr_T top, linenr_T bot) |
| 3019 | { |
| 3020 | signlist_T *p; |
| 3021 | int lnum; |
| 3022 | |
| 3023 | for (p = curbuf->b_signlist; p != NULL; p = p->next) |
| 3024 | if (p->id >= GUARDEDOFFSET) |
| 3025 | for (lnum = top + 1; lnum < bot; lnum++) |
| 3026 | if (lnum == p->lnum) |
| 3027 | return TRUE; |
| 3028 | |
| 3029 | return FALSE; |
| 3030 | } |
| 3031 | |
| 3032 | #if defined(FEAT_GUI_MOTIF) || defined(PROTO) |
| 3033 | /* |
| 3034 | * We have multiple signs to draw at the same location. Draw the |
| 3035 | * multi-sign indicator instead. This is the Motif version. |
| 3036 | */ |
| 3037 | void |
| 3038 | netbeans_draw_multisign_indicator(int row) |
| 3039 | { |
| 3040 | int i; |
| 3041 | int y; |
| 3042 | int x; |
| 3043 | |
| 3044 | x = 0; |
| 3045 | y = row * gui.char_height + 2; |
| 3046 | |
| 3047 | for (i = 0; i < gui.char_height - 3; i++) |
| 3048 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y++); |
| 3049 | |
| 3050 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+0, y); |
| 3051 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y); |
| 3052 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+4, y++); |
| 3053 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+1, y); |
| 3054 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y); |
| 3055 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+3, y++); |
| 3056 | XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y); |
| 3057 | } |
| 3058 | #endif /* FEAT_GUI_MOTIF */ |
| 3059 | |
| 3060 | #ifdef FEAT_GUI_GTK |
| 3061 | /* |
| 3062 | * We have multiple signs to draw at the same location. Draw the |
| 3063 | * multi-sign indicator instead. This is the GTK/Gnome version. |
| 3064 | */ |
| 3065 | void |
| 3066 | netbeans_draw_multisign_indicator(int row) |
| 3067 | { |
| 3068 | int i; |
| 3069 | int y; |
| 3070 | int x; |
| 3071 | GdkDrawable *drawable = gui.drawarea->window; |
| 3072 | |
| 3073 | x = 0; |
| 3074 | y = row * gui.char_height + 2; |
| 3075 | |
| 3076 | for (i = 0; i < gui.char_height - 3; i++) |
| 3077 | gdk_draw_point(drawable, gui.text_gc, x+2, y++); |
| 3078 | |
| 3079 | gdk_draw_point(drawable, gui.text_gc, x+0, y); |
| 3080 | gdk_draw_point(drawable, gui.text_gc, x+2, y); |
| 3081 | gdk_draw_point(drawable, gui.text_gc, x+4, y++); |
| 3082 | gdk_draw_point(drawable, gui.text_gc, x+1, y); |
| 3083 | gdk_draw_point(drawable, gui.text_gc, x+2, y); |
| 3084 | gdk_draw_point(drawable, gui.text_gc, x+3, y++); |
| 3085 | gdk_draw_point(drawable, gui.text_gc, x+2, y); |
| 3086 | } |
| 3087 | #endif /* FEAT_GUI_GTK */ |
| 3088 | |
| 3089 | /* |
| 3090 | * If the mouse is clicked in the gutter of a line with multiple |
| 3091 | * annotations, cycle through the set of signs. |
| 3092 | */ |
| 3093 | void |
| 3094 | netbeans_gutter_click(linenr_T lnum) |
| 3095 | { |
| 3096 | signlist_T *p; |
| 3097 | |
| 3098 | for (p = curbuf->b_signlist; p != NULL; p = p->next) |
| 3099 | { |
| 3100 | if (p->lnum == lnum && p->next && p->next->lnum == lnum) |
| 3101 | { |
| 3102 | signlist_T *tail; |
| 3103 | |
| 3104 | /* remove "p" from list, reinsert it at the tail of the sublist */ |
| 3105 | if (p->prev) |
| 3106 | p->prev->next = p->next; |
| 3107 | else |
| 3108 | curbuf->b_signlist = p->next; |
| 3109 | p->next->prev = p->prev; |
| 3110 | /* now find end of sublist and insert p */ |
| 3111 | for (tail = p->next; |
| 3112 | tail->next && tail->next->lnum == lnum |
| 3113 | && tail->next->id < GUARDEDOFFSET; |
| 3114 | tail = tail->next) |
| 3115 | ; |
| 3116 | /* tail now points to last entry with same lnum (except |
| 3117 | * that "guarded" annotations are always last) */ |
| 3118 | p->next = tail->next; |
| 3119 | if (tail->next) |
| 3120 | tail->next->prev = p; |
| 3121 | p->prev = tail; |
| 3122 | tail->next = p; |
| 3123 | update_debug_sign(curbuf, lnum); |
| 3124 | break; |
| 3125 | } |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | |
| 3130 | /* |
| 3131 | * Add a sign of the reqested type at the requested location. |
| 3132 | * |
| 3133 | * Reverse engineering: |
| 3134 | * Apparently an annotation is defined the first time it is used in a buffer. |
| 3135 | * When the same annotation is used in two buffers, the second time we do not |
| 3136 | * need to define a new sign name but reuse the existing one. But since the |
| 3137 | * ID number used in the second buffer starts counting at one again, a mapping |
| 3138 | * is made from the ID specifically for the buffer to the global sign name |
| 3139 | * (which is a number). |
| 3140 | * |
| 3141 | * globalsignmap[] stores the signs that have been defined globally. |
| 3142 | * buf->signmapused[] maps buffer-local annotation IDs to an index in |
| 3143 | * globalsignmap[]. |
| 3144 | */ |
| 3145 | /*ARGSUSED*/ |
| 3146 | static void |
| 3147 | addsigntype( |
| 3148 | nbbuf_T *buf, |
| 3149 | int typeNum, |
| 3150 | char_u *typeName, |
| 3151 | char_u *tooltip, |
| 3152 | char_u *glyphFile, |
| 3153 | int use_fg, |
| 3154 | int fg, |
| 3155 | int use_bg, |
| 3156 | int bg) |
| 3157 | { |
| 3158 | char fgbuf[32]; |
| 3159 | char bgbuf[32]; |
| 3160 | int i, j; |
| 3161 | |
| 3162 | for (i = 0; i < globalsignmapused; i++) |
| 3163 | if (STRCMP(typeName, globalsignmap[i]) == 0) |
| 3164 | break; |
| 3165 | |
| 3166 | if (i == globalsignmapused) /* not found; add it to global map */ |
| 3167 | { |
| 3168 | nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%d,%d)\n", |
| 3169 | typeNum, typeName, tooltip, glyphFile, fg, bg)); |
| 3170 | if (use_fg || use_bg) |
| 3171 | { |
| 3172 | sprintf(fgbuf, "guifg=#%06x", fg & 0xFFFFFF); |
| 3173 | sprintf(bgbuf, "guibg=#%06x", bg & 0xFFFFFF); |
| 3174 | |
| 3175 | coloncmd(":highlight NB_%s %s %s", typeName, (use_fg) ? fgbuf : "", |
| 3176 | (use_bg) ? bgbuf : ""); |
| 3177 | if (*glyphFile == NUL) |
| 3178 | /* no glyph, line highlighting only */ |
| 3179 | coloncmd(":sign define %d linehl=NB_%s", i + 1, typeName); |
| 3180 | else if (vim_strsize(glyphFile) <= 2) |
| 3181 | /* one- or two-character glyph name, use as text glyph with |
| 3182 | * texthl */ |
| 3183 | coloncmd(":sign define %d text=%s texthl=NB_%s", i + 1, |
| 3184 | glyphFile, typeName); |
| 3185 | else |
| 3186 | /* glyph, line highlighting */ |
| 3187 | coloncmd(":sign define %d icon=%s linehl=NB_%s", i + 1, |
| 3188 | glyphFile, typeName); |
| 3189 | } |
| 3190 | else |
| 3191 | /* glyph, no line highlighting */ |
| 3192 | coloncmd(":sign define %d icon=%s", i + 1, glyphFile); |
| 3193 | |
| 3194 | if (STRCMP(typeName,"CurrentPC") == 0) |
| 3195 | curPCtype = typeNum; |
| 3196 | |
| 3197 | if (globalsignmapused == globalsignmaplen) |
| 3198 | { |
| 3199 | if (globalsignmaplen == 0) /* first allocation */ |
| 3200 | { |
| 3201 | globalsignmaplen = 20; |
| 3202 | globalsignmap = (char **)alloc_clear(globalsignmaplen*sizeof(char *)); |
| 3203 | } |
| 3204 | else /* grow it */ |
| 3205 | { |
| 3206 | int incr; |
| 3207 | int oldlen = globalsignmaplen; |
| 3208 | |
| 3209 | globalsignmaplen *= 2; |
| 3210 | incr = globalsignmaplen - oldlen; |
| 3211 | globalsignmap = (char **)vim_realloc(globalsignmap, |
| 3212 | globalsignmaplen * sizeof(char *)); |
| 3213 | memset(globalsignmap + oldlen, 0, incr * sizeof(char *)); |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | globalsignmap[i] = (char *)typeName; |
| 3218 | globalsignmapused = i + 1; |
| 3219 | } |
| 3220 | |
| 3221 | /* check local map; should *not* be found! */ |
| 3222 | for (j = 0; j < buf->signmapused; j++) |
| 3223 | if (buf->signmap[j] == i + 1) |
| 3224 | return; |
| 3225 | |
| 3226 | /* add to local map */ |
| 3227 | if (buf->signmapused == buf->signmaplen) |
| 3228 | { |
| 3229 | if (buf->signmaplen == 0) /* first allocation */ |
| 3230 | { |
| 3231 | buf->signmaplen = 5; |
| 3232 | buf->signmap = (int *)alloc_clear(buf->signmaplen * sizeof(int *)); |
| 3233 | } |
| 3234 | else /* grow it */ |
| 3235 | { |
| 3236 | int incr; |
| 3237 | int oldlen = buf->signmaplen; |
| 3238 | buf->signmaplen *= 2; |
| 3239 | incr = buf->signmaplen - oldlen; |
| 3240 | buf->signmap = (int *)vim_realloc(buf->signmap, |
| 3241 | buf->signmaplen*sizeof(int *)); |
| 3242 | memset(buf->signmap + oldlen, 0, incr * sizeof(int *)); |
| 3243 | } |
| 3244 | } |
| 3245 | |
| 3246 | buf->signmap[buf->signmapused++] = i + 1; |
| 3247 | |
| 3248 | } |
| 3249 | |
| 3250 | |
| 3251 | /* |
| 3252 | * See if we have the requested sign type in the buffer. |
| 3253 | */ |
| 3254 | static int |
| 3255 | mapsigntype(nbbuf_T *buf, int localsigntype) |
| 3256 | { |
| 3257 | if (--localsigntype >= 0 && localsigntype < buf->signmapused) |
| 3258 | return buf->signmap[localsigntype]; |
| 3259 | |
| 3260 | return 0; |
| 3261 | } |
| 3262 | |
| 3263 | |
| 3264 | /* |
| 3265 | * Compute length of buffer, don't print anything. |
| 3266 | */ |
| 3267 | static long |
| 3268 | get_buf_size(buf_T *bufp) |
| 3269 | { |
| 3270 | linenr_T lnum; |
| 3271 | long char_count = 0; |
| 3272 | int eol_size; |
| 3273 | long last_check = 100000L; |
| 3274 | |
| 3275 | if (bufp->b_ml.ml_flags & ML_EMPTY) |
| 3276 | return 0; |
| 3277 | else |
| 3278 | { |
| 3279 | if (get_fileformat(bufp) == EOL_DOS) |
| 3280 | eol_size = 2; |
| 3281 | else |
| 3282 | eol_size = 1; |
| 3283 | for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum) |
| 3284 | { |
| 3285 | char_count += STRLEN(ml_get(lnum)) + eol_size; |
| 3286 | /* Check for a CTRL-C every 100000 characters */ |
| 3287 | if (char_count > last_check) |
| 3288 | { |
| 3289 | ui_breakcheck(); |
| 3290 | if (got_int) |
| 3291 | return char_count; |
| 3292 | last_check = char_count + 100000L; |
| 3293 | } |
| 3294 | } |
| 3295 | /* Correction for when last line doesn't have an EOL. */ |
| 3296 | if (!bufp->b_p_eol && bufp->b_p_bin) |
| 3297 | char_count -= eol_size; |
| 3298 | } |
| 3299 | |
| 3300 | return char_count; |
| 3301 | } |
| 3302 | |
| 3303 | /* |
| 3304 | * Convert character offset to lnum,col |
| 3305 | */ |
| 3306 | static pos_T * |
| 3307 | off2pos(buf_T *buf, long offset) |
| 3308 | { |
| 3309 | linenr_T lnum; |
| 3310 | static pos_T pos; |
| 3311 | |
| 3312 | pos.lnum = 0; |
| 3313 | pos.col = 0; |
| 3314 | #ifdef FEAT_VIRTUALEDIT |
| 3315 | pos.coladd = 0; |
| 3316 | #endif |
| 3317 | |
| 3318 | if (!(buf->b_ml.ml_flags & ML_EMPTY)) |
| 3319 | { |
| 3320 | if ((lnum = ml_find_line_or_offset(buf, (linenr_T)0, &offset)) < 0) |
| 3321 | return NULL; |
| 3322 | pos.lnum = lnum; |
| 3323 | pos.col = offset; |
| 3324 | } |
| 3325 | |
| 3326 | return &pos; |
| 3327 | } |
| 3328 | |
| 3329 | /* |
| 3330 | * Convert an argument in the form "1234" to an offset and compute the |
| 3331 | * lnum/col from it. Convert an argument in the form "123/12" directly to a |
| 3332 | * lnum/col. |
| 3333 | * "argp" is advanced to after the argument. |
| 3334 | * Return a pointer to the position, NULL if something is wrong. |
| 3335 | */ |
| 3336 | static pos_T * |
| 3337 | get_off_or_lnum(buf_T *buf, char_u **argp) |
| 3338 | { |
| 3339 | static pos_T mypos; |
| 3340 | long off; |
| 3341 | |
| 3342 | off = strtol((char *)*argp, (char **)argp, 10); |
| 3343 | if (**argp == '/') |
| 3344 | { |
| 3345 | mypos.lnum = (linenr_T)off; |
| 3346 | ++*argp; |
| 3347 | mypos.col = strtol((char *)*argp, (char **)argp, 10); |
| 3348 | #ifdef FEAT_VIRTUALEDIT |
| 3349 | mypos.coladd = 0; |
| 3350 | #endif |
| 3351 | return &mypos; |
| 3352 | } |
| 3353 | return off2pos(buf, off); |
| 3354 | } |
| 3355 | |
| 3356 | |
| 3357 | /* |
| 3358 | * Convert lnum,col to character offset |
| 3359 | */ |
| 3360 | static long |
| 3361 | pos2off(buf_T *buf, pos_T *pos) |
| 3362 | { |
| 3363 | long offset = 0; |
| 3364 | |
| 3365 | if (!(buf->b_ml.ml_flags & ML_EMPTY)) |
| 3366 | { |
| 3367 | if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0) |
| 3368 | return 0; |
| 3369 | offset += pos->col; |
| 3370 | } |
| 3371 | |
| 3372 | return offset; |
| 3373 | } |
| 3374 | |
| 3375 | |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 3376 | /* |
| 3377 | * This message is printed after NetBeans opens a new file. Its |
| 3378 | * similar to the message readfile() uses, but since NetBeans |
| 3379 | * doesn't normally call readfile, we do our own. |
| 3380 | */ |
| 3381 | static void |
| 3382 | print_read_msg(buf) |
| 3383 | nbbuf_T *buf; |
| 3384 | { |
| 3385 | int lnum = buf->bufp->b_ml.ml_line_count; |
| 3386 | long nchars = buf->bufp->b_orig_size; |
| 3387 | char_u c; |
| 3388 | |
| 3389 | msg_add_fname(buf->bufp, buf->bufp->b_ffname); |
| 3390 | c = FALSE; |
| 3391 | |
| 3392 | if (buf->bufp->b_p_ro) |
| 3393 | { |
| 3394 | STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]")); |
| 3395 | c = TRUE; |
| 3396 | } |
| 3397 | if (!buf->bufp->b_start_eol) |
| 3398 | { |
| 3399 | STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]")); |
| 3400 | c = TRUE; |
| 3401 | } |
| 3402 | msg_add_lines(c, (long)lnum, nchars); |
| 3403 | |
| 3404 | /* Now display it */ |
| 3405 | vim_free(keep_msg); |
| 3406 | keep_msg = NULL; |
| 3407 | msg_scrolled_ign = TRUE; |
| 3408 | msg_trunc_attr(IObuff, FALSE, 0); |
| 3409 | msg_scrolled_ign = FALSE; |
| 3410 | } |
| 3411 | |
| 3412 | |
| 3413 | /* |
| 3414 | * Print a message after NetBeans writes the file. This message should be identical |
| 3415 | * to the standard message a non-netbeans user would see when writing a file. |
| 3416 | */ |
| 3417 | static void |
| 3418 | print_save_msg(buf, nchars) |
| 3419 | nbbuf_T *buf; |
| 3420 | long nchars; |
| 3421 | { |
| 3422 | char_u c; |
| 3423 | char_u *p; |
| 3424 | |
| 3425 | if (nchars >= 0) |
| 3426 | { |
| 3427 | msg_add_fname(buf->bufp, buf->bufp->b_ffname); /* fname in IObuff with quotes */ |
| 3428 | c = FALSE; |
| 3429 | |
| 3430 | msg_add_lines(c, buf->bufp->b_ml.ml_line_count, |
| 3431 | (long)buf->bufp->b_orig_size); |
| 3432 | |
| 3433 | vim_free(keep_msg); |
| 3434 | keep_msg = NULL; |
| 3435 | msg_scrolled_ign = TRUE; |
| 3436 | p = msg_trunc_attr(IObuff, FALSE, 0); |
| 3437 | if ((msg_scrolled && !need_wait_return) || !buf->initDone) |
| 3438 | { |
| 3439 | /* Need to repeat the message after redrawing when: |
| 3440 | * - When reading from stdin (the screen will be cleared next). |
| 3441 | * - When restart_edit is set (otherwise there will be a delay |
| 3442 | * before redrawing). |
| 3443 | * - When the screen was scrolled but there is no wait-return |
| 3444 | * prompt. */ |
| 3445 | set_keep_msg(p); |
| 3446 | keep_msg_attr = 0; |
| 3447 | } |
| 3448 | msg_scrolled_ign = FALSE; |
| 3449 | /* add_to_input_buf((char_u *)"\f", 1); */ |
| 3450 | } |
| 3451 | else |
| 3452 | { |
| 3453 | char_u ebuf[BUFSIZ]; |
| 3454 | |
| 3455 | STRCPY(ebuf, (char_u *)_("E505: ")); |
| 3456 | STRCAT(ebuf, IObuff); |
| 3457 | STRCAT(ebuf, (char_u *)_("is read-only (add ! to override)")); |
| 3458 | STRCPY(IObuff, ebuf); |
| 3459 | emsg(IObuff); |
| 3460 | } |
| 3461 | } |
| 3462 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3463 | #endif /* defined(FEAT_NETBEANS_INTG) */ |