degesch: fix binding Meta keys
At last.
This commit is contained in:
		
							parent
							
								
									5dbd6eaa7e
								
							
						
					
					
						commit
						cbda184461
					
				
							
								
								
									
										24
									
								
								degesch.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								degesch.c
									
									
									
									
									
								
							| @ -1422,7 +1422,7 @@ on_readline_goto_buffer (int count, int key) | |||||||
| { | { | ||||||
| 	(void) count; | 	(void) count; | ||||||
| 
 | 
 | ||||||
| 	int n = (key & 0x7F) - '0'; | 	int n = UNMETA (key) - '0'; | ||||||
| 	if (n < 0 || n > 9) | 	if (n < 0 || n > 9) | ||||||
| 		return 0; | 		return 0; | ||||||
| 
 | 
 | ||||||
| @ -1485,10 +1485,19 @@ on_readline_return (int count, int key) | |||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static void | ||||||
|  | app_readline_bind_meta (char key, rl_command_func_t cb) | ||||||
|  | { | ||||||
|  | 	// One of these is going to work
 | ||||||
|  | 	char keyseq[] = { '\\', 'e', key, 0 }; | ||||||
|  | 	rl_bind_key (META (key), cb); | ||||||
|  | 	rl_bind_keyseq (keyseq, cb); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static int | static int | ||||||
| init_readline (void) | init_readline (void) | ||||||
| { | { | ||||||
| 	// TODO: maybe use rl_make_bare_keymap() and start from there;
 | 	// XXX: maybe use rl_make_bare_keymap() and start from there;
 | ||||||
| 	//   our dear user could potentionally rig things up in a way that might
 | 	//   our dear user could potentionally rig things up in a way that might
 | ||||||
| 	//   result in some funny unspecified behaviour
 | 	//   result in some funny unspecified behaviour
 | ||||||
| 
 | 
 | ||||||
| @ -1496,18 +1505,15 @@ init_readline (void) | |||||||
| 	rl_add_defun ("next-buffer", on_readline_next_buffer, -1); | 	rl_add_defun ("next-buffer", on_readline_next_buffer, -1); | ||||||
| 
 | 
 | ||||||
| 	// Redefine M-0 through M-9 to switch buffers
 | 	// Redefine M-0 through M-9 to switch buffers
 | ||||||
| 	char keyseq[] = "\\M-0"; |  | ||||||
| 	for (int i = 0; i <= 9; i++) | 	for (int i = 0; i <= 9; i++) | ||||||
| 	{ | 		app_readline_bind_meta ('0' + i, on_readline_goto_buffer); | ||||||
| 		keyseq[3] = '0' + i; |  | ||||||
| 		rl_bind_keyseq (keyseq, on_readline_goto_buffer); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	rl_bind_keyseq ("\\C-p", rl_named_function ("previous-buffer")); | 	rl_bind_keyseq ("\\C-p", rl_named_function ("previous-buffer")); | ||||||
| 	rl_bind_keyseq ("\\C-n", rl_named_function ("next-buffer")); | 	rl_bind_keyseq ("\\C-n", rl_named_function ("next-buffer")); | ||||||
| 	rl_bind_keyseq ("\\M-p", rl_named_function ("previous-history")); | 	app_readline_bind_meta ('p', rl_named_function ("previous-history")); | ||||||
| 	rl_bind_keyseq ("\\M-n", rl_named_function ("next-history")); | 	app_readline_bind_meta ('n', rl_named_function ("next-history")); | ||||||
| 
 | 
 | ||||||
|  | 	// We need to hide the prompt first
 | ||||||
| 	rl_bind_key (RETURN, on_readline_return); | 	rl_bind_key (RETURN, on_readline_return); | ||||||
| 
 | 
 | ||||||
| 	return 0; | 	return 0; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user