diff options
| author | Stefan Monnier | 2013-03-10 21:17:40 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2013-03-10 21:17:40 -0400 |
| commit | cbae07d5e07f53472fa972cd31418a4fe851ac31 (patch) | |
| tree | 1d10110dc3408b650aba2e8f311f7e36f4074933 /src | |
| parent | 819e2da92a18d7af03ccd9cf0a2e5b940eb7b54f (diff) | |
| download | emacs-cbae07d5e07f53472fa972cd31418a4fe851ac31.tar.gz emacs-cbae07d5e07f53472fa972cd31418a4fe851ac31.zip | |
* src/keyboard.c: Move keyboard decoding to read_key_sequence.
(decode_keyboard_code): Remove.
(tty_read_avail_input): Don't try to decode input.
(read_decoded_char): New function.
(read_key_sequence): Use it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/keyboard.c | 145 | ||||
| -rw-r--r-- | src/term.c | 2 | ||||
| -rw-r--r-- | src/termhooks.h | 28 | ||||
| -rw-r--r-- | src/terminal.c | 2 | ||||
| -rw-r--r-- | src/textprop.c | 2 |
6 files changed, 95 insertions, 92 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index b553c96a1db..2359311f98a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-03-11 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * keyboard.c: Move keyboard decoding to read_key_sequence. | ||
| 4 | (decode_keyboard_code): Remove. | ||
| 5 | (tty_read_avail_input): Don't try to decode input. | ||
| 6 | (read_decoded_char): New function. | ||
| 7 | (read_key_sequence): Use it. | ||
| 8 | |||
| 1 | 2013-03-10 Daniel Colascione <dancol@dancol.org> | 9 | 2013-03-10 Daniel Colascione <dancol@dancol.org> |
| 2 | 10 | ||
| 3 | * w32term.h (GUISTR, GUI_ENCODE_FILE, GUI_ENCODE_SYSTEM, GUI_FN) | 11 | * w32term.h (GUISTR, GUI_ENCODE_FILE, GUI_ENCODE_SYSTEM, GUI_FN) |
diff --git a/src/keyboard.c b/src/keyboard.c index a66c28dc3d3..fe8b45a0130 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -6815,48 +6815,6 @@ gobble_input (void) | |||
| 6815 | return nread; | 6815 | return nread; |
| 6816 | } | 6816 | } |
| 6817 | 6817 | ||
| 6818 | static void | ||
| 6819 | decode_keyboard_code (struct tty_display_info *tty, | ||
| 6820 | struct coding_system *coding, | ||
| 6821 | unsigned char *buf, int nbytes) | ||
| 6822 | { | ||
| 6823 | unsigned char *src = buf; | ||
| 6824 | const unsigned char *p; | ||
| 6825 | int i; | ||
| 6826 | |||
| 6827 | if (nbytes == 0) | ||
| 6828 | return; | ||
| 6829 | if (tty->meta_key != 2) | ||
| 6830 | for (i = 0; i < nbytes; i++) | ||
| 6831 | buf[i] &= ~0x80; | ||
| 6832 | if (coding->carryover_bytes > 0) | ||
| 6833 | { | ||
| 6834 | src = alloca (coding->carryover_bytes + nbytes); | ||
| 6835 | memcpy (src, coding->carryover, coding->carryover_bytes); | ||
| 6836 | memcpy (src + coding->carryover_bytes, buf, nbytes); | ||
| 6837 | nbytes += coding->carryover_bytes; | ||
| 6838 | } | ||
| 6839 | coding->destination = alloca (nbytes * 4); | ||
| 6840 | coding->dst_bytes = nbytes * 4; | ||
| 6841 | decode_coding_c_string (coding, src, nbytes, Qnil); | ||
| 6842 | if (coding->produced_char == 0) | ||
| 6843 | return; | ||
| 6844 | for (i = 0, p = coding->destination; i < coding->produced_char; i++) | ||
| 6845 | { | ||
| 6846 | struct input_event event_buf; | ||
| 6847 | |||
| 6848 | EVENT_INIT (event_buf); | ||
| 6849 | event_buf.code = STRING_CHAR_ADVANCE (p); | ||
| 6850 | event_buf.kind = | ||
| 6851 | (ASCII_CHAR_P (event_buf.code) | ||
| 6852 | ? ASCII_KEYSTROKE_EVENT : MULTIBYTE_CHAR_KEYSTROKE_EVENT); | ||
| 6853 | /* See the comment in tty_read_avail_input. */ | ||
| 6854 | event_buf.frame_or_window = tty->top_frame; | ||
| 6855 | event_buf.arg = Qnil; | ||
| 6856 | kbd_buffer_store_event (&event_buf); | ||
| 6857 | } | ||
| 6858 | } | ||
| 6859 | |||
| 6860 | /* This is the tty way of reading available input. | 6818 | /* This is the tty way of reading available input. |
| 6861 | 6819 | ||
| 6862 | Note that each terminal device has its own `struct terminal' object, | 6820 | Note that each terminal device has its own `struct terminal' object, |
| @@ -7014,36 +6972,6 @@ tty_read_avail_input (struct terminal *terminal, | |||
| 7014 | #endif /* not MSDOS */ | 6972 | #endif /* not MSDOS */ |
| 7015 | #endif /* not WINDOWSNT */ | 6973 | #endif /* not WINDOWSNT */ |
| 7016 | 6974 | ||
| 7017 | if (TERMINAL_KEYBOARD_CODING (terminal)->common_flags | ||
| 7018 | & CODING_REQUIRE_DECODING_MASK) | ||
| 7019 | { | ||
| 7020 | struct coding_system *coding = TERMINAL_KEYBOARD_CODING (terminal); | ||
| 7021 | int from; | ||
| 7022 | |||
| 7023 | /* Decode the key sequence except for those with meta | ||
| 7024 | modifiers. */ | ||
| 7025 | for (i = from = 0; ; i++) | ||
| 7026 | if (i == nread || (tty->meta_key == 1 && (cbuf[i] & 0x80))) | ||
| 7027 | { | ||
| 7028 | struct input_event buf; | ||
| 7029 | |||
| 7030 | decode_keyboard_code (tty, coding, cbuf + from, i - from); | ||
| 7031 | if (i == nread) | ||
| 7032 | break; | ||
| 7033 | |||
| 7034 | EVENT_INIT (buf); | ||
| 7035 | buf.kind = ASCII_KEYSTROKE_EVENT; | ||
| 7036 | buf.modifiers = meta_modifier; | ||
| 7037 | buf.code = cbuf[i] & ~0x80; | ||
| 7038 | /* See the comment below. */ | ||
| 7039 | buf.frame_or_window = tty->top_frame; | ||
| 7040 | buf.arg = Qnil; | ||
| 7041 | kbd_buffer_store_event (&buf); | ||
| 7042 | from = i + 1; | ||
| 7043 | } | ||
| 7044 | return nread; | ||
| 7045 | } | ||
| 7046 | |||
| 7047 | for (i = 0; i < nread; i++) | 6975 | for (i = 0; i < nread; i++) |
| 7048 | { | 6976 | { |
| 7049 | struct input_event buf; | 6977 | struct input_event buf; |
| @@ -8783,6 +8711,71 @@ test_undefined (Lisp_Object binding) | |||
| 8783 | && EQ (Fcommand_remapping (binding, Qnil, Qnil), Qundefined))); | 8711 | && EQ (Fcommand_remapping (binding, Qnil, Qnil), Qundefined))); |
| 8784 | } | 8712 | } |
| 8785 | 8713 | ||
| 8714 | /* Like `read_char' but applies keyboard-coding-system to tty input. */ | ||
| 8715 | static Lisp_Object | ||
| 8716 | read_decoded_char (int commandflag, Lisp_Object map, | ||
| 8717 | Lisp_Object prev_event, bool *used_mouse_menu) | ||
| 8718 | { | ||
| 8719 | #define MAX_ENCODED_BYTES 16 | ||
| 8720 | Lisp_Object events[MAX_ENCODED_BYTES]; | ||
| 8721 | int n = 0; | ||
| 8722 | while (true) | ||
| 8723 | { | ||
| 8724 | Lisp_Object nextevt | ||
| 8725 | = read_char (commandflag, map, prev_event, used_mouse_menu, NULL); | ||
| 8726 | struct frame *frame = XFRAME (selected_frame); | ||
| 8727 | struct terminal *terminal = frame->terminal; | ||
| 8728 | if (!((FRAME_TERMCAP_P (frame) || FRAME_MSDOS_P (frame)) | ||
| 8729 | && (TERMINAL_KEYBOARD_CODING (terminal)->common_flags | ||
| 8730 | & CODING_REQUIRE_DECODING_MASK))) | ||
| 8731 | return nextevt; /* No decoding needed. */ | ||
| 8732 | else | ||
| 8733 | { | ||
| 8734 | int meta_key = terminal->display_info.tty->meta_key; | ||
| 8735 | eassert (n < MAX_ENCODED_BYTES); | ||
| 8736 | events[n++] = nextevt; | ||
| 8737 | if (NATNUMP (nextevt) | ||
| 8738 | && XINT (nextevt) < (meta_key == 1 ? 0x80 : 0x100)) | ||
| 8739 | { /* An encoded byte sequence, let's try to decode it. */ | ||
| 8740 | struct coding_system *coding | ||
| 8741 | = TERMINAL_KEYBOARD_CODING (terminal); | ||
| 8742 | unsigned char *src = alloca (n); | ||
| 8743 | int i; | ||
| 8744 | for (i = 0; i < n; i++) | ||
| 8745 | src[i] = XINT (events[i]); | ||
| 8746 | if (meta_key != 2) | ||
| 8747 | for (i = 0; i < n; i++) | ||
| 8748 | src[i] &= ~0x80; | ||
| 8749 | coding->destination = alloca (n * 4); | ||
| 8750 | coding->dst_bytes = n * 4; | ||
| 8751 | decode_coding_c_string (coding, src, n, Qnil); | ||
| 8752 | eassert (coding->produced_char <= n); | ||
| 8753 | if (coding->produced_char == 0) | ||
| 8754 | { /* The encoded sequence is incomplete. */ | ||
| 8755 | if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow. */ | ||
| 8756 | continue; /* Read on! */ | ||
| 8757 | } | ||
| 8758 | else | ||
| 8759 | { | ||
| 8760 | const unsigned char *p = coding->destination; | ||
| 8761 | eassert (coding->carryover_bytes == 0); | ||
| 8762 | n = 0; | ||
| 8763 | while (n < coding->produced_char) | ||
| 8764 | events[n++] = make_number (STRING_CHAR_ADVANCE (p)); | ||
| 8765 | } | ||
| 8766 | } | ||
| 8767 | /* Now `events' should hold decoded events. | ||
| 8768 | Normally, n should be equal to 1, but better not rely on it. | ||
| 8769 | We can only return one event here, so return the first we | ||
| 8770 | had and keep the others (if any) for later. */ | ||
| 8771 | while (n > 1) | ||
| 8772 | Vunread_command_events | ||
| 8773 | = Fcons (events[--n], Vunread_command_events); | ||
| 8774 | return events[0]; | ||
| 8775 | } | ||
| 8776 | } | ||
| 8777 | } | ||
| 8778 | |||
| 8786 | /* Read a sequence of keys that ends with a non prefix character, | 8779 | /* Read a sequence of keys that ends with a non prefix character, |
| 8787 | storing it in KEYBUF, a buffer of size BUFSIZE. | 8780 | storing it in KEYBUF, a buffer of size BUFSIZE. |
| 8788 | Prompt with PROMPT. | 8781 | Prompt with PROMPT. |
| @@ -9060,9 +9053,9 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt, | |||
| 9060 | { | 9053 | { |
| 9061 | KBOARD *interrupted_kboard = current_kboard; | 9054 | KBOARD *interrupted_kboard = current_kboard; |
| 9062 | struct frame *interrupted_frame = SELECTED_FRAME (); | 9055 | struct frame *interrupted_frame = SELECTED_FRAME (); |
| 9063 | key = read_char (NILP (prompt), | 9056 | key = read_decoded_char (NILP (prompt), |
| 9064 | current_binding, last_nonmenu_event, | 9057 | current_binding, last_nonmenu_event, |
| 9065 | &used_mouse_menu, NULL); | 9058 | &used_mouse_menu); |
| 9066 | if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */ | 9059 | if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */ |
| 9067 | /* When switching to a new tty (with a new keyboard), | 9060 | /* When switching to a new tty (with a new keyboard), |
| 9068 | read_char returns the new buffer, rather than -2 | 9061 | read_char returns the new buffer, rather than -2 |
| @@ -10553,7 +10546,7 @@ See also `current-input-mode'. */) | |||
| 10553 | if (tty->flow_control != !NILP (flow)) | 10546 | if (tty->flow_control != !NILP (flow)) |
| 10554 | { | 10547 | { |
| 10555 | #ifndef DOS_NT | 10548 | #ifndef DOS_NT |
| 10556 | /* this causes startup screen to be restored and messes with the mouse */ | 10549 | /* This causes startup screen to be restored and messes with the mouse. */ |
| 10557 | reset_sys_modes (tty); | 10550 | reset_sys_modes (tty); |
| 10558 | #endif | 10551 | #endif |
| 10559 | 10552 | ||
diff --git a/src/term.c b/src/term.c index a31fd51084e..822b74aa44e 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -1321,7 +1321,7 @@ term_get_fkeys_1 (void) | |||
| 1321 | if (!KEYMAPP (KVAR (kboard, Vinput_decode_map))) | 1321 | if (!KEYMAPP (KVAR (kboard, Vinput_decode_map))) |
| 1322 | kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil)); | 1322 | kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil)); |
| 1323 | 1323 | ||
| 1324 | for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++) | 1324 | for (i = 0; i < (sizeof (keys) / sizeof (keys[0])); i++) |
| 1325 | { | 1325 | { |
| 1326 | char *sequence = tgetstr (keys[i].cap, address); | 1326 | char *sequence = tgetstr (keys[i].cap, address); |
| 1327 | if (sequence) | 1327 | if (sequence) |
diff --git a/src/termhooks.h b/src/termhooks.h index 7385298d3d4..252dbabb6f9 100644 --- a/src/termhooks.h +++ b/src/termhooks.h | |||
| @@ -382,7 +382,7 @@ struct terminal | |||
| 382 | struct image_cache *image_cache; | 382 | struct image_cache *image_cache; |
| 383 | #endif /* HAVE_WINDOW_SYSTEM */ | 383 | #endif /* HAVE_WINDOW_SYSTEM */ |
| 384 | 384 | ||
| 385 | /* Device-type dependent data shared amongst all frames on this terminal. */ | 385 | /* Device-type dependent data shared amongst all frames on this terminal. */ |
| 386 | union display_info | 386 | union display_info |
| 387 | { | 387 | { |
| 388 | struct tty_display_info *tty; /* termchar.h */ | 388 | struct tty_display_info *tty; /* termchar.h */ |
| @@ -403,22 +403,22 @@ struct terminal | |||
| 403 | the function `set-keyboard-coding-system'. */ | 403 | the function `set-keyboard-coding-system'. */ |
| 404 | struct coding_system *keyboard_coding; | 404 | struct coding_system *keyboard_coding; |
| 405 | 405 | ||
| 406 | /* Terminal characteristics. */ | 406 | /* Terminal characteristics. */ |
| 407 | /* XXX Are these really used on non-termcap displays? */ | 407 | /* XXX Are these really used on non-termcap displays? */ |
| 408 | 408 | ||
| 409 | int must_write_spaces; /* Nonzero means spaces in the text must | 409 | int must_write_spaces; /* Nonzero means spaces in the text must |
| 410 | actually be output; can't just skip over | 410 | actually be output; can't just skip over |
| 411 | some columns to leave them blank. */ | 411 | some columns to leave them blank. */ |
| 412 | int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string */ | 412 | int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string. */ |
| 413 | 413 | ||
| 414 | int line_ins_del_ok; /* Terminal can insert and delete lines */ | 414 | int line_ins_del_ok; /* Terminal can insert and delete lines. */ |
| 415 | int char_ins_del_ok; /* Terminal can insert and delete chars */ | 415 | int char_ins_del_ok; /* Terminal can insert and delete chars. */ |
| 416 | int scroll_region_ok; /* Terminal supports setting the scroll | 416 | int scroll_region_ok; /* Terminal supports setting the scroll |
| 417 | window */ | 417 | window. */ |
| 418 | int scroll_region_cost; /* Cost of setting the scroll window, | 418 | int scroll_region_cost; /* Cost of setting the scroll window, |
| 419 | measured in characters. */ | 419 | measured in characters. */ |
| 420 | int memory_below_frame; /* Terminal remembers lines scrolled | 420 | int memory_below_frame; /* Terminal remembers lines scrolled |
| 421 | off bottom */ | 421 | off bottom. */ |
| 422 | 422 | ||
| 423 | /* Window-based redisplay interface for this device (0 for tty | 423 | /* Window-based redisplay interface for this device (0 for tty |
| 424 | devices). */ | 424 | devices). */ |
| @@ -617,7 +617,7 @@ tset_selection_alist (struct terminal *t, Lisp_Object val) | |||
| 617 | t->Vselection_alist = val; | 617 | t->Vselection_alist = val; |
| 618 | } | 618 | } |
| 619 | 619 | ||
| 620 | /* Chain of all terminal devices currently in use. */ | 620 | /* Chain of all terminal devices currently in use. */ |
| 621 | extern struct terminal *terminal_list; | 621 | extern struct terminal *terminal_list; |
| 622 | 622 | ||
| 623 | #define FRAME_MUST_WRITE_SPACES(f) ((f)->terminal->must_write_spaces) | 623 | #define FRAME_MUST_WRITE_SPACES(f) ((f)->terminal->must_write_spaces) |
| @@ -638,14 +638,16 @@ extern struct terminal *terminal_list; | |||
| 638 | 638 | ||
| 639 | #define FRAME_TERMINAL(f) ((f)->terminal) | 639 | #define FRAME_TERMINAL(f) ((f)->terminal) |
| 640 | 640 | ||
| 641 | /* Return true if the terminal device is not suspended. */ | 641 | /* Return true if the terminal device is not suspended. */ |
| 642 | #define TERMINAL_ACTIVE_P(d) (((d)->type != output_termcap && (d)->type !=output_msdos_raw) || (d)->display_info.tty->input) | 642 | #define TERMINAL_ACTIVE_P(d) \ |
| 643 | (((d)->type != output_termcap && (d)->type != output_msdos_raw) \ | ||
| 644 | || (d)->display_info.tty->input) | ||
| 643 | 645 | ||
| 644 | extern struct terminal *get_terminal (Lisp_Object terminal, int); | 646 | extern struct terminal *get_terminal (Lisp_Object terminal, int); |
| 645 | extern struct terminal *create_terminal (void); | 647 | extern struct terminal *create_terminal (void); |
| 646 | extern void delete_terminal (struct terminal *); | 648 | extern void delete_terminal (struct terminal *); |
| 647 | 649 | ||
| 648 | /* The initial terminal device, created by initial_term_init. */ | 650 | /* The initial terminal device, created by initial_term_init. */ |
| 649 | extern struct terminal *initial_terminal; | 651 | extern struct terminal *initial_terminal; |
| 650 | 652 | ||
| 651 | extern unsigned char *encode_terminal_code (struct glyph *, int, | 653 | extern unsigned char *encode_terminal_code (struct glyph *, int, |
diff --git a/src/terminal.c b/src/terminal.c index 5e1f1ff77f7..c99c39c64ae 100644 --- a/src/terminal.c +++ b/src/terminal.c | |||
| @@ -280,7 +280,7 @@ delete_terminal (struct terminal *terminal) | |||
| 280 | xfree (terminal->name); | 280 | xfree (terminal->name); |
| 281 | terminal->name = NULL; | 281 | terminal->name = NULL; |
| 282 | 282 | ||
| 283 | /* Check for live frames that are still on this terminal. */ | 283 | /* Check for live frames that are still on this terminal. */ |
| 284 | FOR_EACH_FRAME (tail, frame) | 284 | FOR_EACH_FRAME (tail, frame) |
| 285 | { | 285 | { |
| 286 | struct frame *f = XFRAME (frame); | 286 | struct frame *f = XFRAME (frame); |
diff --git a/src/textprop.c b/src/textprop.c index 18e893b3ef2..2b454485370 100644 --- a/src/textprop.c +++ b/src/textprop.c | |||
| @@ -60,7 +60,7 @@ Lisp_Object Qinvisible, Qintangible, Qmouse_face; | |||
| 60 | static Lisp_Object Qread_only; | 60 | static Lisp_Object Qread_only; |
| 61 | Lisp_Object Qminibuffer_prompt; | 61 | Lisp_Object Qminibuffer_prompt; |
| 62 | 62 | ||
| 63 | /* Sticky properties */ | 63 | /* Sticky properties. */ |
| 64 | Lisp_Object Qfront_sticky, Qrear_nonsticky; | 64 | Lisp_Object Qfront_sticky, Qrear_nonsticky; |
| 65 | 65 | ||
| 66 | /* If o1 is a cons whose cdr is a cons, return non-zero and set o2 to | 66 | /* If o1 is a cons whose cdr is a cons, return non-zero and set o2 to |