diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 2 | ||||
| -rw-r--r-- | src/lread.c | 190 |
2 files changed, 82 insertions, 110 deletions
| @@ -1111,7 +1111,7 @@ Also accepts Space to mean yes, or Delete to mean no.") | |||
| 1111 | cursor_in_echo_area = 1; | 1111 | cursor_in_echo_area = 1; |
| 1112 | message ("%s(y or n) ", XSTRING (xprompt)->data); | 1112 | message ("%s(y or n) ", XSTRING (xprompt)->data); |
| 1113 | 1113 | ||
| 1114 | obj = read_char (0, 0, 0, Qnil, 0); | 1114 | obj = read_filtered_event (1, 0, 0); |
| 1115 | cursor_in_echo_area = 0; | 1115 | cursor_in_echo_area = 0; |
| 1116 | /* If we need to quit, quit with cursor_in_echo_area = 0. */ | 1116 | /* If we need to quit, quit with cursor_in_echo_area = 0. */ |
| 1117 | QUIT; | 1117 | QUIT; |
diff --git a/src/lread.c b/src/lread.c index 5d54b7ee704..8615288f06b 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -172,6 +172,84 @@ static Lisp_Object read0 (), read1 (), read_list (), read_vector (); | |||
| 172 | 172 | ||
| 173 | extern Lisp_Object read_char (); | 173 | extern Lisp_Object read_char (); |
| 174 | 174 | ||
| 175 | /* Read input events until we get one that's acceptable for our purposes. | ||
| 176 | |||
| 177 | If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed | ||
| 178 | until we get a character we like, and then stuffed into | ||
| 179 | unread_switch_frame. | ||
| 180 | |||
| 181 | If ASCII_REQUIRED is non-zero, we check function key events to see | ||
| 182 | if the unmodified version of the symbol has a Qascii_character | ||
| 183 | property, and use that character, if present. | ||
| 184 | |||
| 185 | If ERROR_NONASCII is non-zero, we signal an error if the input we | ||
| 186 | get isn't an ASCII character with modifiers. If it's zero but | ||
| 187 | ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII | ||
| 188 | character. */ | ||
| 189 | Lisp_Object | ||
| 190 | read_filtered_event (no_switch_frame, ascii_required, error_nonascii) | ||
| 191 | int no_switch_frame, ascii_required, error_nonascii; | ||
| 192 | { | ||
| 193 | #ifdef standalone | ||
| 194 | return make_number (getchar ()); | ||
| 195 | #else | ||
| 196 | register Lisp_Object val; | ||
| 197 | register Lisp_Object delayed_switch_frame = Qnil; | ||
| 198 | |||
| 199 | /* Read until we get an acceptable event. */ | ||
| 200 | retry: | ||
| 201 | val = read_char (0, 0, 0, Qnil, 0); | ||
| 202 | |||
| 203 | /* switch-frame events are put off until after the next ASCII | ||
| 204 | character. This is better than signalling an error just because | ||
| 205 | the last characters were typed to a separate minibuffer frame, | ||
| 206 | for example. Eventually, some code which can deal with | ||
| 207 | switch-frame events will read it and process it. */ | ||
| 208 | if (no_switch_frame | ||
| 209 | && EVENT_HAS_PARAMETERS (val) | ||
| 210 | && EQ (EVENT_HEAD (val), Qswitch_frame)) | ||
| 211 | { | ||
| 212 | delayed_switch_frame = val; | ||
| 213 | goto retry; | ||
| 214 | } | ||
| 215 | |||
| 216 | if (ascii_required) | ||
| 217 | { | ||
| 218 | /* Convert certain symbols to their ASCII equivalents. */ | ||
| 219 | if (XTYPE (val) == Lisp_Symbol) | ||
| 220 | { | ||
| 221 | Lisp_Object tem, tem1, tem2; | ||
| 222 | tem = Fget (val, Qevent_symbol_element_mask); | ||
| 223 | if (!NILP (tem)) | ||
| 224 | { | ||
| 225 | tem1 = Fget (Fcar (tem), Qascii_character); | ||
| 226 | /* Merge this symbol's modifier bits | ||
| 227 | with the ASCII equivalent of its basic code. */ | ||
| 228 | if (!NILP (tem1)) | ||
| 229 | XFASTINT (val) = XINT (tem1) | XINT (Fcar (Fcdr (tem))); | ||
| 230 | } | ||
| 231 | } | ||
| 232 | |||
| 233 | /* If we don't have a character now, deal with it appropriately. */ | ||
| 234 | if (XTYPE (val) != Lisp_Int) | ||
| 235 | { | ||
| 236 | if (error_nonascii) | ||
| 237 | { | ||
| 238 | unread_command_events = Fcons (val, Qnil); | ||
| 239 | error ("Non-character input-event"); | ||
| 240 | } | ||
| 241 | else | ||
| 242 | goto retry; | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 246 | if (! NILP (delayed_switch_frame)) | ||
| 247 | unread_switch_frame = delayed_switch_frame; | ||
| 248 | |||
| 249 | return val; | ||
| 250 | #endif | ||
| 251 | } | ||
| 252 | |||
| 175 | DEFUN ("read-char", Fread_char, Sread_char, 0, 0, 0, | 253 | DEFUN ("read-char", Fread_char, Sread_char, 0, 0, 0, |
| 176 | "Read a character from the command input (keyboard or macro).\n\ | 254 | "Read a character from the command input (keyboard or macro).\n\ |
| 177 | It is returned as a number.\n\ | 255 | It is returned as a number.\n\ |
| @@ -183,70 +261,14 @@ If you want to read non-character events, or ignore them, call\n\ | |||
| 183 | `read-event' or `read-char-exclusive' instead.") | 261 | `read-event' or `read-char-exclusive' instead.") |
| 184 | () | 262 | () |
| 185 | { | 263 | { |
| 186 | register Lisp_Object val; | 264 | return read_filtered_event (1, 1, 1); |
| 187 | |||
| 188 | #ifndef standalone | ||
| 189 | { | ||
| 190 | register Lisp_Object delayed_switch_frame; | ||
| 191 | |||
| 192 | delayed_switch_frame = Qnil; | ||
| 193 | |||
| 194 | for (;;) | ||
| 195 | { | ||
| 196 | val = read_char (0, 0, 0, Qnil, 0); | ||
| 197 | |||
| 198 | /* switch-frame events are put off until after the next ASCII | ||
| 199 | character. This is better than signalling an error just | ||
| 200 | because the last characters were typed to a separate | ||
| 201 | minibuffer frame, for example. Eventually, some code which | ||
| 202 | can deal with switch-frame events will read it and process | ||
| 203 | it. */ | ||
| 204 | if (EVENT_HAS_PARAMETERS (val) | ||
| 205 | && EQ (EVENT_HEAD (val), Qswitch_frame)) | ||
| 206 | delayed_switch_frame = val; | ||
| 207 | else | ||
| 208 | break; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (! NILP (delayed_switch_frame)) | ||
| 212 | unread_switch_frame = delayed_switch_frame; | ||
| 213 | |||
| 214 | /* Only ASCII characters are acceptable. | ||
| 215 | But convert certain symbols to their ASCII equivalents. */ | ||
| 216 | if (XTYPE (val) == Lisp_Symbol) | ||
| 217 | { | ||
| 218 | Lisp_Object tem, tem1, tem2; | ||
| 219 | tem = Fget (val, Qevent_symbol_element_mask); | ||
| 220 | if (!NILP (tem)) | ||
| 221 | { | ||
| 222 | tem1 = Fget (Fcar (tem), Qascii_character); | ||
| 223 | /* Merge this symbol's modifier bits | ||
| 224 | with the ASCII equivalent of its basic code. */ | ||
| 225 | if (!NILP (tem1)) | ||
| 226 | XFASTINT (val) = XINT (tem1) | XINT (Fcar (Fcdr (tem))); | ||
| 227 | } | ||
| 228 | } | ||
| 229 | if (XTYPE (val) != Lisp_Int) | ||
| 230 | { | ||
| 231 | unread_command_events = Fcons (val, Qnil); | ||
| 232 | error ("Non-character input-event"); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | #else | ||
| 236 | val = getchar (); | ||
| 237 | #endif | ||
| 238 | |||
| 239 | return val; | ||
| 240 | } | 265 | } |
| 241 | 266 | ||
| 242 | DEFUN ("read-event", Fread_event, Sread_event, 0, 0, 0, | 267 | DEFUN ("read-event", Fread_event, Sread_event, 0, 0, 0, |
| 243 | "Read an event object from the input stream.") | 268 | "Read an event object from the input stream.") |
| 244 | () | 269 | () |
| 245 | { | 270 | { |
| 246 | register Lisp_Object val; | 271 | return read_filtered_event (0, 0, 0); |
| 247 | |||
| 248 | val = read_char (0, 0, 0, Qnil, 0); | ||
| 249 | return val; | ||
| 250 | } | 272 | } |
| 251 | 273 | ||
| 252 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 0, 0, | 274 | DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 0, 0, |
| @@ -254,57 +276,7 @@ DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 0, | |||
| 254 | It is returned as a number. Non character events are ignored.") | 276 | It is returned as a number. Non character events are ignored.") |
| 255 | () | 277 | () |
| 256 | { | 278 | { |
| 257 | register Lisp_Object val; | 279 | return read_filtered_event (1, 1, 0); |
| 258 | |||
| 259 | #ifndef standalone | ||
| 260 | { | ||
| 261 | Lisp_Object delayed_switch_frame; | ||
| 262 | |||
| 263 | delayed_switch_frame = Qnil; | ||
| 264 | |||
| 265 | for (;;) | ||
| 266 | { | ||
| 267 | val = read_char (0, 0, 0, Qnil, 0); | ||
| 268 | |||
| 269 | /* Convert certain symbols (for keys like RET, DEL, TAB) | ||
| 270 | to ASCII integers. */ | ||
| 271 | if (XTYPE (val) == Lisp_Symbol) | ||
| 272 | { | ||
| 273 | Lisp_Object tem, tem1; | ||
| 274 | tem = Fget (val, Qevent_symbol_element_mask); | ||
| 275 | if (!NILP (tem)) | ||
| 276 | { | ||
| 277 | tem1 = Fget (Fcar (tem), Qascii_character); | ||
| 278 | /* Merge this symbol's modifier bits | ||
| 279 | with the ASCII equivalent of its basic code. */ | ||
| 280 | if (!NILP (tem1)) | ||
| 281 | XFASTINT (val) = XINT (tem1) | XINT (Fcar (Fcdr (tem))); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | if (XTYPE (val) == Lisp_Int) | ||
| 285 | break; | ||
| 286 | |||
| 287 | /* switch-frame events are put off until after the next ASCII | ||
| 288 | character. This is better than signalling an error just | ||
| 289 | because the last characters were typed to a separate | ||
| 290 | minibuffer frame, for example. Eventually, some code which | ||
| 291 | can deal with switch-frame events will read it and process | ||
| 292 | it. */ | ||
| 293 | else if (EVENT_HAS_PARAMETERS (val) | ||
| 294 | && EQ (EVENT_HEAD (val), Qswitch_frame)) | ||
| 295 | delayed_switch_frame = val; | ||
| 296 | |||
| 297 | /* Drop everything else. */ | ||
| 298 | } | ||
| 299 | |||
| 300 | if (! NILP (delayed_switch_frame)) | ||
| 301 | unread_switch_frame = delayed_switch_frame; | ||
| 302 | } | ||
| 303 | #else | ||
| 304 | val = getchar (); | ||
| 305 | #endif | ||
| 306 | |||
| 307 | return val; | ||
| 308 | } | 280 | } |
| 309 | 281 | ||
| 310 | DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, | 282 | DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0, |