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