1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * Netbeans integration by David Weatherford
5 * Adopted for Win32 by Sergey Khorev
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.
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.
21 #if defined(FEAT_NETBEANS_INTG) || defined(PROTO)
23 /* Note: when making changes here also adjust configure.in. */
27 # include <tchar.h> /* for _T definition for TRACEn macros */
30 /* WinSock API is separated from C API, thus we can't use read(), write(),
32 # define sock_errno WSAGetLastError()
33 # define ECONNREFUSED WSAECONNREFUSED
37 # define EINTR WSAEINTR
38 # define sock_write(sd, buf, len) send(sd, buf, len, 0)
39 # define sock_read(sd, buf, len) recv(sd, buf, len, 0)
40 # define sock_close(sd) closesocket(sd)
41 # define sleep(t) Sleep(t*1000) /* WinAPI Sleep() accepts milliseconds */
44 # include <netinet/in.h>
45 # include <sys/socket.h>
49 # define sock_errno errno
50 # define sock_write(sd, buf, len) write(sd, buf, len)
51 # define sock_read(sd, buf, len) read(sd, buf, len)
52 # define sock_close(sd) close(sd)
59 #define GUARDED 10000 /* typenr for "guarded" annotation */
60 #define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */
62 /* The first implementation (working only with Netbeans) returned "1.1". The
63 * protocol implemented here also supports A-A-P. */
64 static char *ExtEdProtocolVersion
= "2.3";
66 static long pos2off
__ARGS((buf_T
*, pos_T
*));
67 static pos_T
*off2pos
__ARGS((buf_T
*, long));
68 static pos_T
*get_off_or_lnum
__ARGS((buf_T
*buf
, char_u
**argp
));
69 static long get_buf_size
__ARGS((buf_T
*));
70 static void netbeans_keystring
__ARGS((int key
, char *keystr
));
71 static void special_keys
__ARGS((char_u
*args
));
73 static void netbeans_connect
__ARGS((void));
74 static int getConnInfo
__ARGS((char *file
, char **host
, char **port
, char **password
));
76 static void nb_init_graphics
__ARGS((void));
77 static void coloncmd
__ARGS((char *cmd
, ...));
78 static void nb_set_curbuf
__ARGS((buf_T
*buf
));
80 static void messageFromNetbeans
__ARGS((XtPointer
, int *, XtInputId
*));
83 static void messageFromNetbeans
__ARGS((gpointer
, gint
, GdkInputCondition
));
85 static void nb_parse_cmd
__ARGS((char_u
*));
86 static int nb_do_cmd
__ARGS((int, char_u
*, int, int, char_u
*));
87 static void nb_send
__ARGS((char *buf
, char *fun
));
90 typedef __int64 NBSOCK
;
95 static NBSOCK sd
= -1; /* socket fd for Netbeans connection */
97 static XtInputId inputHandler
; /* Cookie for input */
100 static gint inputHandler
; /* Cookie for input */
103 static int inputHandler
= -1; /* simply ret.value of WSAAsyncSelect() */
104 extern HWND s_hwnd
; /* Gvim's Window handle */
106 static int r_cmdno
; /* current command number for reply */
107 static int haveConnection
= FALSE
; /* socket is connected and
108 initialization is done */
109 #ifdef FEAT_GUI_MOTIF
110 static void netbeans_Xt_connect
__ARGS((void *context
));
113 static void netbeans_gtk_connect
__ARGS((void));
116 static void netbeans_w32_connect
__ARGS((void));
119 static int dosetvisible
= FALSE
;
122 * Include the debugging code if wanted.
125 # include "nbdebug.c"
128 /* Connect back to Netbeans process */
129 #ifdef FEAT_GUI_MOTIF
131 netbeans_Xt_connect(void *context
)
136 /* tell notifier we are interested in being called
137 * when there is input on the editor connection socket
139 inputHandler
= XtAppAddInput((XtAppContext
)context
, sd
,
140 (XtPointer
)(XtInputReadMask
+ XtInputExceptMask
),
141 messageFromNetbeans
, NULL
);
146 netbeans_disconnect(void)
148 if (inputHandler
!= (XtInputId
)NULL
)
150 XtRemoveInput(inputHandler
);
151 inputHandler
= (XtInputId
)NULL
;
154 haveConnection
= FALSE
;
156 bevalServers
&= ~BEVAL_NETBEANS
;
159 #endif /* FEAT_MOTIF_GUI */
163 netbeans_gtk_connect(void)
169 * Tell gdk we are interested in being called when there
170 * is input on the editor connection socket
172 inputHandler
= gdk_input_add((gint
)sd
, (GdkInputCondition
)
173 ((int)GDK_INPUT_READ
+ (int)GDK_INPUT_EXCEPTION
),
174 messageFromNetbeans
, NULL
);
179 netbeans_disconnect(void)
181 if (inputHandler
!= 0)
183 gdk_input_remove(inputHandler
);
187 haveConnection
= FALSE
;
189 bevalServers
&= ~BEVAL_NETBEANS
;
192 #endif /* FEAT_GUI_GTK */
194 #if defined(FEAT_GUI_W32) || defined(PROTO)
196 netbeans_w32_connect(void)
202 * Tell Windows we are interested in receiving message when there
203 * is input on the editor connection socket
205 inputHandler
= WSAAsyncSelect(sd
, s_hwnd
, WM_NETBEANS
, FD_READ
);
210 netbeans_disconnect(void)
212 if (inputHandler
== 0)
214 WSAAsyncSelect(sd
, s_hwnd
, 0, 0);
218 haveConnection
= FALSE
;
220 bevalServers
&= ~BEVAL_NETBEANS
;
223 #endif /* FEAT_GUI_W32 */
225 #define NB_DEF_HOST "localhost"
226 #define NB_DEF_ADDR "3219"
227 #define NB_DEF_PASS "changeme"
230 netbeans_connect(void)
233 struct sockaddr_in server
;
234 struct hostent
* host
;
241 struct sockaddr_un server
;
244 char *hostname
= NULL
;
245 char *address
= NULL
;
246 char *password
= NULL
;
250 if (netbeansArg
[3] == '=')
252 /* "-nb=fname": Read info from specified file. */
253 if (getConnInfo(netbeansArg
+ 4, &hostname
, &address
, &password
)
259 if (netbeansArg
[3] == ':')
260 /* "-nb:<host>:<addr>:<password>": get info from argument */
261 arg
= netbeansArg
+ 4;
262 if (arg
== NULL
&& (fname
= getenv("__NETBEANS_CONINFO")) != NULL
)
264 /* "-nb": get info from file specified in environment */
265 if (getConnInfo(fname
, &hostname
, &address
, &password
) == FAIL
)
272 /* "-nb:<host>:<addr>:<password>": get info from argument */
274 address
= strchr(hostname
, ':');
278 password
= strchr(address
, ':');
279 if (password
!= NULL
)
284 /* Get the missing values from the environment. */
285 if (hostname
== NULL
|| *hostname
== '\0')
286 hostname
= getenv("__NETBEANS_HOST");
288 address
= getenv("__NETBEANS_SOCKET");
289 if (password
== NULL
)
290 password
= getenv("__NETBEANS_VIM_PASSWORD");
292 /* Move values to allocated memory. */
293 if (hostname
!= NULL
)
294 hostname
= (char *)vim_strsave((char_u
*)hostname
);
296 address
= (char *)vim_strsave((char_u
*)address
);
297 if (password
!= NULL
)
298 password
= (char *)vim_strsave((char_u
*)password
);
302 /* Use the default when a value is missing. */
303 if (hostname
== NULL
|| *hostname
== '\0')
306 hostname
= (char *)vim_strsave((char_u
*)NB_DEF_HOST
);
308 if (address
== NULL
|| *address
== '\0')
311 address
= (char *)vim_strsave((char_u
*)NB_DEF_ADDR
);
313 if (password
== NULL
|| *password
== '\0')
316 password
= (char *)vim_strsave((char_u
*)NB_DEF_PASS
);
318 if (hostname
== NULL
|| address
== NULL
|| password
== NULL
)
319 goto theend
; /* out of memory */
322 port
= atoi(address
);
324 if ((sd
= (NBSOCK
)socket(AF_INET
, SOCK_STREAM
, 0)) == (NBSOCK
)-1)
326 PERROR("socket() in netbeans_connect()");
330 /* Get the server internet address and put into addr structure */
331 /* fill in the socket address structure and connect to server */
332 memset((char *)&server
, '\0', sizeof(server
));
333 server
.sin_family
= AF_INET
;
334 server
.sin_port
= htons(port
);
335 if ((host
= gethostbyname(hostname
)) == NULL
)
337 if (mch_access(hostname
, R_OK
) >= 0)
339 /* DEBUG: input file */
340 sd
= mch_open(hostname
, O_RDONLY
, 0);
343 PERROR("gethostbyname() in netbeans_connect()");
347 memcpy((char *)&server
.sin_addr
, host
->h_addr
, host
->h_length
);
349 if ((sd
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1)
355 server
.sun_family
= AF_UNIX
;
356 strcpy(server
.sun_path
, address
);
358 /* Connect to server */
359 if (connect(sd
, (struct sockaddr
*)&server
, sizeof(server
)))
361 nbdebug(("netbeans_connect: Connect failed with errno %d\n", sock_errno
));
362 if (sock_errno
== ECONNREFUSED
)
366 if ((sd
= (NBSOCK
)socket(AF_INET
, SOCK_STREAM
, 0)) == (NBSOCK
)-1)
368 PERROR("socket()#2 in netbeans_connect()");
372 if ((sd
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1)
374 PERROR("socket()#2 in netbeans_connect()");
378 if (connect(sd
, (struct sockaddr
*)&server
, sizeof(server
)))
383 && ((sock_errno
== ECONNREFUSED
) || (sock_errno
== EINTR
)))
385 nbdebug(("retrying...\n"));
387 if (connect(sd
, (struct sockaddr
*)&server
,
388 sizeof(server
)) == 0)
396 /* Get here when the server can't be found. */
397 PERROR(_("Cannot connect to Netbeans #2"));
405 PERROR(_("Cannot connect to Netbeans"));
410 vim_snprintf(buf
, sizeof(buf
), "AUTH %s\n", password
);
411 nb_send(buf
, "netbeans_connect");
413 sprintf(buf
, "0:version=0 \"%s\"\n", ExtEdProtocolVersion
);
414 nb_send(buf
, "externaleditor_version");
416 /* nb_init_graphics(); delay until needed */
418 haveConnection
= TRUE
;
428 * Obtain the NetBeans hostname, port address and password from a file.
429 * Return the strings in allocated memory.
430 * Return FAIL if the file could not be read, OK otherwise (no matter what it
434 getConnInfo(char *file
, char **host
, char **port
, char **auth
)
444 * For Unix only accept the file when it's not accessible by others.
445 * The open will then fail if we don't own the file.
447 if (mch_stat(file
, &st
) == 0 && (st
.st_mode
& 0077) != 0)
449 EMSG2(_("E668: Wrong access mode for NetBeans connection info file: \"%s\""),
455 fp
= mch_fopen(file
, "r");
458 PERROR("E660: Cannot open NetBeans connection info file");
462 /* Read the file. There should be one of each parameter */
463 while ((lp
= (char_u
*)fgets((char *)buf
, BUFSIZ
, fp
)) != NULL
)
465 if ((nl
= vim_strchr(lp
, '\n')) != NULL
)
466 *nl
= 0; /* strip off the trailing newline */
468 if (STRNCMP(lp
, "host=", 5) == 0)
471 *host
= (char *)vim_strsave(&buf
[5]);
473 else if (STRNCMP(lp
, "port=", 5) == 0)
476 *port
= (char *)vim_strsave(&buf
[5]);
478 else if (STRNCMP(lp
, "auth=", 5) == 0)
481 *auth
= (char *)vim_strsave(&buf
[5]);
493 struct keyqueue
*next
;
494 struct keyqueue
*prev
;
497 typedef struct keyqueue keyQ_T
;
499 static keyQ_T keyHead
; /* dummy node, header for circular queue */
503 * Queue up key commands sent from netbeans.
506 postpone_keycommand(int key
)
510 node
= (keyQ_T
*)alloc(sizeof(keyQ_T
));
512 if (keyHead
.next
== NULL
) /* initialize circular queue */
514 keyHead
.next
= &keyHead
;
515 keyHead
.prev
= &keyHead
;
518 /* insert node at tail of queue */
519 node
->next
= &keyHead
;
520 node
->prev
= keyHead
.prev
;
521 keyHead
.prev
->next
= node
;
528 * Handle any queued-up NetBeans keycommands to be send.
531 handle_key_queue(void)
533 while (keyHead
.next
&& keyHead
.next
!= &keyHead
)
535 /* first, unlink the node */
536 keyQ_T
*node
= keyHead
.next
;
537 keyHead
.next
= node
->next
;
538 node
->next
->prev
= node
->prev
;
540 /* now, send the keycommand */
541 netbeans_keycommand(node
->key
);
543 /* Finally, dispose of the node */
552 struct cmdqueue
*next
;
553 struct cmdqueue
*prev
;
556 typedef struct cmdqueue queue_T
;
558 static queue_T head
; /* dummy node, header for circular queue */
562 * Put the buffer on the work queue; possibly save it to a file as well.
565 save(char_u
*buf
, int len
)
569 node
= (queue_T
*)alloc(sizeof(queue_T
));
571 return; /* out of memory */
572 node
->buffer
= alloc(len
+ 1);
573 if (node
->buffer
== NULL
)
576 return; /* out of memory */
578 mch_memmove(node
->buffer
, buf
, (size_t)len
);
579 node
->buffer
[len
] = NUL
;
581 if (head
.next
== NULL
) /* initialize circular queue */
587 /* insert node at tail of queue */
589 node
->prev
= head
.prev
;
590 head
.prev
->next
= node
;
595 static int outfd
= -2;
597 /* possibly write buffer out to a file */
603 char *file
= getenv("__NETBEANS_SAVE");
607 outfd
= mch_open(file
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0666);
611 write(outfd
, buf
, len
);
618 * While there's still a command in the work queue, parse and execute it.
621 nb_parse_messages(void)
626 while (head
.next
!= &head
)
630 /* Locate the first line in the first buffer. */
631 p
= vim_strchr(node
->buffer
, '\n');
634 /* Command isn't complete. If there is no following buffer,
635 * return (wait for more). If there is another buffer following,
636 * prepend the text to that buffer and delete this one. */
637 if (node
->next
== &head
)
639 p
= alloc((unsigned)(STRLEN(node
->buffer
) + STRLEN(node
->next
->buffer
) + 1));
641 return; /* out of memory */
642 STRCPY(p
, node
->buffer
);
643 STRCAT(p
, node
->next
->buffer
);
644 vim_free(node
->next
->buffer
);
645 node
->next
->buffer
= p
;
647 /* dispose of the node and buffer */
648 head
.next
= node
->next
;
649 node
->next
->prev
= node
->prev
;
650 vim_free(node
->buffer
);
655 /* There is a complete command at the start of the buffer.
656 * Terminate it with a NUL. When no more text is following unlink
657 * the buffer. Do this before executing, because new buffers can
658 * be added while busy handling the command. */
662 head
.next
= node
->next
;
663 node
->next
->prev
= node
->prev
;
666 /* now, parse and execute the commands */
667 nb_parse_cmd(node
->buffer
);
671 /* buffer finished, dispose of the node and buffer */
672 vim_free(node
->buffer
);
677 /* more follows, move to the start */
678 mch_memmove(node
->buffer
, p
, STRLEN(p
) + 1);
684 /* Buffer size for reading incoming messages. */
685 #define MAXMSGSIZE 4096
688 * Read and process a command from netbeans.
691 #if defined(FEAT_GUI_W32) || defined(PROTO)
692 /* Use this one when generating prototypes, the others are static. */
694 messageFromNetbeansW32()
696 # ifdef FEAT_GUI_MOTIF
698 messageFromNetbeans(XtPointer clientData
, int *unused1
, XtInputId
*unused2
)
702 messageFromNetbeans(gpointer clientData
, gint unused1
,
703 GdkInputCondition unused2
)
707 static char_u
*buf
= NULL
;
710 static int level
= 0;
714 nbdebug(("messageFromNetbeans() called without a socket\n"));
718 ++level
; /* recursion guard; this will be called from the X event loop */
720 /* Allocate a buffer to read into. */
723 buf
= alloc(MAXMSGSIZE
);
725 return; /* out of memory! */
728 /* Keep on reading for as long as there is something to read. */
731 len
= sock_read(sd
, buf
, MAXMSGSIZE
);
733 break; /* error or nothing more to read */
735 /* Store the read message in the queue. */
738 if (len
< MAXMSGSIZE
)
739 break; /* did read everything that's available */
744 /* read error or didn't read anything */
745 netbeans_disconnect();
746 nbdebug(("messageFromNetbeans: Error in read() from socket\n"));
748 PERROR(_("read from Netbeans socket"));
749 return; /* don't try to parse it */
752 /* Parse the messages, but avoid recursion. */
760 * Handle one NUL terminated command.
762 * format of a command from netbeans:
764 * 6:setTitle!84 "a.c"
773 * for function calls, the ! is replaced by a /
776 nb_parse_cmd(char_u
*cmd
)
783 if (STRCMP(cmd
, "DISCONNECT") == 0)
785 /* We assume the server knows that we can safely exit! */
788 /* Disconnect before exiting, Motif hangs in a Select error
789 * message otherwise. */
790 netbeans_disconnect();
795 if (STRCMP(cmd
, "DETACH") == 0)
797 /* The IDE is breaking the connection. */
800 netbeans_disconnect();
804 bufno
= strtol((char *)cmd
, &verb
, 10);
808 EMSG2("E627: missing colon: %s", cmd
);
811 ++verb
; /* skip colon */
813 for (q
= verb
; *q
; q
++)
831 EMSG2("E628: missing ! or / in: %s", cmd
);
835 r_cmdno
= strtol(q
, &q
, 10);
837 q
= (char *)skipwhite((char_u
*)q
);
839 if (nb_do_cmd(bufno
, (char_u
*)verb
, isfunc
, r_cmdno
, (char_u
*)q
) == FAIL
)
843 * This happens because the ExtEd can send a cammand or 2 after
844 * doing a stopDocumentListen command. It doesn't harm anything
845 * so I'm disabling it except for debugging.
847 nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd
));
848 EMSG("E629: bad return from nb_do_cmd");
856 unsigned int fireChanges
:1;
857 unsigned int initDone
:1;
858 unsigned int insertDone
:1;
859 unsigned int modified
:1;
867 typedef struct nbbuf_struct nbbuf_T
;
869 static nbbuf_T
*buf_list
= 0;
870 static int buf_list_size
= 0; /* size of buf_list */
871 static int buf_list_used
= 0; /* nr of entries in buf_list actually in use */
873 static char **globalsignmap
;
874 static int globalsignmaplen
;
875 static int globalsignmapused
;
877 static int mapsigntype
__ARGS((nbbuf_T
*, int localsigntype
));
878 static void addsigntype
__ARGS((nbbuf_T
*, int localsigntype
, char_u
*typeName
,
879 char_u
*tooltip
, char_u
*glyphfile
,
880 int usefg
, int fg
, int usebg
, int bg
));
881 static void print_read_msg
__ARGS((nbbuf_T
*buf
));
882 static void print_save_msg
__ARGS((nbbuf_T
*buf
, long nchars
));
884 static int curPCtype
= -1;
887 * Get the Netbeans buffer number for the specified buffer.
890 nb_getbufno(buf_T
*bufp
)
894 for (i
= 0; i
< buf_list_used
; i
++)
895 if (buf_list
[i
].bufp
== bufp
)
901 * Is this a NetBeans-owned buffer?
904 isNetbeansBuffer(buf_T
*bufp
)
906 return usingNetbeans
&& bufp
->b_netbeans_file
;
910 * NetBeans and Vim have different undo models. In Vim, the file isn't
911 * changed if changes are undone via the undo command. In NetBeans, once
912 * a change has been made the file is marked as modified until saved. It
913 * doesn't matter if the change was undone.
915 * So this function is for the corner case where Vim thinks a buffer is
916 * unmodified but NetBeans thinks it IS modified.
919 isNetbeansModified(buf_T
*bufp
)
921 if (usingNetbeans
&& bufp
->b_netbeans_file
)
923 int bufno
= nb_getbufno(bufp
);
926 return buf_list
[bufno
].modified
;
935 * Given a Netbeans buffer number, return the netbeans buffer.
936 * Returns NULL for 0 or a negative number. A 0 bufno means a
937 * non-buffer related command has been sent.
940 nb_get_buf(int bufno
)
942 /* find or create a buffer with the given number */
951 buf_list
= (nbbuf_T
*)alloc_clear(100 * sizeof(nbbuf_T
));
954 if (bufno
>= buf_list_used
) /* new */
956 if (bufno
>= buf_list_size
) /* grow list */
958 incr
= bufno
- buf_list_size
+ 90;
959 buf_list_size
+= incr
;
960 buf_list
= (nbbuf_T
*)vim_realloc(
961 buf_list
, buf_list_size
* sizeof(nbbuf_T
));
962 memset(buf_list
+ buf_list_size
- incr
, 0, incr
* sizeof(nbbuf_T
));
965 while (buf_list_used
<= bufno
)
967 /* Default is to fire text changes. */
968 buf_list
[buf_list_used
].fireChanges
= 1;
973 return buf_list
+ bufno
;
977 * Return the number of buffers that are modified.
980 count_changed_buffers(void)
986 for (bufp
= firstbuf
; bufp
!= NULL
; bufp
= bufp
->b_next
)
993 * End the netbeans session.
999 static char buf
[128];
1001 if (!haveConnection
)
1004 for (i
= 0; i
< buf_list_used
; i
++)
1006 if (!buf_list
[i
].bufp
)
1008 if (netbeansForcedQuit
)
1010 /* mark as unmodified so NetBeans won't put up dialog on "killed" */
1011 sprintf(buf
, "%d:unmodified=%d\n", i
, r_cmdno
);
1012 nbdebug(("EVT: %s", buf
));
1013 nb_send(buf
, "netbeans_end");
1015 sprintf(buf
, "%d:killed=%d\n", i
, r_cmdno
);
1016 nbdebug(("EVT: %s", buf
));
1017 /* nb_send(buf, "netbeans_end"); avoid "write failed" messages */
1019 sock_write(sd
, buf
, (int)STRLEN(buf
)); /* ignore errors */
1024 * Send a message to netbeans.
1027 nb_send(char *buf
, char *fun
)
1029 /* Avoid giving pages full of error messages when the other side has
1030 * exited, only mention the first error until the connection works again. */
1031 static int did_error
= FALSE
;
1036 EMSG2("E630: %s(): write while not connected", fun
);
1039 else if (sock_write(sd
, buf
, (int)STRLEN(buf
)) != (int)STRLEN(buf
))
1042 EMSG2("E631: %s(): write failed", fun
);
1050 * Some input received from netbeans requires a response. This function
1051 * handles a response with no information (except the command number).
1054 nb_reply_nil(int cmdno
)
1058 if (!haveConnection
)
1061 nbdebug(("REP %d: <none>\n", cmdno
));
1063 sprintf(reply
, "%d\n", cmdno
);
1064 nb_send(reply
, "nb_reply_nil");
1069 * Send a response with text.
1070 * "result" must have been quoted already (using nb_quote()).
1073 nb_reply_text(int cmdno
, char_u
*result
)
1077 if (!haveConnection
)
1080 nbdebug(("REP %d: %s\n", cmdno
, (char *)result
));
1082 reply
= alloc((unsigned)STRLEN(result
) + 32);
1083 sprintf((char *)reply
, "%d %s\n", cmdno
, (char *)result
);
1084 nb_send((char *)reply
, "nb_reply_text");
1091 * Send a response with a number result code.
1094 nb_reply_nr(int cmdno
, long result
)
1098 if (!haveConnection
)
1101 nbdebug(("REP %d: %ld\n", cmdno
, result
));
1103 sprintf(reply
, "%d %ld\n", cmdno
, result
);
1104 nb_send(reply
, "nb_reply_nr");
1109 * Encode newline, ret, backslash, double quote for transmission to NetBeans.
1112 nb_quote(char_u
*txt
)
1114 char_u
*buf
= alloc((unsigned)(2 * STRLEN(txt
) + 1));
1126 *q
++ = '\\'; *q
++ = *p
; break;
1128 /* *q++ = '\\'; *q++ = 't'; break; */
1130 *q
++ = '\\'; *q
++ = 'n'; break;
1132 *q
++ = '\\'; *q
++ = 'r'; break;
1145 * Remove top level double quotes; convert backslashed chars.
1146 * Returns an allocated string (NULL for failure).
1147 * If "endp" is not NULL it is set to the character after the terminating
1151 nb_unquote(char_u
*p
, char_u
**endp
)
1157 /* result is never longer than input */
1158 result
= (char *)alloc_clear((unsigned)STRLEN(p
) + 1);
1164 nbdebug(("nb_unquote called with string that doesn't start with a quote!: %s\n",
1170 for (q
= result
; !done
&& *p
!= NUL
;)
1176 * Unbackslashed dquote marks the end, if first char was dquote.
1185 case '\\': *q
++ = '\\'; break;
1186 case 'n': *q
++ = '\n'; break;
1187 case 't': *q
++ = '\t'; break;
1188 case 'r': *q
++ = '\r'; break;
1189 case '"': *q
++ = '"'; break;
1190 case NUL
: --p
; break;
1191 /* default: skip over illegal chars */
1208 #define streq(a,b) (strcmp(a,b) == 0)
1209 static int needupdate
= 0;
1210 static int inAtomic
= 0;
1213 * Do the actual processing of a single netbeans command or function.
1214 * The differance between a command and function is that a function
1215 * gets a response (its required) but a command does not.
1216 * For arguments see comment for nb_parse_cmd().
1224 char_u
*args
) /* points to space before arguments or NUL */
1228 nbbuf_T
*buf
= nb_get_buf(bufno
);
1229 static int skip
= 0;
1231 char *cp
; /* for when a char pointer is needed */
1233 nbdebug(("%s %d: (%d) %s %s\n", (func
) ? "FUN" : "CMD", cmdno
, bufno
, cmd
,
1234 STRCMP(cmd
, "insert") == 0 ? "<text>" : (char *)args
));
1238 /* =====================================================================*/
1239 if (streq((char *)cmd
, "getModified"))
1241 if (buf
== NULL
|| buf
->bufp
== NULL
)
1242 /* Return the number of buffers that are modified. */
1243 nb_reply_nr(cmdno
, (long)count_changed_buffers());
1245 /* Return whether the buffer is modified. */
1246 nb_reply_nr(cmdno
, (long)(buf
->bufp
->b_changed
1247 || isNetbeansModified(buf
->bufp
)));
1248 /* =====================================================================*/
1250 else if (streq((char *)cmd
, "saveAndExit"))
1252 /* Note: this will exit Vim if successful. */
1253 coloncmd(":confirm qall");
1255 /* We didn't exit: return the number of changed buffers. */
1256 nb_reply_nr(cmdno
, (long)count_changed_buffers());
1257 /* =====================================================================*/
1259 else if (streq((char *)cmd
, "getCursor"))
1263 /* Note: nb_getbufno() may return -1. This indicates the IDE
1264 * didn't assign a number to the current buffer in response to a
1265 * fileOpened event. */
1266 sprintf((char *)text
, "%d %ld %d %ld",
1267 nb_getbufno(curbuf
),
1268 (long)curwin
->w_cursor
.lnum
,
1269 (int)curwin
->w_cursor
.col
,
1270 pos2off(curbuf
, &curwin
->w_cursor
));
1271 nb_reply_text(cmdno
, text
);
1272 /* =====================================================================*/
1274 else if (streq((char *)cmd
, "getLength"))
1278 if (buf
== NULL
|| buf
->bufp
== NULL
)
1280 nbdebug((" null bufp in getLength"));
1281 EMSG("E632: null bufp in getLength");
1286 len
= get_buf_size(buf
->bufp
);
1288 nb_reply_nr(cmdno
, len
);
1289 /* =====================================================================*/
1291 else if (streq((char *)cmd
, "getText"))
1295 char_u
*text
= NULL
;
1300 if (buf
== NULL
|| buf
->bufp
== NULL
)
1302 nbdebug((" null bufp in getText"));
1303 EMSG("E633: null bufp in getText");
1308 len
= get_buf_size(buf
->bufp
);
1309 nlines
= buf
->bufp
->b_ml
.ml_line_count
;
1310 text
= alloc((unsigned)((len
> 0)
1311 ? ((len
+ nlines
) * 2) : 4));
1314 nbdebug((" nb_do_cmd: getText has null text field\n"));
1321 for (; lno
<= nlines
; lno
++)
1323 line
= nb_quote(ml_get_buf(buf
->bufp
, lno
, FALSE
));
1338 nb_reply_text(cmdno
, (char_u
*)"");
1341 nb_reply_text(cmdno
, text
);
1344 /* =====================================================================*/
1346 else if (streq((char *)cmd
, "remove"))
1351 int oldFire
= netbeansFireChanges
;
1352 int oldSuppress
= netbeansSuppressNoLines
;
1355 if (skip
>= SKIP_STOP
)
1357 nbdebug((" Skipping %s command\n", (char *) cmd
));
1358 nb_reply_nil(cmdno
);
1362 if (buf
== NULL
|| buf
->bufp
== NULL
)
1364 nbdebug((" null bufp in remove"));
1365 EMSG("E634: null bufp in remove");
1370 netbeansFireChanges
= FALSE
;
1371 netbeansSuppressNoLines
= TRUE
;
1373 nb_set_curbuf(buf
->bufp
);
1374 wasChanged
= buf
->bufp
->b_changed
;
1376 off
= strtol(cp
, &cp
, 10);
1377 count
= strtol(cp
, &cp
, 10);
1378 args
= (char_u
*)cp
;
1379 /* delete "count" chars, starting at "off" */
1380 pos
= off2pos(buf
->bufp
, off
);
1383 nb_reply_text(cmdno
, (char_u
*)"!bad position");
1384 netbeansFireChanges
= oldFire
;
1385 netbeansSuppressNoLines
= oldSuppress
;
1389 nbdebug((" FIRST POS: line %d, col %d\n", first
.lnum
, first
.col
));
1390 pos
= off2pos(buf
->bufp
, off
+count
-1);
1393 nb_reply_text(cmdno
, (char_u
*)"!bad count");
1394 netbeansFireChanges
= oldFire
;
1395 netbeansSuppressNoLines
= oldSuppress
;
1399 nbdebug((" LAST POS: line %d, col %d\n", last
.lnum
, last
.col
));
1400 curwin
->w_cursor
= first
;
1403 /* keep part of first line */
1404 if (first
.lnum
== last
.lnum
&& first
.col
!= last
.col
)
1406 /* deletion is within one line */
1407 char_u
*p
= ml_get(first
.lnum
);
1408 mch_memmove(p
+ first
.col
, p
+ last
.col
+ 1, STRLEN(p
+ last
.col
) + 1);
1409 nbdebug((" NEW LINE %d: %s\n", first
.lnum
, p
));
1410 ml_replace(first
.lnum
, p
, TRUE
);
1413 if (first
.lnum
< last
.lnum
)
1417 /* delete signs from the lines being deleted */
1418 for (i
= first
.lnum
; i
<= last
.lnum
; i
++)
1420 int id
= buf_findsign_id(buf
->bufp
, (linenr_T
)i
);
1423 nbdebug((" Deleting sign %d on line %d\n", id
, i
));
1424 buf_delsign(buf
->bufp
, id
);
1427 nbdebug((" No sign on line %d\n", i
));
1430 /* delete whole lines */
1431 nbdebug((" Deleting lines %d through %d\n", first
.lnum
, last
.lnum
));
1432 del_lines(last
.lnum
- first
.lnum
+ 1, FALSE
);
1434 buf
->bufp
->b_changed
= wasChanged
; /* logically unchanged */
1435 netbeansFireChanges
= oldFire
;
1436 netbeansSuppressNoLines
= oldSuppress
;
1438 u_blockfree(buf
->bufp
);
1439 u_clearall(buf
->bufp
);
1441 nb_reply_nil(cmdno
);
1442 /* =====================================================================*/
1444 else if (streq((char *)cmd
, "insert"))
1448 if (skip
>= SKIP_STOP
)
1450 nbdebug((" Skipping %s command\n", (char *) cmd
));
1451 nb_reply_nil(cmdno
);
1457 off
= strtol(cp
, &cp
, 10);
1458 args
= (char_u
*)cp
;
1460 /* get text to be inserted */
1461 args
= skipwhite(args
);
1462 args
= to_free
= (char_u
*)nb_unquote(args
, NULL
);
1464 nbdebug((" CHUNK[%d]: %d bytes at offset %d\n",
1465 buf->bufp->b_ml.ml_line_count, STRLEN(args), off));
1468 if (buf
== NULL
|| buf
->bufp
== NULL
)
1470 nbdebug((" null bufp in insert"));
1471 EMSG("E635: null bufp in insert");
1474 else if (args
!= NULL
)
1476 int ff_detected
= EOL_UNKNOWN
;
1477 int buf_was_empty
= (buf
->bufp
->b_ml
.ml_flags
& ML_EMPTY
);
1480 int oldFire
= netbeansFireChanges
;
1484 linenr_T lnum_start
;
1487 netbeansFireChanges
= 0;
1489 /* Jump to the buffer where we insert. After this "curbuf"
1491 nb_set_curbuf(buf
->bufp
);
1492 old_b_changed
= curbuf
->b_changed
;
1494 /* Convert the specified character offset into a lnum/col
1496 pos
= off2pos(curbuf
, off
);
1502 lnum_start
= pos
->lnum
;
1506 /* If the given position is not found, assume we want
1507 * the end of the file. See setLocAndSize HACK. */
1509 lnum_start
= 1; /* above empty line */
1511 lnum_start
= curbuf
->b_ml
.ml_line_count
+ 1;
1514 /* "lnum" is the line where we insert: either append to it or
1515 * insert a new line above it. */
1518 /* Loop over the "\n" separated lines of the argument. */
1520 while (*args
!= NUL
)
1522 nl
= vim_strchr(args
, '\n');
1525 /* Incomplete line, probably truncated. Next "insert"
1526 * command should append to this one. */
1534 * We need to detect EOL style, because the commands
1535 * use a character offset.
1537 if (nl
> args
&& nl
[-1] == '\r')
1539 ff_detected
= EOL_DOS
;
1543 ff_detected
= EOL_UNIX
;
1547 if (lnum
== lnum_start
1548 && ((pos
!= NULL
&& pos
->col
> 0)
1549 || (lnum
== 1 && buf_was_empty
)))
1551 char_u
*oldline
= ml_get(lnum
);
1554 /* Insert halfway a line. For simplicity we assume we
1555 * need to append to the line. */
1556 newline
= alloc_check((unsigned)(STRLEN(oldline
) + len
+ 1));
1557 if (newline
!= NULL
)
1559 STRCPY(newline
, oldline
);
1560 STRCAT(newline
, args
);
1561 ml_replace(lnum
, newline
, FALSE
);
1566 /* Append a new line. Not that we always do this,
1567 * also when the text doesn't end in a "\n". */
1568 ml_append((linenr_T
)(lnum
- 1), args
, (colnr_T
)(len
+ 1), FALSE
);
1578 /* Adjust the marks below the inserted lines. */
1579 appended_lines_mark(lnum_start
- 1, (long)added
);
1582 * When starting with an empty buffer set the fileformat.
1583 * This is just guessing...
1587 if (ff_detected
== EOL_UNKNOWN
)
1588 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1589 ff_detected
= EOL_DOS
;
1591 ff_detected
= EOL_UNIX
;
1593 set_fileformat(ff_detected
, OPT_LOCAL
);
1594 curbuf
->b_start_ffc
= *curbuf
->b_p_ff
;
1598 * XXX - GRP - Is the next line right? If I've inserted
1599 * text the buffer has been updated but not written. Will
1600 * netbeans guarantee to write it? Even if I do a :q! ?
1602 curbuf
->b_changed
= old_b_changed
; /* logically unchanged */
1603 netbeansFireChanges
= oldFire
;
1605 /* Undo info is invalid now... */
1606 u_blockfree(curbuf
);
1610 nb_reply_nil(cmdno
); /* or !error */
1614 nbdebug(("UNIMPLEMENTED FUNCTION: %s\n", cmd
));
1615 nb_reply_nil(cmdno
);
1619 else /* Not a function; no reply required. */
1621 /* =====================================================================*/
1622 if (streq((char *)cmd
, "create"))
1624 /* Create a buffer without a name. */
1627 EMSG("E636: null buf in create");
1630 vim_free(buf
->displayname
);
1631 buf
->displayname
= NULL
;
1633 netbeansReadFile
= 0; /* don't try to open disk file */
1634 do_ecmd(0, NULL
, 0, 0, ECMD_ONE
, ECMD_HIDE
+ ECMD_OLDBUF
);
1635 netbeansReadFile
= 1;
1638 buf
->insertDone
= FALSE
;
1639 gui_update_menus(0);
1640 /* =====================================================================*/
1642 else if (streq((char *)cmd
, "insertDone"))
1644 if (buf
== NULL
|| buf
->bufp
== NULL
)
1646 nbdebug((" null bufp in insertDone"));
1650 buf
->bufp
->b_start_eol
= *args
== 'T';
1651 buf
->insertDone
= TRUE
;
1653 buf
->bufp
->b_p_ro
= *args
== 'T';
1654 print_read_msg(buf
);
1656 /* =====================================================================*/
1658 else if (streq((char *)cmd
, "saveDone"))
1660 long savedChars
= atol((char *)args
);
1662 if (buf
== NULL
|| buf
->bufp
== NULL
)
1664 nbdebug((" null bufp in saveDone"));
1667 print_save_msg(buf
, savedChars
);
1668 /* =====================================================================*/
1670 else if (streq((char *)cmd
, "startDocumentListen"))
1674 EMSG("E637: null buf in startDocumentListen");
1677 buf
->fireChanges
= 1;
1678 /* =====================================================================*/
1680 else if (streq((char *)cmd
, "stopDocumentListen"))
1684 EMSG("E638: null buf in stopDocumentListen");
1687 buf
->fireChanges
= 0;
1688 if (buf
->bufp
!= NULL
&& buf
->bufp
->b_was_netbeans_file
)
1690 if (!buf
->bufp
->b_netbeans_file
)
1691 EMSGN(_("E658: NetBeans connection lost for buffer %ld"),
1695 /* NetBeans uses stopDocumentListen when it stops editing
1696 * a file. It then expects the buffer in Vim to
1698 do_bufdel(DOBUF_DEL
, (char_u
*)"", 1,
1699 buf
->bufp
->b_fnum
, buf
->bufp
->b_fnum
, TRUE
);
1700 vim_memset(buf
, 0, sizeof(nbbuf_T
));
1703 /* =====================================================================*/
1705 else if (streq((char *)cmd
, "setTitle"))
1709 EMSG("E639: null buf in setTitle");
1712 vim_free(buf
->displayname
);
1713 buf
->displayname
= nb_unquote(args
, NULL
);
1714 /* =====================================================================*/
1716 else if (streq((char *)cmd
, "initDone"))
1718 if (buf
== NULL
|| buf
->bufp
== NULL
)
1720 EMSG("E640: null buf in initDone");
1724 buf
->initDone
= TRUE
;
1725 nb_set_curbuf(buf
->bufp
);
1726 #if defined(FEAT_AUTOCMD)
1727 apply_autocmds(EVENT_BUFREADPOST
, 0, 0, FALSE
, buf
->bufp
);
1730 /* handle any postponed key commands */
1732 /* =====================================================================*/
1734 else if (streq((char *)cmd
, "setBufferNumber")
1735 || streq((char *)cmd
, "putBufferNumber"))
1742 EMSG("E641: null buf in setBufferNumber");
1745 path
= (char_u
*)nb_unquote(args
, NULL
);
1748 bufp
= buflist_findname(path
);
1752 EMSG2("E642: File %s not found in setBufferNumber", args
);
1756 buf
->nbbuf_number
= bufp
->b_fnum
;
1758 /* "setBufferNumber" has the side effect of jumping to the buffer
1759 * (don't know why!). Don't do that for "putBufferNumber". */
1761 coloncmd(":buffer %d", bufp
->b_fnum
);
1764 buf
->initDone
= TRUE
;
1766 /* handle any postponed key commands */
1770 #if 0 /* never used */
1771 buf
->internalname
= (char *)alloc_clear(8);
1772 sprintf(buf
->internalname
, "<%d>", bufno
);
1773 buf
->netbeansOwns
= 0;
1775 /* =====================================================================*/
1777 else if (streq((char *)cmd
, "setFullName"))
1781 EMSG("E643: null buf in setFullName");
1784 vim_free(buf
->displayname
);
1785 buf
->displayname
= nb_unquote(args
, NULL
);
1787 netbeansReadFile
= 0; /* don't try to open disk file */
1788 do_ecmd(0, (char_u
*)buf
->displayname
, 0, 0, ECMD_ONE
,
1789 ECMD_HIDE
+ ECMD_OLDBUF
);
1790 netbeansReadFile
= 1;
1793 gui_update_menus(0);
1794 /* =====================================================================*/
1796 else if (streq((char *)cmd
, "editFile"))
1800 EMSG("E644: null buf in editFile");
1803 /* Edit a file: like create + setFullName + read the file. */
1804 vim_free(buf
->displayname
);
1805 buf
->displayname
= nb_unquote(args
, NULL
);
1806 do_ecmd(0, (char_u
*)buf
->displayname
, NULL
, NULL
, ECMD_ONE
,
1807 ECMD_HIDE
+ ECMD_OLDBUF
);
1809 buf
->initDone
= TRUE
;
1811 #if defined(FEAT_TITLE)
1814 gui_update_menus(0);
1815 /* =====================================================================*/
1817 else if (streq((char *)cmd
, "setVisible"))
1819 if (buf
== NULL
|| buf
->bufp
== NULL
)
1821 /* EMSG("E645: null bufp in setVisible"); */
1824 if (streq((char *)args
, "T") && buf
->bufp
!= curbuf
)
1827 exarg
.cmd
= (char_u
*)"goto";
1828 exarg
.forceit
= FALSE
;
1829 dosetvisible
= TRUE
;
1830 goto_buffer(&exarg
, DOBUF_FIRST
, FORWARD
, buf
->bufp
->b_fnum
);
1832 dosetvisible
= FALSE
;
1834 /* Side effect!!!. */
1836 gui_mch_set_foreground();
1838 /* =====================================================================*/
1840 else if (streq((char *)cmd
, "raise"))
1842 /* Bring gvim to the foreground. */
1844 gui_mch_set_foreground();
1845 /* =====================================================================*/
1847 else if (streq((char *)cmd
, "setModified"))
1849 if (buf
== NULL
|| buf
->bufp
== NULL
)
1851 /* EMSG("E646: null bufp in setModified"); */
1854 if (streq((char *)args
, "T"))
1855 buf
->bufp
->b_changed
= 1;
1860 /* Assume NetBeans stored the file. Reset the timestamp to
1861 * avoid "file changed" warnings. */
1862 if (buf
->bufp
->b_ffname
!= NULL
1863 && mch_stat((char *)buf
->bufp
->b_ffname
, &st
) >= 0)
1864 buf_store_time(buf
->bufp
, &st
, buf
->bufp
->b_ffname
);
1865 buf
->bufp
->b_changed
= 0;
1867 buf
->modified
= buf
->bufp
->b_changed
;
1868 /* =====================================================================*/
1870 else if (streq((char *)cmd
, "setModtime"))
1872 if (buf
== NULL
|| buf
->bufp
== NULL
)
1873 nbdebug((" null bufp in setModtime"));
1875 buf
->bufp
->b_mtime
= atoi((char *)args
);
1876 /* =====================================================================*/
1878 else if (streq((char *)cmd
, "setReadOnly"))
1880 if (buf
== NULL
|| buf
->bufp
== NULL
)
1881 nbdebug((" null bufp in setReadOnly"));
1882 else if (streq((char *)args
, "T"))
1883 buf
->bufp
->b_p_ro
= TRUE
;
1885 buf
->bufp
->b_p_ro
= FALSE
;
1886 /* =====================================================================*/
1888 else if (streq((char *)cmd
, "setMark"))
1891 /* =====================================================================*/
1893 else if (streq((char *)cmd
, "showBalloon"))
1895 #if defined(FEAT_BEVAL)
1896 static char *text
= NULL
;
1899 * Set up the Balloon Expression Evaluation area.
1900 * Ignore 'ballooneval' here.
1901 * The text pointer must remain valid for a while.
1903 if (balloonEval
!= NULL
)
1906 text
= nb_unquote(args
, NULL
);
1908 gui_mch_post_balloon(balloonEval
, (char_u
*)text
);
1911 /* =====================================================================*/
1913 else if (streq((char *)cmd
, "setDot"))
1920 if (buf
== NULL
|| buf
->bufp
== NULL
)
1922 EMSG("E647: null bufp in setDot");
1926 nb_set_curbuf(buf
->bufp
);
1929 /* Don't want Visual mode now. */
1936 pos
= get_off_or_lnum(buf
->bufp
, &args
);
1939 curwin
->w_cursor
= *pos
;
1946 nbdebug((" BAD POSITION in setDot: %s\n", s
));
1948 /* gui_update_cursor(TRUE, FALSE); */
1949 /* update_curbuf(NOT_VALID); */
1950 update_topline(); /* scroll to show the line */
1951 update_screen(VALID
);
1954 gui_update_cursor(TRUE
, FALSE
);
1956 /* Quit a hit-return or more prompt. */
1957 if (State
== HITRETURN
|| State
== ASKMORE
)
1960 if (gtk_main_level() > 0)
1964 /* =====================================================================*/
1966 else if (streq((char *)cmd
, "close"))
1969 char *name
= "<NONE>";
1974 EMSG("E648: null buf in close");
1979 if (buf
->displayname
!= NULL
)
1980 name
= buf
->displayname
;
1982 /* if (buf->bufp == NULL) */
1983 /* EMSG("E649: null bufp in close"); */
1984 nbdebug((" CLOSE %d: %s\n", bufno
, name
));
1985 need_mouse_correct
= TRUE
;
1986 if (buf
->bufp
!= NULL
)
1987 do_buffer(DOBUF_WIPE
, DOBUF_FIRST
, FORWARD
,
1988 buf
->bufp
->b_fnum
, TRUE
);
1990 buf
->initDone
= FALSE
;
1992 /* =====================================================================*/
1994 else if (streq((char *)cmd
, "setStyle")) /* obsolete... */
1996 nbdebug((" setStyle is obsolete!"));
1997 /* =====================================================================*/
1999 else if (streq((char *)cmd
, "setExitDelay"))
2001 /* Only used in version 2.1. */
2002 /* =====================================================================*/
2004 else if (streq((char *)cmd
, "defineAnnoType"))
2019 EMSG("E650: null buf in defineAnnoType");
2024 typeNum
= strtol(cp
, &cp
, 10);
2025 args
= (char_u
*)cp
;
2026 args
= skipwhite(args
);
2027 typeName
= (char_u
*)nb_unquote(args
, &args
);
2028 args
= skipwhite(args
+ 1);
2029 tooltip
= (char_u
*)nb_unquote(args
, &args
);
2030 args
= skipwhite(args
+ 1);
2032 p
= (char_u
*)nb_unquote(args
, &args
);
2033 glyphFile
= vim_strsave_escaped(p
, escape_chars
);
2036 args
= skipwhite(args
+ 1);
2037 if (STRNCMP(args
, "none", 4) == 0)
2043 fg
= strtol(cp
, &cp
, 10);
2044 args
= (char_u
*)cp
;
2046 if (STRNCMP(args
, "none", 4) == 0)
2052 bg
= strtol(cp
, &cp
, 10);
2053 args
= (char_u
*)cp
;
2055 if (typeName
!= NULL
&& tooltip
!= NULL
&& glyphFile
!= NULL
)
2056 addsigntype(buf
, typeNum
, typeName
, tooltip
, glyphFile
,
2057 use_fg
, fg
, use_bg
, bg
);
2061 /* don't free typeName; it's used directly in addsigntype() */
2063 vim_free(glyphFile
);
2066 /* =====================================================================*/
2068 else if (streq((char *)cmd
, "addAnno"))
2079 if (buf
== NULL
|| buf
->bufp
== NULL
)
2081 EMSG("E651: null bufp in addAnno");
2088 serNum
= strtol(cp
, &cp
, 10);
2090 /* Get the typenr specific for this buffer and convert it to
2091 * the global typenumber, as used for the sign name. */
2092 localTypeNum
= strtol(cp
, &cp
, 10);
2093 args
= (char_u
*)cp
;
2094 typeNum
= mapsigntype(buf
, localTypeNum
);
2096 pos
= get_off_or_lnum(buf
->bufp
, &args
);
2102 strtol(cp
, &cp
, 10);
2103 args
= (char_u
*)cp
;
2107 nbdebug((" partial line annotation -- Not Yet Implemented!"));
2110 if (serNum
>= GUARDEDOFFSET
)
2112 nbdebug((" too many annotations! ignoring..."));
2117 coloncmd(":sign place %d line=%d name=%d buffer=%d",
2118 serNum
, pos
->lnum
, typeNum
, buf
->bufp
->b_fnum
);
2119 if (typeNum
== curPCtype
)
2120 coloncmd(":sign jump %d buffer=%d", serNum
,
2123 /* XXX only redraw what changed. */
2124 redraw_later(CLEAR
);
2126 /* =====================================================================*/
2128 else if (streq((char *)cmd
, "removeAnno"))
2133 if (buf
== NULL
|| buf
->bufp
== NULL
)
2135 nbdebug((" null bufp in removeAnno"));
2140 serNum
= strtol(cp
, &cp
, 10);
2141 args
= (char_u
*)cp
;
2142 coloncmd(":sign unplace %d buffer=%d",
2143 serNum
, buf
->bufp
->b_fnum
);
2144 redraw_buf_later(buf
->bufp
, NOT_VALID
);
2146 /* =====================================================================*/
2148 else if (streq((char *)cmd
, "moveAnnoToFront"))
2151 nbdebug((" moveAnnoToFront: Not Yet Implemented!"));
2153 /* =====================================================================*/
2155 else if (streq((char *)cmd
, "guard") || streq((char *)cmd
, "unguard"))
2161 int un
= (cmd
[0] == 'u');
2162 static int guardId
= GUARDEDOFFSET
;
2164 if (skip
>= SKIP_STOP
)
2166 nbdebug((" Skipping %s command\n", (char *) cmd
));
2172 if (buf
== NULL
|| buf
->bufp
== NULL
)
2174 nbdebug((" null bufp in %s command", cmd
));
2177 nb_set_curbuf(buf
->bufp
);
2179 off
= strtol(cp
, &cp
, 10);
2180 len
= strtol(cp
, NULL
, 10);
2181 args
= (char_u
*)cp
;
2182 pos
= off2pos(buf
->bufp
, off
);
2185 nbdebug((" no such start pos in %s, %ld\n", cmd
, off
));
2189 pos
= off2pos(buf
->bufp
, off
+ len
- 1);
2190 if (pos
!= NULL
&& pos
->col
== 0)
2193 * In Java Swing the offset is a position between 2
2194 * characters. If col == 0 then we really want the
2195 * previous line as the end.
2197 pos
= off2pos(buf
->bufp
, off
+ len
- 2);
2200 nbdebug((" no such end pos in %s, %ld\n",
2201 cmd
, off
+ len
- 1));
2206 /* set highlight for region */
2207 nbdebug((" %sGUARD %ld,%d to %ld,%d\n", (un
) ? "UN" : "",
2208 first
.lnum
, first
.col
,
2209 last
.lnum
, last
.col
));
2211 for (lnum
= first
.lnum
; lnum
<= last
.lnum
; lnum
++)
2219 if (buf_findsigntype_id(buf
->bufp
, lnum
,
2223 ":sign place %d line=%d name=%d buffer=%d",
2224 guardId
++, lnum
, GUARDED
,
2230 redraw_buf_later(buf
->bufp
, NOT_VALID
);
2233 /* =====================================================================*/
2235 else if (streq((char *)cmd
, "startAtomic"))
2238 /* =====================================================================*/
2240 else if (streq((char *)cmd
, "endAtomic"))
2248 /* =====================================================================*/
2250 else if (streq((char *)cmd
, "save"))
2253 * NOTE - This command is obsolete wrt NetBeans. Its left in
2254 * only for historical reasons.
2256 if (buf
== NULL
|| buf
->bufp
== NULL
)
2258 nbdebug((" null bufp in %s command", cmd
));
2262 /* the following is taken from ex_cmds.c (do_wqall function) */
2263 if (bufIsChanged(buf
->bufp
))
2265 /* Only write if the buffer can be written. */
2267 && !buf
->bufp
->b_p_ro
2268 && buf
->bufp
->b_ffname
!= NULL
2269 #ifdef FEAT_QUICKFIX
2270 && !bt_dontwrite(buf
->bufp
)
2274 buf_write_all(buf
->bufp
, FALSE
);
2276 /* an autocommand may have deleted the buffer */
2277 if (!buf_valid(buf
->bufp
))
2282 /* =====================================================================*/
2284 else if (streq((char *)cmd
, "netbeansBuffer"))
2286 if (buf
== NULL
|| buf
->bufp
== NULL
)
2288 nbdebug((" null bufp in %s command", cmd
));
2293 buf
->bufp
->b_netbeans_file
= TRUE
;
2294 buf
->bufp
->b_was_netbeans_file
= TRUE
;
2297 buf
->bufp
->b_netbeans_file
= FALSE
;
2298 /* =====================================================================*/
2300 else if (streq((char *)cmd
, "specialKeys"))
2303 /* =====================================================================*/
2305 else if (streq((char *)cmd
, "actionMenuItem"))
2308 /* =====================================================================*/
2310 else if (streq((char *)cmd
, "version"))
2315 * Unrecognized command is ignored.
2318 if (inAtomic
&& doupdate
)
2325 * Is this needed? I moved the netbeans_Xt_connect() later during startup
2326 * and it may no longer be necessary. If its not needed then needupdate
2327 * and doupdate can also be removed.
2329 if (buf
!= NULL
&& buf
->initDone
&& doupdate
)
2331 update_screen(NOT_VALID
);
2334 gui_update_cursor(TRUE
, FALSE
);
2336 /* Quit a hit-return or more prompt. */
2337 if (State
== HITRETURN
|| State
== ASKMORE
)
2340 if (gtk_main_level() > 0)
2351 * If "buf" is not the current buffer try changing to a window that edits this
2352 * buffer. If there is no such window then close the current buffer and set
2353 * the current buffer as "buf".
2359 if (curbuf
!= buf
&& buf_jump_open_win(buf
) == NULL
)
2360 set_curbuf(buf
, DOBUF_GOTO
);
2364 * Process a vim colon command.
2367 coloncmd(char *cmd
, ...)
2373 vsprintf(buf
, cmd
, ap
);
2376 nbdebug((" COLONCMD %s\n", buf
));
2378 /* ALT_INPUT_LOCK_ON; */
2379 do_cmdline((char_u
*)buf
, NULL
, NULL
, DOCMD_NOWAIT
| DOCMD_KEYTYPED
);
2380 /* ALT_INPUT_LOCK_OFF; */
2382 setcursor(); /* restore the cursor position */
2383 out_flush(); /* make sure output has been written */
2385 gui_update_cursor(TRUE
, FALSE
);
2391 * Parse the specialKeys argument and issue the appropriate map commands.
2394 special_keys(char_u
*args
)
2396 char *save_str
= nb_unquote(args
, NULL
);
2397 char *tok
= strtok(save_str
, " ");
2406 if ((sep
= strchr(tok
, '-')) != NULL
)
2426 strcpy(&keybuf
[i
], tok
);
2427 vim_snprintf(cmdbuf
, sizeof(cmdbuf
),
2428 "<silent><%s> :nbkey %s<CR>", keybuf
, keybuf
);
2429 do_map(0, (char_u
*)cmdbuf
, NORMAL
, FALSE
);
2430 tok
= strtok(NULL
, " ");
2440 netbeans_keystring(0, (char *)eap
->arg
);
2445 * Initialize highlights and signs for use by netbeans (mostly obsolete)
2448 nb_init_graphics(void)
2450 static int did_init
= FALSE
;
2454 coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black");
2455 coloncmd(":sign define %d linehl=NBGuarded", GUARDED
);
2462 * Convert key to netbeans name.
2465 netbeans_keyname(int key
, char *buf
)
2473 if (mod_mask
& MOD_MASK_CTRL
)
2475 if (mod_mask
& MOD_MASK_SHIFT
)
2477 if (mod_mask
& MOD_MASK_ALT
)
2483 case K_F1
: name
= "F1"; break;
2484 case K_S_F1
: name
= "F1"; shift
= 1; break;
2485 case K_F2
: name
= "F2"; break;
2486 case K_S_F2
: name
= "F2"; shift
= 1; break;
2487 case K_F3
: name
= "F3"; break;
2488 case K_S_F3
: name
= "F3"; shift
= 1; break;
2489 case K_F4
: name
= "F4"; break;
2490 case K_S_F4
: name
= "F4"; shift
= 1; break;
2491 case K_F5
: name
= "F5"; break;
2492 case K_S_F5
: name
= "F5"; shift
= 1; break;
2493 case K_F6
: name
= "F6"; break;
2494 case K_S_F6
: name
= "F6"; shift
= 1; break;
2495 case K_F7
: name
= "F7"; break;
2496 case K_S_F7
: name
= "F7"; shift
= 1; break;
2497 case K_F8
: name
= "F8"; break;
2498 case K_S_F8
: name
= "F8"; shift
= 1; break;
2499 case K_F9
: name
= "F9"; break;
2500 case K_S_F9
: name
= "F9"; shift
= 1; break;
2501 case K_F10
: name
= "F10"; break;
2502 case K_S_F10
: name
= "F10"; shift
= 1; break;
2503 case K_F11
: name
= "F11"; break;
2504 case K_S_F11
: name
= "F11"; shift
= 1; break;
2505 case K_F12
: name
= "F12"; break;
2506 case K_S_F12
: name
= "F12"; shift
= 1; break;
2508 if (key
>= ' ' && key
<= '~')
2510 /* Allow ASCII characters. */
2526 strcat(buf
, "M"); /* META */
2527 if (ctrl
|| shift
|| alt
)
2534 * Function to be called for balloon evaluation. Grabs the text under the
2535 * cursor and sends it to the debugger for evaluation. The debugger should
2536 * respond with a showBalloon command when there is a useful result.
2548 char buf
[MAXPATHL
* 2 + 25];
2551 /* Don't do anything when 'ballooneval' is off, messages scrolled the
2552 * windows up or we have no connection. */
2553 if (!p_beval
|| msg_scrolled
> 0 || !haveConnection
)
2556 if (get_beval_info(beval
, TRUE
, &wp
, &lnum
, &text
, &col
) == OK
)
2558 /* Send debugger request. Only when the text is of reasonable
2560 if (text
!= NULL
&& text
[0] != NUL
&& STRLEN(text
) < MAXPATHL
)
2565 vim_snprintf(buf
, sizeof(buf
),
2566 "0:balloonText=%d \"%s\"\n", r_cmdno
, p
);
2569 nbdebug(("EVT: %s", buf
));
2570 nb_send(buf
, "netbeans_beval_cb");
2578 * Tell netbeans that the window was opened, ready for commands.
2581 netbeans_startup_done(void)
2583 char *cmd
= "0:startupDone=0\n";
2586 #ifdef FEAT_GUI_MOTIF
2587 netbeans_Xt_connect(app_context
);
2589 # ifdef FEAT_GUI_GTK
2590 netbeans_gtk_connect();
2592 # ifdef FEAT_GUI_W32
2593 netbeans_w32_connect();
2598 if (!haveConnection
)
2602 bevalServers
|= BEVAL_NETBEANS
;
2605 nbdebug(("EVT: %s", cmd
));
2606 nb_send(cmd
, "netbeans_startup_done");
2610 * Tell netbeans that we're exiting. This should be called right
2611 * before calling exit.
2614 netbeans_send_disconnect()
2620 sprintf(buf
, "0:disconnect=%d\n", r_cmdno
);
2621 nbdebug(("EVT: %s", buf
));
2622 nb_send(buf
, "netbeans_disconnect");
2626 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_W32) || defined(PROTO)
2628 * Tell netbeans that the window was moved or resized.
2631 netbeans_frame_moved(int new_x
, int new_y
)
2635 if (!haveConnection
)
2638 sprintf(buf
, "0:geometry=%d %d %d %d %d\n",
2639 r_cmdno
, (int)Columns
, (int)Rows
, new_x
, new_y
);
2640 /*nbdebug(("EVT: %s", buf)); happens too many times during a move */
2641 nb_send(buf
, "netbeans_frame_moved");
2646 * Tell netbeans the user opened or activated a file.
2649 netbeans_file_activated(buf_T
*bufp
)
2651 int bufno
= nb_getbufno(bufp
);
2652 nbbuf_T
*bp
= nb_get_buf(bufno
);
2653 char buffer
[2*MAXPATHL
];
2656 if (!haveConnection
|| dosetvisible
)
2659 q
= nb_quote(bufp
->b_ffname
);
2660 if (q
== NULL
|| bp
== NULL
)
2663 vim_snprintf(buffer
, sizeof(buffer
), "%d:fileOpened=%d \"%s\" %s %s\n",
2667 "T", /* open in NetBeans */
2668 "F"); /* modified */
2671 nbdebug(("EVT: %s", buffer
));
2673 nb_send(buffer
, "netbeans_file_opened");
2677 * Tell netbeans the user opened a file.
2680 netbeans_file_opened(buf_T
*bufp
)
2682 int bufno
= nb_getbufno(bufp
);
2683 char buffer
[2*MAXPATHL
];
2685 nbbuf_T
*bp
= nb_get_buf(nb_getbufno(bufp
));
2688 if (!haveConnection
)
2691 q
= nb_quote(bufp
->b_ffname
);
2699 vim_snprintf(buffer
, sizeof(buffer
), "%d:fileOpened=%d \"%s\" %s %s\n",
2703 "T", /* open in NetBeans */
2704 "F"); /* modified */
2707 nbdebug(("EVT: %s", buffer
));
2709 nb_send(buffer
, "netbeans_file_opened");
2710 if (p_acd
&& vim_chdirfile(bufp
->b_ffname
) == OK
)
2711 shorten_fnames(TRUE
);
2715 * Tell netbeans a file was closed.
2718 netbeans_file_closed(buf_T
*bufp
)
2720 int bufno
= nb_getbufno(bufp
);
2721 nbbuf_T
*nbbuf
= nb_get_buf(bufno
);
2722 char buffer
[2*MAXPATHL
];
2724 if (!haveConnection
|| bufno
< 0)
2727 if (!netbeansCloseFile
)
2729 nbdebug(("Ignoring file_closed for %s. File was closed from IDE\n",
2734 nbdebug(("netbeans_file_closed:\n"));
2735 nbdebug((" Closing bufno: %d", bufno
));
2736 if (curbuf
!= NULL
&& curbuf
!= bufp
)
2738 nbdebug((" Curbuf bufno: %d\n", nb_getbufno(curbuf
)));
2740 else if (curbuf
== bufp
)
2742 nbdebug((" curbuf == bufp\n"));
2748 sprintf(buffer
, "%d:killed=%d\n", bufno
, r_cmdno
);
2750 nbdebug(("EVT: %s", buffer
));
2752 nb_send(buffer
, "netbeans_file_closed");
2759 * Get a pointer to the Netbeans buffer for Vim buffer "bufp".
2760 * Return NULL if there is no such buffer or changes are not to be reported.
2761 * Otherwise store the buffer number in "*bufnop".
2764 nb_bufp2nbbuf_fire(buf_T
*bufp
, int *bufnop
)
2769 if (!haveConnection
|| !netbeansFireChanges
)
2770 return NULL
; /* changes are not reported at all */
2772 bufno
= nb_getbufno(bufp
);
2774 return NULL
; /* file is not known to NetBeans */
2776 nbbuf
= nb_get_buf(bufno
);
2777 if (nbbuf
!= NULL
&& !nbbuf
->fireChanges
)
2778 return NULL
; /* changes in this buffer are not reported */
2785 * Tell netbeans the user inserted some text.
2803 nbbuf
= nb_bufp2nbbuf_fire(bufp
, &bufno
);
2807 /* Don't mark as modified for initial read */
2808 if (nbbuf
->insertDone
)
2809 nbbuf
->modified
= 1;
2813 off
= pos2off(bufp
, &pos
);
2815 /* send the "insert" EVT */
2816 newtxt
= alloc(newlen
+ 1);
2817 vim_strncpy(newtxt
, txt
, newlen
);
2818 p
= nb_quote(newtxt
);
2821 buf
= alloc(128 + 2*newlen
);
2822 sprintf((char *)buf
, "%d:insert=%d %ld \"%s\"\n",
2823 bufno
, r_cmdno
, off
, p
);
2824 nbdebug(("EVT: %s", buf
));
2825 nb_send((char *)buf
, "netbeans_inserted");
2833 * Tell netbeans some bytes have been removed.
2848 nbbuf
= nb_bufp2nbbuf_fire(bufp
, &bufno
);
2854 nbdebug(("Negative len %ld in netbeans_removed()!", len
));
2858 nbbuf
->modified
= 1;
2863 off
= pos2off(bufp
, &pos
);
2865 sprintf((char *)buf
, "%d:remove=%d %ld %ld\n", bufno
, r_cmdno
, off
, len
);
2866 nbdebug(("EVT: %s", buf
));
2867 nb_send((char *)buf
, "netbeans_removed");
2871 * Send netbeans an unmodufied command.
2875 netbeans_unmodified(buf_T
*bufp
)
2882 /* This has been disabled, because NetBeans considers a buffer modified
2883 * even when all changes have been undone. */
2884 nbbuf
= nb_bufp2nbbuf_fire(bufp
, &bufno
);
2888 nbbuf
->modified
= 0;
2890 sprintf((char *)buf
, "%d:unmodified=%d\n", bufno
, r_cmdno
);
2891 nbdebug(("EVT: %s", buf
));
2892 nb_send((char *)buf
, "netbeans_unmodified");
2897 * Send a button release event back to netbeans. Its up to netbeans
2898 * to decide what to do (if anything) with this event.
2901 netbeans_button_release(int button
)
2906 bufno
= nb_getbufno(curbuf
);
2908 if (bufno
>= 0 && curwin
!= NULL
&& curwin
->w_buffer
== curbuf
)
2910 int col
= mouse_col
- W_WINCOL(curwin
) - (curwin
->w_p_nu
? 9 : 1);
2911 long off
= pos2off(curbuf
, &curwin
->w_cursor
);
2913 /* sync the cursor position */
2914 sprintf(buf
, "%d:newDotAndMark=%d %ld %ld\n", bufno
, r_cmdno
, off
, off
);
2915 nbdebug(("EVT: %s", buf
));
2916 nb_send(buf
, "netbeans_button_release[newDotAndMark]");
2918 sprintf(buf
, "%d:buttonRelease=%d %d %ld %d\n", bufno
, r_cmdno
,
2919 button
, (long)curwin
->w_cursor
.lnum
, col
);
2920 nbdebug(("EVT: %s", buf
));
2921 nb_send(buf
, "netbeans_button_release");
2927 * Send a keypress event back to netbeans. This usualy simulates some
2928 * kind of function key press. This function operates on a key code.
2931 netbeans_keycommand(int key
)
2935 netbeans_keyname(key
, keyName
);
2936 netbeans_keystring(key
, keyName
);
2941 * Send a keypress event back to netbeans. This usualy simulates some
2942 * kind of function key press. This function operates on a key string.
2945 netbeans_keystring(int key
, char *keyName
)
2947 char buf
[2*MAXPATHL
];
2948 int bufno
= nb_getbufno(curbuf
);
2952 if (!haveConnection
)
2958 nbdebug(("got keycommand for non-NetBeans buffer, opening...\n"));
2959 q
= curbuf
->b_ffname
== NULL
? (char_u
*)""
2960 : nb_quote(curbuf
->b_ffname
);
2963 vim_snprintf(buf
, sizeof(buf
), "0:fileOpened=%d \"%s\" %s %s\n", 0,
2965 "T", /* open in NetBeans */
2966 "F"); /* modified */
2967 if (curbuf
->b_ffname
!= NULL
)
2969 nbdebug(("EVT: %s", buf
));
2970 nb_send(buf
, "netbeans_keycommand");
2973 postpone_keycommand(key
);
2977 /* sync the cursor position */
2978 off
= pos2off(curbuf
, &curwin
->w_cursor
);
2979 sprintf(buf
, "%d:newDotAndMark=%d %ld %ld\n", bufno
, r_cmdno
, off
, off
);
2980 nbdebug(("EVT: %s", buf
));
2981 nb_send(buf
, "netbeans_keycommand");
2983 /* To work on Win32 you must apply patch to ExtEditor module
2984 * from ExtEdCaret.java.diff - make EVT_newDotAndMark handler
2988 /* now send keyCommand event */
2989 vim_snprintf(buf
, sizeof(buf
), "%d:keyCommand=%d \"%s\"\n",
2990 bufno
, r_cmdno
, keyName
);
2991 nbdebug(("EVT: %s", buf
));
2992 nb_send(buf
, "netbeans_keycommand");
2994 /* New: do both at once and include the lnum/col. */
2995 vim_snprintf(buf
, sizeof(buf
), "%d:keyAtPos=%d \"%s\" %ld %ld/%ld\n",
2996 bufno
, r_cmdno
, keyName
,
2997 off
, (long)curwin
->w_cursor
.lnum
, (long)curwin
->w_cursor
.col
);
2998 nbdebug(("EVT: %s", buf
));
2999 nb_send(buf
, "netbeans_keycommand");
3004 * Send a save event to netbeans.
3007 netbeans_save_buffer(buf_T
*bufp
)
3013 nbbuf
= nb_bufp2nbbuf_fire(bufp
, &bufno
);
3017 nbbuf
->modified
= 0;
3019 sprintf((char *)buf
, "%d:save=%d\n", bufno
, r_cmdno
);
3020 nbdebug(("EVT: %s", buf
));
3021 nb_send((char *)buf
, "netbeans_save_buffer");
3026 * Send remove command to netbeans (this command has been turned off).
3029 netbeans_deleted_all_lines(buf_T
*bufp
)
3035 nbbuf
= nb_bufp2nbbuf_fire(bufp
, &bufno
);
3039 /* Don't mark as modified for initial read */
3040 if (nbbuf
->insertDone
)
3041 nbbuf
->modified
= 1;
3043 sprintf((char *)buf
, "%d:remove=%d 0 -1\n", bufno
, r_cmdno
);
3044 nbdebug(("EVT(suppressed): %s", buf
));
3045 /* nb_send(buf, "netbeans_deleted_all_lines"); */
3050 * See if the lines are guarded. The top and bot parameters are from
3051 * u_savecommon(), these are the line above the change and the line below the
3055 netbeans_is_guarded(linenr_T top
, linenr_T bot
)
3060 for (p
= curbuf
->b_signlist
; p
!= NULL
; p
= p
->next
)
3061 if (p
->id
>= GUARDEDOFFSET
)
3062 for (lnum
= top
+ 1; lnum
< bot
; lnum
++)
3063 if (lnum
== p
->lnum
)
3069 #if defined(FEAT_GUI_MOTIF) || defined(PROTO)
3071 * We have multiple signs to draw at the same location. Draw the
3072 * multi-sign indicator instead. This is the Motif version.
3075 netbeans_draw_multisign_indicator(int row
)
3082 y
= row
* gui
.char_height
+ 2;
3084 for (i
= 0; i
< gui
.char_height
- 3; i
++)
3085 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+2, y
++);
3087 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+0, y
);
3088 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+2, y
);
3089 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+4, y
++);
3090 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+1, y
);
3091 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+2, y
);
3092 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+3, y
++);
3093 XDrawPoint(gui
.dpy
, gui
.wid
, gui
.text_gc
, x
+2, y
);
3095 #endif /* FEAT_GUI_MOTIF */
3099 * We have multiple signs to draw at the same location. Draw the
3100 * multi-sign indicator instead. This is the GTK/Gnome version.
3103 netbeans_draw_multisign_indicator(int row
)
3108 GdkDrawable
*drawable
= gui
.drawarea
->window
;
3111 y
= row
* gui
.char_height
+ 2;
3113 for (i
= 0; i
< gui
.char_height
- 3; i
++)
3114 gdk_draw_point(drawable
, gui
.text_gc
, x
+2, y
++);
3116 gdk_draw_point(drawable
, gui
.text_gc
, x
+0, y
);
3117 gdk_draw_point(drawable
, gui
.text_gc
, x
+2, y
);
3118 gdk_draw_point(drawable
, gui
.text_gc
, x
+4, y
++);
3119 gdk_draw_point(drawable
, gui
.text_gc
, x
+1, y
);
3120 gdk_draw_point(drawable
, gui
.text_gc
, x
+2, y
);
3121 gdk_draw_point(drawable
, gui
.text_gc
, x
+3, y
++);
3122 gdk_draw_point(drawable
, gui
.text_gc
, x
+2, y
);
3124 #endif /* FEAT_GUI_GTK */
3127 * If the mouse is clicked in the gutter of a line with multiple
3128 * annotations, cycle through the set of signs.
3131 netbeans_gutter_click(linenr_T lnum
)
3135 for (p
= curbuf
->b_signlist
; p
!= NULL
; p
= p
->next
)
3137 if (p
->lnum
== lnum
&& p
->next
&& p
->next
->lnum
== lnum
)
3141 /* remove "p" from list, reinsert it at the tail of the sublist */
3143 p
->prev
->next
= p
->next
;
3145 curbuf
->b_signlist
= p
->next
;
3146 p
->next
->prev
= p
->prev
;
3147 /* now find end of sublist and insert p */
3148 for (tail
= p
->next
;
3149 tail
->next
&& tail
->next
->lnum
== lnum
3150 && tail
->next
->id
< GUARDEDOFFSET
;
3153 /* tail now points to last entry with same lnum (except
3154 * that "guarded" annotations are always last) */
3155 p
->next
= tail
->next
;
3157 tail
->next
->prev
= p
;
3160 update_debug_sign(curbuf
, lnum
);
3168 * Add a sign of the reqested type at the requested location.
3170 * Reverse engineering:
3171 * Apparently an annotation is defined the first time it is used in a buffer.
3172 * When the same annotation is used in two buffers, the second time we do not
3173 * need to define a new sign name but reuse the existing one. But since the
3174 * ID number used in the second buffer starts counting at one again, a mapping
3175 * is made from the ID specifically for the buffer to the global sign name
3176 * (which is a number).
3178 * globalsignmap[] stores the signs that have been defined globally.
3179 * buf->signmapused[] maps buffer-local annotation IDs to an index in
3199 for (i
= 0; i
< globalsignmapused
; i
++)
3200 if (STRCMP(typeName
, globalsignmap
[i
]) == 0)
3203 if (i
== globalsignmapused
) /* not found; add it to global map */
3205 nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%d,%d)\n",
3206 typeNum
, typeName
, tooltip
, glyphFile
, fg
, bg
));
3207 if (use_fg
|| use_bg
)
3209 sprintf(fgbuf
, "guifg=#%06x", fg
& 0xFFFFFF);
3210 sprintf(bgbuf
, "guibg=#%06x", bg
& 0xFFFFFF);
3212 coloncmd(":highlight NB_%s %s %s", typeName
, (use_fg
) ? fgbuf
: "",
3213 (use_bg
) ? bgbuf
: "");
3214 if (*glyphFile
== NUL
)
3215 /* no glyph, line highlighting only */
3216 coloncmd(":sign define %d linehl=NB_%s", i
+ 1, typeName
);
3217 else if (vim_strsize(glyphFile
) <= 2)
3218 /* one- or two-character glyph name, use as text glyph with
3220 coloncmd(":sign define %d text=%s texthl=NB_%s", i
+ 1,
3221 glyphFile
, typeName
);
3223 /* glyph, line highlighting */
3224 coloncmd(":sign define %d icon=%s linehl=NB_%s", i
+ 1,
3225 glyphFile
, typeName
);
3228 /* glyph, no line highlighting */
3229 coloncmd(":sign define %d icon=%s", i
+ 1, glyphFile
);
3231 if (STRCMP(typeName
,"CurrentPC") == 0)
3232 curPCtype
= typeNum
;
3234 if (globalsignmapused
== globalsignmaplen
)
3236 if (globalsignmaplen
== 0) /* first allocation */
3238 globalsignmaplen
= 20;
3239 globalsignmap
= (char **)alloc_clear(globalsignmaplen
*sizeof(char *));
3244 int oldlen
= globalsignmaplen
;
3246 globalsignmaplen
*= 2;
3247 incr
= globalsignmaplen
- oldlen
;
3248 globalsignmap
= (char **)vim_realloc(globalsignmap
,
3249 globalsignmaplen
* sizeof(char *));
3250 memset(globalsignmap
+ oldlen
, 0, incr
* sizeof(char *));
3254 globalsignmap
[i
] = (char *)typeName
;
3255 globalsignmapused
= i
+ 1;
3258 /* check local map; should *not* be found! */
3259 for (j
= 0; j
< buf
->signmapused
; j
++)
3260 if (buf
->signmap
[j
] == i
+ 1)
3263 /* add to local map */
3264 if (buf
->signmapused
== buf
->signmaplen
)
3266 if (buf
->signmaplen
== 0) /* first allocation */
3268 buf
->signmaplen
= 5;
3269 buf
->signmap
= (int *)alloc_clear(buf
->signmaplen
* sizeof(int *));
3274 int oldlen
= buf
->signmaplen
;
3275 buf
->signmaplen
*= 2;
3276 incr
= buf
->signmaplen
- oldlen
;
3277 buf
->signmap
= (int *)vim_realloc(buf
->signmap
,
3278 buf
->signmaplen
*sizeof(int *));
3279 memset(buf
->signmap
+ oldlen
, 0, incr
* sizeof(int *));
3283 buf
->signmap
[buf
->signmapused
++] = i
+ 1;
3289 * See if we have the requested sign type in the buffer.
3292 mapsigntype(nbbuf_T
*buf
, int localsigntype
)
3294 if (--localsigntype
>= 0 && localsigntype
< buf
->signmapused
)
3295 return buf
->signmap
[localsigntype
];
3302 * Compute length of buffer, don't print anything.
3305 get_buf_size(buf_T
*bufp
)
3308 long char_count
= 0;
3310 long last_check
= 100000L;
3312 if (bufp
->b_ml
.ml_flags
& ML_EMPTY
)
3316 if (get_fileformat(bufp
) == EOL_DOS
)
3320 for (lnum
= 1; lnum
<= bufp
->b_ml
.ml_line_count
; ++lnum
)
3322 char_count
+= (long)STRLEN(ml_get(lnum
)) + eol_size
;
3323 /* Check for a CTRL-C every 100000 characters */
3324 if (char_count
> last_check
)
3329 last_check
= char_count
+ 100000L;
3332 /* Correction for when last line doesn't have an EOL. */
3333 if (!bufp
->b_p_eol
&& bufp
->b_p_bin
)
3334 char_count
-= eol_size
;
3341 * Convert character offset to lnum,col
3344 off2pos(buf_T
*buf
, long offset
)
3351 #ifdef FEAT_VIRTUALEDIT
3355 if (!(buf
->b_ml
.ml_flags
& ML_EMPTY
))
3357 if ((lnum
= ml_find_line_or_offset(buf
, (linenr_T
)0, &offset
)) < 0)
3367 * Convert an argument in the form "1234" to an offset and compute the
3368 * lnum/col from it. Convert an argument in the form "123/12" directly to a
3370 * "argp" is advanced to after the argument.
3371 * Return a pointer to the position, NULL if something is wrong.
3374 get_off_or_lnum(buf_T
*buf
, char_u
**argp
)
3379 off
= strtol((char *)*argp
, (char **)argp
, 10);
3382 mypos
.lnum
= (linenr_T
)off
;
3384 mypos
.col
= strtol((char *)*argp
, (char **)argp
, 10);
3385 #ifdef FEAT_VIRTUALEDIT
3390 return off2pos(buf
, off
);
3395 * Convert (lnum,col) to byte offset in the file.
3398 pos2off(buf_T
*buf
, pos_T
*pos
)
3402 if (!(buf
->b_ml
.ml_flags
& ML_EMPTY
))
3404 if ((offset
= ml_find_line_or_offset(buf
, pos
->lnum
, 0)) < 0)
3414 * This message is printed after NetBeans opens a new file. Its
3415 * similar to the message readfile() uses, but since NetBeans
3416 * doesn't normally call readfile, we do our own.
3422 int lnum
= buf
->bufp
->b_ml
.ml_line_count
;
3423 long nchars
= (long)buf
->bufp
->b_orig_size
;
3426 msg_add_fname(buf
->bufp
, buf
->bufp
->b_ffname
);
3429 if (buf
->bufp
->b_p_ro
)
3431 STRCAT(IObuff
, shortmess(SHM_RO
) ? _("[RO]") : _("[readonly]"));
3434 if (!buf
->bufp
->b_start_eol
)
3436 STRCAT(IObuff
, shortmess(SHM_LAST
) ? _("[noeol]") : _("[Incomplete last line]"));
3439 msg_add_lines(c
, (long)lnum
, nchars
);
3441 /* Now display it */
3444 msg_scrolled_ign
= TRUE
;
3445 msg_trunc_attr(IObuff
, FALSE
, 0);
3446 msg_scrolled_ign
= FALSE
;
3451 * Print a message after NetBeans writes the file. This message should be identical
3452 * to the standard message a non-netbeans user would see when writing a file.
3455 print_save_msg(buf
, nchars
)
3464 msg_add_fname(buf
->bufp
, buf
->bufp
->b_ffname
); /* fname in IObuff with quotes */
3467 msg_add_lines(c
, buf
->bufp
->b_ml
.ml_line_count
,
3468 (long)buf
->bufp
->b_orig_size
);
3472 msg_scrolled_ign
= TRUE
;
3473 p
= msg_trunc_attr(IObuff
, FALSE
, 0);
3474 if ((msg_scrolled
&& !need_wait_return
) || !buf
->initDone
)
3476 /* Need to repeat the message after redrawing when:
3477 * - When reading from stdin (the screen will be cleared next).
3478 * - When restart_edit is set (otherwise there will be a delay
3479 * before redrawing).
3480 * - When the screen was scrolled but there is no wait-return
3484 msg_scrolled_ign
= FALSE
;
3485 /* add_to_input_buf((char_u *)"\f", 1); */
3489 char_u ebuf
[BUFSIZ
];
3491 STRCPY(ebuf
, (char_u
*)_("E505: "));
3492 STRCAT(ebuf
, IObuff
);
3493 STRCAT(ebuf
, (char_u
*)_("is read-only (add ! to override)"));
3494 STRCPY(IObuff
, ebuf
);
3499 #endif /* defined(FEAT_NETBEANS_INTG) */