81c2858
To: vim-dev@vim.org
81c2858
Subject: Patch 7.2.166
81c2858
Fcc: outbox
81c2858
From: Bram Moolenaar <Bram@moolenaar.net>
81c2858
Mime-Version: 1.0
81c2858
Content-Type: text/plain; charset=ISO-8859-1
81c2858
Content-Transfer-Encoding: 8bit
81c2858
------------
81c2858
81c2858
Patch 7.2.166
81c2858
Problem:    No completion for ":sign" command.
81c2858
Solution:   Add ":sign" completion. (Dominique Pelle)
81c2858
Files:	    src/ex_cmds.c, src/ex_docmd.c, src/ex_getln.c, src/vim.h,
81c2858
	    src/proto/ex_cmds.pro
81c2858
81c2858
81c2858
*** ../vim-7.2.165/src/ex_cmds.c	Tue Feb 24 04:28:40 2009
81c2858
--- src/ex_cmds.c	Wed Apr 29 17:08:27 2009
81c2858
***************
81c2858
*** 6543,6562 ****
81c2858
  static void sign_list_defined __ARGS((sign_T *sp));
81c2858
  static void sign_undefine __ARGS((sign_T *sp, sign_T *sp_prev));
81c2858
  
81c2858
! /*
81c2858
!  * ":sign" command
81c2858
!  */
81c2858
!     void
81c2858
! ex_sign(eap)
81c2858
!     exarg_T	*eap;
81c2858
! {
81c2858
!     char_u	*arg = eap->arg;
81c2858
!     char_u	*p;
81c2858
!     int		idx;
81c2858
!     sign_T	*sp;
81c2858
!     sign_T	*sp_prev;
81c2858
!     buf_T	*buf;
81c2858
!     static char	*cmds[] = {
81c2858
  			"define",
81c2858
  #define SIGNCMD_DEFINE	0
81c2858
  			"undefine",
81c2858
--- 6543,6549 ----
81c2858
  static void sign_list_defined __ARGS((sign_T *sp));
81c2858
  static void sign_undefine __ARGS((sign_T *sp, sign_T *sp_prev));
81c2858
  
81c2858
! static char *cmds[] = {
81c2858
  			"define",
81c2858
  #define SIGNCMD_DEFINE	0
81c2858
  			"undefine",
81c2858
***************
81c2858
*** 6569,6590 ****
81c2858
  #define SIGNCMD_UNPLACE	4
81c2858
  			"jump",
81c2858
  #define SIGNCMD_JUMP	5
81c2858
  #define SIGNCMD_LAST	6
81c2858
!     };
81c2858
  
81c2858
      /* Parse the subcommand. */
81c2858
      p = skiptowhite(arg);
81c2858
!     if (*p != NUL)
81c2858
! 	*p++ = NUL;
81c2858
!     for (idx = 0; ; ++idx)
81c2858
      {
81c2858
! 	if (idx == SIGNCMD_LAST)
81c2858
! 	{
81c2858
! 	    EMSG2(_("E160: Unknown sign command: %s"), arg);
81c2858
! 	    return;
81c2858
! 	}
81c2858
! 	if (STRCMP(arg, cmds[idx]) == 0)
81c2858
! 	    break;
81c2858
      }
81c2858
      arg = skipwhite(p);
81c2858
  
81c2858
--- 6556,6606 ----
81c2858
  #define SIGNCMD_UNPLACE	4
81c2858
  			"jump",
81c2858
  #define SIGNCMD_JUMP	5
81c2858
+ 			NULL
81c2858
  #define SIGNCMD_LAST	6
81c2858
! };
81c2858
! 
81c2858
! /*
81c2858
!  * Find index of a ":sign" subcmd from its name.
81c2858
!  * "*end_cmd" must be writable.
81c2858
!  */
81c2858
!     static int
81c2858
! sign_cmd_idx(begin_cmd, end_cmd)
81c2858
!     char	*begin_cmd;	/* begin of sign subcmd */
81c2858
!     char	*end_cmd;	/* just after sign subcmd */
81c2858
! {
81c2858
!     int		idx;
81c2858
!     char	save = *end_cmd;
81c2858
! 
81c2858
!     *end_cmd = NUL;
81c2858
!     for (idx = 0; ; ++idx)
81c2858
! 	if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0)
81c2858
! 	    break;
81c2858
!     *end_cmd = save;
81c2858
!     return idx;
81c2858
! }
81c2858
! 
81c2858
! /*
81c2858
!  * ":sign" command
81c2858
!  */
81c2858
!     void
81c2858
! ex_sign(eap)
81c2858
!     exarg_T	*eap;
81c2858
! {
81c2858
!     char_u	*arg = eap->arg;
81c2858
!     char_u	*p;
81c2858
!     int		idx;
81c2858
!     sign_T	*sp;
81c2858
!     sign_T	*sp_prev;
81c2858
!     buf_T	*buf;
81c2858
  
81c2858
      /* Parse the subcommand. */
81c2858
      p = skiptowhite(arg);
81c2858
!     idx = sign_cmd_idx(arg, p);
81c2858
!     if (idx == SIGNCMD_LAST)
81c2858
      {
81c2858
! 	EMSG2(_("E160: Unknown sign command: %s"), arg);
81c2858
! 	return;
81c2858
      }
81c2858
      arg = skipwhite(p);
81c2858
  
81c2858
***************
81c2858
*** 7110,7115 ****
81c2858
--- 7126,7311 ----
81c2858
  }
