@@ -61,6 +61,7 @@ static char_u *do_one_cmd __ARGS((char_u **, int, struct condstack *, char_u *(*
6161static char_u * do_one_cmd __ARGS ((char_u * * , int , char_u * (* fgetline )(int , void * , int ), void * cookie ));
6262static int if_level = 0 ; /* depth in :if */
6363#endif
64+ static void append_command __ARGS ((char_u * cmd ));
6465static char_u * find_command __ARGS ((exarg_T * eap , int * full ));
6566
6667static void ex_abbreviate __ARGS ((exarg_T * eap ));
@@ -2136,10 +2137,7 @@ do_one_cmd(cmdlinep, sourcing,
21362137 {
21372138 STRCPY (IObuff , _ ("E492: Not an editor command" ));
21382139 if (!sourcing )
2139- {
2140- STRCAT (IObuff , ": " );
2141- STRNCAT (IObuff , * cmdlinep , 40 );
2142- }
2140+ append_command (* cmdlinep );
21432141 errormsg = IObuff ;
21442142 }
21452143 goto doend ;
@@ -2708,8 +2706,7 @@ do_one_cmd(cmdlinep, sourcing,
27082706 STRCPY (IObuff , errormsg );
27092707 errormsg = IObuff ;
27102708 }
2711- STRCAT (errormsg , ": " );
2712- STRNCAT (errormsg , * cmdlinep , IOSIZE - STRLEN (IObuff ) - 1 );
2709+ append_command (* cmdlinep );
27132710 }
27142711 emsg (errormsg );
27152712 }
@@ -2796,6 +2793,42 @@ checkforcmd(pp, cmd, len)
27962793 return FALSE;
27972794}
27982795
2796+ /*
2797+ * Append "cmd" to the error message in IObuff.
2798+ * Takes care of limiting the length and handling 0xa0, which would be
2799+ * invisible otherwise.
2800+ */
2801+ static void
2802+ append_command (cmd )
2803+ char_u * cmd ;
2804+ {
2805+ char_u * s = cmd ;
2806+ char_u * d ;
2807+
2808+ STRCAT (IObuff , ": " );
2809+ d = IObuff + STRLEN (IObuff );
2810+ while (* s != NUL && d - IObuff < IOSIZE - 7 )
2811+ {
2812+ if (
2813+ #ifdef FEAT_MBYTE
2814+ enc_utf8 ? (s [0 ] == 0xc2 && s [1 ] == 0xa0 ) :
2815+ #endif
2816+ * s == 0xa0 )
2817+ {
2818+ s +=
2819+ #ifdef FEAT_MBYTE
2820+ enc_utf8 ? 2 :
2821+ #endif
2822+ 1 ;
2823+ STRCPY (d , "<a0>" );
2824+ d += 4 ;
2825+ }
2826+ else
2827+ MB_COPY_CHAR (s , d );
2828+ }
2829+ * d = NUL ;
2830+ }
2831+
27992832/*
28002833 * Find an Ex command by its name, either built-in or user.
28012834 * Start of the name can be found at eap->cmd.
0 commit comments