diff options
| author | Stefan Monnier | 2000-09-30 17:00:32 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-09-30 17:00:32 +0000 |
| commit | b1904cd946ddef2e94e93946c2bc10bcd3b0cb71 (patch) | |
| tree | 41e842599a585683c122b4c17e651ef9fcbedf2b | |
| parent | 068127d64b6ae60e0d143438fd252d091998aec8 (diff) | |
| download | emacs-b1904cd946ddef2e94e93946c2bc10bcd3b0cb71.tar.gz emacs-b1904cd946ddef2e94e93946c2bc10bcd3b0cb71.zip | |
(keymap_memberp): New function.
(Fset_keymap_parent): Use it.
(fix_submap_inheritance): Use get_keyelt, get_keymap_1 and KEYMAPP.
Use keymap_memberp to avoid creating cycles.
(access_keymap): Use KEYMAPP.
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/keymap.c | 69 |
2 files changed, 30 insertions, 47 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index b3f37d6a557..1b68592eced 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2000-09-30 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * keymap.c (keymap_memberp): New function. | ||
| 4 | (Fset_keymap_parent): Use it. | ||
| 5 | (fix_submap_inheritance): Use get_keyelt, get_keymap_1 and KEYMAPP. | ||
| 6 | Use keymap_memberp to avoid creating cycles. | ||
| 7 | (access_keymap): Use KEYMAPP. | ||
| 8 | |||
| 1 | 2000-09-30 Gerd Moellmann <gerd@gnu.org> | 9 | 2000-09-30 Gerd Moellmann <gerd@gnu.org> |
| 2 | 10 | ||
| 3 | * process.c (Fopen_network_stream) [HAVE_GETADDRINFO]: Use | 11 | * process.c (Fopen_network_stream) [HAVE_GETADDRINFO]: Use |
diff --git a/src/keymap.c b/src/keymap.c index 7bb7b0d7f6c..a9b659804cd 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -306,6 +306,16 @@ DEFUN ("keymap-parent", Fkeymap_parent, Skeymap_parent, 1, 1, 0, | |||
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | 308 | ||
| 309 | /* Check whether MAP is one of MAPS parents. */ | ||
| 310 | int | ||
| 311 | keymap_memberp (map, maps) | ||
| 312 | Lisp_Object map, maps; | ||
| 313 | { | ||
| 314 | while (KEYMAPP (maps) && !EQ (map, maps)) | ||
| 315 | maps = Fkeymap_parent (maps); | ||
| 316 | return (EQ (map, maps)); | ||
| 317 | } | ||
| 318 | |||
| 309 | /* Set the parent keymap of MAP to PARENT. */ | 319 | /* Set the parent keymap of MAP to PARENT. */ |
| 310 | 320 | ||
| 311 | DEFUN ("set-keymap-parent", Fset_keymap_parent, Sset_keymap_parent, 2, 2, 0, | 321 | DEFUN ("set-keymap-parent", Fset_keymap_parent, Sset_keymap_parent, 2, 2, 0, |
| @@ -323,15 +333,10 @@ PARENT should be nil or another keymap.") | |||
| 323 | 333 | ||
| 324 | if (!NILP (parent)) | 334 | if (!NILP (parent)) |
| 325 | { | 335 | { |
| 326 | Lisp_Object k; | ||
| 327 | |||
| 328 | parent = get_keymap_1 (parent, 1, 1); | 336 | parent = get_keymap_1 (parent, 1, 1); |
| 329 | 337 | ||
| 330 | /* Check for cycles. */ | 338 | /* Check for cycles. */ |
| 331 | k = parent; | 339 | if (keymap_memberp (keymap, parent)) |
| 332 | while (KEYMAPP (k) && !EQ (keymap, k)) | ||
| 333 | k = Fkeymap_parent (k); | ||
| 334 | if (EQ (keymap, k)) | ||
| 335 | error ("Cyclic keymap inheritance"); | 340 | error ("Cyclic keymap inheritance"); |
| 336 | } | 341 | } |
| 337 | 342 | ||
| @@ -400,51 +405,21 @@ fix_submap_inheritance (map, event, submap) | |||
| 400 | /* SUBMAP is a cons that we found as a key binding. | 405 | /* SUBMAP is a cons that we found as a key binding. |
| 401 | Discard the other things found in a menu key binding. */ | 406 | Discard the other things found in a menu key binding. */ |
| 402 | 407 | ||
| 403 | if (CONSP (submap)) | 408 | submap = get_keymap_1 (get_keyelt (submap, 0), 0, 0); |
| 404 | { | ||
| 405 | /* May be an old format menu item */ | ||
| 406 | if (STRINGP (XCAR (submap))) | ||
| 407 | { | ||
| 408 | submap = XCDR (submap); | ||
| 409 | /* Also remove a menu help string, if any, | ||
| 410 | following the menu item name. */ | ||
| 411 | if (CONSP (submap) && STRINGP (XCAR (submap))) | ||
| 412 | submap = XCDR (submap); | ||
| 413 | /* Also remove the sublist that caches key equivalences, if any. */ | ||
| 414 | if (CONSP (submap) | ||
| 415 | && CONSP (XCAR (submap))) | ||
| 416 | { | ||
| 417 | Lisp_Object carcar; | ||
| 418 | carcar = XCAR (XCAR (submap)); | ||
| 419 | if (NILP (carcar) || VECTORP (carcar)) | ||
| 420 | submap = XCDR (submap); | ||
| 421 | } | ||
| 422 | } | ||
| 423 | |||
| 424 | /* Or a new format menu item */ | ||
| 425 | else if (EQ (XCAR (submap), Qmenu_item) | ||
| 426 | && CONSP (XCDR (submap))) | ||
| 427 | { | ||
| 428 | submap = XCDR (XCDR (submap)); | ||
| 429 | if (CONSP (submap)) | ||
| 430 | submap = XCAR (submap); | ||
| 431 | } | ||
| 432 | } | ||
| 433 | 409 | ||
| 434 | /* If it isn't a keymap now, there's no work to do. */ | 410 | /* If it isn't a keymap now, there's no work to do. */ |
| 435 | if (! CONSP (submap) | 411 | if (NILP (submap)) |
| 436 | || ! EQ (XCAR (submap), Qkeymap)) | ||
| 437 | return; | 412 | return; |
| 438 | 413 | ||
| 439 | map_parent = Fkeymap_parent (map); | 414 | map_parent = Fkeymap_parent (map); |
| 440 | if (! NILP (map_parent)) | 415 | if (! NILP (map_parent)) |
| 441 | parent_entry = access_keymap (map_parent, event, 0, 0); | 416 | parent_entry = get_keyelt (access_keymap (map_parent, event, 0, 0), 0); |
| 442 | else | 417 | else |
| 443 | parent_entry = Qnil; | 418 | parent_entry = Qnil; |
| 444 | 419 | ||
| 445 | /* If MAP's parent has something other than a keymap, | 420 | /* If MAP's parent has something other than a keymap, |
| 446 | our own submap shadows it completely, so use nil as SUBMAP's parent. */ | 421 | our own submap shadows it completely, so use nil as SUBMAP's parent. */ |
| 447 | if (! (CONSP (parent_entry) && EQ (XCAR (parent_entry), Qkeymap))) | 422 | if (! KEYMAPP (parent_entry)) |
| 448 | parent_entry = Qnil; | 423 | parent_entry = Qnil; |
| 449 | 424 | ||
| 450 | if (! EQ (parent_entry, submap)) | 425 | if (! EQ (parent_entry, submap)) |
| @@ -455,10 +430,10 @@ fix_submap_inheritance (map, event, submap) | |||
| 455 | { | 430 | { |
| 456 | Lisp_Object tem; | 431 | Lisp_Object tem; |
| 457 | tem = Fkeymap_parent (submap_parent); | 432 | tem = Fkeymap_parent (submap_parent); |
| 458 | if (EQ (tem, parent_entry)) | 433 | if (keymap_memberp (tem, parent_entry)) |
| 434 | /* Fset_keymap_parent could create a cycle. */ | ||
| 459 | return; | 435 | return; |
| 460 | if (CONSP (tem) | 436 | if (KEYMAPP (tem)) |
| 461 | && EQ (XCAR (tem), Qkeymap)) | ||
| 462 | submap_parent = tem; | 437 | submap_parent = tem; |
| 463 | else | 438 | else |
| 464 | break; | 439 | break; |
| @@ -525,7 +500,7 @@ access_keymap (map, idx, t_ok, noinherit) | |||
| 525 | if (EQ (XCAR (binding), idx)) | 500 | if (EQ (XCAR (binding), idx)) |
| 526 | { | 501 | { |
| 527 | val = XCDR (binding); | 502 | val = XCDR (binding); |
| 528 | if (noprefix && CONSP (val) && EQ (XCAR (val), Qkeymap)) | 503 | if (noprefix && KEYMAPP (val)) |
| 529 | return Qnil; | 504 | return Qnil; |
| 530 | if (CONSP (val)) | 505 | if (CONSP (val)) |
| 531 | fix_submap_inheritance (map, idx, val); | 506 | fix_submap_inheritance (map, idx, val); |
| @@ -539,7 +514,7 @@ access_keymap (map, idx, t_ok, noinherit) | |||
| 539 | if (NATNUMP (idx) && XFASTINT (idx) < XVECTOR (binding)->size) | 514 | if (NATNUMP (idx) && XFASTINT (idx) < XVECTOR (binding)->size) |
| 540 | { | 515 | { |
| 541 | val = XVECTOR (binding)->contents[XFASTINT (idx)]; | 516 | val = XVECTOR (binding)->contents[XFASTINT (idx)]; |
| 542 | if (noprefix && CONSP (val) && EQ (XCAR (val), Qkeymap)) | 517 | if (noprefix && KEYMAPP (val)) |
| 543 | return Qnil; | 518 | return Qnil; |
| 544 | if (CONSP (val)) | 519 | if (CONSP (val)) |
| 545 | fix_submap_inheritance (map, idx, val); | 520 | fix_submap_inheritance (map, idx, val); |
| @@ -557,7 +532,7 @@ access_keymap (map, idx, t_ok, noinherit) | |||
| 557 | | CHAR_SHIFT | CHAR_CTL | CHAR_META))) | 532 | | CHAR_SHIFT | CHAR_CTL | CHAR_META))) |
| 558 | { | 533 | { |
| 559 | val = Faref (binding, idx); | 534 | val = Faref (binding, idx); |
| 560 | if (noprefix && CONSP (val) && EQ (XCAR (val), Qkeymap)) | 535 | if (noprefix && KEYMAPP (val)) |
| 561 | return Qnil; | 536 | return Qnil; |
| 562 | if (CONSP (val)) | 537 | if (CONSP (val)) |
| 563 | fix_submap_inheritance (map, idx, val); | 538 | fix_submap_inheritance (map, idx, val); |
| @@ -782,7 +757,7 @@ store_in_keymap (keymap, idx, def) | |||
| 782 | XCDR (insertion_point) | 757 | XCDR (insertion_point) |
| 783 | = Fcons (Fcons (idx, def), XCDR (insertion_point)); | 758 | = Fcons (Fcons (idx, def), XCDR (insertion_point)); |
| 784 | } | 759 | } |
| 785 | 760 | ||
| 786 | return def; | 761 | return def; |
| 787 | } | 762 | } |
| 788 | 763 | ||