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