81c2858
  #endif
81c2858
  
81c2858
+ #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
81c2858
+ static enum
81c2858
+ {
81c2858
+     EXP_SUBCMD,		/* expand :sign sub-commands */
81c2858
+     EXP_DEFINE,		/* expand :sign define {name} args */
81c2858
+     EXP_PLACE,		/* expand :sign place {id} args */
81c2858
+     EXP_UNPLACE,	/* expand :sign unplace" */
81c2858
+     EXP_SIGN_NAMES	/* expand with name of placed signs */
81c2858
+ } expand_what;
81c2858
+ 
81c2858
+ /*
81c2858
+  * Function given to ExpandGeneric() to obtain the sign command
81c2858
+  * expansion.
81c2858
+  */
81c2858
+ /*ARGSUSED*/
81c2858
+     char_u *
81c2858
+ get_sign_name(xp, idx)
81c2858
+     expand_T	*xp;
81c2858
+     int		idx;
81c2858
+ {
81c2858
+     sign_T	*sp;
81c2858
+     int		current_idx;
81c2858
+ 
81c2858
+     switch (expand_what)
81c2858
+     {
81c2858
+     case EXP_SUBCMD:
81c2858
+ 	return (char_u *)cmds[idx];
81c2858
+     case EXP_DEFINE:
81c2858
+ 	{
81c2858
+ 	    char *define_arg[] =
81c2858
+ 	    {
81c2858
+ 		"icon=", "linehl=", "text=", "texthl=", NULL
81c2858
+ 	    };
81c2858
+ 	    return (char_u *)define_arg[idx];
81c2858
+ 	}
81c2858
+     case EXP_PLACE:
81c2858
+ 	{
81c2858
+ 	    char *place_arg[] =
81c2858
+ 	    {
81c2858
+ 		"line=", "name=", "file=", "buffer=", NULL
81c2858
+ 	    };
81c2858
+ 	    return (char_u *)place_arg[idx];
81c2858
+ 	}
81c2858
+     case EXP_UNPLACE:
81c2858
+ 	{
81c2858
+ 	    char *unplace_arg[] = { "file=", "buffer=", NULL };
81c2858
+ 	    return (char_u *)unplace_arg[idx];
81c2858
+ 	}
81c2858
+     case EXP_SIGN_NAMES:
81c2858
+ 	/* Complete with name of signs already defined */
81c2858
+ 	current_idx = 0;
81c2858
+ 	for (sp = first_sign; sp != NULL; sp = sp->sn_next)
81c2858
+ 	    if (current_idx++ == idx)
81c2858
+ 		return sp->sn_name;
81c2858
+ 	return NULL;
81c2858
+     default:
81c2858
+ 	return NULL;
81c2858
+     }
81c2858
+ }
81c2858
+ 
81c2858
+ /*
81c2858
+  * Handle command line completion for :sign command.
81c2858
+  */
81c2858
+     void
81c2858
+ set_context_in_sign_cmd(xp, arg)
81c2858
+     expand_T	*xp;
81c2858
+     char_u	*arg;
81c2858
+ {
81c2858
+     char_u	*p;
81c2858
+     char_u	*end_subcmd;
81c2858
+     char_u	*last;
81c2858
+     int		cmd_idx;
81c2858
+     char_u	*begin_subcmd_args;
81c2858
+ 
81c2858
+     /* Default: expand subcommands. */
81c2858
+     xp->xp_context = EXPAND_SIGN;
81c2858
+     expand_what = EXP_SUBCMD;
81c2858
+     xp->xp_pattern = arg;
81c2858
+ 
81c2858
+     end_subcmd = skiptowhite(arg);
81c2858
+     if (*end_subcmd == NUL)
81c2858
+ 	/* expand subcmd name
81c2858
+ 	 * :sign {subcmd}<CTRL-D>*/
81c2858
+ 	return;
81c2858
+ 
81c2858
+     cmd_idx = sign_cmd_idx(arg, end_subcmd);
81c2858
+ 
81c2858
+     /* :sign {subcmd} {subcmd_args}
81c2858
+      *                |
81c2858
+      *                begin_subcmd_args */
81c2858
+     begin_subcmd_args = skipwhite(end_subcmd);
81c2858
+     p = skiptowhite(begin_subcmd_args);
81c2858
+     if (*p == NUL)
81c2858
+     {
81c2858
+ 	/*
81c2858
+ 	 * Expand first argument of subcmd when possible.
81c2858
+ 	 * For ":jump {id}" and ":unplace {id}", we could
81c2858
+ 	 * possibly expand the ids of all signs already placed.
81c2858
+ 	 */
81c2858
+ 	xp->xp_pattern = begin_subcmd_args;
81c2858
+ 	switch (cmd_idx)
81c2858
+ 	{
81c2858
+ 	    case SIGNCMD_LIST:
81c2858
+ 	    case SIGNCMD_UNDEFINE:
81c2858
+ 		/* :sign list <CTRL-D>
81c2858
+ 		 * :sign undefine <CTRL-D> */
81c2858
+ 		expand_what = EXP_SIGN_NAMES;
81c2858
+ 		break;
81c2858
+ 	    default:
81c2858
+ 		xp->xp_context = EXPAND_NOTHING;
81c2858
+ 	}
81c2858
+ 	return;
81c2858
+     }
81c2858
+ 
81c2858
+     /* expand last argument of subcmd */
81c2858
+ 
81c2858
+     /* :sign define {name} {args}...
81c2858
+      *              |
81c2858
+      *              p */
81c2858
+ 
81c2858
+     /* Loop until reaching last argument. */
81c2858
+     do
81c2858
+     {
81c2858
+ 	p = skipwhite(p);
81c2858
+ 	last = p;
81c2858
+ 	p = skiptowhite(p);
81c2858
+     } while (*p != NUL);
81c2858
+ 
81c2858
+     p = vim_strchr(last, '=');
81c2858
+ 
81c2858
+     /* :sign define {name} {args}... {last}=
81c2858
+      *                               |     |
81c2858
+      *                            last     p */
81c2858
+     if (p == NUL)
81c2858
+     {
81c2858
+ 	/* Expand last argument name (before equal sign). */
81c2858
+ 	xp->xp_pattern = last;
81c2858
+ 	switch (cmd_idx)
81c2858
+ 	{
81c2858
+ 	    case SIGNCMD_DEFINE:
81c2858
+ 		expand_what = EXP_DEFINE;
81c2858
+ 		break;
81c2858
+ 	    case SIGNCMD_PLACE:
81c2858
+ 		expand_what = EXP_PLACE;
81c2858
+ 		break;
81c2858
+ 	    case SIGNCMD_JUMP:
81c2858
+ 	    case SIGNCMD_UNPLACE:
81c2858
+ 		expand_what = EXP_UNPLACE;
81c2858
+ 		break;
81c2858
+ 	    default:
81c2858
+ 		xp->xp_context = EXPAND_NOTHING;
81c2858
+ 	}
81c2858
+     }
81c2858
+     else
81c2858
+     {
81c2858
+ 	/* Expand last argument value (after equal sign). */
81c2858
+ 	xp->xp_pattern = p + 1;
81c2858
+ 	switch (cmd_idx)
81c2858
+ 	{
81c2858
+ 	    case SIGNCMD_DEFINE:
81c2858
+ 		if (STRNCMP(last, "texthl", p - last) == 0 ||
81c2858
+ 		    STRNCMP(last, "linehl", p - last) == 0)
81c2858
+ 		    xp->xp_context = EXPAND_HIGHLIGHT;
81c2858
+ 		else if (STRNCMP(last, "icon", p - last) == 0)
81c2858
+ 		    xp->xp_context = EXPAND_FILES;
81c2858
+ 		else
81c2858
+ 		    xp->xp_context = EXPAND_NOTHING;
81c2858
+ 		break;
81c2858
+ 	    case SIGNCMD_PLACE:
81c2858
+ 		if (STRNCMP(last, "name", p - last) == 0)
81c2858
+ 		    expand_what = EXP_SIGN_NAMES;
81c2858
+ 		else
81c2858
+ 		    xp->xp_context = EXPAND_NOTHING;
81c2858
+ 		break;
81c2858
+ 	    default:
81c2858
+ 		xp->xp_context = EXPAND_NOTHING;
81c2858
+ 	}
81c2858
+     }
81c2858
+ }
81c2858
+ #endif
81c2858
  #endif
