Hi Bram!

On Fr, 13 Apr 2012, Bram Moolenaar wrote:

> Can we use another command to list user-defined digraphs?  Perhaps
> ":dig ?"?
> 
> This patch would also need documentation.  And a test would be good too.

Updated patch.
The patch introduces the following changes:
1) :dig?                    print only user-defined digraphs
2) :dig? <char1>[<char2>]   print an exact match, if 2 chars are given,
                            else print all digraphs matching char1
3) :dig? Number             print digraph for decimal value Number
4) :dig!                    clear all user-defined digraphs
5) :dig! <char1><char2>     clear user-defined digraph <char1><char2>
6) documentation update
7) including a test (test85)


regards,
Christian

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/digraph.txt b/runtime/doc/digraph.txt
--- a/runtime/doc/digraph.txt
+++ b/runtime/doc/digraph.txt
@@ -25,6 +25,7 @@
 
 						*:dig* *:digraphs*
 :dig[raphs]		show currently defined digraphs.
+
 							*E104* *E39*
 :dig[raphs] {char1}{char2} {number} ...
 			Add digraph {char1}{char2} to the list.  {number} is
@@ -36,6 +37,21 @@
 			first character, it has a special meaning in the
 			future.
 
+						*:dig?* *:digraphs?*
+:dig[raphs]?		show currently user-defined digraphs.
+
+:dig[raphs]? nr	show definition for digraph whose decimal value is
+			nr
+
+:dig[raphs]? {char1}[{char2}]
+			show all digraphs matching char1 (and char2 if given)
+
+						*:dig!* *:digraphs!*
+:dig[raphs]!		Clear all user-defined digraphs.
+
+:dig[raphs]! {char1}{char2}
+			Delete digraph {char1}{char2} from the list.
+
 Vim is normally compiled with the |+digraphs| feature.  If the feature is
 disabled, the ":digraph" command will display an error message.
 
diff --git a/src/digraph.c b/src/digraph.c
--- a/src/digraph.c
+++ b/src/digraph.c
@@ -2190,13 +2190,16 @@
  * format: {c1}{c2} char {c1}{c2} char ...
  */
     void
-putdigraph(str)
+putdigraph(str, rem)
     char_u *str;
+    int	    rem;
 {
     int		char1, char2, n;
     int		i;
     digr_T	*dp;
 
+    if (*str == NUL && rem)
+	 ga_clear(&user_digraphs);
     while (*str != NUL)
     {
 	str = skipwhite(str);
@@ -2214,82 +2217,193 @@
 	    EMSG(_("E104: Escape not allowed in digraph"));
 	    return;
 	}
-	str = skipwhite(str);
-	if (!VIM_ISDIGIT(*str))
+	if (!rem)
 	{
-	    EMSG(_(e_number_exp));
-	    return;
+	    str = skipwhite(str);
+	    if (!VIM_ISDIGIT(*str))
+	    {
+		EMSG(_(e_number_exp));
+		return;
+	    }
+	    n = getdigits(&str);
+
+	    /* If the digraph already exists, replace the result. */
+	    dp = (digr_T *)user_digraphs.ga_data;
+	    for (i = 0; i < user_digraphs.ga_len; ++i)
+	    {
+		if ((int)dp->char1 == char1 && (int)dp->char2 == char2)
+		{
+		    dp->result = n;
+		    break;
+		}
+		++dp;
+	    }
+
+	    /* Add a new digraph to the table. */
+	    if (i == user_digraphs.ga_len)
+	    {
+		if (ga_grow(&user_digraphs, 1) == OK)
+		{
+		    dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len;
+		    dp->char1 = char1;
+		    dp->char2 = char2;
+		    dp->result = n;
+		    ++user_digraphs.ga_len;
+		}
+	    }
 	}
-	n = getdigits(&str);
-
-	/* If the digraph already exists, replace the result. */
-	dp = (digr_T *)user_digraphs.ga_data;
-	for (i = 0; i < user_digraphs.ga_len; ++i)
+	else
 	{
-	    if ((int)dp->char1 == char1 && (int)dp->char2 == char2)
-	    {
-		dp->result = n;
-		break;
-	    }
-	    ++dp;
-	}
-
-	/* Add a new digraph to the table. */
-	if (i == user_digraphs.ga_len)
-	{
-	    if (ga_grow(&user_digraphs, 1) == OK)
-	    {
-		dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len;
-		dp->char1 = char1;
-		dp->char2 = char2;
-		dp->result = n;
-		++user_digraphs.ga_len;
-	    }
+	  int found = FALSE;
+	  dp = (digr_T *)user_digraphs.ga_data;
+	  for (i = 0; i < user_digraphs.ga_len && dp != NULL; ++i)
+	  {
+	      if ((int)dp->char1 == char1 && (int)dp->char2 == char2)
+	      {
+		  found = TRUE;
+		  user_digraphs.ga_len--;
+	      }
+	      /* move all digraphs to the front */
+	      if (found)
+		  *(dp) = *(dp+1);
+	      ++dp;
+	  }
+	  if (user_digraphs.ga_len == 0)
+	    ga_clear(&user_digraphs);
 	}
     }
 }
 
     void
