Bram,
On Mi, 11 Apr 2012, Chris Jones wrote:
> Is there a format of the ‘:digraphs’ command that lets you list only
> custom user-defined digraphs - i.e. those that are different from the
> defaults..?
>
> Couldn't find such a thing in Vim 7.2..
>
> If there isn't, something like ‘:dig!’ would be nice..
Here is a patch, that makes :dig! display only user-defined digraphs and
:dig! xy remove the digraph, that is defined by the chars xy
This sounds like a useful addition.
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/src/digraph.c b/src/digraph.c
--- a/src/digraph.c
+++ b/src/digraph.c
@@ -2190,8 +2190,9 @@
* format: {c1}{c2} char {c1}{c2} char ...
*/
void
-putdigraph(str)
+putdigraph(str, rem)
char_u *str;
+ int rem;
{
int char1, char2, n;
int i;
@@ -2214,43 +2215,61 @@
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;
- }
+ 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) = *(dp+1);
+ user_digraphs.ga_len--;
+ break;
+ }
+ ++dp;
+ }
}
}
}
void
-listdigraphs()
+listdigraphs(force)
+ int force;
{
int i;
digr_T *dp;
@@ -2258,7 +2277,7 @@
msg_putchar('\n');
dp = digraphdefault;
- for (i = 0; dp->char1 != NUL && !got_int; ++i)
+ for (i = 0; dp->char1 != NUL && !got_int && !force; ++i)
{
#if defined(USE_UNICODE_DIGRAPHS) && defined(FEAT_MBYTE)
digr_T tmp;
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
@@ -11193,9 +11193,9 @@
{
#ifdef FEAT_DIGRAPHS
if (*eap->arg != NUL)
- putdigraph(eap->arg);
+ putdigraph(eap->arg, eap->forceit);
else
- listdigraphs();
+ listdigraphs(eap->forceit);
#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 *keymap_init __ARGS((void));
void ex_loadkeymap __ARGS((exarg_T *eap));
/* vim: set ft=c : */