Hi, Here's a little nit that has been bugging me while writing tests for Emacs editing mode in ksh. Since the map-CR-to-NL (ONLCR) output mode is enabled by default on the tty, emitting a newline gets translated into a carriage return (CR) followed by newline (NL). Parts of the Emacs related code emits a explicit CR prior to NL causing two CR characters to be emitted. The diff below disables ONLCR and explicitly ensures a CR is present prior to every emitted NL. Vi mode already does this. I find this approach more favorable and explicit as opposed of keeping ONLCR enabled and removing the double CRs.
Comments? OK? Index: edit.c =================================================================== RCS file: /cvs/src/bin/ksh/edit.c,v retrieving revision 1.57 diff -u -p -r1.57 edit.c --- edit.c 8 Sep 2016 12:12:40 -0000 1.57 +++ edit.c 11 Dec 2017 20:10:00 -0000 @@ -178,6 +178,7 @@ x_mode(bool onoff) edchars.werase = cb.c_cc[VWERASE]; cb.c_iflag &= ~(INLCR|ICRNL); cb.c_lflag &= ~(ISIG|ICANON|ECHO); + cb.c_oflag &= ~(ONLCR); /* osf/1 processes lnext when ~icanon */ cb.c_cc[VLNEXT] = _POSIX_VDISABLE; /* sunos 4.1.x & osf/1 processes discard(flush) when ~icanon */ Index: emacs.c =================================================================== RCS file: /cvs/src/bin/ksh/emacs.c,v retrieving revision 1.75 diff -u -p -r1.75 emacs.c --- emacs.c 26 Nov 2017 20:34:15 -0000 1.75 +++ emacs.c 11 Dec 2017 20:10:00 -0000 @@ -881,7 +881,7 @@ x_search_hist(int c) *p = '\0'; while (1) { if (offset < 0) { - x_e_puts("\nI-search: "); + x_e_puts("\r\nI-search: "); x_e_puts(pat); } x_flush(); @@ -943,8 +943,10 @@ x_search(char *pat, int sameline, int of for (hp = x_histp - (sameline ? 0 : 1) ; hp >= history; --hp) { i = x_match(*hp, pat); if (i >= 0) { - if (offset < 0) + if (offset < 0) { + x_e_putc('\r'); x_e_putc('\n'); + } x_load_hist(hp); x_goto(xbuf + i + strlen(pat) - (*pat == '^')); return i; @@ -1018,10 +1020,9 @@ x_redraw(int limit) char *cp; x_adj_ok = 0; + x_e_putc('\r'); if (limit == -1) x_e_putc('\n'); - else - x_e_putc('\r'); x_flush(); if (xbp == xbuf) { x_col = promptlen(prompt, NULL); @@ -1171,7 +1172,7 @@ x_yank(int c) killtp = killsp; killtp --; if (killstack[killtp] == 0) { - x_e_puts("\nnothing to yank"); + x_e_puts("\r\nnothing to yank"); x_redraw(-1); return KSTD; } @@ -1187,7 +1188,7 @@ x_meta_yank(int c) if ((x_last_command != x_yank && x_last_command != x_meta_yank) || killstack[killtp] == 0) { killtp = killsp; - x_e_puts("\nyank something first"); + x_e_puts("\r\nyank something first"); x_redraw(-1); return KSTD; }