[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Icicles, Printing and Easy Menu
RE: Icicles, Printing and Easy Menu
Sat, 28 Oct 2006 12:45:56 -0700
But Icicles mode put something in local maps so
that `easy-menu-get-map' returns the local map but not the
global map, so Printing complained, an error was signaled, and
customizations was cleared.
It sounds to me like a bug in Icicles.
So far I don't see that Emacs is wrong.
No, I don't think so. Herbert can provide more information; he has tracked
this down in detail. In a nutshell, easy-menu-get-map is not getting the
global map, in which printing.el has placed its File > Print menu. Instead,
it is getting a minor-mode map, which has only a limited File menu (with no
Icicles defines a menu item in the File menu-bar menu in icicle-mode-map, a
minor-mode map - it does not change the global-map. If Icicle mode is turned
on before loading printing.el is loaded, then when printing.el is loaded it
calls the easy-menu functions that Herbert mentioned, which pass nil instead
of the global map, which causes easy-menu to look at the current map only (I
think). Since the current map is icicle-mode-map, and it has only an Icicles
entry in its tiny File menu, printing.el fails, because easy-menu does not
find any Print submenu under File.
Herbert can explain the details better. Probably his details will be
necessary to see just what fix is needed.
This really has nothing per se to do with Icicles. Here is a test that
reproduces the error:
1. create file foo.el with these contents:
(defun define-foo-mode-map () ""
(setq foo-mode-map (make-sparse-keymap))
;; Bind foo-find-file in foo-mode-map to whatever
;; whatever find-file is bound to globally.
(define-minor-mode foo-mode "" (define-foo-mode-map))
(defun foo-find-file (file &optional wild) "" (interactive))
2. emacs -Q
3. M-x load-file foo.el
4. M-x foo-mode
5. M-x load-file printing.el
6. M-: (pr-update-menus t)
The problem is that there is no Print submenu in menu File, and there should
With the above recipe, you will in fact get a wrong-type arg, 3 error in
pr-menu-get-item, because the key [menu-bar file Print PostScript\ Print
File] is too long to look up. However, if a test of the result of lookup-key
is added to the code to avoid that error being raised, the real problem
shows up anyway: no Print submenu under File.
(defun pr-menu-get-item (name-list)
;; NAME-LIST is a string or a list of strings.
(or (listp name-list)
(setq name-list (list name-list)))
(let* ((reversed (reverse name-list))
(name (pr-get-symbol (car reversed)))
(path (nreverse (cdr reversed)))
(mapcar 'pr-get-symbol path)))))
(and (not (wholenump menu)) ;; *** THIS TEST ADDED ***
(assq name (nthcdr 2 menu))))))
The problem, I believe, is that easy-menu is not trying to update the right
menu (keymap). In foo mode, the minor-mode keymap is `foo-mode-map'. The
following is the menu-bar stuff in foo-mode-map - the File menu has only one
(open . foo-find-file)
menu-item "Visit New File..." foo-find-file
. " (C-x C-f)")
:help "Specify a new file's name, to edit the file")))
(6 . foo-find-file)))
It is this map that is (first) used by easy-menu, and it chokes when it
cannot look up [menu-bar file Print PostScript\ Print File] in it. It looks
as if the printing.el call to `easy-menu-get-map' mistakenly uses nil as the
first argument. According to the doc, that stands for "the local menu-bar
keymap". (Probably, it would be more exact to say "local or minor-mode
Herbert mentioned that the code actually picks up all maps, but it picks up
the global-map last. I didn't look into this in detail - I just went by the
doc string here, which suggests that only the local map is used. If the
local or minor-mode map is used, whether as the first or the only map, no
Print menu is found under File in that map (because Print is only in the
Perhaps the first arg to easy-menu-get-map should be `global-map', but I'm
not sure if that is appropriate or is even a fix. If all maps are checked
during the menu update, then the updating needs to be tolerant wherever the
Print menu is not present in the map.