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