mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 15:26:23 -05:00
Improve support for Unicode in describe-key.
This commit is contained in:
parent
c4fab606d1
commit
d48120a557
60
bind.c
60
bind.c
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static int buildlist( char *mstring) ;
|
static int buildlist( char *mstring) ;
|
||||||
static void cmdstr( int c, char *seq) ;
|
static char *cmdstr( unsigned c, char *seq) ;
|
||||||
static unsigned int getckey( int mflag) ;
|
static unsigned int getckey( int mflag) ;
|
||||||
static unsigned int stock( char *keyname) ;
|
static unsigned int stock( char *keyname) ;
|
||||||
static const char *getfname( unsigned keycode, char *failmsg) ;
|
static const char *getfname( unsigned keycode, char *failmsg) ;
|
||||||
@ -75,19 +75,19 @@ BINDABLE( help) {
|
|||||||
|
|
||||||
/* describe the command for a certain key */
|
/* describe the command for a certain key */
|
||||||
BINDABLE( deskey) {
|
BINDABLE( deskey) {
|
||||||
|
const char cmdname[] = "describe-key" ;
|
||||||
char outseq[ NSTRING] ; /* output buffer for command sequence */
|
char outseq[ NSTRING] ; /* output buffer for command sequence */
|
||||||
|
|
||||||
/* prompt the user to type a key to describe */
|
/* prompt the user to type a key to describe */
|
||||||
mlwrite( "describe-key: ");
|
mlwrite( "%s: ", cmdname) ;
|
||||||
|
|
||||||
/* get the command sequence to describe
|
/* get the command sequence to describe
|
||||||
* change it to something we can print as well */
|
* change it to something we can print as well */
|
||||||
int c = getckey( FALSE) ;
|
unsigned keycode = getckey( FALSE) ;
|
||||||
cmdstr( c, outseq) ;
|
|
||||||
|
|
||||||
/* output the command sequence */
|
/* output the command sequence */
|
||||||
mlwrite( "describe-key %s: 0x%x, %s",
|
mlwrite( "%s %s: 0x%x, %s", cmdname, cmdstr( keycode, outseq), keycode,
|
||||||
outseq, c, getfname( c, "Not Bound")) ;
|
getfname( keycode, "Not Bound")) ;
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,10 +123,8 @@ BINDABLE( bindtokey) {
|
|||||||
int c = getckey( prefix_f) ;
|
int c = getckey( prefix_f) ;
|
||||||
|
|
||||||
/* change it to something we can print as well */
|
/* change it to something we can print as well */
|
||||||
cmdstr( c, outseq) ;
|
|
||||||
|
|
||||||
/* and dump it out */
|
/* and dump it out */
|
||||||
ostring( outseq) ;
|
ostring( cmdstr( c, outseq)) ;
|
||||||
|
|
||||||
/* key sequence can't be an active prefix key */
|
/* key sequence can't be an active prefix key */
|
||||||
if( c == metac || c == ctlxc || c == reptc || c == abortc) {
|
if( c == metac || c == ctlxc || c == reptc || c == abortc) {
|
||||||
@ -185,10 +183,8 @@ BINDABLE( unbindkey) {
|
|||||||
int c = getckey( FALSE) ; /* get a command sequence */
|
int c = getckey( FALSE) ; /* get a command sequence */
|
||||||
|
|
||||||
/* change it to something we can print as well */
|
/* change it to something we can print as well */
|
||||||
cmdstr( c, outseq) ;
|
|
||||||
|
|
||||||
/* and dump it out */
|
/* and dump it out */
|
||||||
ostring( outseq) ;
|
ostring( cmdstr( c, outseq)) ;
|
||||||
|
|
||||||
/* prefix key sequence can't be undound, just redefined */
|
/* prefix key sequence can't be undound, just redefined */
|
||||||
if( c == reptc || c == abortc) {
|
if( c == reptc || c == abortc) {
|
||||||
@ -403,41 +399,37 @@ int startup( const char *fname) {
|
|||||||
* int c; sequence to translate
|
* int c; sequence to translate
|
||||||
* char *seq; destination string for sequence
|
* char *seq; destination string for sequence
|
||||||
*/
|
*/
|
||||||
static void cmdstr( int c, char *seq) {
|
static char *cmdstr( unsigned c, char *seq) {
|
||||||
char *ptr; /* pointer into current position in sequence */
|
char *ptr = seq ; /* pointer into current position in sequence */
|
||||||
|
|
||||||
ptr = seq;
|
/* apply meta sequence if needed */
|
||||||
|
if( c & META) {
|
||||||
/* apply meta sequence if needed */
|
|
||||||
if (c & META) {
|
|
||||||
*ptr++ = 'M';
|
*ptr++ = 'M';
|
||||||
*ptr++ = '-';
|
*ptr++ = '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* apply ^X sequence if needed */
|
/* apply ^X sequence if needed */
|
||||||
if (c & CTLX) {
|
if( c & CTLX) {
|
||||||
if( ctlxc & CTRL)
|
if( ctlxc & CTRL)
|
||||||
*ptr++ = '^' ;
|
*ptr++ = '^' ;
|
||||||
|
|
||||||
*ptr++ = ctlxc & 0x1FFFFF ;
|
*ptr++ = ctlxc & ~PRFXMASK ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* apply SPEC sequence if needed */
|
/* apply SPEC sequence if needed */
|
||||||
if (c & SPEC) {
|
if( c & SPEC) {
|
||||||
*ptr++ = 'F';
|
*ptr++ = 'F' ;
|
||||||
*ptr++ = 'N';
|
*ptr++ = 'N' ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* apply control sequence if needed */
|
/* apply control sequence if needed */
|
||||||
if (c & CTRL) {
|
if( c & CTRL)
|
||||||
*ptr++ = '^';
|
*ptr++ = '^' ;
|
||||||
}
|
|
||||||
|
|
||||||
/* and output the final sequence */
|
/* and output the final sequence */
|
||||||
|
ptr += unicode_to_utf8( c & ~PRFXMASK, ptr) ;
|
||||||
*ptr++ = c & 0x1FFFFF ; /* strip the prefixes */
|
*ptr = 0 ; /* terminate the string */
|
||||||
|
return seq ;
|
||||||
*ptr = 0; /* terminate the string */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *getfname( unsigned keycode, char *failmsg) {
|
static const char *getfname( unsigned keycode, char *failmsg) {
|
||||||
|
56
display.c
56
display.c
@ -89,7 +89,7 @@ static void modeline(struct window *wp);
|
|||||||
static void mlputi(int i, int r);
|
static void mlputi(int i, int r);
|
||||||
static void mlputli(long l, int r);
|
static void mlputli(long l, int r);
|
||||||
static void mlputf(int s);
|
static void mlputf(int s);
|
||||||
static void mlputs( unsigned char *s) ;
|
static void mlputs( const char *s) ;
|
||||||
#if SIGWINCH
|
#if SIGWINCH
|
||||||
static int newscreensize(int h, int w);
|
static int newscreensize(int h, int w);
|
||||||
#endif
|
#endif
|
||||||
@ -1274,7 +1274,7 @@ void mlerase( void) {
|
|||||||
static void mlputc( unicode_t c) {
|
static void mlputc( unicode_t c) {
|
||||||
if( ttcol < term.t_ncol) {
|
if( ttcol < term.t_ncol) {
|
||||||
TTputc( c) ;
|
TTputc( c) ;
|
||||||
++ttcol ;
|
ttcol += utf8_width( c) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1284,11 +1284,8 @@ static void mlputc( unicode_t c) {
|
|||||||
* char *s; string to output
|
* char *s; string to output
|
||||||
*/
|
*/
|
||||||
void ostring( const char *s) {
|
void ostring( const char *s) {
|
||||||
unsigned char c ;
|
|
||||||
|
|
||||||
if( discmd)
|
if( discmd)
|
||||||
while( (c = *s++) != 0)
|
mlputs( s) ;
|
||||||
mlputc( c) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1302,8 +1299,6 @@ void ostring( const char *s) {
|
|||||||
* char *arg; pointer to first argument to print
|
* char *arg; pointer to first argument to print
|
||||||
*/
|
*/
|
||||||
void vmlwrite( const char *fmt, va_list ap) {
|
void vmlwrite( const char *fmt, va_list ap) {
|
||||||
int c; /* current char in format string */
|
|
||||||
|
|
||||||
/* if we are not currently echoing on the command line, abort this */
|
/* if we are not currently echoing on the command line, abort this */
|
||||||
if (discmd == FALSE) {
|
if (discmd == FALSE) {
|
||||||
movecursor(term.t_nrow, 0);
|
movecursor(term.t_nrow, 0);
|
||||||
@ -1322,13 +1317,17 @@ void vmlwrite( const char *fmt, va_list ap) {
|
|||||||
movecursor( term.t_nrow, 0) ;
|
movecursor( term.t_nrow, 0) ;
|
||||||
|
|
||||||
mpresf = *fmt ? TRUE : FALSE ; /* flag if line has content or not */
|
mpresf = *fmt ? TRUE : FALSE ; /* flag if line has content or not */
|
||||||
while( ( c = *fmt++) != 0)
|
while( *fmt) {
|
||||||
|
unicode_t c ;
|
||||||
|
|
||||||
|
fmt += utf8_to_unicode( fmt, 0, 4, &c) ;
|
||||||
if( c != '%')
|
if( c != '%')
|
||||||
mlputc( c) ;
|
mlputc( c) ;
|
||||||
else if( ( c = *fmt++) == 0) {
|
else if( *fmt == 0) {
|
||||||
mlputc( '%') ;
|
mlputc( '%') ;
|
||||||
break ;
|
break ;
|
||||||
} else
|
} else {
|
||||||
|
fmt += utf8_to_unicode( fmt, 0, 4, &c) ;
|
||||||
switch( c) {
|
switch( c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
mlputi(va_arg(ap, int), 10);
|
mlputi(va_arg(ap, int), 10);
|
||||||
@ -1347,7 +1346,7 @@ void vmlwrite( const char *fmt, va_list ap) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
mlputs( (unsigned char *) va_arg( ap, char *)) ;
|
mlputs( (char *) va_arg( ap, char *)) ;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -1364,6 +1363,8 @@ void vmlwrite( const char *fmt, va_list ap) {
|
|||||||
case '%':
|
case '%':
|
||||||
mlputc( c) ;
|
mlputc( c) ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* if we can, erase to the end of screen */
|
/* if we can, erase to the end of screen */
|
||||||
if( eolexist == TRUE && ttcol < term.t_ncol)
|
if( eolexist == TRUE && ttcol < term.t_ncol)
|
||||||
@ -1385,31 +1386,16 @@ void mlwrite( const char *fmt, ...) {
|
|||||||
* the characters in the string all have width "1"; if this is not the case
|
* the characters in the string all have width "1"; if this is not the case
|
||||||
* things will get screwed up a little.
|
* things will get screwed up a little.
|
||||||
*/
|
*/
|
||||||
static void mlputs( unsigned char *s) {
|
static void mlputs( const char *s) {
|
||||||
unicode_t c ;
|
while( *s && (ttcol < term.t_ncol)) {
|
||||||
|
unicode_t uc ;
|
||||||
|
|
||||||
while( ((c = *s++) != 0) && (ttcol < term.t_ncol)) {
|
s += utf8_to_unicode( (char *) s, 0, 4, &uc) ;
|
||||||
if( c == '\t') /* Don't render tabulation */
|
if( uc == '\t') /* Don't render tabulation */
|
||||||
c = ' ' ;
|
uc = ' ' ;
|
||||||
else if( c > 0xC1 && c <= 0xF4) { /* Accept UTF-8 sequence */
|
|
||||||
char utf[ 4] ;
|
|
||||||
char cc ;
|
|
||||||
int bytes ;
|
|
||||||
|
|
||||||
utf[ 0] = c ;
|
TTputc( uc) ;
|
||||||
utf[ 1] = cc = *s ;
|
ttcol += utf8_width( uc) ;
|
||||||
if( (c & 0x20) && ((cc & 0xC0) == 0x80)) { /* at least 3 bytes and a valid encoded char */
|
|
||||||
utf[ 2] = cc = s[ 1] ;
|
|
||||||
if( (c & 0x10) && ((cc & 0xC0) == 0x80)) /* at least 4 bytes and a valid encoded char */
|
|
||||||
utf[ 3] = s[ 2] ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes = utf8_to_unicode( utf, 0, sizeof utf, (unicode_t *) &c) ;
|
|
||||||
s += bytes - 1 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
TTputc( c) ;
|
|
||||||
++ttcol ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
names.h
9
names.h
@ -6,10 +6,11 @@
|
|||||||
#include "retcode.h"
|
#include "retcode.h"
|
||||||
|
|
||||||
|
|
||||||
#define CTRL 0x01000000 /* Control flag, or'ed in */
|
#define CTRL 0x01000000 /* Control flag, or'ed in */
|
||||||
#define META 0x02000000 /* Meta flag, or'ed in */
|
#define META 0x02000000 /* Meta flag, or'ed in */
|
||||||
#define CTLX 0x04000000 /* ^X flag, or'ed in */
|
#define CTLX 0x04000000 /* ^X flag, or'ed in */
|
||||||
#define SPEC 0x08000000 /* special key (function keys) */
|
#define SPEC 0x08000000 /* special key (function keys) */
|
||||||
|
#define PRFXMASK 0x0F000000 /* prefix mask */
|
||||||
|
|
||||||
|
|
||||||
/* Bindable uEMACS function pointer type and definition template */
|
/* Bindable uEMACS function pointer type and definition template */
|
||||||
|
Loading…
Reference in New Issue
Block a user