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