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