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);
60 static int computeIndex(int, char_u
*, int);
62 static char *fixAccelText(char *);
63 static void addMenu(char *, char *, char *);
64 static char *lookupVerb(char *, int);
65 static void coloncmd(char *, Boolean
);
67 extern Widget vimShell
;
68 extern Widget textArea
;
69 extern XtAppContext app_context
;
71 static int tbpri
; /* ToolBar priority */
72 int usingSunWorkShop
= 0; /* set if -ws flag is used */
73 char curMenuName
[BUFSIZ
];
74 char curMenuPriority
[BUFSIZ
];
76 static Boolean workshopInitDone
= False
;
77 static Boolean workshopHotKeysEnabled
= False
;
80 * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it
81 * here because its C++.
85 GPLineEval_EVALUATE
, /* evaluate expression */
86 GPLineEval_INDIRECT
, /* evaluate *<expression> */
87 GPLineEval_TYPE
/* type of expression */
91 * Store each verb in the MenuMap. This lets us map from a verb to a menu.
92 * There may be multiple matches for a single verb in this table.
94 #define MENU_INC 50 /* menuMap incremental size increases */
97 char *name
; /* name of the menu */
98 char *accel
; /* optional accelerator key */
99 char *verb
; /* menu verb */
101 static MenuMap
*menuMap
; /* list of verb/menu mappings */
102 static int menuMapSize
; /* current size of menuMap */
103 static int menuMapMax
; /* allocated size of menuMap */
104 static char *initialFileCmd
; /* save command but defer doing it */
111 int is_dirty
= FALSE
;
116 * Turn on MenuBar, ToolBar, and Footer.
119 if (vim_strchr(p_go
, GO_MENUS
) == NULL
)
124 if (vim_strchr(p_go
, GO_TOOLBAR
) == NULL
)
129 if (vim_strchr(p_go
, GO_FOOTER
) == NULL
)
135 set_option_value((char_u
*)"go", 0L, buf
, 0);
138 * Set size from workshop_get_width_height().
141 if (workshop_get_width_height(&width
, &height
))
143 XtVaSetValues(vimShell
,
150 * Now read in the initial messages from eserve.
152 while ((mask
= XtAppPending(app_context
))
153 && (mask
& XtIMAlternateInput
) && !workshopInitDone
)
154 XtAppProcessEvent(app_context
, (XtInputMask
)XtIMAlternateInput
);
160 do_cmdline_cmd((char_u
*)initialFileCmd
);
162 free(initialFileCmd
);
163 initialFileCmd
= NULL
;
167 ex_wsverb(exarg_T
*eap
)
170 workshop_perform_verb((char *) eap
->arg
, NULL
);
175 * This string is recognized by eserve and should be all lower case.
176 * This is how the editor detects that it is talking to gvim instead
177 * of NEdit, for example, when the connection is initiated from the editor.
180 workshop_get_editor_name()
186 * Version number of the editor.
187 * This number is communicated along with the protocol
188 * version to the application.
191 workshop_get_editor_version()
197 * Answer functions: called by eserve
205 * Load a given file into the WorkShop buffer.
209 char *filename
, /* the file to load */
210 int line
, /* an optional line number (or 0) */
211 char *frameid UNUSED
) /* used for multi-frame support */
214 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
215 wstrace("workshop_load_file(%s, %d)\n", filename
, line
);
219 bevalServers
|= BEVAL_WORKSHOP
;
222 load_window(filename
, line
);
226 * Reload the WorkShop buffer
229 workshop_reload_file(
234 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
235 wstrace("workshop_reload_file(%s, %d)\n", filename
, line
);
237 load_window(filename
, line
);
245 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
246 wstrace("workshop_show_file(%s)\n", filename
);
249 load_window(filename
, 0);
258 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
259 wstrace("workshop_goto_line(%s, %d)\n", filename
, lineno
);
262 load_window(filename
, lineno
);
267 char *filename UNUSED
)
270 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
271 wstrace("workshop_front_file()\n");
274 * Assumption: This function will always be called after a call to
275 * workshop_show_file(), so the file is always showing.
277 if (vimShell
!= NULL
)
278 XRaiseWindow(gui
.dpy
, XtWindow(vimShell
));
285 char cbuf
[BUFSIZ
]; /* build vim command here */
288 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
289 wstrace("workshop_save_file(%s)\n", filename
);
292 /* Save the given file */
293 vim_snprintf(cbuf
, sizeof(cbuf
), "w %s", filename
);
294 coloncmd(cbuf
, TRUE
);
298 workshop_save_files()
300 /* Save the given file */
302 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
303 wstrace("workshop_save_files()\n");
306 add_to_input_buf((char_u
*) ":wall\n", 6);
313 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
314 wstrace("workshop_quit()\n");
317 add_to_input_buf((char_u
*) ":qall\n", 6);
324 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
325 wstrace("workshop_minimize()\n");
327 workshop_minimize_shell(vimShell
);
333 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
334 wstrace("workshop_maximize()\n");
337 workshop_maximize_shell(vimShell
);
341 workshop_add_mark_type(
346 char gbuf
[BUFSIZ
]; /* buffer for sign name */
347 char cibuf
[BUFSIZ
]; /* color information */
348 char cbuf
[BUFSIZ
]; /* command buffer */
352 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
356 cp
= strrchr(sign
, '/');
360 cp
++; /* skip '/' character */
361 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx
,
362 colorspec
&& *colorspec
? colorspec
: "<None>", cp
);
367 * Isolate the basename of sign in gbuf. We will use this for the
368 * GroupName in the highlight command sent to vim.
370 STRCPY(gbuf
, gettail((char_u
*)sign
));
371 bp
= strrchr(gbuf
, '.');
375 if (gbuf
[0] != '-' && gbuf
[1] != NUL
)
377 if (colorspec
!= NULL
&& *colorspec
)
379 vim_snprintf(cbuf
, sizeof(cbuf
),
380 "highlight WS%s guibg=%s", gbuf
, colorspec
);
381 coloncmd(cbuf
, FALSE
);
382 vim_snprintf(cibuf
, sizeof(cibuf
), "linehl=WS%s", gbuf
);
387 vim_snprintf(cbuf
, sizeof(cbuf
),
388 "sign define %d %s icon=%s", idx
, cibuf
, sign
);
389 coloncmd(cbuf
, TRUE
);
395 char *filename
, /* filename which gets the mark */
396 int lineno
, /* line number which gets the mark */
397 int markId
, /* unique mark identifier */
398 int idx
) /* which mark to use */
400 char cbuf
[BUFSIZ
]; /* command buffer */
402 /* Set mark in a given file */
404 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
405 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n",
406 filename
, lineno
, markId
, idx
);
409 vim_snprintf(cbuf
, sizeof(cbuf
), "sign place %d line=%d name=%d file=%s",
410 markId
, lineno
, idx
, filename
);
411 coloncmd(cbuf
, TRUE
);
415 workshop_change_mark_type(
416 char *filename
, /* filename which gets the mark */
417 int markId
, /* unique mark identifier */
418 int idx
) /* which mark to use */
420 char cbuf
[BUFSIZ
]; /* command buffer */
422 /* Change mark type */
424 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
425 wstrace("workshop_change_mark_type(%s, %d, %d)\n",
426 filename
, markId
, idx
);
429 vim_snprintf(cbuf
, sizeof(cbuf
),
430 "sign place %d name=%d file=%s", markId
, idx
, filename
);
431 coloncmd(cbuf
, TRUE
);
435 * Goto the given mark in a file (e.g. show it).
436 * If message is not null, display it in the footer.
444 char cbuf
[BUFSIZ
]; /* command buffer */
448 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
449 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
450 filename
, markId
, message
&& *message
&&
451 !(*message
== ' ' && message
[1] == NULL
) ?
455 vim_snprintf(cbuf
, sizeof(cbuf
), "sign jump %d file=%s", markId
, filename
);
456 coloncmd(cbuf
, TRUE
);
457 if (message
!= NULL
&& *message
!= NUL
)
458 gui_mch_set_footer((char_u
*)message
);
462 workshop_delete_mark(
466 char cbuf
[BUFSIZ
]; /* command buffer */
470 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
471 wstrace("workshop_delete_mark(%s, %d (id))\n",
475 vim_snprintf(cbuf
, sizeof(cbuf
),
476 "sign unplace %d file=%s", markId
, filename
);
477 coloncmd(cbuf
, TRUE
);
482 workshop_delete_all_marks(
487 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
488 wstrace("workshop_delete_all_marks(%#x, %s)\n",
489 window
, doRefresh
? "True" : "False");
492 coloncmd("sign unplace *", TRUE
);
497 workshop_get_mark_lineno(
501 buf_T
*buf
; /* buffer containing filename */
502 int lineno
; /* line number of filename in buf */
504 /* Get mark line number */
506 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
507 wstrace("workshop_get_mark_lineno(%s, %d)\n",
512 buf
= buflist_findname((char_u
*)filename
);
514 lineno
= buf_findsign(buf
, markId
);
522 workshop_adjust_marks(Widget
*window
, int pos
,
523 int inserted
, int deleted
)
526 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
527 wstrace("XXXworkshop_adjust_marks(%s, %d, %d, %d)\n",
528 window
? XtName(window
) : "<None>", pos
, inserted
, deleted
);
534 * Are there any moved marks? If so, call workshop_move_mark on
535 * each of them now. This is how eserve can find out if for example
536 * breakpoints have moved when a program has been recompiled and
540 workshop_moved_marks(char *filename UNUSED
)
543 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
544 wstrace("XXXworkshop_moved_marks(%s)\n", filename
);
549 workshop_get_font_height()
551 XmFontList fontList
; /* fontList made from gui.norm_font */
557 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
558 wstrace("workshop_get_font_height()\n");
561 /* Pick the proper signs for this font size */
562 fontList
= gui_motif_create_fontlist((XFontStruct
*)gui
.norm_font
);
564 if (fontList
!= NULL
)
566 str
= XmStringCreateLocalized("A");
567 XmStringExtent(fontList
, str
, &w
, &h
);
569 XmFontListFree(fontList
);
576 workshop_footer_message(
578 int severity UNUSED
) /* severity is currently unused */
581 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
582 wstrace("workshop_footer_message(%s, %d)\n", message
, severity
);
585 gui_mch_set_footer((char_u
*) message
);
589 * workshop_menu_begin() is passed the menu name. We determine its mnemonic
590 * here and store its name and priority.
596 vimmenu_T
*menu
; /* pointer to last menu */
597 int menuPriority
= 0; /* priority of new menu */
598 char mnembuf
[64]; /* store menubar mnemonics here */
599 char *name
; /* label with a mnemonic */
600 char *p
; /* used to find mnemonics */
601 int idx
; /* index into mnembuf */
604 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
605 wstrace("workshop_menu_begin()\n");
609 * Look through all existing (non-PopUp and non-Toolbar) menus
610 * and gather their mnemonics. Use this list to decide what
611 * mnemonic should be used for label.
615 mnembuf
[idx
++] = 'H'; /* H is mnemonic for Help */
616 for (menu
= root_menu
; menu
!= NULL
; menu
= menu
->next
)
618 if (menu_is_menubar(menu
->name
))
620 p
= strchr((char *)menu
->name
, '&');
622 mnembuf
[idx
++] = *++p
;
624 if (menu
->next
!= NULL
625 && strcmp((char *) menu
->next
->dname
, "Help") == 0)
627 menuPriority
= menu
->priority
+ 10;
631 mnembuf
[idx
++] = NUL
;
632 name
= addUniqueMnemonic(mnembuf
, label
);
634 vim_snprintf(curMenuName
, sizeof(curMenuName
), "%s", name
);
635 sprintf(curMenuPriority
, "%d.0", menuPriority
);
639 * Append the name and priority to strings to be used in vim menu commands.
642 workshop_submenu_begin(
646 if (ws_debug
&& ws_dlevel
& WS_TRACE
647 && strncmp(curMenuName
, "ToolBar", 7) != 0)
648 wstrace("workshop_submenu_begin(%s)\n", label
);
651 strcat(curMenuName
, ".");
652 strcat(curMenuName
, fixup(label
));
654 updatePriority(True
);
658 * Remove the submenu name and priority from curMenu*.
662 workshop_submenu_end()
667 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
)
668 && strncmp(curMenuName
, "ToolBar", 7) != 0)
669 wstrace("workshop_submenu_end()\n");
672 p
= strrchr(curMenuPriority
, '.');
676 p
= strrchr(curMenuName
, '.');
682 * This is where menus are really made. Each item will generate an amenu vim
683 * command. The globals curMenuName and curMenuPriority contain the name and
684 * priority of the parent menu tree.
690 char *accelerator UNUSED
,
691 char *acceleratorText
,
693 char *filepos UNUSED
,
697 char namebuf
[BUFSIZ
];
698 char accText
[BUFSIZ
];
701 if (WSDLEVEL(WS_TRACE_VERBOSE
)
702 && strncmp(curMenuName
, "ToolBar", 7) != 0)
704 if (ws_dlevel
& WS_TRACE_VERBOSE
)
705 wsdebug("workshop_menu_item(\n"
706 "\tlabel = \"%s\",\n"
708 "\taccelerator = %s,\n"
709 "\tacceleratorText = \"%s\",\n"
712 "\tsensitive = %s)\n",
713 label
&& *label
? label
: "<None>",
714 verb
&& *verb
? verb
: "<None>",
715 accelerator
&& *accelerator
?
716 accelerator
: "<None>",
717 acceleratorText
&& *acceleratorText
?
718 acceleratorText
: "<None>",
719 name
&& *name
? name
: "<None>",
720 filepos
&& *filepos
? filepos
: "<None>",
722 else if (ws_dlevel
& WS_TRACE
)
723 wstrace("workshop_menu_item(\"%s\", %s)\n",
724 label
&& *label
? label
: "<None>",
725 verb
&& *verb
? verb
: "<None>", sensitive
);
730 wstrace("menu: %-21.20s%-21.20s(%s)\n", label
, verb
,
731 *sensitive
== '1' ? "Sensitive" : "Insensitive");
734 if (acceleratorText
!= NULL
)
735 vim_snprintf(accText
, sizeof(accText
), "<Tab>%s", acceleratorText
);
738 updatePriority(False
);
739 vim_snprintf(namebuf
, sizeof(namebuf
), "%s.%s", curMenuName
, fixup(label
));
740 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu %s %s%s\t:wsverb %s<CR>",
741 curMenuPriority
, namebuf
, accText
, verb
);
743 coloncmd(cbuf
, TRUE
);
744 addMenu(namebuf
, fixAccelText(acceleratorText
), verb
);
746 if (*sensitive
== '0')
748 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
749 coloncmd(cbuf
, TRUE
);
754 * This function is called when a complete WorkShop menu description has been
755 * sent over from eserve. We do some menu cleanup.
761 Boolean using_tearoff
; /* set per current option setting */
764 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
765 wstrace("workshop_menu_end()\n");
768 using_tearoff
= vim_strchr(p_go
, GO_TEAROFF
) != NULL
;
769 gui_mch_toggle_tearoffs(using_tearoff
);
773 workshop_toolbar_begin()
776 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
777 wstrace("workshop_toolbar_begin()\n");
780 coloncmd("aunmenu ToolBar", True
);
785 workshop_toolbar_end()
790 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
792 wstrace("workshop_toolbar_end()\n");
800 if (vim_strchr(p_go
, 'T') == NULL
)
803 set_option_value((char_u
*)"go", 0L, buf
, 0);
805 workshopInitDone
= True
;
809 workshop_toolbar_button(
812 char *senseVerb UNUSED
,
813 char *filepos UNUSED
,
819 char cbuf
[BUFSIZ
+ MAXPATHLEN
];
820 char namebuf
[BUFSIZ
];
826 if (WSDLEVEL(WS_TRACE_VERBOSE
))
827 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
828 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
829 label
&& *label
? label
: "<None>",
830 verb
&& *verb
? verb
: "<None>",
831 senseVerb
&& *senseVerb
? senseVerb
: "<None>",
832 filepos
&& *filepos
? filepos
: "<None>",
833 help
&& *help
? help
: "<None>",
834 sense
&& *sense
? sense
: "<None>",
835 file
&& *file
? file
: "<None>",
836 left
&& *left
? left
: "<None>");
837 else if (WSDLEVEL(WS_TRACE
))
838 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
839 label
&& *label
? label
: "<None>",
840 verb
&& *verb
? verb
: "<None>");
844 wsdebug("button: %-21.20s%-21.20s(%s)\n", label
, verb
,
845 *sense
== '1' ? "Sensitive" : "Insensitive");
848 if (left
&& *left
&& atoi(left
) > 0)
850 /* Add a separator (but pass the width passed after the ':') */
851 sprintf(cbuf
, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
852 tbpri
- 5, tbid
++, left
);
854 coloncmd(cbuf
, True
);
857 p
= vim_strsave_escaped((char_u
*)label
, (char_u
*)"\\. ");
858 vim_snprintf(namebuf
, sizeof(namebuf
), "ToolBar.%s", p
);
860 STRCPY(cbuf
, "amenu <silent> ");
861 if (file
!= NULL
&& *file
!= NUL
)
863 p
= vim_strsave_escaped((char_u
*)file
, (char_u
*)" ");
865 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
, "icon=%s ", p
);
869 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
,"1.%d %s :wsverb %s<CR>",
870 tbpri
, namebuf
, verb
);
872 /* Define the menu item */
873 coloncmd(cbuf
, True
);
877 /* If menu isn't sensitive at startup... */
878 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
879 coloncmd(cbuf
, True
);
885 vim_snprintf(cbuf
, sizeof(cbuf
), "tmenu %s %s", namebuf
, help
);
886 coloncmd(cbuf
, True
);
889 addMenu(namebuf
, NULL
, verb
);
894 workshop_frame_sensitivities(
895 VerbSense
*vs
) /* list of verbs to (de)sensitize */
897 VerbSense
*vp
; /* iterate through vs */
898 char *menu_name
; /* used in menu lookup */
899 int cnt
; /* count of verbs to skip */
900 int len
; /* length of nonvariant part of command */
904 if (WSDLEVEL(WS_TRACE_VERBOSE
) || WSDLEVEL(4))
906 wsdebug("workshop_frame_sensitivities(\n");
907 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
908 wsdebug("\t%-25s%d\n", vp
->verb
, vp
->sense
);
911 else if (WSDLEVEL(WS_TRACE
))
912 wstrace("workshop_frame_sensitivities()\n");
916 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
917 wsdebug("change: %-21.20s%-21.20s(%s)\n",
918 "", vp
->verb
, vp
->sense
== 1 ?
919 "Sensitive" : "Insensitive");
923 * Look for all matching menu entries for the verb. There may be more
924 * than one if the verb has both a menu and toolbar entry.
926 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
929 strcpy(cbuf
, "amenu");
931 strcat(cbuf
, vp
->sense
? "enable" : "disable");
934 while ((menu_name
= lookupVerb(vp
->verb
, cnt
++)) != NULL
)
936 strcpy(&cbuf
[len
], menu_name
);
937 coloncmd(cbuf
, FALSE
);
946 char *option
, /* name of a supported option */
947 char *value
) /* value to set option to */
949 char cbuf
[BUFSIZ
]; /* command buffer */
952 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
954 wstrace("workshop_set_option(%s, %s)\n", option
, value
);
959 switch (*option
) /* switch on 1st letter */
962 if (strcmp(option
, "syntax") == 0)
963 vim_snprintf(cbuf
, sizeof(cbuf
), "syntax %s", value
);
964 else if (strcmp(option
, "savefiles") == 0)
966 /* XXX - Not yet implemented */
971 if (strcmp(option
, "lineno") == 0)
972 sprintf(cbuf
, "set %snu",
973 (strcmp(value
, "on") == 0) ? "" : "no");
977 if (strcmp(option
, "parentheses") == 0)
978 sprintf(cbuf
, "set %ssm",
979 (strcmp(value
, "on") == 0) ? "" : "no");
983 /* this option is set by a direct call */
985 wsdebug("workshop_set_option: "
986 "Got unexpected workshopkeys option");
990 case 'b': /* these options are set from direct calls */
991 if (option
[7] == NUL
&& strcmp(option
, "balloon") == 0)
994 /* set by direct call to workshop_balloon_mode */
995 wsdebug("workshop_set_option: "
996 "Got unexpected ballooneval option");
999 else if (strcmp(option
, "balloondelay") == 0)
1002 /* set by direct call to workshop_balloon_delay */
1003 wsdebug("workshop_set_option: "
1004 "Got unexpected balloondelay option");
1010 coloncmd(cbuf
, TRUE
);
1015 workshop_balloon_mode(
1018 char cbuf
[BUFSIZ
]; /* command buffer */
1020 #ifdef WSDEBUG_TRACE
1021 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1022 wstrace("workshop_balloon_mode(%s)\n", on
? "True" : "False");
1025 sprintf(cbuf
, "set %sbeval", on
? "" : "no");
1026 coloncmd(cbuf
, TRUE
);
1031 workshop_balloon_delay(
1034 char cbuf
[BUFSIZ
]; /* command buffer */
1036 #ifdef WSDEBUG_TRACE
1037 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1038 wstrace("workshop_balloon_delay(%d)\n", delay
);
1041 sprintf(cbuf
, "set bdlay=%d", delay
);
1042 coloncmd(cbuf
, TRUE
);
1047 workshop_show_balloon_tip(
1050 #ifdef WSDEBUG_TRACE
1051 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1052 wstrace("workshop_show_balloon_tip(%s)\n", tip
);
1055 if (balloonEval
!= NULL
)
1056 gui_mch_post_balloon(balloonEval
, (char_u
*)tip
);
1064 char cbuf
[BUFSIZ
]; /* command buffer */
1065 MenuMap
*mp
; /* iterate over menuMap entries */
1067 #ifdef WSDEBUG_TRACE
1068 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1069 wstrace("workshop_hotkeys(%s)\n", on
? "True" : "False");
1072 workshopHotKeysEnabled
= on
;
1073 if (workshopHotKeysEnabled
)
1074 for (mp
= menuMap
; mp
< &menuMap
[menuMapSize
]; mp
++)
1076 if (mp
->accel
!= NULL
)
1078 vim_snprintf(cbuf
, sizeof(cbuf
),
1079 "map %s :wsverb %s<CR>", mp
->accel
, mp
->verb
);
1080 coloncmd(cbuf
, TRUE
);
1084 for (mp
= menuMap
; mp
< &menuMap
[menuMapSize
]; mp
++)
1086 if (mp
->accel
!= NULL
)
1088 vim_snprintf(cbuf
, sizeof(cbuf
), "unmap %s", mp
->accel
);
1089 coloncmd(cbuf
, TRUE
);
1095 * A button in the toolbar has been pushed.
1098 workshop_get_positions(
1099 void *clientData UNUSED
,
1100 char **filename
, /* output data */
1101 int *curLine
, /* output data */
1102 int *curCol
, /* output data */
1103 int *selStartLine
, /* output data */
1104 int *selStartCol
, /* output data */
1105 int *selEndLine
, /* output data */
1106 int *selEndCol
, /* output data */
1107 int *selLength
, /* output data */
1108 char **selection
) /* output data */
1110 static char ffname
[MAXPATHLEN
];
1112 #ifdef WSDEBUG_TRACE
1113 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1114 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1115 clientData
, (curbuf
&& curbuf
->b_sfname
!= NULL
)
1116 ? (char *)curbuf
->b_sfname
: "<None>");
1119 if (curbuf
->b_ffname
== NULL
)
1122 /* copy so nobody can change b_ffname */
1123 strcpy(ffname
, (char *) curbuf
->b_ffname
);
1125 *curLine
= curwin
->w_cursor
.lnum
;
1126 *curCol
= curwin
->w_cursor
.col
;
1128 if (curbuf
->b_visual
.vi_mode
== 'v' &&
1129 equalpos(curwin
->w_cursor
, curbuf
->b_visual
.vi_end
))
1131 *selStartLine
= curbuf
->b_visual
.vi_start
.lnum
;
1132 *selStartCol
= curbuf
->b_visual
.vi_start
.col
;
1133 *selEndLine
= curbuf
->b_visual
.vi_end
.lnum
;
1134 *selEndCol
= curbuf
->b_visual
.vi_end
.col
;
1135 *selection
= get_selection(curbuf
);
1137 *selLength
= strlen(*selection
);
1143 *selStartLine
= *selEndLine
= -1;
1144 *selStartCol
= *selEndCol
= -1;
1154 /************************************************************************
1156 ************************************************************************/
1160 buf_T
*buf
) /* buffer whose selection we want */
1162 pos_T
*start
; /* start of the selection */
1163 pos_T
*end
; /* end of the selection */
1164 char *lp
; /* pointer to actual line data */
1165 int llen
; /* length of actual line data */
1166 char *sp
; /* pointer to selection buffer */
1167 int slen
; /* string length in selection buffer */
1168 int size
; /* size of selection buffer */
1169 char *new_sp
; /* temp pointer to new sp */
1170 int lnum
; /* line number we are appending */
1172 if (buf
->b_visual
.vi_mode
== 'v')
1174 start
= &buf
->b_visual
.vi_start
;
1175 end
= &buf
->b_visual
.vi_end
;
1176 if (start
->lnum
== end
->lnum
)
1178 /* selection is all on one line */
1179 lp
= (char *) ml_get_pos(start
);
1180 llen
= end
->col
- start
->col
+ 1;
1181 sp
= (char *) malloc(llen
+ 1);
1184 strncpy(sp
, lp
, llen
);
1190 /* multi-line selection */
1191 lp
= (char *) ml_get_pos(start
);
1193 sp
= (char *) malloc(BUFSIZ
+ llen
);
1196 size
= BUFSIZ
+ llen
;
1201 lnum
= start
->lnum
+ 1;
1202 while (lnum
< end
->lnum
)
1203 sp
= append_selection(lnum
++, sp
, &size
, &slen
);
1205 lp
= (char *) ml_get(end
->lnum
);
1206 llen
= end
->col
+ 1;
1207 if ((slen
+ llen
) >= size
)
1210 realloc(sp
, slen
+ llen
+ 1);
1217 if ((slen
+ llen
) < size
)
1219 strncpy(&sp
[slen
], lp
, llen
);
1220 sp
[slen
+ llen
] = NUL
;
1234 int lnum
, /* line number to append */
1235 char *sp
, /* pointer to selection buffer */
1236 int *size
, /* ptr to size of sp */
1237 int *slen
) /* ptr to length of selection string */
1239 char *lp
; /* line of data from buffer */
1240 int llen
; /* strlen of lp */
1241 char *new_sp
; /* temp pointer to new sp */
1243 lp
= (char *)ml_get((linenr_T
)lnum
);
1246 if ((*slen
+ llen
) <= *size
)
1248 new_sp
= (char *) realloc((void *) sp
, BUFSIZ
+ *slen
+ llen
);
1251 *size
= BUFSIZ
+ *slen
+ llen
;
1255 if ((*slen
+ llen
) > *size
)
1257 strcat(&sp
[*slen
], lp
);
1268 load_buffer_by_name(
1269 char *filename
, /* the file to load */
1270 int lnum
) /* an optional line number (or 0) */
1272 char lnumbuf
[16]; /* make line number option for :e */
1273 char cbuf
[BUFSIZ
]; /* command buffer */
1276 sprintf(lnumbuf
, "+%d", lnum
);
1280 vim_snprintf(cbuf
, sizeof(cbuf
), "e %s %s", lnumbuf
, filename
);
1281 coloncmd(cbuf
, False
);
1287 char *filename
, /* filename to load */
1288 int lnum
) /* linenumber to go to */
1290 buf_T
*buf
; /* buffer filename is stored in */
1291 win_T
*win
; /* window filenme is displayed in */
1294 * Make sure filename is displayed and is the current window.
1297 buf
= buflist_findname((char_u
*)filename
);
1298 if (buf
== NULL
|| (win
= get_window(buf
)) == NULL
)
1300 /* No buffer or buffer is not in current window */
1301 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1303 load_buffer_by_name(filename
, lnum
);
1307 /* buf is in a window */
1310 win_enter(win
, False
);
1311 /* wsdebug("load_window: window endter %s\n",
1312 win->w_buffer->b_sfname); */
1314 if (lnum
> 0 && win
->w_cursor
.lnum
!= lnum
)
1317 /* wsdebug("load_window: warp to %s[%d]\n",
1318 win->w_buffer->b_sfname, lnum); */
1328 int lnum
) /* line number to warp to */
1330 char lbuf
[256]; /* build line command here */
1335 add_to_input_buf((char_u
*) "\033", 1);
1336 if (isShowing(lnum
))
1337 sprintf(lbuf
, "%dG", lnum
);
1339 sprintf(lbuf
, "%dz.", lnum
);
1340 add_to_input_buf((char_u
*) lbuf
, strlen(lbuf
));
1346 int lnum
) /* tell if line number is showing */
1348 return lnum
>= curwin
->w_topline
&& lnum
< curwin
->w_botline
;
1355 buf_T
*buf
) /* buffer to find window for */
1357 win_T
*wp
= NULL
; /* window filename is in */
1359 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
1360 if (buf
== wp
->w_buffer
)
1366 #if 0 /* not used */
1369 buf_T
*buf
) /* buffer to get position of */
1371 buf_T
*bp
; /* iterate over buffer list */
1372 int pos
; /* the position in the buffer list */
1375 for (bp
= firstbuf
; bp
!= NULL
; bp
= bp
->b_next
)
1388 Boolean subMenu
) /* if True then start new submenu pri */
1390 int pri
; /* priority of this menu/item */
1393 p
= strrchr(curMenuPriority
, '.');
1397 pri
= atoi(p
) + 10; /* our new priority */
1400 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1401 "%s.%d.0", curMenuPriority
, pri
);
1403 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1404 "%s.%d", curMenuPriority
, pri
);
1409 char *mnemonics
, /* currently used mnemonics */
1410 char *label
) /* label of menu needing mnemonic */
1412 static char name
[BUFSIZ
]; /* buffer for the updated name */
1413 char *p
; /* pointer into label */
1414 char *found
; /* pointer to possible mnemonic */
1417 for (p
= label
; *p
!= NUL
; p
++)
1418 if (strchr(mnemonics
, *p
) == 0)
1419 if (found
== NULL
|| (isupper((int)*p
) && islower((int)*found
)))
1424 strncpy(name
, label
, (found
- label
));
1426 strcat(name
, found
);
1429 strcpy(name
, label
);
1435 * Some characters in a menu name must be escaped in vim. Since this is vim
1436 * specific, it must be done on this side.
1442 static char buf
[BUFSIZ
];
1443 char *bp
; /* pointer into buf */
1444 char *lp
; /* pointer into label */
1450 if (*lp
== ' ' || *lp
== '.')
1460 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1462 /* For the NoHands test suite */
1465 workshop_test_getcurrentfile()
1467 char *filename
, *selection
;
1468 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1469 int selEndCol
, selLength
;
1471 if (workshop_get_positions(
1472 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1473 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1481 workshop_test_getcursorrow()
1487 workshop_test_getcursorcol()
1489 char *filename
, *selection
;
1490 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1491 int selEndCol
, selLength
;
1493 if (workshop_get_positions(
1494 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1495 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1503 workshop_test_getcursorrowtext()
1509 workshop_test_getselectedtext()
1511 char *filename
, *selection
;
1512 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1513 int selEndCol
, selLength
;
1515 if (workshop_get_positions(
1516 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1517 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1525 workshop_save_sensitivity(char *filename UNUSED
)
1533 char *ap
) /* original acceleratorText */
1535 char buf
[256]; /* build in temp buffer */
1536 char *shift
; /* shift string of "" */
1541 /* If the accelerator is shifted use the vim form */
1542 if (strncmp("Shift+", ap
, 6) == 0)
1550 if (*ap
== 'F' && atoi(&ap
[1]) > 0)
1552 vim_snprintf(buf
, sizeof(buf
), "<%s%s>", shift
, ap
);
1571 char buf
[MAXPATHLEN
* 2];
1572 static int serialNo
= -1;
1577 if (get_beval_info(beval
, FALSE
, &wp
, &lnum
, &text
, &col
) == OK
)
1579 if (text
&& text
[0])
1581 /* Send debugger request */
1582 if (strlen((char *) text
) > (MAXPATHLEN
/2))
1585 * The user has probably selected the entire
1586 * buffer or something like that - don't attempt
1593 * WorkShop expects the col to be a character index, not
1594 * a column number. Compute the index from col. Also set
1595 * line to 0 because thats what dbx expects.
1597 idx
= computeIndex(col
, text
, beval
->ts
);
1603 * If successful, it will respond with a balloon cmd.
1605 if (state
& ControlMask
)
1606 /* Evaluate *(expression) */
1607 type
= (int)GPLineEval_INDIRECT
;
1608 else if (state
& ShiftMask
)
1609 /* Evaluate type(expression) */
1610 type
= (int)GPLineEval_TYPE
;
1612 /* Evaluate value(expression) */
1613 type
= (int)GPLineEval_EVALUATE
;
1615 /* Send request to dbx */
1616 vim_snprintf(buf
, sizeof(buf
), "toolVerb debug.balloonEval "
1617 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1618 (char *)wp
->w_buffer
->b_ffname
,
1619 (long)lnum
, idx
, type
, serialNo
++,
1620 (long)strlen((char *)text
), (char *)text
);
1621 balloonEval
= beval
;
1622 workshop_send_message(buf
);
1639 if (line
[idx
] == '\t')
1640 col
+= ts
- (col
% ts
);
1644 if (col
>= wantedCol
)
1654 char *menu
, /* menu name */
1655 char *accel
, /* accelerator text (optional) */
1656 char *verb
) /* WorkShop action-verb */
1661 if (menuMapSize
>= menuMapMax
)
1663 newMap
= realloc(menuMap
,
1664 sizeof(MenuMap
) * (menuMapMax
+ MENU_INC
));
1668 menuMapMax
+= MENU_INC
;
1671 if (menuMapSize
< menuMapMax
)
1673 menuMap
[menuMapSize
].name
= strdup(menu
);
1674 menuMap
[menuMapSize
].accel
= accel
&& *accel
? strdup(accel
) : NULL
;
1675 menuMap
[menuMapSize
++].verb
= strdup(verb
);
1676 if (accel
&& workshopHotKeysEnabled
)
1678 vim_snprintf(cbuf
, sizeof(cbuf
),
1679 "map %s :wsverb %s<CR>", accel
, verb
);
1680 coloncmd(cbuf
, TRUE
);
1687 char *raw
) /* menu name, possibly with & chars */
1689 static char buf
[BUFSIZ
]; /* build stripped name here */
1706 int skip
) /* number of matches to skip */
1708 int i
; /* loop iterator */
1710 for (i
= 0; i
< menuMapSize
; i
++)
1711 if (strcmp(menuMap
[i
].verb
, verb
) == 0 && skip
-- == 0)
1712 return nameStrip(menuMap
[i
].name
);
1720 char *cmd
, /* the command to print */
1721 Boolean force
) /* force cursor update */
1723 char_u
*cpo_save
= p_cpo
;
1726 if (WSDLEVEL(WS_TRACE_COLONCMD
))
1727 wsdebug("Cmd: %s\n", cmd
);
1730 p_cpo
= empty_option
;
1733 do_cmdline_cmd((char_u
*)cmd
);
1739 gui_update_screen();
1743 * setDollarVim - Given the run directory, search for the vim install
1744 * directory and set $VIM.
1746 * We can be running out of SUNWspro/bin or out of
1747 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1748 * relative to both of these directories.
1754 char buf
[MAXPATHLEN
];
1758 * First case: Running from <install-dir>/SUNWspro/bin
1760 strcpy(buf
, rundir
);
1761 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1762 VIM_VERSION_NODOT
"/syntax/syntax.vim");
1763 if (access(buf
, R_OK
) == 0)
1765 strcpy(buf
, "SPRO_WSDIR=");
1766 strcat(buf
, rundir
);
1767 cp
= strrchr(buf
, '/');
1769 strcpy(cp
, "/WS6U2");
1770 putenv(strdup(buf
));
1772 strcpy(buf
, "VIM=");
1773 strcat(buf
, rundir
);
1774 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1776 putenv(strdup(buf
));
1781 * Second case: Probably running from
1782 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1784 strcpy(buf
, rundir
);
1785 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1786 "/share/vim/" VIM_VERSION_NODOT
"/syntax/syntax.vim");
1787 if (access(buf
, R_OK
) == 0)
1789 strcpy(buf
, "SPRO_WSDIR=");
1790 strcat(buf
, rundir
);
1791 cp
= strrchr(buf
, '/');
1793 strcpy(cp
, "../../../../WS6U2");
1794 putenv(strdup(buf
));
1796 strcpy(buf
, "VIM=");
1797 strcat(buf
, rundir
);
1798 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1799 "/share/vim/" VIM_VERSION_NODOT
);
1800 putenv(strdup(buf
));
1806 * findYourself - Find the directory we are running from. This is used to
1807 * set $VIM. We need to set this because users can install
1808 * the package in a different directory than the compiled
1809 * directory. This is a Sun Visual WorkShop requirement!
1811 * Note: We override a user's $VIM because it won't have the
1812 * WorkShop specific files. S/he may not like this but its
1813 * better than getting the wrong files (especially as the
1814 * user is likely to have $VIM set to 5.4 or later).
1820 char *runpath
= NULL
;
1825 runpath
= strdup(argv0
);
1826 else if (*argv0
== '.' || strchr(argv0
, '/'))
1828 runpath
= (char *) malloc(MAXPATHLEN
);
1829 getcwd(runpath
, MAXPATHLEN
);
1830 strcat(runpath
, "/");
1831 strcat(runpath
, argv0
);
1835 path
= getenv("PATH");
1838 runpath
= (char *) malloc(MAXPATHLEN
);
1839 pathbuf
= strdup(path
);
1840 path
= strtok(pathbuf
, ":");
1843 strcpy(runpath
, path
);
1844 strcat(runpath
, "/");
1845 strcat(runpath
, argv0
);
1846 if (access(runpath
, X_OK
) == 0)
1848 } while ((path
= strtok(NULL
, ":")) != NULL
);
1853 if (runpath
!= NULL
)
1855 char runbuf
[MAXPATHLEN
];
1858 * We found the run directory. Now find the install dir.
1860 (void)vim_FullName((char_u
*)runpath
, (char_u
*)runbuf
, MAXPATHLEN
, 1);
1861 path
= strrchr(runbuf
, '/');
1863 *path
= NUL
; /* remove the vim/gvim name */
1864 path
= strrchr(runbuf
, '/');
1867 if (strncmp(path
, "/bin", 4) == 0)
1868 setDollarVim(runbuf
);
1869 else if (strncmp(path
, "/src", 4) == 0)
1871 *path
= NUL
; /* development tree */
1872 setDollarVim(runbuf
);