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