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"
16 #include <sys/types.h>
18 #include <netinet/in.h>
20 #include <sys/socket.h>
29 #include <X11/Intrinsic.h>
33 #include "integration.h" /* <EditPlugin/integration.h> */
37 #include "gui_beval.h"
40 void workshop_hotkeys(Boolean
);
42 static Boolean
isShowing(int);
43 static win_T
*get_window(buf_T
*);
45 static int get_buffer_number(buf_T
*);
47 static void updatePriority(Boolean
);
48 static char *addUniqueMnemonic(char *, char *);
49 static char *fixup(char *);
50 static char *get_selection(buf_T
*);
51 static char *append_selection(int, char *, int *, int *);
52 static void load_buffer_by_name(char *, int);
54 static void load_buffer_by_number(int, int);
56 static void load_window(char *, int lnum
);
57 static void warp_to_pc(int);
59 void workshop_beval_cb(BalloonEval
*, int);
61 static int computeIndex(int, char_u
*, int, int *);
63 static int computeIndex(int, char_u
*, int);
66 static char *fixAccelText(char *);
67 static void addMenu(char *, char *, char *);
68 static char *lookupVerb(char *, int);
69 static void coloncmd(char *, Boolean
);
71 extern Widget vimShell
;
72 extern Widget textArea
;
73 extern XtAppContext app_context
;
75 static int tbpri
; /* ToolBar priority */
76 int usingSunWorkShop
= 0; /* set if -ws flag is used */
77 char curMenuName
[BUFSIZ
];
78 char curMenuPriority
[BUFSIZ
];
80 static Boolean workshopInitDone
= False
;
81 static Boolean workshopHotKeysEnabled
= False
;
84 * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it
85 * here because its C++.
89 GPLineEval_EVALUATE
, /* evaluate expression */
90 GPLineEval_INDIRECT
, /* evaluate *<expression> */
91 GPLineEval_TYPE
/* type of expression */
95 * Store each verb in the MenuMap. This lets us map from a verb to a menu.
96 * There may be multiple matches for a single verb in this table.
98 #define MENU_INC 50 /* menuMap incremental size increases */
101 char *name
; /* name of the menu */
102 char *accel
; /* optional accelerator key */
103 char *verb
; /* menu verb */
105 static MenuMap
*menuMap
; /* list of verb/menu mappings */
106 static int menuMapSize
; /* current size of menuMap */
107 static int menuMapMax
; /* allocated size of menuMap */
108 static char *initialFileCmd
; /* save command but defer doing it */
115 int is_dirty
= FALSE
;
120 * Turn on MenuBar, ToolBar, and Footer.
123 if (vim_strchr(p_go
, GO_MENUS
) == NULL
)
128 if (vim_strchr(p_go
, GO_TOOLBAR
) == NULL
)
133 if (vim_strchr(p_go
, GO_FOOTER
) == NULL
)
139 set_option_value((char_u
*)"go", 0L, buf
, 0);
142 * Set size from workshop_get_width_height().
145 if (workshop_get_width_height(&width
, &height
))
147 XtVaSetValues(vimShell
,
154 * Now read in the initial messages from eserve.
156 while ((mask
= XtAppPending(app_context
))
157 && (mask
& XtIMAlternateInput
) && !workshopInitDone
)
158 XtAppProcessEvent(app_context
, (XtInputMask
)XtIMAlternateInput
);
164 do_cmdline_cmd((char_u
*)initialFileCmd
);
166 free(initialFileCmd
);
167 initialFileCmd
= NULL
;
171 ex_wsverb(exarg_T
*eap
)
174 workshop_perform_verb((char *) eap
->arg
, NULL
);
179 * This string is recognized by eserve and should be all lower case.
180 * This is how the editor detects that it is talking to gvim instead
181 * of NEdit, for example, when the connection is initiated from the editor.
184 workshop_get_editor_name()
190 * Version number of the editor.
191 * This number is communicated along with the protocol
192 * version to the application.
195 workshop_get_editor_version()
201 * Answer functions: called by eserve
209 * Load a given file into the WorkShop buffer.
213 char *filename
, /* the file to load */
214 int line
, /* an optional line number (or 0) */
215 char *frameid UNUSED
) /* used for multi-frame support */
218 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
219 wstrace("workshop_load_file(%s, %d)\n", filename
, line
);
223 bevalServers
|= BEVAL_WORKSHOP
;
226 load_window(filename
, line
);
230 * Reload the WorkShop buffer
233 workshop_reload_file(
238 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
239 wstrace("workshop_reload_file(%s, %d)\n", filename
, line
);
241 load_window(filename
, line
);
249 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
250 wstrace("workshop_show_file(%s)\n", filename
);
253 load_window(filename
, 0);
262 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
263 wstrace("workshop_goto_line(%s, %d)\n", filename
, lineno
);
266 load_window(filename
, lineno
);
271 char *filename UNUSED
)
274 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
275 wstrace("workshop_front_file()\n");
278 * Assumption: This function will always be called after a call to
279 * workshop_show_file(), so the file is always showing.
281 if (vimShell
!= NULL
)
282 XRaiseWindow(gui
.dpy
, XtWindow(vimShell
));
289 char cbuf
[BUFSIZ
]; /* build vim command here */
292 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
293 wstrace("workshop_save_file(%s)\n", filename
);
296 /* Save the given file */
297 vim_snprintf(cbuf
, sizeof(cbuf
), "w %s", filename
);
298 coloncmd(cbuf
, TRUE
);
302 workshop_save_files()
304 /* Save the given file */
306 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
307 wstrace("workshop_save_files()\n");
310 add_to_input_buf((char_u
*) ":wall\n", 6);
317 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
318 wstrace("workshop_quit()\n");
321 add_to_input_buf((char_u
*) ":qall\n", 6);
328 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
329 wstrace("workshop_minimize()\n");
331 workshop_minimize_shell(vimShell
);
337 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
338 wstrace("workshop_maximize()\n");
341 workshop_maximize_shell(vimShell
);
345 workshop_add_mark_type(
350 char gbuf
[BUFSIZ
]; /* buffer for sign name */
351 char cibuf
[BUFSIZ
]; /* color information */
352 char cbuf
[BUFSIZ
]; /* command buffer */
356 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
360 cp
= strrchr(sign
, '/');
364 cp
++; /* skip '/' character */
365 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx
,
366 colorspec
&& *colorspec
? colorspec
: "<None>", cp
);
371 * Isolate the basename of sign in gbuf. We will use this for the
372 * GroupName in the highlight command sent to vim.
374 STRCPY(gbuf
, gettail((char_u
*)sign
));
375 bp
= strrchr(gbuf
, '.');
379 if (gbuf
[0] != '-' && gbuf
[1] != NUL
)
381 if (colorspec
!= NULL
&& *colorspec
)
383 vim_snprintf(cbuf
, sizeof(cbuf
),
384 "highlight WS%s guibg=%s", gbuf
, colorspec
);
385 coloncmd(cbuf
, FALSE
);
386 vim_snprintf(cibuf
, sizeof(cibuf
), "linehl=WS%s", gbuf
);
391 vim_snprintf(cbuf
, sizeof(cbuf
),
392 "sign define %d %s icon=%s", idx
, cibuf
, sign
);
393 coloncmd(cbuf
, TRUE
);
399 char *filename
, /* filename which gets the mark */
400 int lineno
, /* line number which gets the mark */
401 int markId
, /* unique mark identifier */
402 int idx
) /* which mark to use */
404 char cbuf
[BUFSIZ
]; /* command buffer */
406 /* Set mark in a given file */
408 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
409 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n",
410 filename
, lineno
, markId
, idx
);
413 vim_snprintf(cbuf
, sizeof(cbuf
), "sign place %d line=%d name=%d file=%s",
414 markId
, lineno
, idx
, filename
);
415 coloncmd(cbuf
, TRUE
);
419 workshop_change_mark_type(
420 char *filename
, /* filename which gets the mark */
421 int markId
, /* unique mark identifier */
422 int idx
) /* which mark to use */
424 char cbuf
[BUFSIZ
]; /* command buffer */
426 /* Change mark type */
428 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
429 wstrace("workshop_change_mark_type(%s, %d, %d)\n",
430 filename
, markId
, idx
);
433 vim_snprintf(cbuf
, sizeof(cbuf
),
434 "sign place %d name=%d file=%s", markId
, idx
, filename
);
435 coloncmd(cbuf
, TRUE
);
439 * Goto the given mark in a file (e.g. show it).
440 * If message is not null, display it in the footer.
448 char cbuf
[BUFSIZ
]; /* command buffer */
452 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
453 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
454 filename
, markId
, message
&& *message
&&
455 !(*message
== ' ' && message
[1] == NULL
) ?
459 vim_snprintf(cbuf
, sizeof(cbuf
), "sign jump %d file=%s", markId
, filename
);
460 coloncmd(cbuf
, TRUE
);
461 if (message
!= NULL
&& *message
!= NUL
)
462 gui_mch_set_footer((char_u
*)message
);
466 workshop_delete_mark(
470 char cbuf
[BUFSIZ
]; /* command buffer */
474 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
475 wstrace("workshop_delete_mark(%s, %d (id))\n",
479 vim_snprintf(cbuf
, sizeof(cbuf
),
480 "sign unplace %d file=%s", markId
, filename
);
481 coloncmd(cbuf
, TRUE
);
486 workshop_delete_all_marks(
491 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
492 wstrace("workshop_delete_all_marks(%#x, %s)\n",
493 window
, doRefresh
? "True" : "False");
496 coloncmd("sign unplace *", TRUE
);
501 workshop_get_mark_lineno(
505 buf_T
*buf
; /* buffer containing filename */
506 int lineno
; /* line number of filename in buf */
508 /* Get mark line number */
510 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
511 wstrace("workshop_get_mark_lineno(%s, %d)\n",
516 buf
= buflist_findname((char_u
*)filename
);
518 lineno
= buf_findsign(buf
, markId
);
526 workshop_adjust_marks(Widget
*window
, int pos
,
527 int inserted
, int deleted
)
530 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
531 wstrace("XXXworkshop_adjust_marks(%s, %d, %d, %d)\n",
532 window
? XtName(window
) : "<None>", pos
, inserted
, deleted
);
538 * Are there any moved marks? If so, call workshop_move_mark on
539 * each of them now. This is how eserve can find out if for example
540 * breakpoints have moved when a program has been recompiled and
544 workshop_moved_marks(char *filename UNUSED
)
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
);
580 workshop_footer_message(
582 int severity UNUSED
) /* severity is currently unused */
585 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
586 wstrace("workshop_footer_message(%s, %d)\n", message
, severity
);
589 gui_mch_set_footer((char_u
*) message
);
593 * workshop_menu_begin() is passed the menu name. We determine its mnemonic
594 * here and store its name and priority.
600 vimmenu_T
*menu
; /* pointer to last menu */
601 int menuPriority
= 0; /* priority of new menu */
602 char mnembuf
[64]; /* store menubar mnemonics here */
603 char *name
; /* label with a mnemonic */
604 char *p
; /* used to find mnemonics */
605 int idx
; /* index into mnembuf */
608 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
609 wstrace("workshop_menu_begin()\n");
613 * Look through all existing (non-PopUp and non-Toolbar) menus
614 * and gather their mnemonics. Use this list to decide what
615 * mnemonic should be used for label.
619 mnembuf
[idx
++] = 'H'; /* H is mnemonic for Help */
620 for (menu
= root_menu
; menu
!= NULL
; menu
= menu
->next
)
622 if (menu_is_menubar(menu
->name
))
624 p
= strchr((char *)menu
->name
, '&');
626 mnembuf
[idx
++] = *++p
;
628 if (menu
->next
!= NULL
629 && strcmp((char *) menu
->next
->dname
, "Help") == 0)
631 menuPriority
= menu
->priority
+ 10;
635 mnembuf
[idx
++] = NUL
;
636 name
= addUniqueMnemonic(mnembuf
, label
);
638 vim_snprintf(curMenuName
, sizeof(curMenuName
), "%s", name
);
639 sprintf(curMenuPriority
, "%d.0", menuPriority
);
643 * Append the name and priority to strings to be used in vim menu commands.
646 workshop_submenu_begin(
650 if (ws_debug
&& ws_dlevel
& WS_TRACE
651 && strncmp(curMenuName
, "ToolBar", 7) != 0)
652 wstrace("workshop_submenu_begin(%s)\n", label
);
655 strcat(curMenuName
, ".");
656 strcat(curMenuName
, fixup(label
));
658 updatePriority(True
);
662 * Remove the submenu name and priority from curMenu*.
666 workshop_submenu_end()
671 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
)
672 && strncmp(curMenuName
, "ToolBar", 7) != 0)
673 wstrace("workshop_submenu_end()\n");
676 p
= strrchr(curMenuPriority
, '.');
680 p
= strrchr(curMenuName
, '.');
686 * This is where menus are really made. Each item will generate an amenu vim
687 * command. The globals curMenuName and curMenuPriority contain the name and
688 * priority of the parent menu tree.
694 char *accelerator UNUSED
,
695 char *acceleratorText
,
697 char *filepos UNUSED
,
701 char namebuf
[BUFSIZ
];
702 char accText
[BUFSIZ
];
705 if (WSDLEVEL(WS_TRACE_VERBOSE
)
706 && strncmp(curMenuName
, "ToolBar", 7) != 0)
708 if (ws_dlevel
& WS_TRACE_VERBOSE
)
709 wsdebug("workshop_menu_item(\n"
710 "\tlabel = \"%s\",\n"
712 "\taccelerator = %s,\n"
713 "\tacceleratorText = \"%s\",\n"
716 "\tsensitive = %s)\n",
717 label
&& *label
? label
: "<None>",
718 verb
&& *verb
? verb
: "<None>",
719 accelerator
&& *accelerator
?
720 accelerator
: "<None>",
721 acceleratorText
&& *acceleratorText
?
722 acceleratorText
: "<None>",
723 name
&& *name
? name
: "<None>",
724 filepos
&& *filepos
? filepos
: "<None>",
726 else if (ws_dlevel
& WS_TRACE
)
727 wstrace("workshop_menu_item(\"%s\", %s)\n",
728 label
&& *label
? label
: "<None>",
729 verb
&& *verb
? verb
: "<None>", sensitive
);
734 wstrace("menu: %-21.20s%-21.20s(%s)\n", label
, verb
,
735 *sensitive
== '1' ? "Sensitive" : "Insensitive");
738 if (acceleratorText
!= NULL
)
739 vim_snprintf(accText
, sizeof(accText
), "<Tab>%s", acceleratorText
);
742 updatePriority(False
);
743 vim_snprintf(namebuf
, sizeof(namebuf
), "%s.%s", curMenuName
, fixup(label
));
744 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu %s %s%s\t:wsverb %s<CR>",
745 curMenuPriority
, namebuf
, accText
, verb
);
747 coloncmd(cbuf
, TRUE
);
748 addMenu(namebuf
, fixAccelText(acceleratorText
), verb
);
750 if (*sensitive
== '0')
752 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
753 coloncmd(cbuf
, TRUE
);
758 * This function is called when a complete WorkShop menu description has been
759 * sent over from eserve. We do some menu cleanup.
765 Boolean using_tearoff
; /* set per current option setting */
768 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
769 wstrace("workshop_menu_end()\n");
772 using_tearoff
= vim_strchr(p_go
, GO_TEAROFF
) != NULL
;
773 gui_mch_toggle_tearoffs(using_tearoff
);
777 workshop_toolbar_begin()
780 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
781 wstrace("workshop_toolbar_begin()\n");
784 coloncmd("aunmenu ToolBar", True
);
789 workshop_toolbar_end()
794 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
796 wstrace("workshop_toolbar_end()\n");
804 if (vim_strchr(p_go
, 'T') == NULL
)
807 set_option_value((char_u
*)"go", 0L, buf
, 0);
809 workshopInitDone
= True
;
813 workshop_toolbar_button(
816 char *senseVerb UNUSED
,
817 char *filepos UNUSED
,
823 char cbuf
[BUFSIZ
+ MAXPATHLEN
];
824 char namebuf
[BUFSIZ
];
830 if (WSDLEVEL(WS_TRACE_VERBOSE
))
831 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
832 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
833 label
&& *label
? label
: "<None>",
834 verb
&& *verb
? verb
: "<None>",
835 senseVerb
&& *senseVerb
? senseVerb
: "<None>",
836 filepos
&& *filepos
? filepos
: "<None>",
837 help
&& *help
? help
: "<None>",
838 sense
&& *sense
? sense
: "<None>",
839 file
&& *file
? file
: "<None>",
840 left
&& *left
? left
: "<None>");
841 else if (WSDLEVEL(WS_TRACE
))
842 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
843 label
&& *label
? label
: "<None>",
844 verb
&& *verb
? verb
: "<None>");
848 wsdebug("button: %-21.20s%-21.20s(%s)\n", label
, verb
,
849 *sense
== '1' ? "Sensitive" : "Insensitive");
852 if (left
&& *left
&& atoi(left
) > 0)
854 /* Add a separator (but pass the width passed after the ':') */
855 sprintf(cbuf
, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
856 tbpri
- 5, tbid
++, left
);
858 coloncmd(cbuf
, True
);
861 p
= vim_strsave_escaped((char_u
*)label
, (char_u
*)"\\. ");
862 vim_snprintf(namebuf
, sizeof(namebuf
), "ToolBar.%s", p
);
864 STRCPY(cbuf
, "amenu <silent> ");
865 if (file
!= NULL
&& *file
!= NUL
)
867 p
= vim_strsave_escaped((char_u
*)file
, (char_u
*)" ");
869 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
, "icon=%s ", p
);
873 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
,"1.%d %s :wsverb %s<CR>",
874 tbpri
, namebuf
, verb
);
876 /* Define the menu item */
877 coloncmd(cbuf
, True
);
881 /* If menu isn't sensitive at startup... */
882 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
883 coloncmd(cbuf
, True
);
889 vim_snprintf(cbuf
, sizeof(cbuf
), "tmenu %s %s", namebuf
, help
);
890 coloncmd(cbuf
, True
);
893 addMenu(namebuf
, NULL
, verb
);
898 workshop_frame_sensitivities(
899 VerbSense
*vs
) /* list of verbs to (de)sensitize */
901 VerbSense
*vp
; /* iterate through vs */
902 char *menu_name
; /* used in menu lookup */
903 int cnt
; /* count of verbs to skip */
904 int len
; /* length of nonvariant part of command */
908 if (WSDLEVEL(WS_TRACE_VERBOSE
) || WSDLEVEL(4))
910 wsdebug("workshop_frame_sensitivities(\n");
911 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
912 wsdebug("\t%-25s%d\n", vp
->verb
, vp
->sense
);
915 else if (WSDLEVEL(WS_TRACE
))
916 wstrace("workshop_frame_sensitivities()\n");
920 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
921 wsdebug("change: %-21.20s%-21.20s(%s)\n",
922 "", vp
->verb
, vp
->sense
== 1 ?
923 "Sensitive" : "Insensitive");
927 * Look for all matching menu entries for the verb. There may be more
928 * than one if the verb has both a menu and toolbar entry.
930 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
933 strcpy(cbuf
, "amenu");
935 strcat(cbuf
, vp
->sense
? "enable" : "disable");
938 while ((menu_name
= lookupVerb(vp
->verb
, cnt
++)) != NULL
)
940 strcpy(&cbuf
[len
], menu_name
);
941 coloncmd(cbuf
, FALSE
);
950 char *option
, /* name of a supported option */
951 char *value
) /* value to set option to */
953 char cbuf
[BUFSIZ
]; /* command buffer */
956 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
958 wstrace("workshop_set_option(%s, %s)\n", option
, value
);
963 switch (*option
) /* switch on 1st letter */
966 if (strcmp(option
, "syntax") == 0)
967 vim_snprintf(cbuf
, sizeof(cbuf
), "syntax %s", value
);
968 else if (strcmp(option
, "savefiles") == 0)
970 /* XXX - Not yet implemented */
975 if (strcmp(option
, "lineno") == 0)
976 sprintf(cbuf
, "set %snu",
977 (strcmp(value
, "on") == 0) ? "" : "no");
981 if (strcmp(option
, "parentheses") == 0)
982 sprintf(cbuf
, "set %ssm",
983 (strcmp(value
, "on") == 0) ? "" : "no");
987 /* this option is set by a direct call */
989 wsdebug("workshop_set_option: "
990 "Got unexpected workshopkeys option");
994 case 'b': /* these options are set from direct calls */
995 if (option
[7] == NUL
&& strcmp(option
, "balloon") == 0)
998 /* set by direct call to workshop_balloon_mode */
999 wsdebug("workshop_set_option: "
1000 "Got unexpected ballooneval option");
1003 else if (strcmp(option
, "balloondelay") == 0)
1006 /* set by direct call to workshop_balloon_delay */
1007 wsdebug("workshop_set_option: "
1008 "Got unexpected balloondelay option");
1014 coloncmd(cbuf
, TRUE
);
1019 workshop_balloon_mode(
1022 char cbuf
[BUFSIZ
]; /* command buffer */
1024 #ifdef WSDEBUG_TRACE
1025 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1026 wstrace("workshop_balloon_mode(%s)\n", on
? "True" : "False");
1029 sprintf(cbuf
, "set %sbeval", on
? "" : "no");
1030 coloncmd(cbuf
, TRUE
);
1035 workshop_balloon_delay(
1038 char cbuf
[BUFSIZ
]; /* command buffer */
1040 #ifdef WSDEBUG_TRACE
1041 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1042 wstrace("workshop_balloon_delay(%d)\n", delay
);
1045 sprintf(cbuf
, "set bdlay=%d", delay
);
1046 coloncmd(cbuf
, TRUE
);
1051 workshop_show_balloon_tip(
1054 #ifdef WSDEBUG_TRACE
1055 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1056 wstrace("workshop_show_balloon_tip(%s)\n", tip
);
1059 if (balloonEval
!= NULL
)
1060 gui_mch_post_balloon(balloonEval
, (char_u
*)tip
);
1068 char cbuf
[BUFSIZ
]; /* command buffer */
1069 MenuMap
*mp
; /* iterate over menuMap entries */
1071 #ifdef WSDEBUG_TRACE
1072 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1073 wstrace("workshop_hotkeys(%s)\n", on
? "True" : "False");
1076 workshopHotKeysEnabled
= on
;
1077 if (workshopHotKeysEnabled
)
1078 for (mp
= menuMap
; mp
< &menuMap
[menuMapSize
]; mp
++)
1080 if (mp
->accel
!= NULL
)
1082 vim_snprintf(cbuf
, sizeof(cbuf
),
1083 "map %s :wsverb %s<CR>", mp
->accel
, mp
->verb
);
1084 coloncmd(cbuf
, TRUE
);
1088 for (mp
= menuMap
; mp
< &menuMap
[menuMapSize
]; mp
++)
1090 if (mp
->accel
!= NULL
)
1092 vim_snprintf(cbuf
, sizeof(cbuf
), "unmap %s", mp
->accel
);
1093 coloncmd(cbuf
, TRUE
);
1099 * A button in the toolbar has been pushed.
1102 workshop_get_positions(
1103 void *clientData UNUSED
,
1104 char **filename
, /* output data */
1105 int *curLine
, /* output data */
1106 int *curCol
, /* output data */
1107 int *selStartLine
, /* output data */
1108 int *selStartCol
, /* output data */
1109 int *selEndLine
, /* output data */
1110 int *selEndCol
, /* output data */
1111 int *selLength
, /* output data */
1112 char **selection
) /* output data */
1114 static char ffname
[MAXPATHLEN
];
1116 #ifdef WSDEBUG_TRACE
1117 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1118 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1119 clientData
, (curbuf
&& curbuf
->b_sfname
!= NULL
)
1120 ? (char *)curbuf
->b_sfname
: "<None>");
1123 if (curbuf
->b_ffname
== NULL
)
1126 /* copy so nobody can change b_ffname */
1127 strcpy(ffname
, (char *) curbuf
->b_ffname
);
1129 *curLine
= curwin
->w_cursor
.lnum
;
1130 *curCol
= curwin
->w_cursor
.col
;
1132 if (curbuf
->b_visual
.vi_mode
== 'v' &&
1133 equalpos(curwin
->w_cursor
, curbuf
->b_visual
.vi_end
))
1135 *selStartLine
= curbuf
->b_visual
.vi_start
.lnum
;
1136 *selStartCol
= curbuf
->b_visual
.vi_start
.col
;
1137 *selEndLine
= curbuf
->b_visual
.vi_end
.lnum
;
1138 *selEndCol
= curbuf
->b_visual
.vi_end
.col
;
1139 *selection
= get_selection(curbuf
);
1141 *selLength
= strlen(*selection
);
1147 *selStartLine
= *selEndLine
= -1;
1148 *selStartCol
= *selEndCol
= -1;
1158 /************************************************************************
1160 ************************************************************************/
1164 buf_T
*buf
) /* buffer whose selection we want */
1166 pos_T
*start
; /* start of the selection */
1167 pos_T
*end
; /* end of the selection */
1168 char *lp
; /* pointer to actual line data */
1169 int llen
; /* length of actual line data */
1170 char *sp
; /* pointer to selection buffer */
1171 int slen
; /* string length in selection buffer */
1172 int size
; /* size of selection buffer */
1173 char *new_sp
; /* temp pointer to new sp */
1174 int lnum
; /* line number we are appending */
1176 if (buf
->b_visual
.vi_mode
== 'v')
1178 start
= &buf
->b_visual
.vi_start
;
1179 end
= &buf
->b_visual
.vi_end
;
1180 if (start
->lnum
== end
->lnum
)
1182 /* selection is all on one line */
1183 lp
= (char *) ml_get_pos(start
);
1184 llen
= end
->col
- start
->col
+ 1;
1185 sp
= (char *) malloc(llen
+ 1);
1188 strncpy(sp
, lp
, llen
);
1194 /* multi-line selection */
1195 lp
= (char *) ml_get_pos(start
);
1197 sp
= (char *) malloc(BUFSIZ
+ llen
);
1200 size
= BUFSIZ
+ llen
;
1205 lnum
= start
->lnum
+ 1;
1206 while (lnum
< end
->lnum
)
1207 sp
= append_selection(lnum
++, sp
, &size
, &slen
);
1209 lp
= (char *) ml_get(end
->lnum
);
1210 llen
= end
->col
+ 1;
1211 if ((slen
+ llen
) >= size
)
1214 realloc(sp
, slen
+ llen
+ 1);
1221 if ((slen
+ llen
) < size
)
1223 strncpy(&sp
[slen
], lp
, llen
);
1224 sp
[slen
+ llen
] = NUL
;
1238 int lnum
, /* line number to append */
1239 char *sp
, /* pointer to selection buffer */
1240 int *size
, /* ptr to size of sp */
1241 int *slen
) /* ptr to length of selection string */
1243 char *lp
; /* line of data from buffer */
1244 int llen
; /* strlen of lp */
1245 char *new_sp
; /* temp pointer to new sp */
1247 lp
= (char *)ml_get((linenr_T
)lnum
);
1250 if ((*slen
+ llen
) <= *size
)
1252 new_sp
= (char *) realloc((void *) sp
, BUFSIZ
+ *slen
+ llen
);
1255 *size
= BUFSIZ
+ *slen
+ llen
;
1259 if ((*slen
+ llen
) > *size
)
1261 strcat(&sp
[*slen
], lp
);
1272 load_buffer_by_name(
1273 char *filename
, /* the file to load */
1274 int lnum
) /* an optional line number (or 0) */
1276 char lnumbuf
[16]; /* make line number option for :e */
1277 char cbuf
[BUFSIZ
]; /* command buffer */
1280 sprintf(lnumbuf
, "+%d", lnum
);
1284 vim_snprintf(cbuf
, sizeof(cbuf
), "e %s %s", lnumbuf
, filename
);
1285 coloncmd(cbuf
, False
);
1291 char *filename
, /* filename to load */
1292 int lnum
) /* linenumber to go to */
1294 buf_T
*buf
; /* buffer filename is stored in */
1295 win_T
*win
; /* window filenme is displayed in */
1298 * Make sure filename is displayed and is the current window.
1301 buf
= buflist_findname((char_u
*)filename
);
1302 if (buf
== NULL
|| (win
= get_window(buf
)) == NULL
)
1304 /* No buffer or buffer is not in current window */
1305 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1307 load_buffer_by_name(filename
, lnum
);
1311 /* buf is in a window */
1314 win_enter(win
, False
);
1315 /* wsdebug("load_window: window endter %s\n",
1316 win->w_buffer->b_sfname); */
1318 if (lnum
> 0 && win
->w_cursor
.lnum
!= lnum
)
1321 /* wsdebug("load_window: warp to %s[%d]\n",
1322 win->w_buffer->b_sfname, lnum); */
1332 int lnum
) /* line number to warp to */
1334 char lbuf
[256]; /* build line command here */
1339 add_to_input_buf((char_u
*) "\033", 1);
1340 if (isShowing(lnum
))
1341 sprintf(lbuf
, "%dG", lnum
);
1343 sprintf(lbuf
, "%dz.", lnum
);
1344 add_to_input_buf((char_u
*) lbuf
, strlen(lbuf
));
1350 int lnum
) /* tell if line number is showing */
1352 return lnum
>= curwin
->w_topline
&& lnum
< curwin
->w_botline
;
1359 buf_T
*buf
) /* buffer to find window for */
1361 win_T
*wp
= NULL
; /* window filename is in */
1363 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
1364 if (buf
== wp
->w_buffer
)
1370 #if 0 /* not used */
1373 buf_T
*buf
) /* buffer to get position of */
1375 buf_T
*bp
; /* iterate over buffer list */
1376 int pos
; /* the position in the buffer list */
1379 for (bp
= firstbuf
; bp
!= NULL
; bp
= bp
->b_next
)
1392 Boolean subMenu
) /* if True then start new submenu pri */
1394 int pri
; /* priority of this menu/item */
1397 p
= strrchr(curMenuPriority
, '.');
1401 pri
= atoi(p
) + 10; /* our new priority */
1404 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1405 "%s.%d.0", curMenuPriority
, pri
);
1407 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1408 "%s.%d", curMenuPriority
, pri
);
1413 char *mnemonics
, /* currently used mnemonics */
1414 char *label
) /* label of menu needing mnemonic */
1416 static char name
[BUFSIZ
]; /* buffer for the updated name */
1417 char *p
; /* pointer into label */
1418 char *found
; /* pointer to possible mnemonic */
1421 for (p
= label
; *p
!= NUL
; p
++)
1422 if (strchr(mnemonics
, *p
) == 0)
1423 if (found
== NULL
|| (isupper((int)*p
) && islower((int)*found
)))
1428 strncpy(name
, label
, (found
- label
));
1430 strcat(name
, found
);
1433 strcpy(name
, label
);
1439 * Some characters in a menu name must be escaped in vim. Since this is vim
1440 * specific, it must be done on this side.
1446 static char buf
[BUFSIZ
];
1447 char *bp
; /* pointer into buf */
1448 char *lp
; /* pointer into label */
1454 if (*lp
== ' ' || *lp
== '.')
1464 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1466 /* For the NoHands test suite */
1469 workshop_test_getcurrentfile()
1471 char *filename
, *selection
;
1472 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1473 int selEndCol
, selLength
;
1475 if (workshop_get_positions(
1476 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1477 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1485 workshop_test_getcursorrow()
1491 workshop_test_getcursorcol()
1493 char *filename
, *selection
;
1494 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1495 int selEndCol
, selLength
;
1497 if (workshop_get_positions(
1498 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1499 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1507 workshop_test_getcursorrowtext()
1513 workshop_test_getselectedtext()
1515 char *filename
, *selection
;
1516 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1517 int selEndCol
, selLength
;
1519 if (workshop_get_positions(
1520 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1521 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1529 workshop_save_sensitivity(char *filename UNUSED
)
1537 char *ap
) /* original acceleratorText */
1539 char buf
[256]; /* build in temp buffer */
1540 char *shift
; /* shift string of "" */
1545 /* If the accelerator is shifted use the vim form */
1546 if (strncmp("Shift+", ap
, 6) == 0)
1554 if (*ap
== 'F' && atoi(&ap
[1]) > 0)
1556 vim_snprintf(buf
, sizeof(buf
), "<%s%s>", shift
, ap
);
1575 char buf
[MAXPATHLEN
* 2];
1576 static int serialNo
= -1;
1581 if (get_beval_info(beval
, FALSE
, &wp
, &lnum
, &text
, &col
) == OK
)
1583 if (text
&& text
[0])
1585 /* Send debugger request */
1586 if (strlen((char *) text
) > (MAXPATHLEN
/2))
1589 * The user has probably selected the entire
1590 * buffer or something like that - don't attempt
1597 * WorkShop expects the col to be a character index, not
1598 * a column number. Compute the index from col. Also set
1599 * line to 0 because thats what dbx expects.
1602 idx
= computeIndex(col
, text
, beval
->ts
, beval
->vts
);
1604 idx
= computeIndex(col
, text
, beval
->ts
);
1611 * If successful, it will respond with a balloon cmd.
1613 if (state
& ControlMask
)
1614 /* Evaluate *(expression) */
1615 type
= (int)GPLineEval_INDIRECT
;
1616 else if (state
& ShiftMask
)
1617 /* Evaluate type(expression) */
1618 type
= (int)GPLineEval_TYPE
;
1620 /* Evaluate value(expression) */
1621 type
= (int)GPLineEval_EVALUATE
;
1623 /* Send request to dbx */
1624 vim_snprintf(buf
, sizeof(buf
), "toolVerb debug.balloonEval "
1625 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1626 (char *)wp
->w_buffer
->b_ffname
,
1627 (long)lnum
, idx
, type
, serialNo
++,
1628 (long)strlen((char *)text
), (char *)text
);
1629 balloonEval
= beval
;
1630 workshop_send_message(buf
);
1651 if (line
[idx
] == '\t')
1653 col
+= tabstop_padding(col
, ts
, vts
);
1655 col
+= ts
- (col
% ts
);
1660 if (col
>= wantedCol
)
1670 char *menu
, /* menu name */
1671 char *accel
, /* accelerator text (optional) */
1672 char *verb
) /* WorkShop action-verb */
1677 if (menuMapSize
>= menuMapMax
)
1679 newMap
= realloc(menuMap
,
1680 sizeof(MenuMap
) * (menuMapMax
+ MENU_INC
));
1684 menuMapMax
+= MENU_INC
;
1687 if (menuMapSize
< menuMapMax
)
1689 menuMap
[menuMapSize
].name
= strdup(menu
);
1690 menuMap
[menuMapSize
].accel
= accel
&& *accel
? strdup(accel
) : NULL
;
1691 menuMap
[menuMapSize
++].verb
= strdup(verb
);
1692 if (accel
&& workshopHotKeysEnabled
)
1694 vim_snprintf(cbuf
, sizeof(cbuf
),
1695 "map %s :wsverb %s<CR>", accel
, verb
);
1696 coloncmd(cbuf
, TRUE
);
1703 char *raw
) /* menu name, possibly with & chars */
1705 static char buf
[BUFSIZ
]; /* build stripped name here */
1722 int skip
) /* number of matches to skip */
1724 int i
; /* loop iterator */
1726 for (i
= 0; i
< menuMapSize
; i
++)
1727 if (strcmp(menuMap
[i
].verb
, verb
) == 0 && skip
-- == 0)
1728 return nameStrip(menuMap
[i
].name
);
1736 char *cmd
, /* the command to print */
1737 Boolean force
) /* force cursor update */
1739 char_u
*cpo_save
= p_cpo
;
1742 if (WSDLEVEL(WS_TRACE_COLONCMD
))
1743 wsdebug("Cmd: %s\n", cmd
);
1746 p_cpo
= empty_option
;
1749 do_cmdline_cmd((char_u
*)cmd
);
1755 gui_update_screen();
1759 * setDollarVim - Given the run directory, search for the vim install
1760 * directory and set $VIM.
1762 * We can be running out of SUNWspro/bin or out of
1763 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1764 * relative to both of these directories.
1770 char buf
[MAXPATHLEN
];
1774 * First case: Running from <install-dir>/SUNWspro/bin
1776 strcpy(buf
, rundir
);
1777 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1778 VIM_VERSION_NODOT
"/syntax/syntax.vim");
1779 if (access(buf
, R_OK
) == 0)
1781 strcpy(buf
, "SPRO_WSDIR=");
1782 strcat(buf
, rundir
);
1783 cp
= strrchr(buf
, '/');
1785 strcpy(cp
, "/WS6U2");
1786 putenv(strdup(buf
));
1788 strcpy(buf
, "VIM=");
1789 strcat(buf
, rundir
);
1790 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1792 putenv(strdup(buf
));
1797 * Second case: Probably running from
1798 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1800 strcpy(buf
, rundir
);
1801 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1802 "/share/vim/" VIM_VERSION_NODOT
"/syntax/syntax.vim");
1803 if (access(buf
, R_OK
) == 0)
1805 strcpy(buf
, "SPRO_WSDIR=");
1806 strcat(buf
, rundir
);
1807 cp
= strrchr(buf
, '/');
1809 strcpy(cp
, "../../../../WS6U2");
1810 putenv(strdup(buf
));
1812 strcpy(buf
, "VIM=");
1813 strcat(buf
, rundir
);
1814 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1815 "/share/vim/" VIM_VERSION_NODOT
);
1816 putenv(strdup(buf
));
1822 * findYourself - Find the directory we are running from. This is used to
1823 * set $VIM. We need to set this because users can install
1824 * the package in a different directory than the compiled
1825 * directory. This is a Sun Visual WorkShop requirement!
1827 * Note: We override a user's $VIM because it won't have the
1828 * WorkShop specific files. S/he may not like this but its
1829 * better than getting the wrong files (especially as the
1830 * user is likely to have $VIM set to 5.4 or later).
1836 char *runpath
= NULL
;
1841 runpath
= strdup(argv0
);
1842 else if (*argv0
== '.' || strchr(argv0
, '/'))
1844 runpath
= (char *) malloc(MAXPATHLEN
);
1845 getcwd(runpath
, MAXPATHLEN
);
1846 strcat(runpath
, "/");
1847 strcat(runpath
, argv0
);
1851 path
= getenv("PATH");
1854 runpath
= (char *) malloc(MAXPATHLEN
);
1855 pathbuf
= strdup(path
);
1856 path
= strtok(pathbuf
, ":");
1859 strcpy(runpath
, path
);
1860 strcat(runpath
, "/");
1861 strcat(runpath
, argv0
);
1862 if (access(runpath
, X_OK
) == 0)
1864 } while ((path
= strtok(NULL
, ":")) != NULL
);
1869 if (runpath
!= NULL
)
1871 char runbuf
[MAXPATHLEN
];
1874 * We found the run directory. Now find the install dir.
1876 (void)vim_FullName((char_u
*)runpath
, (char_u
*)runbuf
, MAXPATHLEN
, 1);
1877 path
= strrchr(runbuf
, '/');
1879 *path
= NUL
; /* remove the vim/gvim name */
1880 path
= strrchr(runbuf
, '/');
1883 if (strncmp(path
, "/bin", 4) == 0)
1884 setDollarVim(runbuf
);
1885 else if (strncmp(path
, "/src", 4) == 0)
1887 *path
= NUL
; /* development tree */
1888 setDollarVim(runbuf
);