81c2858
  
81c2858
  #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO)
81c2858
*** ../vim-7.2.165/src/ex_docmd.c	Wed Apr 22 16:22:44 2009
81c2858
--- src/ex_docmd.c	Wed Apr 29 17:05:23 2009
81c2858
***************
81c2858
*** 3695,3700 ****
81c2858
--- 3695,3705 ----
81c2858
  	    set_context_in_cscope_cmd(xp, arg, ea.cmdidx);
81c2858
  	    break;
81c2858
  #endif
81c2858
+ #ifdef FEAT_SIGNS
81c2858
+ 	case CMD_sign:
81c2858
+ 	    set_context_in_sign_cmd(xp, arg);
81c2858
+ 	    break;
81c2858
+ #endif
81c2858
  #ifdef FEAT_LISTCMDS
81c2858
  	case CMD_bdelete:
81c2858
  	case CMD_bwipeout:
81c2858
***************
81c2858
*** 5218,5223 ****
81c2858
--- 5223,5231 ----
81c2858
      {EXPAND_MENUS, "menu"},
81c2858
      {EXPAND_SETTINGS, "option"},
81c2858
      {EXPAND_SHELLCMD, "shellcmd"},
81c2858
+ #if defined(FEAT_SIGNS)
81c2858
+     {EXPAND_SIGN, "sign"},
81c2858
+ #endif
81c2858
      {EXPAND_TAGS, "tag"},
