Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In the friendly manual page, we find the following under "Emacs Editing Mode" (note that M- stands for the historic 'meta' modifier key but actually means ESC on all current systems): M-[letter Soft-key - Your alias list is searched for an alias by the name __letter and if an alias of this name is defined, its value will be inserted on the input queue. This can be used to program function keys on many terminals. The bug: unlike the M-letter variant, the above simply does not work. For example, if an alias __x is defined, ESC [ x just beeps. Analysis: In this case, ed_macro() in completion.c is called from escape() in emacs.c with i set to '_' (emacs.c lines 1179, 1184). The ed_macro() code in completion.c makes the bug clear: 604: /* undocumented feature, macros of the form <ESC>[c evoke alias __c */ 605: if(i=='_') 606: ep->e_macro[2] = ed_getchar(ep,1); 607: else 608: ep->e_macro[2] = 0; 609: if (isalnum(i)&&(np=nv_search(ep->e_macro,sh.alias_tree,0)) &&(out=nv_getval(np))) //...handle the macro The bug is on line 606. If i is '_' (so we have 'ESC [' in emacs), it gets another character, but it does not update i, so that isalnum(i) on line 609 checks if a constant value '_' is alphanumeric, which is always false. The fix is obvious: on line 606, set i to the value returned by ed_getchar(). Tracing this bug in historic source code, I determined it was there as early as ksh88, when this code was introduced! Yet, at some point, someone seems to have thought it was a good idea to document this in the manual page (while forgetting to edit the comment that says the feature is undocumented). So either they used a fixed version but the fix was never committed to AT&T's version control system, or they documented it without ever trying it. The closed-source ksh88 that shipped with Solaris 10 (2005), as /usr/bin/ksh and /usr/xpg4/bin/sh, has this feature working. So it did get fixed somewhere at some point, but the fix never made it into any publicly available source code -- until now.
- Loading branch information