1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * Visual Workshop integration by Gordon Prieur
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
12 # include "auto/config.h"
17 #include <sys/types.h>
19 #include <netinet/in.h>
21 #include <sys/socket.h>
30 #include <X11/Intrinsic.h>
34 #include "integration.h" /* <EditPlugin/integration.h> */
38 #include "gui_beval.h"
41 void workshop_hotkeys(Boolean
);
43 static Boolean
isShowing(int);
44 static win_T
*get_window(buf_T
*);
46 static int get_buffer_number(buf_T
*);
48 static void updatePriority(Boolean
);
49 static char *addUniqueMnemonic(char *, char *);
50 static char *fixup(char *);
51 static char *get_selection(buf_T
*);
52 static char *append_selection(int, char *, int *, int *);
53 static void load_buffer_by_name(char *, int);
55 static void load_buffer_by_number(int, int);
57 static void load_window(char *, int lnum
);
58 static void warp_to_pc(int);
60 void workshop_beval_cb(BalloonEval
*, int);
62 static char *fixAccelText(char *);
63 static void addMenu(char *, char *, char *);
64 static char *lookupVerb(char *, int);
65 static int computeIndex(int, char_u
*, int);
66 static void coloncmd(char *, Boolean
);
68 extern Widget vimShell
;
69 extern Widget textArea
;
70 extern XtAppContext app_context
;
72 static int tbpri
; /* ToolBar priority */
73 int usingSunWorkShop
= 0; /* set if -ws flag is used */
74 char curMenuName
[BUFSIZ
];
75 char curMenuPriority
[BUFSIZ
];
77 static Boolean workshopInitDone
= False
;
78 static Boolean workshopHotKeysEnabled
= False
;
81 * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it
82 * here because its C++.
86 GPLineEval_EVALUATE
, /* evaluate expression */
87 GPLineEval_INDIRECT
, /* evaluate *<expression> */
88 GPLineEval_TYPE
/* type of expression */
92 * Store each verb in the MenuMap. This lets us map from a verb to a menu.
93 * There may be multiple matches for a single verb in this table.
95 #define MENU_INC 50 /* menuMap incremental size increases */
98 char *name
; /* name of the menu */
99 char *accel
; /* optional accelerator key */
100 char *verb
; /* menu verb */
102 static MenuMap
*menuMap
; /* list of verb/menu mappings */
103 static int menuMapSize
; /* current size of menuMap */
104 static int menuMapMax
; /* allocated size of menuMap */
105 static char *initialFileCmd
; /* save command but defer doing it */
112 int is_dirty
= FALSE
;
117 * Turn on MenuBar, ToolBar, and Footer.
120 if (vim_strchr(p_go
, GO_MENUS
) == NULL
)
125 if (vim_strchr(p_go
, GO_TOOLBAR
) == NULL
)
130 if (vim_strchr(p_go
, GO_FOOTER
) == NULL
)
136 set_option_value((char_u
*)"go", 0L, buf
, 0);
139 * Set size from workshop_get_width_height().
142 if (workshop_get_width_height(&width
, &height
))
144 XtVaSetValues(vimShell
,
151 * Now read in the initial messages from eserve.
153 while ((mask
= XtAppPending(app_context
))
154 && (mask
& XtIMAlternateInput
) && !workshopInitDone
)
155 XtAppProcessEvent(app_context
, (XtInputMask
)XtIMAlternateInput
);
161 do_cmdline_cmd((char_u
*)initialFileCmd
);
163 free(initialFileCmd
);
164 initialFileCmd
= NULL
;
168 ex_wsverb(exarg_T
*eap
)
171 workshop_perform_verb((char *) eap
->arg
, NULL
);
176 * This string is recognized by eserve and should be all lower case.
177 * This is how the editor detects that it is talking to gvim instead
178 * of NEdit, for example, when the connection is initiated from the editor.
181 workshop_get_editor_name()
187 * Version number of the editor.
188 * This number is communicated along with the protocol
189 * version to the application.
192 workshop_get_editor_version()
198 * Answer functions: called by eserve
206 * Load a given file into the WorkShop buffer.
211 char *filename
, /* the file to load */
212 int line
, /* an optional line number (or 0) */
213 char *frameid
) /* used for multi-frame support */
216 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
217 wstrace("workshop_load_file(%s, %d)\n", filename
, line
);
221 bevalServers
|= BEVAL_WORKSHOP
;
224 load_window(filename
, line
);
228 * Reload the WorkShop buffer
231 workshop_reload_file(
236 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
237 wstrace("workshop_reload_file(%s, %d)\n", filename
, line
);
239 load_window(filename
, line
);
247 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
248 wstrace("workshop_show_file(%s)\n", filename
);
251 load_window(filename
, 0);
260 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
261 wstrace("workshop_goto_line(%s, %d)\n", filename
, lineno
);
264 load_window(filename
, lineno
);
273 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
274 wstrace("workshop_front_file()\n");
277 * Assumption: This function will always be called after a call to
278 * workshop_show_file(), so the file is always showing.
280 if (vimShell
!= NULL
)
281 XRaiseWindow(gui
.dpy
, XtWindow(vimShell
));
288 char cbuf
[BUFSIZ
]; /* build vim command here */
291 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
292 wstrace("workshop_save_file(%s)\n", filename
);
295 /* Save the given file */
296 vim_snprintf(cbuf
, sizeof(cbuf
), "w %s", filename
);
297 coloncmd(cbuf
, TRUE
);
301 workshop_save_files()
303 /* Save the given file */
305 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
306 wstrace("workshop_save_files()\n");
309 add_to_input_buf((char_u
*) ":wall\n", 6);
316 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
317 wstrace("workshop_quit()\n");
320 add_to_input_buf((char_u
*) ":qall\n", 6);
327 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
328 wstrace("workshop_minimize()\n");
330 workshop_minimize_shell(vimShell
);
336 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
337 wstrace("workshop_maximize()\n");
340 workshop_maximize_shell(vimShell
);
344 workshop_add_mark_type(
349 char gbuf
[BUFSIZ
]; /* buffer for sign name */
350 char cibuf
[BUFSIZ
]; /* color information */
351 char cbuf
[BUFSIZ
]; /* command buffer */
355 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
359 cp
= strrchr(sign
, '/');
363 cp
++; /* skip '/' character */
364 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx
,
365 colorspec
&& *colorspec
? colorspec
: "<None>", cp
);
370 * Isolate the basename of sign in gbuf. We will use this for the
371 * GroupName in the highlight command sent to vim.
373 STRCPY(gbuf
, gettail((char_u
*)sign
));
374 bp
= strrchr(gbuf
, '.');
378 if (gbuf
[0] != '-' && gbuf
[1] != NUL
)
380 if (colorspec
!= NULL
&& *colorspec
)
382 vim_snprintf(cbuf
, sizeof(cbuf
),
383 "highlight WS%s guibg=%s", gbuf
, colorspec
);
384 coloncmd(cbuf
, FALSE
);
385 vim_snprintf(cibuf
, sizeof(cibuf
), "linehl=WS%s", gbuf
);
390 vim_snprintf(cbuf
, sizeof(cbuf
),
391 "sign define %d %s icon=%s", idx
, cibuf
, sign
);
392 coloncmd(cbuf
, TRUE
);
398 char *filename
, /* filename which gets the mark */
399 int lineno
, /* line number which gets the mark */
400 int markId
, /* unique mark identifier */
401 int idx
) /* which mark to use */
403 char cbuf
[BUFSIZ
]; /* command buffer */
405 /* Set mark in a given file */
407 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
408 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n",
409 filename
, lineno
, markId
, idx
);
412 vim_snprintf(cbuf
, sizeof(cbuf
), "sign place %d line=%d name=%d file=%s",
413 markId
, lineno
, idx
, filename
);
414 coloncmd(cbuf
, TRUE
);
418 workshop_change_mark_type(
419 char *filename
, /* filename which gets the mark */
420 int markId
, /* unique mark identifier */
421 int idx
) /* which mark to use */
423 char cbuf
[BUFSIZ
]; /* command buffer */
425 /* Change mark type */
427 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
428 wstrace("workshop_change_mark_type(%s, %d, %d)\n",
429 filename
, markId
, idx
);
432 vim_snprintf(cbuf
, sizeof(cbuf
),
433 "sign place %d name=%d file=%s", markId
, idx
, filename
);
434 coloncmd(cbuf
, TRUE
);
438 * Goto the given mark in a file (e.g. show it).
439 * If message is not null, display it in the footer.
447 char cbuf
[BUFSIZ
]; /* command buffer */
451 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
452 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
453 filename
, markId
, message
&& *message
&&
454 !(*message
== ' ' && message
[1] == NULL
) ?
458 vim_snprintf(cbuf
, sizeof(cbuf
), "sign jump %d file=%s", markId
, filename
);
459 coloncmd(cbuf
, TRUE
);
460 if (message
!= NULL
&& *message
!= NUL
)
461 gui_mch_set_footer((char_u
*)message
);
465 workshop_delete_mark(
469 char cbuf
[BUFSIZ
]; /* command buffer */
473 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
474 wstrace("workshop_delete_mark(%s, %d (id))\n",
478 vim_snprintf(cbuf
, sizeof(cbuf
),
479 "sign unplace %d file=%s", markId
, filename
);
480 coloncmd(cbuf
, TRUE
);
485 workshop_delete_all_marks(
490 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
491 wstrace("workshop_delete_all_marks(%#x, %s)\n",
492 window
, doRefresh
? "True" : "False");
495 coloncmd("sign unplace *", TRUE
);
500 workshop_get_mark_lineno(
504 buf_T
*buf
; /* buffer containing filename */
505 int lineno
; /* line number of filename in buf */
507 /* Get mark line number */
509 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
510 wstrace("workshop_get_mark_lineno(%s, %d)\n",
515 buf
= buflist_findname((char_u
*)filename
);
517 lineno
= buf_findsign(buf
, markId
);
525 workshop_adjust_marks(Widget
*window
, int pos
,
526 int inserted
, int deleted
)
529 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
530 wstrace("XXXworkshop_adjust_marks(%s, %d, %d, %d)\n",
531 window
? XtName(window
) : "<None>", pos
, inserted
, deleted
);
537 * Are there any moved marks? If so, call workshop_move_mark on
538 * each of them now. This is how eserve can find out if for example
539 * breakpoints have moved when a program has been recompiled and
544 workshop_moved_marks(char *filename
)
547 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
548 wstrace("XXXworkshop_moved_marks(%s)\n", filename
);
553 workshop_get_font_height()
555 XmFontList fontList
; /* fontList made from gui.norm_font */
561 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
562 wstrace("workshop_get_font_height()\n");
565 /* Pick the proper signs for this font size */
566 fontList
= gui_motif_create_fontlist((XFontStruct
*)gui
.norm_font
);
568 if (fontList
!= NULL
)
570 str
= XmStringCreateLocalized("A");
571 XmStringExtent(fontList
, str
, &w
, &h
);
573 XmFontListFree(fontList
);
581 workshop_footer_message(
583 int severity
) /* severity is currently unused */
586 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
587 wstrace("workshop_footer_message(%s, %d)\n", message
, severity
);
590 gui_mch_set_footer((char_u
*) message
);
594 * workshop_menu_begin() is passed the menu name. We determine its mnemonic
595 * here and store its name and priority.
601 vimmenu_T
*menu
; /* pointer to last menu */
602 int menuPriority
= 0; /* priority of new menu */
603 char mnembuf
[64]; /* store menubar mnemonics here */
604 char *name
; /* label with a mnemonic */
605 char *p
; /* used to find mnemonics */
606 int idx
; /* index into mnembuf */
609 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
610 wstrace("workshop_menu_begin()\n");
614 * Look through all existing (non-PopUp and non-Toolbar) menus
615 * and gather their mnemonics. Use this list to decide what
616 * mnemonic should be used for label.
620 mnembuf
[idx
++] = 'H'; /* H is mnemonic for Help */
621 for (menu
= root_menu
; menu
!= NULL
; menu
= menu
->next
)
623 if (menu_is_menubar(menu
->name
))
625 p
= strchr((char *)menu
->name
, '&');
627 mnembuf
[idx
++] = *++p
;
629 if (menu
->next
!= NULL
630 && strcmp((char *) menu
->next
->dname
, "Help") == 0)
632 menuPriority
= menu
->priority
+ 10;
636 mnembuf
[idx
++] = NUL
;
637 name
= addUniqueMnemonic(mnembuf
, label
);
639 vim_snprintf(curMenuName
, sizeof(curMenuName
), "%s", name
);
640 sprintf(curMenuPriority
, "%d.0", menuPriority
);
644 * Append the name and priority to strings to be used in vim menu commands.
647 workshop_submenu_begin(
651 if (ws_debug
&& ws_dlevel
& WS_TRACE
652 && strncmp(curMenuName
, "ToolBar", 7) != 0)
653 wstrace("workshop_submenu_begin(%s)\n", label
);
656 strcat(curMenuName
, ".");
657 strcat(curMenuName
, fixup(label
));
659 updatePriority(True
);
663 * Remove the submenu name and priority from curMenu*.
667 workshop_submenu_end()
672 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
)
673 && strncmp(curMenuName
, "ToolBar", 7) != 0)
674 wstrace("workshop_submenu_end()\n");
677 p
= strrchr(curMenuPriority
, '.');
681 p
= strrchr(curMenuName
, '.');
687 * This is where menus are really made. Each item will generate an amenu vim
688 * command. The globals curMenuName and curMenuPriority contain the name and
689 * priority of the parent menu tree.
697 char *acceleratorText
,
703 char namebuf
[BUFSIZ
];
704 char accText
[BUFSIZ
];
707 if (WSDLEVEL(WS_TRACE_VERBOSE
)
708 && strncmp(curMenuName
, "ToolBar", 7) != 0)
710 if (ws_dlevel
& WS_TRACE_VERBOSE
)
711 wsdebug("workshop_menu_item(\n"
712 "\tlabel = \"%s\",\n"
714 "\taccelerator = %s,\n"
715 "\tacceleratorText = \"%s\",\n"
718 "\tsensitive = %s)\n",
719 label
&& *label
? label
: "<None>",
720 verb
&& *verb
? verb
: "<None>",
721 accelerator
&& *accelerator
?
722 accelerator
: "<None>",
723 acceleratorText
&& *acceleratorText
?
724 acceleratorText
: "<None>",
725 name
&& *name
? name
: "<None>",
726 filepos
&& *filepos
? filepos
: "<None>",
728 else if (ws_dlevel
& WS_TRACE
)
729 wstrace("workshop_menu_item(\"%s\", %s)\n",
730 label
&& *label
? label
: "<None>",
731 verb
&& *verb
? verb
: "<None>", sensitive
);
736 wstrace("menu: %-21.20s%-21.20s(%s)\n", label
, verb
,
737 *sensitive
== '1' ? "Sensitive" : "Insensitive");
740 if (acceleratorText
!= NULL
)
741 vim_snprintf(accText
, sizeof(accText
), "<Tab>%s", acceleratorText
);
744 updatePriority(False
);
745 vim_snprintf(namebuf
, sizeof(namebuf
), "%s.%s", curMenuName
, fixup(label
));
746 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu %s %s%s\t:wsverb %s<CR>",
747 curMenuPriority
, namebuf
, accText
, verb
);
749 coloncmd(cbuf
, TRUE
);
750 addMenu(namebuf
, fixAccelText(acceleratorText
), verb
);
752 if (*sensitive
== '0')
754 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
755 coloncmd(cbuf
, TRUE
);
760 * This function is called when a complete WorkShop menu description has been
761 * sent over from eserve. We do some menu cleanup.
767 Boolean using_tearoff
; /* set per current option setting */
770 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
771 wstrace("workshop_menu_end()\n");
774 using_tearoff
= vim_strchr(p_go
, GO_TEAROFF
) != NULL
;
775 gui_mch_toggle_tearoffs(using_tearoff
);
779 workshop_toolbar_begin()
782 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
783 wstrace("workshop_toolbar_begin()\n");
786 coloncmd("aunmenu ToolBar", True
);
791 workshop_toolbar_end()
796 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
798 wstrace("workshop_toolbar_end()\n");
806 if (vim_strchr(p_go
, 'T') == NULL
)
809 set_option_value((char_u
*)"go", 0L, buf
, 0);
811 workshopInitDone
= True
;
816 workshop_toolbar_button(
826 char cbuf
[BUFSIZ
+ MAXPATHLEN
];
827 char namebuf
[BUFSIZ
];
833 if (WSDLEVEL(WS_TRACE_VERBOSE
))
834 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
835 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
836 label
&& *label
? label
: "<None>",
837 verb
&& *verb
? verb
: "<None>",
838 senseVerb
&& *senseVerb
? senseVerb
: "<None>",
839 filepos
&& *filepos
? filepos
: "<None>",
840 help
&& *help
? help
: "<None>",
841 sense
&& *sense
? sense
: "<None>",
842 file
&& *file
? file
: "<None>",
843 left
&& *left
? left
: "<None>");
844 else if (WSDLEVEL(WS_TRACE
))
845 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
846 label
&& *label
? label
: "<None>",
847 verb
&& *verb
? verb
: "<None>");
851 wsdebug("button: %-21.20s%-21.20s(%s)\n", label
, verb
,
852 *sense
== '1' ? "Sensitive" : "Insensitive");
855 if (left
&& *left
&& atoi(left
) > 0)
857 /* Add a separator (but pass the width passed after the ':') */
858 sprintf(cbuf
, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
859 tbpri
- 5, tbid
++, left
);
861 coloncmd(cbuf
, True
);
864 p
= vim_strsave_escaped((char_u
*)label
, (char_u
*)"\\. ");
865 vim_snprintf(namebuf
, sizeof(namebuf
), "ToolBar.%s", p
);
867 STRCPY(cbuf
, "amenu <silent> ");
868 if (file
!= NULL
&& *file
!= NUL
)
870 p
= vim_strsave_escaped((char_u
*)file
, (char_u
*)" ");
872 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
, "icon=%s ", p
);
876 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
,"1.%d %s :wsverb %s<CR>",
877 tbpri
, namebuf
, verb
);
879 /* Define the menu item */
880 coloncmd(cbuf
, True
);
884 /* If menu isn't sensitive at startup... */
885 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
886 coloncmd(cbuf
, True
);
892 vim_snprintf(cbuf
, sizeof(cbuf
), "tmenu %s %s", namebuf
, help
);
893 coloncmd(cbuf
, True
);
896 addMenu(namebuf
, NULL
, verb
);
901 workshop_frame_sensitivities(
902 VerbSense
*vs
) /* list of verbs to (de)sensitize */
904 VerbSense
*vp
; /* iterate through vs */
905 char *menu_name
; /* used in menu lookup */
906 int cnt
; /* count of verbs to skip */
907 int len
; /* length of nonvariant part of command */
911 if (WSDLEVEL(WS_TRACE_VERBOSE
) || WSDLEVEL(4))
913 wsdebug("workshop_frame_sensitivities(\n");
914 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
915 wsdebug("\t%-25s%d\n", vp
->verb
, vp
->sense
);
918 else if (WSDLEVEL(WS_TRACE
))
919 wstrace("workshop_frame_sensitivities()\n");
923 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
924 wsdebug("change: %-21.20s%-21.20s(%s)\n",
925 "", vp
->verb
, vp
->sense
== 1 ?
926 "Sensitive" : "Insensitive");
930 * Look for all matching menu entries for the verb. There may be more
931 * than one if the verb has both a menu and toolbar entry.
933 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
936 strcpy(cbuf
, "amenu");
938 strcat(cbuf
, vp
->sense
? "enable" : "disable");
941 while ((menu_name
= lookupVerb(vp
->verb
, cnt
++)) != NULL
)
943 strcpy(&cbuf
[len
], menu_name
);
944 coloncmd(cbuf
, FALSE
);
953 char *option
, /* name of a supported option */
954 char *value
) /* value to set option to */
956 char cbuf
[BUFSIZ
]; /* command buffer */
959 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
961 wstrace("workshop_set_option(%s, %s)\n", option
, value
);
966 switch (*option
) /* switch on 1st letter */
969 if (strcmp(option
, "syntax") == 0)
970 vim_snprintf(cbuf
, sizeof(cbuf
), "syntax %s", value
);
971 else if (strcmp(option
, "savefiles") == 0)
972 ; /* XXX - Not yet implemented */
976 if (strcmp(option
, "lineno") == 0)
977 sprintf(cbuf
, "set %snu",
978 (strcmp(value
, "on") == 0) ? "" : "no");
982 if (strcmp(option
, "parentheses") == 0)
983 sprintf(cbuf
, "set %ssm",
984 (strcmp(value
, "on") == 0) ? "" : "no");
988 /* this option is set by a direct call */
990 wsdebug("workshop_set_option: "
991 "Got unexpected workshopkeys option");
995 case 'b': /* these options are set from direct calls */
996 if (option
[7] == NUL
&& strcmp(option
, "balloon") == 0)
999 /* set by direct call to workshop_balloon_mode */
1000 wsdebug("workshop_set_option: "
1001 "Got unexpected ballooneval option");
1004 else if (strcmp(option
, "balloondelay") == 0)
1007 /* set by direct call to workshop_balloon_delay */
1008 wsdebug("workshop_set_option: "
1009 "Got unexpected balloondelay option");
1015 coloncmd(cbuf
, TRUE
);
1020 workshop_balloon_mode(
1023 char cbuf
[BUFSIZ
]; /* command buffer */
1025 #ifdef WSDEBUG_TRACE
1026 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1027 wstrace("workshop_balloon_mode(%s)\n", on
? "True" : "False");
1030 sprintf(cbuf
, "set %sbeval", on
? "" : "no");
1031 coloncmd(cbuf
, TRUE
);
1036 workshop_balloon_delay(
1039 char cbuf
[BUFSIZ
]; /* command buffer */
1041 #ifdef WSDEBUG_TRACE
1042 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1043 wstrace("workshop_balloon_delay(%d)\n", delay
);
1046 sprintf(cbuf
, "set bdlay=%d", delay
);
1047 coloncmd(cbuf
, TRUE
);
1052 workshop_show_balloon_tip(
1055 #ifdef WSDEBUG_TRACE
1056 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1057 wstrace("workshop_show_balloon_tip(%s)\n", tip
);
1060 if (balloonEval
!= NULL
)
1061 gui_mch_post_balloon(balloonEval
, (char_u
*)tip
);
1069 char cbuf
[BUFSIZ
]; /* command buffer */
1070 MenuMap
*mp
; /* iterate over menuMap entries */
1072 #ifdef WSDEBUG_TRACE
1073 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1074 wstrace("workshop_hotkeys(%s)\n", on
? "True" : "False");
1077 workshopHotKeysEnabled
= on
;
1078 if (workshopHotKeysEnabled
)
1079 for (mp
= menuMap
; mp
< &menuMap
[menuMapSize
]; mp
++)
1081 if (mp
->accel
!= NULL
)
1083 vim_snprintf(cbuf
, sizeof(cbuf
),
1084 "map %s :wsverb %s<CR>", mp
->accel
, mp
->verb
);
1085 coloncmd(cbuf
, TRUE
);
1089 for (mp
= menuMap
; mp
< &menuMap
[menuMapSize
]; mp
++)
1091 if (mp
->accel
!= NULL
)
1093 vim_snprintf(cbuf
, sizeof(cbuf
), "unmap %s", mp
->accel
);
1094 coloncmd(cbuf
, TRUE
);
1100 * A button in the toolbar has been pushed.
1104 workshop_get_positions(
1105 void *clientData
, /* unused */
1106 char **filename
, /* output data */
1107 int *curLine
, /* output data */
1108 int *curCol
, /* output data */
1109 int *selStartLine
, /* output data */
1110 int *selStartCol
, /* output data */
1111 int *selEndLine
, /* output data */
1112 int *selEndCol
, /* output data */
1113 int *selLength
, /* output data */
1114 char **selection
) /* output data */
1116 static char ffname
[MAXPATHLEN
];
1118 #ifdef WSDEBUG_TRACE
1119 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1120 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1121 clientData
, (curbuf
&& curbuf
->b_sfname
!= NULL
)
1122 ? (char *)curbuf
->b_sfname
: "<None>");
1125 strcpy(ffname
, (char *) curbuf
->b_ffname
);
1126 *filename
= ffname
; /* copy so nobody can change b_ffname */
1127 *curLine
= curwin
->w_cursor
.lnum
;
1128 *curCol
= curwin
->w_cursor
.col
;
1130 if (curbuf
->b_visual
.vi_mode
== 'v' &&
1131 equalpos(curwin
->w_cursor
, curbuf
->b_visual
.vi_end
))
1133 *selStartLine
= curbuf
->b_visual
.vi_start
.lnum
;
1134 *selStartCol
= curbuf
->b_visual
.vi_start
.col
;
1135 *selEndLine
= curbuf
->b_visual
.vi_end
.lnum
;
1136 *selEndCol
= curbuf
->b_visual
.vi_end
.col
;
1137 *selection
= get_selection(curbuf
);
1139 *selLength
= strlen(*selection
);
1145 *selStartLine
= *selEndLine
= -1;
1146 *selStartCol
= *selEndCol
= -1;
1156 /************************************************************************
1158 ************************************************************************/
1162 buf_T
*buf
) /* buffer whose selection we want */
1164 pos_T
*start
; /* start of the selection */
1165 pos_T
*end
; /* end of the selection */
1166 char *lp
; /* pointer to actual line data */
1167 int llen
; /* length of actual line data */
1168 char *sp
; /* pointer to selection buffer */
1169 int slen
; /* string length in selection buffer */
1170 int size
; /* size of selection buffer */
1171 char *new_sp
; /* temp pointer to new sp */
1172 int lnum
; /* line number we are appending */
1174 if (buf
->b_visual
.vi_mode
== 'v')
1176 start
= &buf
->b_visual
.vi_start
;
1177 end
= &buf
->b_visual
.vi_end
;
1178 if (start
->lnum
== end
->lnum
)
1180 /* selection is all on one line */
1181 lp
= (char *) ml_get_pos(start
);
1182 llen
= end
->col
- start
->col
+ 1;
1183 sp
= (char *) malloc(llen
+ 1);
1186 strncpy(sp
, lp
, llen
);
1192 /* multi-line selection */
1193 lp
= (char *) ml_get_pos(start
);
1195 sp
= (char *) malloc(BUFSIZ
+ llen
);
1198 size
= BUFSIZ
+ llen
;
1203 lnum
= start
->lnum
+ 1;
1204 while (lnum
< end
->lnum
)
1205 sp
= append_selection(lnum
++, sp
, &size
, &slen
);
1207 lp
= (char *) ml_get(end
->lnum
);
1208 llen
= end
->col
+ 1;
1209 if ((slen
+ llen
) >= size
)
1212 realloc(sp
, slen
+ llen
+ 1);
1219 if ((slen
+ llen
) < size
)
1221 strncpy(&sp
[slen
], lp
, llen
);
1222 sp
[slen
+ llen
] = NUL
;
1236 int lnum
, /* line number to append */
1237 char *sp
, /* pointer to selection buffer */
1238 int *size
, /* ptr to size of sp */
1239 int *slen
) /* ptr to length of selection string */
1241 char *lp
; /* line of data from buffer */
1242 int llen
; /* strlen of lp */
1243 char *new_sp
; /* temp pointer to new sp */
1245 lp
= (char *)ml_get((linenr_T
)lnum
);
1248 if ((*slen
+ llen
) <= *size
)
1250 new_sp
= (char *) realloc((void *) sp
, BUFSIZ
+ *slen
+ llen
);
1253 *size
= BUFSIZ
+ *slen
+ llen
;
1257 if ((*slen
+ llen
) > *size
)
1259 strcat(&sp
[*slen
], lp
);
1270 load_buffer_by_name(
1271 char *filename
, /* the file to load */
1272 int lnum
) /* an optional line number (or 0) */
1274 char lnumbuf
[16]; /* make line number option for :e */
1275 char cbuf
[BUFSIZ
]; /* command buffer */
1278 sprintf(lnumbuf
, "+%d", lnum
);
1282 vim_snprintf(cbuf
, sizeof(cbuf
), "e %s %s", lnumbuf
, filename
);
1283 coloncmd(cbuf
, False
);
1289 char *filename
, /* filename to load */
1290 int lnum
) /* linenumber to go to */
1292 buf_T
*buf
; /* buffer filename is stored in */
1293 win_T
*win
; /* window filenme is displayed in */
1296 * Make sure filename is displayed and is the current window.
1299 buf
= buflist_findname((char_u
*)filename
);
1300 if (buf
== NULL
|| (win
= get_window(buf
)) == NULL
)
1302 /* No buffer or buffer is not in current window */
1303 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1305 load_buffer_by_name(filename
, lnum
);
1309 /* buf is in a window */
1312 win_enter(win
, False
);
1313 /* wsdebug("load_window: window endter %s\n",
1314 win->w_buffer->b_sfname); */
1316 if (lnum
> 0 && win
->w_cursor
.lnum
!= lnum
)
1319 /* wsdebug("load_window: warp to %s[%d]\n",
1320 win->w_buffer->b_sfname, lnum); */
1330 int lnum
) /* line number to warp to */
1332 char lbuf
[256]; /* build line command here */
1337 add_to_input_buf((char_u
*) "\033", 1);
1338 if (isShowing(lnum
))
1339 sprintf(lbuf
, "%dG", lnum
);
1341 sprintf(lbuf
, "%dz.", lnum
);
1342 add_to_input_buf((char_u
*) lbuf
, strlen(lbuf
));
1348 int lnum
) /* tell if line number is showing */
1350 return lnum
>= curwin
->w_topline
&& lnum
< curwin
->w_botline
;
1357 buf_T
*buf
) /* buffer to find window for */
1359 win_T
*wp
= NULL
; /* window filename is in */
1361 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
1362 if (buf
== wp
->w_buffer
)
1368 #if 0 /* not used */
1371 buf_T
*buf
) /* buffer to get position of */
1373 buf_T
*bp
; /* iterate over buffer list */
1374 int pos
; /* the position in the buffer list */
1377 for (bp
= firstbuf
; bp
!= NULL
; bp
= bp
->b_next
)
1390 Boolean subMenu
) /* if True then start new submenu pri */
1392 int pri
; /* priority of this menu/item */
1395 p
= strrchr(curMenuPriority
, '.');
1399 pri
= atoi(p
) + 10; /* our new priority */
1402 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1403 "%s.%d.0", curMenuPriority
, pri
);
1405 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1406 "%s.%d", curMenuPriority
, pri
);
1411 char *mnemonics
, /* currently used mnemonics */
1412 char *label
) /* label of menu needing mnemonic */
1414 static char name
[BUFSIZ
]; /* buffer for the updated name */
1415 char *p
; /* pointer into label */
1416 char *found
; /* pointer to possible mnemonic */
1419 for (p
= label
; *p
!= NUL
; p
++)
1420 if (strchr(mnemonics
, *p
) == 0)
1421 if (found
== NULL
|| (isupper((int)*p
) && islower((int)*found
)))
1426 strncpy(name
, label
, (found
- label
));
1428 strcat(name
, found
);
1431 strcpy(name
, label
);
1437 * Some characters in a menu name must be escaped in vim. Since this is vim
1438 * specific, it must be done on this side.
1444 static char buf
[BUFSIZ
];
1445 char *bp
; /* pointer into buf */
1446 char *lp
; /* pointer into label */
1452 if (*lp
== ' ' || *lp
== '.')
1462 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1464 /* For the NoHands test suite */
1467 workshop_test_getcurrentfile()
1469 char *filename
, *selection
;
1470 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1471 int selEndCol
, selLength
;
1473 if (workshop_get_positions(
1474 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1475 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1483 workshop_test_getcursorrow()
1489 workshop_test_getcursorcol()
1491 char *filename
, *selection
;
1492 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1493 int selEndCol
, selLength
;
1495 if (workshop_get_positions(
1496 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1497 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1505 workshop_test_getcursorrowtext()
1511 workshop_test_getselectedtext()
1513 char *filename
, *selection
;
1514 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1515 int selEndCol
, selLength
;
1517 if (workshop_get_positions(
1518 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1519 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1528 workshop_save_sensitivity(char *filename
)
1536 char *ap
) /* original acceleratorText */
1538 char buf
[256]; /* build in temp buffer */
1539 char *shift
; /* shift string of "" */
1544 /* If the accelerator is shifted use the vim form */
1545 if (strncmp("Shift+", ap
, 6) == 0)
1553 if (*ap
== 'F' && atoi(&ap
[1]) > 0)
1555 vim_snprintf(buf
, sizeof(buf
), "<%s%s>", shift
, ap
);
1574 char buf
[MAXPATHLEN
* 2];
1575 static int serialNo
= -1;
1580 if (get_beval_info(beval
, FALSE
, &wp
, &lnum
, &text
, &col
) == OK
)
1582 if (text
&& text
[0])
1584 /* Send debugger request */
1585 if (strlen((char *) text
) > (MAXPATHLEN
/2))
1588 * The user has probably selected the entire
1589 * buffer or something like that - don't attempt
1596 * WorkShop expects the col to be a character index, not
1597 * a column number. Compute the index from col. Also set
1598 * line to 0 because thats what dbx expects.
1600 idx
= computeIndex(col
, text
, beval
->ts
);
1606 * If successful, it will respond with a balloon cmd.
1608 if (state
& ControlMask
)
1609 /* Evaluate *(expression) */
1610 type
= (int)GPLineEval_INDIRECT
;
1611 else if (state
& ShiftMask
)
1612 /* Evaluate type(expression) */
1613 type
= (int)GPLineEval_TYPE
;
1615 /* Evaluate value(expression) */
1616 type
= (int)GPLineEval_EVALUATE
;
1618 /* Send request to dbx */
1619 vim_snprintf(buf
, sizeof(buf
), "toolVerb debug.balloonEval "
1620 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1621 (char *)wp
->w_buffer
->b_ffname
,
1622 (long)lnum
, idx
, type
, serialNo
++,
1623 (long)strlen((char *)text
), (char *)text
);
1624 balloonEval
= beval
;
1625 workshop_send_message(buf
);
1644 if (line
[idx
] == '\t')
1645 col
+= ts
- (col
% ts
);
1649 if (col
>= wantedCol
)
1658 char *menu
, /* menu name */
1659 char *accel
, /* accelerator text (optional) */
1660 char *verb
) /* WorkShop action-verb */
1665 if (menuMapSize
>= menuMapMax
)
1667 newMap
= realloc(menuMap
,
1668 sizeof(MenuMap
) * (menuMapMax
+ MENU_INC
));
1672 menuMapMax
+= MENU_INC
;
1675 if (menuMapSize
< menuMapMax
)
1677 menuMap
[menuMapSize
].name
= strdup(menu
);
1678 menuMap
[menuMapSize
].accel
= accel
&& *accel
? strdup(accel
) : NULL
;
1679 menuMap
[menuMapSize
++].verb
= strdup(verb
);
1680 if (accel
&& workshopHotKeysEnabled
)
1682 vim_snprintf(cbuf
, sizeof(cbuf
),
1683 "map %s :wsverb %s<CR>", accel
, verb
);
1684 coloncmd(cbuf
, TRUE
);
1691 char *raw
) /* menu name, possibly with & chars */
1693 static char buf
[BUFSIZ
]; /* build stripped name here */
1710 int skip
) /* number of matches to skip */
1712 int i
; /* loop iterator */
1714 for (i
= 0; i
< menuMapSize
; i
++)
1715 if (strcmp(menuMap
[i
].verb
, verb
) == 0 && skip
-- == 0)
1716 return nameStrip(menuMap
[i
].name
);
1724 char *cmd
, /* the command to print */
1725 Boolean force
) /* force cursor update */
1727 char_u
*cpo_save
= p_cpo
;
1730 if (WSDLEVEL(WS_TRACE_COLONCMD
))
1731 wsdebug("Cmd: %s\n", cmd
);
1734 p_cpo
= empty_option
;
1737 do_cmdline_cmd((char_u
*)cmd
);
1743 gui_update_screen();
1747 * setDollarVim - Given the run directory, search for the vim install
1748 * directory and set $VIM.
1750 * We can be running out of SUNWspro/bin or out of
1751 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1752 * relative to both of these directories.
1758 char buf
[MAXPATHLEN
];
1762 * First case: Running from <install-dir>/SUNWspro/bin
1764 strcpy(buf
, rundir
);
1765 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1766 VIM_VERSION_NODOT
"/syntax/syntax.vim");
1767 if (access(buf
, R_OK
) == 0)
1769 strcpy(buf
, "SPRO_WSDIR=");
1770 strcat(buf
, rundir
);
1771 cp
= strrchr(buf
, '/');
1773 strcpy(cp
, "/WS6U2");
1774 putenv(strdup(buf
));
1776 strcpy(buf
, "VIM=");
1777 strcat(buf
, rundir
);
1778 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1780 putenv(strdup(buf
));
1785 * Second case: Probably running from
1786 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1788 strcpy(buf
, rundir
);
1789 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1790 "/share/vim/" VIM_VERSION_NODOT
"/syntax/syntax.vim");
1791 if (access(buf
, R_OK
) == 0)
1793 strcpy(buf
, "SPRO_WSDIR=");
1794 strcat(buf
, rundir
);
1795 cp
= strrchr(buf
, '/');
1797 strcpy(cp
, "../../../../WS6U2");
1798 putenv(strdup(buf
));
1800 strcpy(buf
, "VIM=");
1801 strcat(buf
, rundir
);
1802 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1803 "/share/vim/" VIM_VERSION_NODOT
);
1804 putenv(strdup(buf
));
1810 * findYourself - Find the directory we are running from. This is used to
1811 * set $VIM. We need to set this because users can install
1812 * the package in a different directory than the compiled
1813 * directory. This is a Sun Visual WorkShop requirement!
1815 * Note: We override a user's $VIM because it won't have the
1816 * WorkShop specific files. S/he may not like this but its
1817 * better than getting the wrong files (especially as the
1818 * user is likely to have $VIM set to 5.4 or later).
1824 char *runpath
= NULL
;
1829 runpath
= strdup(argv0
);
1830 else if (*argv0
== '.' || strchr(argv0
, '/'))
1832 runpath
= (char *) malloc(MAXPATHLEN
);
1833 getcwd(runpath
, MAXPATHLEN
);
1834 strcat(runpath
, "/");
1835 strcat(runpath
, argv0
);
1839 path
= getenv("PATH");
1842 runpath
= (char *) malloc(MAXPATHLEN
);
1843 pathbuf
= strdup(path
);
1844 path
= strtok(pathbuf
, ":");
1847 strcpy(runpath
, path
);
1848 strcat(runpath
, "/");
1849 strcat(runpath
, argv0
);
1850 if (access(runpath
, X_OK
) == 0)
1852 } while ((path
= strtok(NULL
, ":")) != NULL
);
1857 if (runpath
!= NULL
)
1859 char runbuf
[MAXPATHLEN
];
1862 * We found the run directory. Now find the install dir.
1864 (void)vim_FullName((char_u
*)runpath
, (char_u
*)runbuf
, MAXPATHLEN
, 1);
1865 path
= strrchr(runbuf
, '/');
1867 *path
= NUL
; /* remove the vim/gvim name */
1868 path
= strrchr(runbuf
, '/');
1871 if (strncmp(path
, "/bin", 4) == 0)
1872 setDollarVim(runbuf
);
1873 else if (strncmp(path
, "/src", 4) == 0)
1875 *path
= NUL
; /* development tree */
1876 setDollarVim(runbuf
);