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 char *fixAccelText(char *);
62 static void addMenu(char *, char *, char *);
63 static char *lookupVerb(char *, int);
64 static int computeIndex(int, char_u
*, 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.
210 char *filename
, /* the file to load */
211 int line
, /* an optional line number (or 0) */
212 char *frameid
) /* used for multi-frame support */
215 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
216 wstrace("workshop_load_file(%s, %d)\n", filename
, line
);
220 bevalServers
|= BEVAL_WORKSHOP
;
223 load_window(filename
, line
);
227 * Reload the WorkShop buffer
230 workshop_reload_file(
235 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
236 wstrace("workshop_reload_file(%s, %d)\n", filename
, line
);
238 load_window(filename
, line
);
246 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
247 wstrace("workshop_show_file(%s)\n", filename
);
250 load_window(filename
, 0);
259 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
260 wstrace("workshop_goto_line(%s, %d)\n", filename
, lineno
);
263 load_window(filename
, lineno
);
272 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
273 wstrace("workshop_front_file()\n");
276 * Assumption: This function will always be called after a call to
277 * workshop_show_file(), so the file is always showing.
279 if (vimShell
!= NULL
)
280 XRaiseWindow(gui
.dpy
, XtWindow(vimShell
));
287 char cbuf
[BUFSIZ
]; /* build vim command here */
290 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
291 wstrace("workshop_save_file(%s)\n", filename
);
294 /* Save the given file */
295 vim_snprintf(cbuf
, sizeof(cbuf
), "w %s", filename
);
296 coloncmd(cbuf
, TRUE
);
300 workshop_save_files()
302 /* Save the given file */
304 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
305 wstrace("workshop_save_files()\n");
308 add_to_input_buf((char_u
*) ":wall\n", 6);
315 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
316 wstrace("workshop_quit()\n");
319 add_to_input_buf((char_u
*) ":qall\n", 6);
326 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
327 wstrace("workshop_minimize()\n");
329 workshop_minimize_shell(vimShell
);
335 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
336 wstrace("workshop_maximize()\n");
339 workshop_maximize_shell(vimShell
);
343 workshop_add_mark_type(
348 char gbuf
[BUFSIZ
]; /* buffer for sign name */
349 char cibuf
[BUFSIZ
]; /* color information */
350 char cbuf
[BUFSIZ
]; /* command buffer */
354 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
358 cp
= strrchr(sign
, '/');
362 cp
++; /* skip '/' character */
363 wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx
,
364 colorspec
&& *colorspec
? colorspec
: "<None>", cp
);
369 * Isolate the basename of sign in gbuf. We will use this for the
370 * GroupName in the highlight command sent to vim.
372 STRCPY(gbuf
, gettail((char_u
*)sign
));
373 bp
= strrchr(gbuf
, '.');
377 if (gbuf
[0] != '-' && gbuf
[1] != NUL
)
379 if (colorspec
!= NULL
&& *colorspec
)
381 vim_snprintf(cbuf
, sizeof(cbuf
),
382 "highlight WS%s guibg=%s", gbuf
, colorspec
);
383 coloncmd(cbuf
, FALSE
);
384 vim_snprintf(cibuf
, sizeof(cibuf
), "linehl=WS%s", gbuf
);
389 vim_snprintf(cbuf
, sizeof(cbuf
),
390 "sign define %d %s icon=%s", idx
, cibuf
, sign
);
391 coloncmd(cbuf
, TRUE
);
397 char *filename
, /* filename which gets the mark */
398 int lineno
, /* line number which gets the mark */
399 int markId
, /* unique mark identifier */
400 int idx
) /* which mark to use */
402 char cbuf
[BUFSIZ
]; /* command buffer */
404 /* Set mark in a given file */
406 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
407 wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n",
408 filename
, lineno
, markId
, idx
);
411 vim_snprintf(cbuf
, sizeof(cbuf
), "sign place %d line=%d name=%d file=%s",
412 markId
, lineno
, idx
, filename
);
413 coloncmd(cbuf
, TRUE
);
417 workshop_change_mark_type(
418 char *filename
, /* filename which gets the mark */
419 int markId
, /* unique mark identifier */
420 int idx
) /* which mark to use */
422 char cbuf
[BUFSIZ
]; /* command buffer */
424 /* Change mark type */
426 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
427 wstrace("workshop_change_mark_type(%s, %d, %d)\n",
428 filename
, markId
, idx
);
431 vim_snprintf(cbuf
, sizeof(cbuf
),
432 "sign place %d name=%d file=%s", markId
, idx
, filename
);
433 coloncmd(cbuf
, TRUE
);
437 * Goto the given mark in a file (e.g. show it).
438 * If message is not null, display it in the footer.
446 char cbuf
[BUFSIZ
]; /* command buffer */
450 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
451 wstrace("workshop_goto_mark(%s, %d (id), %s)\n",
452 filename
, markId
, message
&& *message
&&
453 !(*message
== ' ' && message
[1] == NULL
) ?
457 vim_snprintf(cbuf
, sizeof(cbuf
), "sign jump %d file=%s", markId
, filename
);
458 coloncmd(cbuf
, TRUE
);
459 if (message
!= NULL
&& *message
!= NUL
)
460 gui_mch_set_footer((char_u
*)message
);
464 workshop_delete_mark(
468 char cbuf
[BUFSIZ
]; /* command buffer */
472 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
473 wstrace("workshop_delete_mark(%s, %d (id))\n",
477 vim_snprintf(cbuf
, sizeof(cbuf
),
478 "sign unplace %d file=%s", markId
, filename
);
479 coloncmd(cbuf
, TRUE
);
484 workshop_delete_all_marks(
489 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
490 wstrace("workshop_delete_all_marks(%#x, %s)\n",
491 window
, doRefresh
? "True" : "False");
494 coloncmd("sign unplace *", TRUE
);
499 workshop_get_mark_lineno(
503 buf_T
*buf
; /* buffer containing filename */
504 int lineno
; /* line number of filename in buf */
506 /* Get mark line number */
508 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
509 wstrace("workshop_get_mark_lineno(%s, %d)\n",
514 buf
= buflist_findname((char_u
*)filename
);
516 lineno
= buf_findsign(buf
, markId
);
524 workshop_adjust_marks(Widget
*window
, int pos
,
525 int inserted
, int deleted
)
528 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
529 wstrace("XXXworkshop_adjust_marks(%s, %d, %d, %d)\n",
530 window
? XtName(window
) : "<None>", pos
, inserted
, deleted
);
536 * Are there any moved marks? If so, call workshop_move_mark on
537 * each of them now. This is how eserve can find out if for example
538 * breakpoints have moved when a program has been recompiled and
543 workshop_moved_marks(char *filename
)
546 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
547 wstrace("XXXworkshop_moved_marks(%s)\n", filename
);
552 workshop_get_font_height()
554 XmFontList fontList
; /* fontList made from gui.norm_font */
560 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
561 wstrace("workshop_get_font_height()\n");
564 /* Pick the proper signs for this font size */
565 fontList
= gui_motif_create_fontlist((XFontStruct
*)gui
.norm_font
);
567 if (fontList
!= NULL
)
569 str
= XmStringCreateLocalized("A");
570 XmStringExtent(fontList
, str
, &w
, &h
);
572 XmFontListFree(fontList
);
580 workshop_footer_message(
582 int severity
) /* 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.
696 char *acceleratorText
,
702 char namebuf
[BUFSIZ
];
703 char accText
[BUFSIZ
];
706 if (WSDLEVEL(WS_TRACE_VERBOSE
)
707 && strncmp(curMenuName
, "ToolBar", 7) != 0)
709 if (ws_dlevel
& WS_TRACE_VERBOSE
)
710 wsdebug("workshop_menu_item(\n"
711 "\tlabel = \"%s\",\n"
713 "\taccelerator = %s,\n"
714 "\tacceleratorText = \"%s\",\n"
717 "\tsensitive = %s)\n",
718 label
&& *label
? label
: "<None>",
719 verb
&& *verb
? verb
: "<None>",
720 accelerator
&& *accelerator
?
721 accelerator
: "<None>",
722 acceleratorText
&& *acceleratorText
?
723 acceleratorText
: "<None>",
724 name
&& *name
? name
: "<None>",
725 filepos
&& *filepos
? filepos
: "<None>",
727 else if (ws_dlevel
& WS_TRACE
)
728 wstrace("workshop_menu_item(\"%s\", %s)\n",
729 label
&& *label
? label
: "<None>",
730 verb
&& *verb
? verb
: "<None>", sensitive
);
735 wstrace("menu: %-21.20s%-21.20s(%s)\n", label
, verb
,
736 *sensitive
== '1' ? "Sensitive" : "Insensitive");
739 if (acceleratorText
!= NULL
)
740 vim_snprintf(accText
, sizeof(accText
), "<Tab>%s", acceleratorText
);
743 updatePriority(False
);
744 vim_snprintf(namebuf
, sizeof(namebuf
), "%s.%s", curMenuName
, fixup(label
));
745 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu %s %s%s\t:wsverb %s<CR>",
746 curMenuPriority
, namebuf
, accText
, verb
);
748 coloncmd(cbuf
, TRUE
);
749 addMenu(namebuf
, fixAccelText(acceleratorText
), verb
);
751 if (*sensitive
== '0')
753 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
754 coloncmd(cbuf
, TRUE
);
759 * This function is called when a complete WorkShop menu description has been
760 * sent over from eserve. We do some menu cleanup.
766 Boolean using_tearoff
; /* set per current option setting */
769 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
770 wstrace("workshop_menu_end()\n");
773 using_tearoff
= vim_strchr(p_go
, GO_TEAROFF
) != NULL
;
774 gui_mch_toggle_tearoffs(using_tearoff
);
778 workshop_toolbar_begin()
781 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
782 wstrace("workshop_toolbar_begin()\n");
785 coloncmd("aunmenu ToolBar", True
);
790 workshop_toolbar_end()
795 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
797 wstrace("workshop_toolbar_end()\n");
805 if (vim_strchr(p_go
, 'T') == NULL
)
808 set_option_value((char_u
*)"go", 0L, buf
, 0);
810 workshopInitDone
= True
;
815 workshop_toolbar_button(
825 char cbuf
[BUFSIZ
+ MAXPATHLEN
];
826 char namebuf
[BUFSIZ
];
832 if (WSDLEVEL(WS_TRACE_VERBOSE
))
833 wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n"
834 "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n",
835 label
&& *label
? label
: "<None>",
836 verb
&& *verb
? verb
: "<None>",
837 senseVerb
&& *senseVerb
? senseVerb
: "<None>",
838 filepos
&& *filepos
? filepos
: "<None>",
839 help
&& *help
? help
: "<None>",
840 sense
&& *sense
? sense
: "<None>",
841 file
&& *file
? file
: "<None>",
842 left
&& *left
? left
: "<None>");
843 else if (WSDLEVEL(WS_TRACE
))
844 wstrace("workshop_toolbar_button(\"%s\", %s)\n",
845 label
&& *label
? label
: "<None>",
846 verb
&& *verb
? verb
: "<None>");
850 wsdebug("button: %-21.20s%-21.20s(%s)\n", label
, verb
,
851 *sense
== '1' ? "Sensitive" : "Insensitive");
854 if (left
&& *left
&& atoi(left
) > 0)
856 /* Add a separator (but pass the width passed after the ':') */
857 sprintf(cbuf
, "amenu 1.%d ToolBar.-sep%d:%s- <nul>",
858 tbpri
- 5, tbid
++, left
);
860 coloncmd(cbuf
, True
);
863 p
= vim_strsave_escaped((char_u
*)label
, (char_u
*)"\\. ");
864 vim_snprintf(namebuf
, sizeof(namebuf
), "ToolBar.%s", p
);
866 STRCPY(cbuf
, "amenu <silent> ");
867 if (file
!= NULL
&& *file
!= NUL
)
869 p
= vim_strsave_escaped((char_u
*)file
, (char_u
*)" ");
871 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
, "icon=%s ", p
);
875 vim_snprintf(cbuf
+ len
, sizeof(cbuf
) - len
,"1.%d %s :wsverb %s<CR>",
876 tbpri
, namebuf
, verb
);
878 /* Define the menu item */
879 coloncmd(cbuf
, True
);
883 /* If menu isn't sensitive at startup... */
884 vim_snprintf(cbuf
, sizeof(cbuf
), "amenu disable %s", namebuf
);
885 coloncmd(cbuf
, True
);
891 vim_snprintf(cbuf
, sizeof(cbuf
), "tmenu %s %s", namebuf
, help
);
892 coloncmd(cbuf
, True
);
895 addMenu(namebuf
, NULL
, verb
);
900 workshop_frame_sensitivities(
901 VerbSense
*vs
) /* list of verbs to (de)sensitize */
903 VerbSense
*vp
; /* iterate through vs */
904 char *menu_name
; /* used in menu lookup */
905 int cnt
; /* count of verbs to skip */
906 int len
; /* length of nonvariant part of command */
910 if (WSDLEVEL(WS_TRACE_VERBOSE
) || WSDLEVEL(4))
912 wsdebug("workshop_frame_sensitivities(\n");
913 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
914 wsdebug("\t%-25s%d\n", vp
->verb
, vp
->sense
);
917 else if (WSDLEVEL(WS_TRACE
))
918 wstrace("workshop_frame_sensitivities()\n");
922 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
923 wsdebug("change: %-21.20s%-21.20s(%s)\n",
924 "", vp
->verb
, vp
->sense
== 1 ?
925 "Sensitive" : "Insensitive");
929 * Look for all matching menu entries for the verb. There may be more
930 * than one if the verb has both a menu and toolbar entry.
932 for (vp
= vs
; vp
->verb
!= NULL
; vp
++)
935 strcpy(cbuf
, "amenu");
937 strcat(cbuf
, vp
->sense
? "enable" : "disable");
940 while ((menu_name
= lookupVerb(vp
->verb
, cnt
++)) != NULL
)
942 strcpy(&cbuf
[len
], menu_name
);
943 coloncmd(cbuf
, FALSE
);
952 char *option
, /* name of a supported option */
953 char *value
) /* value to set option to */
955 char cbuf
[BUFSIZ
]; /* command buffer */
958 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
960 wstrace("workshop_set_option(%s, %s)\n", option
, value
);
965 switch (*option
) /* switch on 1st letter */
968 if (strcmp(option
, "syntax") == 0)
969 vim_snprintf(cbuf
, sizeof(cbuf
), "syntax %s", value
);
970 else if (strcmp(option
, "savefiles") == 0)
971 ; /* 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.
1103 workshop_get_positions(
1104 void *clientData
, /* unused */
1105 char **filename
, /* output data */
1106 int *curLine
, /* output data */
1107 int *curCol
, /* output data */
1108 int *selStartLine
, /* output data */
1109 int *selStartCol
, /* output data */
1110 int *selEndLine
, /* output data */
1111 int *selEndCol
, /* output data */
1112 int *selLength
, /* output data */
1113 char **selection
) /* output data */
1115 static char ffname
[MAXPATHLEN
];
1117 #ifdef WSDEBUG_TRACE
1118 if (WSDLEVEL(WS_TRACE_VERBOSE
| WS_TRACE
))
1119 wstrace("workshop_get_positions(%#x, \"%s\", ...)\n",
1120 clientData
, (curbuf
&& curbuf
->b_sfname
!= NULL
)
1121 ? (char *)curbuf
->b_sfname
: "<None>");
1124 if (curbuf
->b_ffname
== NULL
)
1127 /* copy so nobody can change b_ffname */
1128 strcpy(ffname
, (char *) curbuf
->b_ffname
);
1130 *curLine
= curwin
->w_cursor
.lnum
;
1131 *curCol
= curwin
->w_cursor
.col
;
1133 if (curbuf
->b_visual
.vi_mode
== 'v' &&
1134 equalpos(curwin
->w_cursor
, curbuf
->b_visual
.vi_end
))
1136 *selStartLine
= curbuf
->b_visual
.vi_start
.lnum
;
1137 *selStartCol
= curbuf
->b_visual
.vi_start
.col
;
1138 *selEndLine
= curbuf
->b_visual
.vi_end
.lnum
;
1139 *selEndCol
= curbuf
->b_visual
.vi_end
.col
;
1140 *selection
= get_selection(curbuf
);
1142 *selLength
= strlen(*selection
);
1148 *selStartLine
= *selEndLine
= -1;
1149 *selStartCol
= *selEndCol
= -1;
1159 /************************************************************************
1161 ************************************************************************/
1165 buf_T
*buf
) /* buffer whose selection we want */
1167 pos_T
*start
; /* start of the selection */
1168 pos_T
*end
; /* end of the selection */
1169 char *lp
; /* pointer to actual line data */
1170 int llen
; /* length of actual line data */
1171 char *sp
; /* pointer to selection buffer */
1172 int slen
; /* string length in selection buffer */
1173 int size
; /* size of selection buffer */
1174 char *new_sp
; /* temp pointer to new sp */
1175 int lnum
; /* line number we are appending */
1177 if (buf
->b_visual
.vi_mode
== 'v')
1179 start
= &buf
->b_visual
.vi_start
;
1180 end
= &buf
->b_visual
.vi_end
;
1181 if (start
->lnum
== end
->lnum
)
1183 /* selection is all on one line */
1184 lp
= (char *) ml_get_pos(start
);
1185 llen
= end
->col
- start
->col
+ 1;
1186 sp
= (char *) malloc(llen
+ 1);
1189 strncpy(sp
, lp
, llen
);
1195 /* multi-line selection */
1196 lp
= (char *) ml_get_pos(start
);
1198 sp
= (char *) malloc(BUFSIZ
+ llen
);
1201 size
= BUFSIZ
+ llen
;
1206 lnum
= start
->lnum
+ 1;
1207 while (lnum
< end
->lnum
)
1208 sp
= append_selection(lnum
++, sp
, &size
, &slen
);
1210 lp
= (char *) ml_get(end
->lnum
);
1211 llen
= end
->col
+ 1;
1212 if ((slen
+ llen
) >= size
)
1215 realloc(sp
, slen
+ llen
+ 1);
1222 if ((slen
+ llen
) < size
)
1224 strncpy(&sp
[slen
], lp
, llen
);
1225 sp
[slen
+ llen
] = NUL
;
1239 int lnum
, /* line number to append */
1240 char *sp
, /* pointer to selection buffer */
1241 int *size
, /* ptr to size of sp */
1242 int *slen
) /* ptr to length of selection string */
1244 char *lp
; /* line of data from buffer */
1245 int llen
; /* strlen of lp */
1246 char *new_sp
; /* temp pointer to new sp */
1248 lp
= (char *)ml_get((linenr_T
)lnum
);
1251 if ((*slen
+ llen
) <= *size
)
1253 new_sp
= (char *) realloc((void *) sp
, BUFSIZ
+ *slen
+ llen
);
1256 *size
= BUFSIZ
+ *slen
+ llen
;
1260 if ((*slen
+ llen
) > *size
)
1262 strcat(&sp
[*slen
], lp
);
1273 load_buffer_by_name(
1274 char *filename
, /* the file to load */
1275 int lnum
) /* an optional line number (or 0) */
1277 char lnumbuf
[16]; /* make line number option for :e */
1278 char cbuf
[BUFSIZ
]; /* command buffer */
1281 sprintf(lnumbuf
, "+%d", lnum
);
1285 vim_snprintf(cbuf
, sizeof(cbuf
), "e %s %s", lnumbuf
, filename
);
1286 coloncmd(cbuf
, False
);
1292 char *filename
, /* filename to load */
1293 int lnum
) /* linenumber to go to */
1295 buf_T
*buf
; /* buffer filename is stored in */
1296 win_T
*win
; /* window filenme is displayed in */
1299 * Make sure filename is displayed and is the current window.
1302 buf
= buflist_findname((char_u
*)filename
);
1303 if (buf
== NULL
|| (win
= get_window(buf
)) == NULL
)
1305 /* No buffer or buffer is not in current window */
1306 /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n",
1308 load_buffer_by_name(filename
, lnum
);
1312 /* buf is in a window */
1315 win_enter(win
, False
);
1316 /* wsdebug("load_window: window endter %s\n",
1317 win->w_buffer->b_sfname); */
1319 if (lnum
> 0 && win
->w_cursor
.lnum
!= lnum
)
1322 /* wsdebug("load_window: warp to %s[%d]\n",
1323 win->w_buffer->b_sfname, lnum); */
1333 int lnum
) /* line number to warp to */
1335 char lbuf
[256]; /* build line command here */
1340 add_to_input_buf((char_u
*) "\033", 1);
1341 if (isShowing(lnum
))
1342 sprintf(lbuf
, "%dG", lnum
);
1344 sprintf(lbuf
, "%dz.", lnum
);
1345 add_to_input_buf((char_u
*) lbuf
, strlen(lbuf
));
1351 int lnum
) /* tell if line number is showing */
1353 return lnum
>= curwin
->w_topline
&& lnum
< curwin
->w_botline
;
1360 buf_T
*buf
) /* buffer to find window for */
1362 win_T
*wp
= NULL
; /* window filename is in */
1364 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
1365 if (buf
== wp
->w_buffer
)
1371 #if 0 /* not used */
1374 buf_T
*buf
) /* buffer to get position of */
1376 buf_T
*bp
; /* iterate over buffer list */
1377 int pos
; /* the position in the buffer list */
1380 for (bp
= firstbuf
; bp
!= NULL
; bp
= bp
->b_next
)
1393 Boolean subMenu
) /* if True then start new submenu pri */
1395 int pri
; /* priority of this menu/item */
1398 p
= strrchr(curMenuPriority
, '.');
1402 pri
= atoi(p
) + 10; /* our new priority */
1405 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1406 "%s.%d.0", curMenuPriority
, pri
);
1408 vim_snprintf(curMenuPriority
, sizeof(curMenuPriority
),
1409 "%s.%d", curMenuPriority
, pri
);
1414 char *mnemonics
, /* currently used mnemonics */
1415 char *label
) /* label of menu needing mnemonic */
1417 static char name
[BUFSIZ
]; /* buffer for the updated name */
1418 char *p
; /* pointer into label */
1419 char *found
; /* pointer to possible mnemonic */
1422 for (p
= label
; *p
!= NUL
; p
++)
1423 if (strchr(mnemonics
, *p
) == 0)
1424 if (found
== NULL
|| (isupper((int)*p
) && islower((int)*found
)))
1429 strncpy(name
, label
, (found
- label
));
1431 strcat(name
, found
);
1434 strcpy(name
, label
);
1440 * Some characters in a menu name must be escaped in vim. Since this is vim
1441 * specific, it must be done on this side.
1447 static char buf
[BUFSIZ
];
1448 char *bp
; /* pointer into buf */
1449 char *lp
; /* pointer into label */
1455 if (*lp
== ' ' || *lp
== '.')
1465 #ifdef NOHANDS_SUPPORT_FUNCTIONS
1467 /* For the NoHands test suite */
1470 workshop_test_getcurrentfile()
1472 char *filename
, *selection
;
1473 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1474 int selEndCol
, selLength
;
1476 if (workshop_get_positions(
1477 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1478 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1486 workshop_test_getcursorrow()
1492 workshop_test_getcursorcol()
1494 char *filename
, *selection
;
1495 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1496 int selEndCol
, selLength
;
1498 if (workshop_get_positions(
1499 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1500 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1508 workshop_test_getcursorrowtext()
1514 workshop_test_getselectedtext()
1516 char *filename
, *selection
;
1517 int curLine
, curCol
, selStartLine
, selStartCol
, selEndLine
;
1518 int selEndCol
, selLength
;
1520 if (workshop_get_positions(
1521 NULL
, &filename
, &curLine
, &curCol
, &selStartLine
,
1522 &selStartCol
, &selEndLine
, &selEndCol
, &selLength
,
1531 workshop_save_sensitivity(char *filename
)
1539 char *ap
) /* original acceleratorText */
1541 char buf
[256]; /* build in temp buffer */
1542 char *shift
; /* shift string of "" */
1547 /* If the accelerator is shifted use the vim form */
1548 if (strncmp("Shift+", ap
, 6) == 0)
1556 if (*ap
== 'F' && atoi(&ap
[1]) > 0)
1558 vim_snprintf(buf
, sizeof(buf
), "<%s%s>", shift
, ap
);
1577 char buf
[MAXPATHLEN
* 2];
1578 static int serialNo
= -1;
1583 if (get_beval_info(beval
, FALSE
, &wp
, &lnum
, &text
, &col
) == OK
)
1585 if (text
&& text
[0])
1587 /* Send debugger request */
1588 if (strlen((char *) text
) > (MAXPATHLEN
/2))
1591 * The user has probably selected the entire
1592 * buffer or something like that - don't attempt
1599 * WorkShop expects the col to be a character index, not
1600 * a column number. Compute the index from col. Also set
1601 * line to 0 because thats what dbx expects.
1603 idx
= computeIndex(col
, text
, beval
->ts
);
1609 * If successful, it will respond with a balloon cmd.
1611 if (state
& ControlMask
)
1612 /* Evaluate *(expression) */
1613 type
= (int)GPLineEval_INDIRECT
;
1614 else if (state
& ShiftMask
)
1615 /* Evaluate type(expression) */
1616 type
= (int)GPLineEval_TYPE
;
1618 /* Evaluate value(expression) */
1619 type
= (int)GPLineEval_EVALUATE
;
1621 /* Send request to dbx */
1622 vim_snprintf(buf
, sizeof(buf
), "toolVerb debug.balloonEval "
1623 "%s %ld,0 %d,0 %d,%d %ld %s\n",
1624 (char *)wp
->w_buffer
->b_ffname
,
1625 (long)lnum
, idx
, type
, serialNo
++,
1626 (long)strlen((char *)text
), (char *)text
);
1627 balloonEval
= beval
;
1628 workshop_send_message(buf
);
1647 if (line
[idx
] == '\t')
1648 col
+= ts
- (col
% ts
);
1652 if (col
>= wantedCol
)
1661 char *menu
, /* menu name */
1662 char *accel
, /* accelerator text (optional) */
1663 char *verb
) /* WorkShop action-verb */
1668 if (menuMapSize
>= menuMapMax
)
1670 newMap
= realloc(menuMap
,
1671 sizeof(MenuMap
) * (menuMapMax
+ MENU_INC
));
1675 menuMapMax
+= MENU_INC
;
1678 if (menuMapSize
< menuMapMax
)
1680 menuMap
[menuMapSize
].name
= strdup(menu
);
1681 menuMap
[menuMapSize
].accel
= accel
&& *accel
? strdup(accel
) : NULL
;
1682 menuMap
[menuMapSize
++].verb
= strdup(verb
);
1683 if (accel
&& workshopHotKeysEnabled
)
1685 vim_snprintf(cbuf
, sizeof(cbuf
),
1686 "map %s :wsverb %s<CR>", accel
, verb
);
1687 coloncmd(cbuf
, TRUE
);
1694 char *raw
) /* menu name, possibly with & chars */
1696 static char buf
[BUFSIZ
]; /* build stripped name here */
1713 int skip
) /* number of matches to skip */
1715 int i
; /* loop iterator */
1717 for (i
= 0; i
< menuMapSize
; i
++)
1718 if (strcmp(menuMap
[i
].verb
, verb
) == 0 && skip
-- == 0)
1719 return nameStrip(menuMap
[i
].name
);
1727 char *cmd
, /* the command to print */
1728 Boolean force
) /* force cursor update */
1730 char_u
*cpo_save
= p_cpo
;
1733 if (WSDLEVEL(WS_TRACE_COLONCMD
))
1734 wsdebug("Cmd: %s\n", cmd
);
1737 p_cpo
= empty_option
;
1740 do_cmdline_cmd((char_u
*)cmd
);
1746 gui_update_screen();
1750 * setDollarVim - Given the run directory, search for the vim install
1751 * directory and set $VIM.
1753 * We can be running out of SUNWspro/bin or out of
1754 * SUNWspro/contrib/contrib6/vim5.6/bin so we check
1755 * relative to both of these directories.
1761 char buf
[MAXPATHLEN
];
1765 * First case: Running from <install-dir>/SUNWspro/bin
1767 strcpy(buf
, rundir
);
1768 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1769 VIM_VERSION_NODOT
"/syntax/syntax.vim");
1770 if (access(buf
, R_OK
) == 0)
1772 strcpy(buf
, "SPRO_WSDIR=");
1773 strcat(buf
, rundir
);
1774 cp
= strrchr(buf
, '/');
1776 strcpy(cp
, "/WS6U2");
1777 putenv(strdup(buf
));
1779 strcpy(buf
, "VIM=");
1780 strcat(buf
, rundir
);
1781 strcat(buf
, "/../contrib/contrib6/vim" VIM_VERSION_SHORT
"/share/vim/"
1783 putenv(strdup(buf
));
1788 * Second case: Probably running from
1789 * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin
1791 strcpy(buf
, rundir
);
1792 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1793 "/share/vim/" VIM_VERSION_NODOT
"/syntax/syntax.vim");
1794 if (access(buf
, R_OK
) == 0)
1796 strcpy(buf
, "SPRO_WSDIR=");
1797 strcat(buf
, rundir
);
1798 cp
= strrchr(buf
, '/');
1800 strcpy(cp
, "../../../../WS6U2");
1801 putenv(strdup(buf
));
1803 strcpy(buf
, "VIM=");
1804 strcat(buf
, rundir
);
1805 strcat(buf
, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT
1806 "/share/vim/" VIM_VERSION_NODOT
);
1807 putenv(strdup(buf
));
1813 * findYourself - Find the directory we are running from. This is used to
1814 * set $VIM. We need to set this because users can install
1815 * the package in a different directory than the compiled
1816 * directory. This is a Sun Visual WorkShop requirement!
1818 * Note: We override a user's $VIM because it won't have the
1819 * WorkShop specific files. S/he may not like this but its
1820 * better than getting the wrong files (especially as the
1821 * user is likely to have $VIM set to 5.4 or later).
1827 char *runpath
= NULL
;
1832 runpath
= strdup(argv0
);
1833 else if (*argv0
== '.' || strchr(argv0
, '/'))
1835 runpath
= (char *) malloc(MAXPATHLEN
);
1836 getcwd(runpath
, MAXPATHLEN
);
1837 strcat(runpath
, "/");
1838 strcat(runpath
, argv0
);
1842 path
= getenv("PATH");
1845 runpath
= (char *) malloc(MAXPATHLEN
);
1846 pathbuf
= strdup(path
);
1847 path
= strtok(pathbuf
, ":");
1850 strcpy(runpath
, path
);
1851 strcat(runpath
, "/");
1852 strcat(runpath
, argv0
);
1853 if (access(runpath
, X_OK
) == 0)
1855 } while ((path
= strtok(NULL
, ":")) != NULL
);
1860 if (runpath
!= NULL
)
1862 char runbuf
[MAXPATHLEN
];
1865 * We found the run directory. Now find the install dir.
1867 (void)vim_FullName((char_u
*)runpath
, (char_u
*)runbuf
, MAXPATHLEN
, 1);
1868 path
= strrchr(runbuf
, '/');
1870 *path
= NUL
; /* remove the vim/gvim name */
1871 path
= strrchr(runbuf
, '/');
1874 if (strncmp(path
, "/bin", 4) == 0)
1875 setDollarVim(runbuf
);
1876 else if (strncmp(path
, "/src", 4) == 0)
1878 *path
= NUL
; /* development tree */
1879 setDollarVim(runbuf
);