Hi
Attached patch from Vim-7.2.127 improves command
line completion of the ":cscope" command:
:cscope <CTRL-D>
... completes with subcommands...
add find help kill reset show
:cscope add <CTRL-D>
... completes with filenames
:cscope find <CTRL-D>
... completes with...
c d e f g i s t
:cscope kill <CTRL-D>
... completes with all active cscope connection numbers
and -1 to kill all connections.
Regards
-- Dominique
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: if_cscope.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/if_cscope.c,v
retrieving revision 1.33
diff -c -r1.33 if_cscope.c
*** if_cscope.c 28 Jan 2009 15:04:42 -0000 1.33
--- if_cscope.c 24 Feb 2009 20:56:53 -0000
***************
*** 93,102 ****
(void)EMSG2(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage);
}
/*
* PRIVATE: do_cscope_general
*
! * find the command, print help if invalid, and the then call the
* corresponding command function,
* called from do_cscope and do_scscope
*/
--- 93,207 ----
(void)EMSG2(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage);
}
+ #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
+
+ static enum
+ {
+ EXP_CSCOPE_SUBCMD, /* expand ":cscope" sub-commands */
+ EXP_CSCOPE_FIND, /* expand ":cscope find" arguments */
+ EXP_CSCOPE_KILL /* expand ":cscope kill" arguments */
+ } expand_what;
+
+ /*
+ * Function given to ExpandGeneric() to obtain the cscope command
+ * expansion.
+ */
+ /*ARGSUSED*/
+ char_u *
+ get_cscope_name(xp, idx)
+ expand_T *xp;
+ int idx;
+ {
+ switch (expand_what)
+ {
+ case EXP_CSCOPE_SUBCMD:
+ /* Complete with sub-commands of ":cscope"
+ * add, find, help, kill, reset, show */
+ return (char_u *)cs_cmds[idx].name;
+ case EXP_CSCOPE_FIND:
+ /* Complete with query type of ":cscope find {query_type}".
+ * query_type can be letters (c, d, ... t) or numbers
+ * (0, 1, ..., 8) but only complete with letters, since
+ * numbers are redundant. */
+ {
+ const char *query_type[] =
+ {
+ "c", "d", "e", "f", "g", "i", "s", "t", NULL
+ };
+ return (char_u *)query_type[idx];
+ }
+ case EXP_CSCOPE_KILL:
+ /* ":cscope kill" accepts connection numbers or partial names
+ * of the pathname of the cscope database as argument. Only
+ * complete with connection numbers. -1 can also be used to
+ * kill all connections. */
+ {
+ int i;
+ int current_idx = 0;
+ static char_u connection[2];
+
+ for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
+ {
+ if (csinfo[i].fname == NULL)
+ continue;
+ if (current_idx++ == idx)
+ {
+ /* Connection number fits in one character since
+ * CSCOPE_MAX_CONNECTIONS is < 10 */
+ connection[0] = i + '0';
+ connection[1] = NUL;
+ return connection;
+ }
+ }
+ return (current_idx == idx && idx > 0) ? (char_u *)"-1" : NULL;
+ }
+ default:
+ return NULL;
+ }
+ }
+
+ /*
+ * Handle command line completion for :cscope command.
+ */
+ void
+ set_context_in_cscope_cmd(xp, arg)
+ expand_T *xp;
+ char_u *arg;
+ {
+ char_u *p;
+
+ /* Default: expand subcommands */
+ xp->xp_context = EXPAND_CSCOPE;
+ expand_what = EXP_CSCOPE_SUBCMD;
+ xp->xp_pattern = arg;
+
+ /* (part of) subcommand already typed */
+ if (*arg != NUL)
+ {
+ p = skiptowhite(arg);
+ if (*p != NUL) /* past first word */
+ {
+ xp->xp_pattern = skipwhite(p);
+ if (*skiptowhite(xp->xp_pattern) != NUL)
+ xp->xp_context = EXPAND_NOTHING;
+ else if (STRNICMP(arg, "add", p - arg) == 0)
+ xp->xp_context = EXPAND_FILES;
+ else if (STRNICMP(arg, "kill", p - arg) == 0)
+ expand_what = EXP_CSCOPE_KILL;
+ else if (STRNICMP(arg, "find", p - arg) == 0)
+ expand_what = EXP_CSCOPE_FIND;
+ else
+ xp->xp_context = EXPAND_NOTHING;
+ }
+ }
+ }
+
+ #endif /* FEAT_CMDL_COMPL */
+
/*
* PRIVATE: do_cscope_general
*
! * find the command, print help if invalid, and then call the
* corresponding command function,
* called from do_cscope and do_scscope
*/
Index: ex_getln.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/ex_getln.c,v
retrieving revision 1.95
diff -c -r1.95 ex_getln.c
*** ex_getln.c 28 Nov 2008 10:00:44 -0000 1.95
--- ex_getln.c 24 Feb 2009 20:56:56 -0000
***************
*** 4503,4508 ****
--- 4503,4511 ----
{EXPAND_EVENTS, get_event_name, TRUE},
{EXPAND_AUGROUP, get_augroup_name, TRUE},
#endif
+ #ifdef FEAT_CSCOPE
+ {EXPAND_CSCOPE, get_cscope_name, TRUE},
+ #endif
#if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
&& (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
{EXPAND_LANGUAGE, get_lang_arg, TRUE},
Index: ex_docmd.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/ex_docmd.c,v
retrieving revision 1.165
diff -c -r1.165 ex_docmd.c
*** ex_docmd.c 21 Feb 2009 19:37:26 -0000 1.165
--- ex_docmd.c 24 Feb 2009 20:57:01 -0000
***************
*** 3683,3688 ****
--- 3683,3693 ----
case CMD_highlight:
set_context_in_highlight_cmd(xp, arg);
break;
+ #ifdef FEAT_CSCOPE
+ case CMD_cscope:
+ set_context_in_cscope_cmd(xp, arg);
+ break;
+ #endif
#ifdef FEAT_LISTCMDS
case CMD_bdelete:
case CMD_bwipeout:
***************
*** 5183,5188 ****
--- 5188,5196 ----
{EXPAND_AUGROUP, "augroup"},
{EXPAND_BUFFERS, "buffer"},
{EXPAND_COMMANDS, "command"},
+ #if defined(FEAT_CSCOPE)
+ {EXPAND_CSCOPE, "cscope"},
+ #endif
#if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
{EXPAND_USER_DEFINED, "custom"},
{EXPAND_USER_LIST, "customlist"},
***************
*** 5941,5947 ****
for (;;)
{
p = cmd->uc_rep; /* source */
! q = buf; /* destinateion */
totlen = 0;
for (;;)
--- 5949,5955 ----
for (;;)
{
p = cmd->uc_rep; /* source */
! q = buf; /* destination */
totlen = 0;
for (;;)
***************
*** 7846,7851 ****
--- 7854,7862 ----
{
vim_free(prev_dir);
prev_dir = NULL;
+
+ vim_free(globaldir);
+ globaldir = NULL;
}
#endif
Index: vim.h
===================================================================
RCS file: /cvsroot/vim/vim7/src/vim.h,v
retrieving revision 1.102
diff -c -r1.102 vim.h
*** vim.h 22 Feb 2009 01:37:37 -0000 1.102
--- vim.h 24 Feb 2009 20:57:02 -0000
***************
*** 708,713 ****
--- 708,714 ----
#define EXPAND_USER_DEFINED 30
#define EXPAND_USER_LIST 31
#define EXPAND_SHELLCMD 32
+ #define EXPAND_CSCOPE 33
/* Values for exmode_active (0 is no exmode) */
#define EXMODE_NORMAL 1
Index: proto/if_cscope.pro
===================================================================
RCS file: /cvsroot/vim/vim7/src/proto/if_cscope.pro,v
retrieving revision 1.4
diff -c -r1.4 if_cscope.pro
*** proto/if_cscope.pro 6 Sep 2007 15:38:21 -0000 1.4
--- proto/if_cscope.pro 24 Feb 2009 20:57:02 -0000
***************
*** 7,10 ****
--- 7,12 ----
void cs_print_tags __ARGS((void));
int cs_connection __ARGS((int num, char_u *dbpath, char_u *ppath));
void cs_end __ARGS((void));
+ char_u *get_cscope_name __ARGS((expand_T *xp, int idx));
+ void set_context_in_cscope_cmd __ARGS((expand_T *xp, char_u *arg));
/* vim: set ft=c : */