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