-listdigraphs()
+listdigraphs(custom, str)
+    int custom;
+    char_u *str;
 {
     int		i;
+    int         j = 0;
     digr_T	*dp;
+    int		char1 = 0;
+    int		char2 = 0;
+    int         n = -1;
+    char_u      *p;
 
     msg_putchar('\n');
 
-    dp = digraphdefault;
-    for (i = 0; dp->char1 != NUL && !got_int; ++i)
+    str = skipwhite(str);
+    p = str;
+    if (VIM_ISDIGIT(*p))
     {
+	/* check for number argument */
+	n = getdigits(&p);
+    }
+    /* char argument given, discard number then */
+    while (*str != NUL && n <= 99)
+    {
+	if (j == 0)
+	{
+	    char1 = *str;
+	    str++;
+	    n = -1;
+	}
+	else
+	    char2 = *str;
+	j++;
+	if (j > 1)
+	    break;
+    }
+
+    /* Loop twice and try to find an exact match first,
+     * if custom is set and char1 and char2 are set*/
+    for (j=0; j < 2; j++)
+    {
+	if (!custom || char1 != NUL || n > -1)
+	{
+	    dp = digraphdefault;
+	    for (i = 0; dp->char1 != NUL && !got_int; ++i)
+	    {
 #if defined(USE_UNICODE_DIGRAPHS) && defined(FEAT_MBYTE)
-	digr_T tmp;
+		digr_T tmp;
 
-	/* May need to convert the result to 'encoding'. */
-	tmp.char1 = dp->char1;
-	tmp.char2 = dp->char2;
-	tmp.result = getexactdigraph(tmp.char1, tmp.char2, FALSE);
-	if (tmp.result != 0 && tmp.result != tmp.char2
-					  && (has_mbyte || tmp.result <= 255))
-	    printdigraph(&tmp);
+		/* May need to convert the result to 'encoding'. */
+		tmp.char1 = dp->char1;
+		tmp.char2 = dp->char2;
+		tmp.result = getexactdigraph(tmp.char1, tmp.char2, FALSE);
+		if (tmp.result != 0 && tmp.result != tmp.char2
+		    && (has_mbyte || tmp.result <= 255))
+		{
+		    /* print all digraphs */
+		    if (!custom)
+			printdigraph(&tmp);
+		    /* exact match */
+		    else if (j == 0 && custom &&
+			    (n == tmp.result ||
+			    (char1 != NUL && char2 != NUL &&
+			    tmp.char1 == char1 && tmp.char2 == char2)))
+		    {
+			printdigraph(&tmp);
+			goto digraph_end;
+		    }
+		    /* print all matching digraphs */
+		    else if (j == 1 && custom && (
+			tmp.char1 == char1 || tmp.char1 == char2 ||
+			tmp.char2 == char1 || tmp.char2 == char2))
+			printdigraph(&tmp);
+		}
 #else
 
-	if (getexactdigraph(dp->char1, dp->char2, FALSE) == dp->result
+		if (getexactdigraph(dp->char1, dp->char2, FALSE) == dp->result
 # ifdef FEAT_MBYTE
-		&& (has_mbyte || dp->result <= 255)
+			&& (has_mbyte || dp->result <= 255)
 # endif
-		)
-	    printdigraph(dp);
+			)
+		{
+		    if (!custom)
+			printdigraph(dp);
+		    else if (j == 0 && custom &&
+			    (n == tmp.result ||
+			    (char1 != NUL && char2 != NUL &&
+			    tmp.char1 == char1 && tmp.char2 == char2)))
+		    {
+			printdigraph(dp);
+			goto digraph_end;
+		    }
+		    else if (j == 1 && custom && (
+			dp->char1 == char1 || dp->char1 == char2 ||
+			dp->char2 == char1 || dp->char2 == char2))
+			printdigraph(dp);
 #endif
-	++dp;
-	ui_breakcheck();
+		++dp;
+		ui_breakcheck();
+	    }
+	}
+
+	dp = (digr_T *)user_digraphs.ga_data;
+	for (i = 0; i < user_digraphs.ga_len && !got_int; ++i)
+	{
+	    /* print only user-defined digraphs */
+	    if (char1 == NUL || n == -1)
+		printdigraph(dp);
+	    /* exact match */
+	    else if (j == 0 && custom &&
+		    ( n == dp->result || 
+		    (char1 != NUL && char2 != NUL &&
+		    dp->char1 == char1 && dp->char1 == char2)))
+	    {
+		printdigraph(dp);
+		goto digraph_end;
+	    }
+	    else if (j == 1 && custom && (
+		dp->char1 == char1 || dp->char1 == char2 ||
+		dp->char2 == char1 || dp->char2 == char2))
+		printdigraph(dp);
+	    ui_breakcheck();
+	    ++dp;
+	}
+	/* loop twice, only when a char has been given, else break here */
+	if (char1 == NUL)
+	    break;
     }
-
-    dp = (digr_T *)user_digraphs.ga_data;
-    for (i = 0; i < user_digraphs.ga_len && !got_int; ++i)
-    {
-	printdigraph(dp);
-	ui_breakcheck();
-	++dp;
-    }
+digraph_end:
     must_redraw = CLEAR;    /* clear screen, because some digraphs may be
 			       wrong, in which case we messed up ScreenLines */
 }
@@ -2536,4 +2650,3 @@
 }
 
 #endif /* FEAT_KEYMAP */
