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