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