-
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -318,7 +318,7 @@
 EX(CMD_diffthis,	"diffthis",	ex_diffthis,
 			TRLBAR),
 EX(CMD_digraphs,	"digraphs",	ex_digraphs,
-			EXTRA|TRLBAR|CMDWIN),
+			BANG|EXTRA|TRLBAR|CMDWIN),
 EX(CMD_djump,		"djump",	ex_findpat,
 			BANG|RANGE|DFLALL|WHOLEFOLD|EXTRA),
 EX(CMD_dlist,		"dlist",	ex_findpat,
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -11192,10 +11192,19 @@
     exarg_T	*eap UNUSED;
 {
 #ifdef FEAT_DIGRAPHS
-    if (*eap->arg != NUL)
-	putdigraph(eap->arg);
+    char_u *p = eap->arg;
+
+    if (*eap->arg != NUL || eap->forceit)
+    {
+        skipwhite(p);
+
+	if (*p == '?')
+	  listdigraphs(TRUE, ++p);
+	else
+	    putdigraph(eap->arg, eap->forceit);
+    }
     else
-	listdigraphs();
+	listdigraphs(FALSE, eap->arg);
 #else
     EMSG(_("E196: No digraphs in this version"));
 #endif
diff --git a/src/proto/digraph.pro b/src/proto/digraph.pro
--- a/src/proto/digraph.pro
+++ b/src/proto/digraph.pro
@@ -2,8 +2,8 @@
 int do_digraph __ARGS((int c));
 int get_digraph __ARGS((int cmdline));
 int getdigraph __ARGS((int char1, int char2, int meta));
-void putdigraph __ARGS((char_u *str));
-void listdigraphs __ARGS((void));
+void putdigraph __ARGS((char_u *str, int remove));
+void listdigraphs __ARGS((int force, char_u *str));
 char_u *keymap_init __ARGS((void));
 void ex_loadkeymap __ARGS((exarg_T *eap));
 /* vim: set ft=c : */
diff --git a/src/testdir/Make_amiga.mak b/src/testdir/Make_amiga.mak
--- a/src/testdir/Make_amiga.mak
+++ b/src/testdir/Make_amiga.mak
@@ -29,7 +29,7 @@
 		test66.out test67.out test68.out test69.out test70.out \
 		test71.out test72.out test73.out test74.out test75.out \
 		test76.out test77.out test78.out test79.out test80.out \
-		test81.out test82.out test83.out test84.out
+		test81.out test82.out test83.out test84.out test85.out
 
 .SUFFIXES: .in .out
 
@@ -133,3 +133,4 @@
 test82.out: test82.in
 test83.out: test83.in
 test84.out: test84.in
+test85.out: test85.in
diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak
--- a/src/testdir/Make_dos.mak
+++ b/src/testdir/Make_dos.mak
@@ -30,7 +30,7 @@
 		test68.out test69.out test71.out test72.out test73.out \
 		test74.out test75.out test76.out test77.out test78.out \
 		test79.out test80.out test81.out test82.out test83.out \
-		test84.out
+		test84.out test85.out
 
 SCRIPTS32 =	test50.out test70.out
 
diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak
--- a/src/testdir/Make_ming.mak
+++ b/src/testdir/Make_ming.mak
@@ -50,7 +50,7 @@
 		test68.out test69.out test71.out test72.out test73.out \
 		test74.out test75.out test76.out test77.out test78.out \
 		test79.out test80.out test81.out test82.out test83.out \
-		test84.out
+		test84.out test85.out
 
 SCRIPTS32 =	test50.out test70.out
 
diff --git a/src/testdir/Make_os2.mak b/src/testdir/Make_os2.mak
--- a/src/testdir/Make_os2.mak
+++ b/src/testdir/Make_os2.mak
@@ -29,7 +29,7 @@
 		test66.out test67.out test68.out test69.out test70.out \
 		test71.out test72.out test73.out test74.out test75.out \
 		test76.out test77.out test78.out test79.out test80.out \
-		test81.out test82.out test83.out test84.out
+		test81.out test82.out test83.out test84.out test85.out
 
 .SUFFIXES: .in .out
 
diff --git a/src/testdir/Make_vms.mms b/src/testdir/Make_vms.mms
--- a/src/testdir/Make_vms.mms
+++ b/src/testdir/Make_vms.mms
@@ -76,7 +76,7 @@
 	 test66.out test67.out test68.out test69.out \
 	 test71.out test72.out test74.out test75.out test76.out \
 	 test77.out test78.out test79.out test80.out test81.out \
-	 test82.out test83.out test84.out
+	 test82.out test83.out test84.out test85.out
 
 # Known problems:
 # Test 30: a problem around mac format - unknown reason
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -27,7 +27,7 @@
 		test69.out test70.out test71.out test72.out test73.out \
 		test74.out test75.out test76.out test77.out test78.out \
 		test79.out test80.out test81.out test82.out test83.out \
-		test84.out
+		test84.out test85.out
 
 SCRIPTS_GUI = test16.out
 
diff --git a/src/testdir/test85.in b/src/testdir/test85.in
new file mode 100644
--- /dev/null
+++ b/src/testdir/test85.in
@@ -0,0 +1,21 @@
+Tests for digraphs, don't test built-in digraphs, they could differ in various platforms.
+
+STARTTEST
+:so small.vim
+:dig -- 8212
+:dig \|- 166
+:dig o: 228
+:dig a: 214
+:dig .3 8230
+:redir @a | dig? |redir end|/^start$/put a|1
+:dig! --
+:redir @a | dig? |redir end|/^start$/put a|1
+:dig!
+:redir @a | dig? |redir end|/^start$/put a|1
+:redir @a | dig? SE|redir end|/^start$/put a|1
+:redir @a | dig? 161|redir end|/^start$/put a|1
+:/^start/
+:/^start$/+,$w test.out
+:qa!
+ENDTEST
+start
diff --git a/src/testdir/test85.ok b/src/testdir/test85.ok
new file mode 100644
--- /dev/null
+++ b/src/testdir/test85.ok
@@ -0,0 +1,9 @@
+
+!I ¡  161
+
+SE §  167
+
+
+|- ¦  166    o: ä  228    a: Ö  214    .3 …  8230
+
+-- —  8212   |- ¦  166    o: ä  228    a: Ö  214    .3 …  8230

Raspunde prin e-mail lui