81c2858
      {EXPAND_TAGS_LISTFILES, "tag_listfiles"},
81c2858
      {EXPAND_USER_VARS, "var"},
81c2858
*** ../vim-7.2.165/src/ex_getln.c	Wed Apr 29 12:03:35 2009
81c2858
--- src/ex_getln.c	Wed Apr 29 12:51:42 2009
81c2858
***************
81c2858
*** 325,331 ****
81c2858
  #endif
81c2858
  
81c2858
  #ifdef FEAT_DIGRAPHS
81c2858
!     do_digraph(-1);		/* init digraph typahead */
81c2858
  #endif
81c2858
  
81c2858
      /*
81c2858
--- 325,331 ----
81c2858
  #endif
81c2858
  
81c2858
  #ifdef FEAT_DIGRAPHS
81c2858
!     do_digraph(-1);		/* init digraph typeahead */
81c2858
  #endif
81c2858
  
81c2858
      /*
81c2858
***************
81c2858
*** 4521,4526 ****
81c2858
--- 4521,4529 ----
81c2858
  #ifdef FEAT_CSCOPE
81c2858
  	    {EXPAND_CSCOPE, get_cscope_name, TRUE},
81c2858
  #endif
81c2858
+ #ifdef FEAT_SIGNS
81c2858
+ 	    {EXPAND_SIGN, get_sign_name, TRUE},
81c2858
+ #endif
81c2858
  #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
81c2858
  	&& (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
81c2858
  	    {EXPAND_LANGUAGE, get_lang_arg, TRUE},
81c2858
*** ../vim-7.2.165/src/vim.h	Wed Mar 18 12:50:58 2009
81c2858
--- src/vim.h	Wed Apr 29 12:51:42 2009
81c2858
***************
81c2858
*** 709,714 ****
81c2858
--- 709,715 ----
81c2858
  #define EXPAND_USER_LIST	31
81c2858
  #define EXPAND_SHELLCMD		32
81c2858
  #define EXPAND_CSCOPE		33
81c2858
+ #define EXPAND_SIGN		34
81c2858
  
81c2858
  /* Values for exmode_active (0 is no exmode) */
