diff options
| author | Stefan Monnier | 2008-04-04 17:31:20 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-04-04 17:31:20 +0000 |
| commit | 00f7c5edc6a0703d84f4a37f273c31364e6ce0fc (patch) | |
| tree | 6b49abd4cff1d6871cde0356e51e196473a29ae1 | |
| parent | 4591d6cbefecb9b967c87be2997e55a9c073a207 (diff) | |
| download | emacs-00f7c5edc6a0703d84f4a37f273c31364e6ce0fc.tar.gz emacs-00f7c5edc6a0703d84f4a37f273c31364e6ce0fc.zip | |
* subr.el (keymap-canonicalize): New function.
* mouse.el (mouse-menu-non-singleton): Use it.
(mouse-major-mode-menu): Remove hack made unnecessary.
* keymap.c (Qkeymap_canonicalize): New var.
(Fmap_keymap_internal): New fun.
(describe_map): Use keymap-canonicalize.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/mouse.el | 45 | ||||
| -rw-r--r-- | lisp/subr.el | 27 | ||||
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/keymap.c | 29 |
5 files changed, 78 insertions, 31 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 951fe1d23fa..533dd7f1bc2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2008-04-04 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2008-04-04 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * subr.el (keymap-canonicalize): New function. | ||
| 4 | * mouse.el (mouse-menu-non-singleton): Use it. | ||
| 5 | (mouse-major-mode-menu): Remove hack made unnecessary. | ||
| 6 | |||
| 3 | * simple.el (set-fill-column): Prompt rather than error by default. | 7 | * simple.el (set-fill-column): Prompt rather than error by default. |
| 4 | 8 | ||
| 5 | 2008-04-04 Andreas Schwab <schwab@suse.de> | 9 | 2008-04-04 Andreas Schwab <schwab@suse.de> |
diff --git a/lisp/mouse.el b/lisp/mouse.el index c26f12c100c..eb20a73f43f 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -201,19 +201,7 @@ Default to the Edit menu if the major mode doesn't define a menu." | |||
| 201 | menu-bar-edit-menu)) | 201 | menu-bar-edit-menu)) |
| 202 | uniq) | 202 | uniq) |
| 203 | (if ancestor | 203 | (if ancestor |
| 204 | ;; Make our menu inherit from the desired keymap which we want | 204 | (set-keymap-parent newmap ancestor)) |
| 205 | ;; to display as the menu now. | ||
| 206 | ;; Sometimes keymaps contain duplicate menu code, leading to | ||
| 207 | ;; duplicates in the popped-up menu. Avoid this by simply | ||
| 208 | ;; taking the first of any identically-named menus. | ||
| 209 | ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg00469.html | ||
| 210 | (set-keymap-parent newmap | ||
| 211 | (progn | ||
| 212 | (dolist (e ancestor) | ||
| 213 | (unless (and (listp e) | ||
| 214 | (assoc (car e) uniq)) | ||
| 215 | (setq uniq (append uniq (list e))))) | ||
| 216 | uniq))) | ||
| 217 | (popup-menu newmap event prefix))) | 205 | (popup-menu newmap event prefix))) |
| 218 | 206 | ||
| 219 | 207 | ||
| @@ -225,7 +213,7 @@ Otherwise return the whole menu." | |||
| 225 | (let (submap) | 213 | (let (submap) |
| 226 | (map-keymap | 214 | (map-keymap |
| 227 | (lambda (k v) (setq submap (if submap t (cons k v)))) | 215 | (lambda (k v) (setq submap (if submap t (cons k v)))) |
| 228 | menubar) | 216 | (keymap-canonicalize menubar)) |
| 229 | (if (eq submap t) | 217 | (if (eq submap t) |
| 230 | menubar | 218 | menubar |
| 231 | (lookup-key menubar (vector (car submap))))))) | 219 | (lookup-key menubar (vector (car submap))))))) |
| @@ -246,21 +234,20 @@ not it is actually displayed." | |||
| 246 | ;; display non-empty menu pane names. | 234 | ;; display non-empty menu pane names. |
| 247 | (minor-mode-menus | 235 | (minor-mode-menus |
| 248 | (mapcar | 236 | (mapcar |
| 249 | (function | 237 | (lambda (menu) |
| 250 | (lambda (menu) | 238 | (let* ((minor-mode (car menu)) |
| 251 | (let* ((minor-mode (car menu)) | 239 | (menu (cdr menu)) |
| 252 | (menu (cdr menu)) | 240 | (title-or-map (cadr menu))) |
| 253 | (title-or-map (cadr menu))) | 241 | (or (stringp title-or-map) |
| 254 | (or (stringp title-or-map) | 242 | (setq menu |
| 255 | (setq menu | 243 | (cons 'keymap |
| 256 | (cons 'keymap | 244 | (cons (concat |
| 257 | (cons (concat | 245 | (capitalize (subst-char-in-string |
| 258 | (capitalize (subst-char-in-string | 246 | ?- ?\s (symbol-name |
| 259 | ?- ?\s (symbol-name | 247 | minor-mode))) |
| 260 | minor-mode))) | 248 | " Menu") |
| 261 | " Menu") | 249 | (cdr menu))))) |
| 262 | (cdr menu))))) | 250 | menu)) |
| 263 | menu))) | ||
| 264 | (minor-mode-key-binding [menu-bar]))) | 251 | (minor-mode-key-binding [menu-bar]))) |
| 265 | (local-title-or-map (and local-menu (cadr local-menu))) | 252 | (local-title-or-map (and local-menu (cadr local-menu))) |
| 266 | (global-title-or-map (cadr global-menu))) | 253 | (global-title-or-map (cadr global-menu))) |
diff --git a/lisp/subr.el b/lisp/subr.el index b656d2ed203..9166d22b602 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -550,6 +550,33 @@ Don't call this function; it is for internal use only." | |||
| 550 | (dolist (p list) | 550 | (dolist (p list) |
| 551 | (funcall function (car p) (cdr p))))) | 551 | (funcall function (car p) (cdr p))))) |
| 552 | 552 | ||
| 553 | (defun keymap-canonicalize (map) | ||
| 554 | "Return an equivalent keymap, without inheritance." | ||
| 555 | (let ((bindings ()) | ||
| 556 | (ranges ())) | ||
| 557 | (while (keymapp map) | ||
| 558 | (setq map (map-keymap-internal | ||
| 559 | (lambda (key item) | ||
| 560 | (if (consp key) | ||
| 561 | ;; Treat char-ranges specially. | ||
| 562 | (push (cons key item) ranges) | ||
| 563 | (push (cons key item) bindings))) | ||
| 564 | map))) | ||
| 565 | (setq map (funcall (if ranges 'make-keymap 'make-sparse-keymap) | ||
| 566 | (keymap-prompt map))) | ||
| 567 | (dolist (binding ranges) | ||
| 568 | ;; Treat char-ranges specially. | ||
| 569 | (define-key map (car binding) (cdr binding))) | ||
| 570 | (dolist (binding (prog1 bindings (setq bindings ()))) | ||
| 571 | (let* ((key (car binding)) | ||
| 572 | (item (cdr binding)) | ||
| 573 | (oldbind (assq key bindings))) | ||
| 574 | ;; Newer bindings override older. | ||
| 575 | (if oldbind (setq bindings (delq oldbind bindings))) | ||
| 576 | (when item ;nil bindings just hide older ones. | ||
| 577 | (push binding bindings)))) | ||
| 578 | (nconc map bindings))) | ||
| 579 | |||
| 553 | (put 'keyboard-translate-table 'char-table-extra-slots 0) | 580 | (put 'keyboard-translate-table 'char-table-extra-slots 0) |
| 554 | 581 | ||
| 555 | (defun keyboard-translate (from to) | 582 | (defun keyboard-translate (from to) |
diff --git a/src/ChangeLog b/src/ChangeLog index 1fdeca7ed57..e8cc705a23c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2008-04-04 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2008-04-04 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * keymap.c (Qkeymap_canonicalize): New var. | ||
| 4 | (Fmap_keymap_internal): New fun. | ||
| 5 | (describe_map): Use keymap-canonicalize. | ||
| 6 | |||
| 3 | * undo.c (last_boundary_buffer, last_boundary_position): New vars. | 7 | * undo.c (last_boundary_buffer, last_boundary_position): New vars. |
| 4 | (Fundo_boundary): Set them. | 8 | (Fundo_boundary): Set them. |
| 5 | (syms_of_undo): Initialize them. | 9 | (syms_of_undo): Initialize them. |
diff --git a/src/keymap.c b/src/keymap.c index 9ed1e92c84b..94d2ab5fe67 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -731,6 +731,26 @@ map_keymap (map, fun, args, data, autoload) | |||
| 731 | UNGCPRO; | 731 | UNGCPRO; |
| 732 | } | 732 | } |
| 733 | 733 | ||
| 734 | Lisp_Object Qkeymap_canonicalize; | ||
| 735 | |||
| 736 | /* Same as map_keymap, but does it right, properly eliminating duplicate | ||
| 737 | bindings due to inheritance. */ | ||
| 738 | void | ||
| 739 | map_keymap_canonical (map, fun, args, data) | ||
| 740 | map_keymap_function_t fun; | ||
| 741 | Lisp_Object map, args; | ||
| 742 | void *data; | ||
| 743 | { | ||
| 744 | struct gcpro gcpro1; | ||
| 745 | GCPRO1 (args); | ||
| 746 | /* map_keymap_canonical may be used from redisplay (e.g. when building menus) | ||
| 747 | so be careful to ignore errors and to inhibit redisplay. */ | ||
| 748 | map = safe_call1 (Qkeymap_canonicalize, map); | ||
| 749 | /* No need to use `map_keymap' here because canonical map has no parent. */ | ||
| 750 | map_keymap_internal (map, fun, args, data); | ||
| 751 | UNGCPRO; | ||
| 752 | } | ||
| 753 | |||
| 734 | DEFUN ("map-keymap-internal", Fmap_keymap_internal, Smap_keymap_internal, 2, 2, 0, | 754 | DEFUN ("map-keymap-internal", Fmap_keymap_internal, Smap_keymap_internal, 2, 2, 0, |
| 735 | doc: /* Call FUNCTION once for each event binding in KEYMAP. | 755 | doc: /* Call FUNCTION once for each event binding in KEYMAP. |
| 736 | FUNCTION is called with two arguments: the event that is bound, and | 756 | FUNCTION is called with two arguments: the event that is bound, and |
| @@ -3407,14 +3427,16 @@ describe_map (map, prefix, elt_describer, partial, shadow, | |||
| 3407 | kludge = Fmake_vector (make_number (1), Qnil); | 3427 | kludge = Fmake_vector (make_number (1), Qnil); |
| 3408 | definition = Qnil; | 3428 | definition = Qnil; |
| 3409 | 3429 | ||
| 3430 | GCPRO3 (prefix, definition, kludge); | ||
| 3431 | |||
| 3432 | map = call1 (Qkeymap_canonicalize, map); | ||
| 3433 | |||
| 3410 | for (tail = map; CONSP (tail); tail = XCDR (tail)) | 3434 | for (tail = map; CONSP (tail); tail = XCDR (tail)) |
| 3411 | length_needed++; | 3435 | length_needed++; |
| 3412 | 3436 | ||
| 3413 | vect = ((struct describe_map_elt *) | 3437 | vect = ((struct describe_map_elt *) |
| 3414 | alloca (sizeof (struct describe_map_elt) * length_needed)); | 3438 | alloca (sizeof (struct describe_map_elt) * length_needed)); |
| 3415 | 3439 | ||
| 3416 | GCPRO3 (prefix, definition, kludge); | ||
| 3417 | |||
| 3418 | for (tail = map; CONSP (tail); tail = XCDR (tail)) | 3440 | for (tail = map; CONSP (tail); tail = XCDR (tail)) |
| 3419 | { | 3441 | { |
| 3420 | QUIT; | 3442 | QUIT; |
| @@ -3850,6 +3872,9 @@ syms_of_keymap () | |||
| 3850 | apropos_predicate = Qnil; | 3872 | apropos_predicate = Qnil; |
| 3851 | apropos_accumulate = Qnil; | 3873 | apropos_accumulate = Qnil; |
| 3852 | 3874 | ||
| 3875 | Qkeymap_canonicalize = intern ("keymap-canonicalize"); | ||
| 3876 | staticpro (&Qkeymap_canonicalize); | ||
| 3877 | |||
| 3853 | /* Now we are ready to set up this property, so we can | 3878 | /* Now we are ready to set up this property, so we can |
| 3854 | create char tables. */ | 3879 | create char tables. */ |
| 3855 | Fput (Qkeymap, Qchar_table_extra_slots, make_number (0)); | 3880 | Fput (Qkeymap, Qchar_table_extra_slots, make_number (0)); |