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