81c2858
  #define EXMODE_NORMAL		1
81c2858
*** ../vim-7.2.165/src/proto/ex_cmds.pro	Tue Feb 24 04:28:40 2009
81c2858
--- src/proto/ex_cmds.pro	Wed Apr 29 17:10:29 2009
81c2858
***************
81c2858
*** 40,46 ****
81c2858
  int read_viminfo_sub_string __ARGS((vir_T *virp, int force));
81c2858
  void write_viminfo_sub_string __ARGS((FILE *fp));
81c2858
  void free_old_sub __ARGS((void));
81c2858
- void free_signs __ARGS((void));
81c2858
  int prepare_tagpreview __ARGS((int undo_sync));
81c2858
  void ex_help __ARGS((exarg_T *eap));
81c2858
  char_u *check_help_lang __ARGS((char_u *arg));
81c2858
--- 40,45 ----
81c2858
***************
81c2858
*** 56,60 ****
81c2858
--- 55,62 ----
81c2858
  char_u *sign_get_text __ARGS((int typenr));
81c2858
  void *sign_get_image __ARGS((int typenr));
81c2858
  char_u *sign_typenr2name __ARGS((int typenr));
81c2858
+ void free_signs __ARGS((void));
81c2858
+ char_u *get_sign_name __ARGS((expand_T *xp, int idx));
81c2858
+ void set_context_in_sign_cmd __ARGS((expand_T *xp, char_u *arg));
81c2858
  void ex_drop __ARGS((exarg_T *eap));
81c2858
  /* vim: set ft=c : */
81c2858
*** ../vim-7.2.165/src/version.c	Wed Apr 29 18:01:23 2009
81c2858
--- src/version.c	Wed Apr 29 18:43:14 2009
81c2858
***************
81c2858
*** 678,679 ****
81c2858
--- 678,681 ----
81c2858
  {   /* Add new patch number below this line */
81c2858
+ /**/
81c2858
+     166,
81c2858
  /**/
81c2858
81c2858
-- 
81c2858
Did you ever stop to think...  and forget to start again?
81c2858
                                  -- Steven Wright
81c2858
81c2858
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
81c2858
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
81c2858
\\\        download, build and distribute -- http://www.A-A-P.org        ///
81c2858
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///