Mercurial > hg > xemacs-beta
comparison lisp/keymap.el @ 5745:f9e4d44504a4
Document #'events-to-keys some more, use it less.
lisp/ChangeLog addition:
2013-07-10 Aidan Kehoe <kehoea@parhasard.net>
* minibuf.el (get-user-response):
* cmdloop.el (y-or-n-p-minibuf):
No need to call #'events-to-keys in these two functions,
#'lookup-key accepts events directly.
* keymap.el:
* keymap.el (events-to-keys):
Document this function some more.
Stop passing strings through unexamined, treat them as vectors of
characters.
Event keys are never integers, remove some code that only ran if
(integerp (event-key ce)).
Event keys are never numbers, don't check for that.
Don't create (menu-selection call-interactively function-name)
keystrokes for menu choices, #'character-to-event doesn't
understand that syntax, so nothing uses it.
Don't ever accept mouse events, #'character-to-event doesn't
accept our synthesising of them.
src/ChangeLog addition:
2013-07-10 Aidan Kehoe <kehoea@parhasard.net>
* keymap.c:
* keymap.c (key_desc_list_to_event):
Drop the allow_menu_events argument.
Don't accept lists starting with Qmenu_selection as describing
keys, nothing generates them in a way this function
understands. The intention is reasonable but the implementation
was never documented and never finished.
* keymap.c (syms_of_keymap):
Drop Qmenu_selection.
* events.c (Fcharacter_to_event):
* keymap.h:
Drop the allow_menu_events argument to key_desc_list_to_event.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 10 Jul 2013 14:14:30 +0100 |
parents | 071b810ceb18 |
children | 0e9f791cc655 |
comparison
equal
deleted
inserted
replaced
5738:f6af091ac654 | 5745:f9e4d44504a4 |
---|---|
303 (set mapvar map))) | 303 (set mapvar map))) |
304 name)) | 304 name)) |
305 | 305 |
306 | 306 |
307 ;;; Converting vectors of events to a read-equivalent form. | 307 ;;; Converting vectors of events to a read-equivalent form. |
308 ;;; This is used both by call-interactively (for the command history) | |
309 ;;; and by macros.el (for saving keyboard macros to a file). | |
310 | |
311 ;; #### why does (events-to-keys [backspace]) return "\C-h"? | |
312 ;; BTW, this function is a mess, and macros.el does *not* use it, in | |
313 ;; spite of the above comment. `format-kbd-macro' is used to save | |
314 ;; keyboard macros to a file. | |
315 (defun events-to-keys (events &optional no-mice) | 308 (defun events-to-keys (events &optional no-mice) |
316 "Given a vector of event objects, returns a vector of key descriptors, | 309 "Given a vector of event objects, return a vector of key descriptors. |
317 or a string (if they all fit in the ASCII range). | 310 |
318 Optional arg NO-MICE means that button events are not allowed." | 311 If all events can be represented unambiguously as characters, return a |
312 string. Both the string and the vector will be equivalent to the events, if | |
313 the elements are passed to `character-to-event'. | |
314 | |
315 If an event represents a key press of a printable ASCII character between ?@ | |
316 and ?_, with the control modifier and only the control modifier, it is | |
317 returned as a character between ?\x00 and ?\x1f, inclusive. ?\\C-i, ?\\C-j, | |
318 ?\\C-m are returned as the symbols `tab', `linefeed' and `return', | |
319 respectively. | |
320 | |
321 There is a similar equivalence between ASCII characters with the meta | |
322 modifier and Latin 1 characters, but this function does not use that | |
323 equivalence. | |
324 | |
325 Obsolete optional argument NO-MICE means that mouse events are not allowed. | |
326 These are actually never allowed, since `character-to-event' never accepts | |
327 them. | |
328 | |
329 EVENTS can be a string, and will be treated as a vector of the events | |
330 corresponding to those characters." | |
331 ;; This is only used in packages. There were some contexts where it was | |
332 ;; used in core, but those dated from before #'lookup-key accepted events | |
333 ;; in KEYS; it conses less and is more accurate to use the events directly, | |
334 ;; rather than calling this function. It'd be nice to move this to | |
335 ;; xemacs-base and add an autoload, there's no need for it to be dumped. | |
319 (if (and events (symbolp events)) (setq events (vector events))) | 336 (if (and events (symbolp events)) (setq events (vector events))) |
320 (cond ((stringp events) | 337 (check-type events array) |
321 events) | 338 (cond ((let* ((length (length events)) |
322 ((not (vectorp events)) | |
323 (signal 'wrong-type-argument (list 'vectorp events))) | |
324 ((let* ((length (length events)) | |
325 (string (make-string length 0)) | 339 (string (make-string length 0)) |
326 c ce | 340 c ce |
327 (i 0)) | 341 (i 0)) |
328 (while (< i length) | 342 (while (< i length) |
329 (setq ce (aref events i)) | 343 (setq ce (aref events i)) |
330 (or (eventp ce) (setq ce (character-to-event ce))) | 344 (or (eventp ce) (setq ce (character-to-event ce))) |
331 ;; Normalize `c' to `?c' and `(control k)' to `?\C-k' | 345 ;; Normalize `c' to `?c' and `(control k)' to `?\C-k' We don't |
332 ;; By passing t for the `allow-meta' arg we could get kbd macros | 346 ;; "normalize" Latin 1 to the corresponding meta characters, or |
333 ;; with meta in them to translate to the string form instead of | 347 ;; vice-versa. |
334 ;; the list/symbol form; but I expect that would cause confusion, | |
335 ;; so let's use the list/symbol form whenever there's | |
336 ;; any ambiguity. | |
337 (setq c (event-to-character ce)) | 348 (setq c (event-to-character ce)) |
338 (if (and c | 349 (if (and c |
339 (key-press-event-p ce)) | 350 (key-press-event-p ce)) |
340 (cond ((symbolp (event-key ce)) | 351 (if (symbolp (event-key ce)) |
341 (if (get (event-key ce) 'character-of-keysym) | 352 (if (get (event-key ce) 'character-of-keysym) |
342 ;; Don't use a string for `backspace' and `tab' to | 353 ;; Don't use a string `tab' to avoid that unpleasant |
343 ;; avoid that unpleasant little ambiguity. | 354 ;; little ambiguity. |
344 (setq c nil))) | 355 (setq c nil)))) |
345 ((and (= (event-modifier-bits ce) 1) ;control | |
346 (integerp (event-key ce))) | |
347 (let* ((te (character-to-event c))) | |
348 (if (and (symbolp (event-key te)) | |
349 (get (event-key te) 'character-of-keysym)) | |
350 ;; Don't "normalize" (control i) to tab | |
351 ;; to avoid the ambiguity in the other direction | |
352 (setq c nil)) | |
353 (deallocate-event te))))) | |
354 (if c | 356 (if c |
355 (aset string i c) | 357 (aset string i c) |
356 (setq i length string nil)) | 358 (setq i length string nil)) |
357 (setq i (1+ i))) | 359 (setq i (1+ i))) |
358 string)) | 360 string)) |
359 (t | 361 (t |
360 (let* ((length (length events)) | 362 (let* ((length (length events)) |
361 (new (copy-sequence events)) | 363 (new (vconcat events nil)) |
362 event mods key | 364 event mods key |
363 (i 0)) | 365 (i 0)) |
364 (while (< i length) | 366 (while (< i length) |
365 (setq event (aref events i)) | 367 (setq event (aref events i)) |
368 (or (eventp event) (setq event (character-to-event event))) | |
366 (cond ((key-press-event-p event) | 369 (cond ((key-press-event-p event) |
367 (setq mods (event-modifiers event) | 370 (setq mods (event-modifiers event) |
368 key (event-key event)) | 371 key (event-key event)) |
369 (if (numberp key) | |
370 (setq key (intern (make-string 1 key)))) | |
371 (aset new i (if mods | |
372 (nconc mods (cons key nil)) | |
373 key))) | |
374 ((misc-user-event-p event) | |
375 (aset new i (list 'menu-selection | |
376 (event-function event) | |
377 (event-object event)))) | |
378 ((or (button-press-event-p event) | |
379 (button-release-event-p event)) | |
380 (if no-mice | |
381 (error | |
382 "Mouse events can't be saved in keyboard macros.")) | |
383 (setq mods (event-modifiers event) | |
384 key (intern (format "button%d%s" | |
385 (event-button event) | |
386 (if (button-release-event-p event) | |
387 "up" "")))) | |
388 (aset new i (if mods | 372 (aset new i (if mods |
389 (nconc mods (cons key nil)) | 373 (nconc mods (cons key nil)) |
390 key))) | 374 key))) |
391 ((or (and event (symbolp event)) | 375 ((or (and event (symbolp event)) |
392 (and (consp event) (symbolp (car event)))) | 376 (and (consp event) (symbolp (car event)))) |
393 (aset new i event)) | 377 (aset new i event)) |
394 (t | 378 (t |
395 (signal 'wrong-type-argument (list 'eventp event)))) | 379 (signal 'wrong-type-argument |
380 (list 'key-press-event-p event)))) | |
396 (setq i (1+ i))) | 381 (setq i (1+ i))) |
397 new)))) | 382 new)))) |
398 | |
399 | 383 |
400 (defun next-key-event () | 384 (defun next-key-event () |
401 "Return the next available keyboard event." | 385 "Return the next available keyboard event." |
402 (let (event) | 386 (let (event) |
403 (while (not (key-press-event-p (setq event (next-command-event)))) | 387 (while (not (key-press-event-p (setq event (next-command-event)))) |