[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: making a toolbar button globaly available
From: |
joakim |
Subject: |
Re: making a toolbar button globaly available |
Date: |
Thu, 29 Jan 2009 20:56:50 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
>
> The problem is that whenever you lookup [tool-bar] in global-map (and
> such a lookup takes place to find the map into which to add the
> pocketcompletion element), you receive a new keymap, built fresh by
> tool-bar-make-keymap.
>
> So you want to manipulate tool-bar-map directly.
> Note that tool-bar-map is buffer-local, so you won't be able to add
> elements truly globally. For that you'll need to advise
> tool-bar-make-keymap :-(
> Stefan
I think that it would be valuable to have a way of adding global tool
bar buttons. I'm not sure about the most elegant way of doing this, but
the below code at least works:
;map to store special global tool bar buttons in
(defvar global-tool-bar-map)
;this is an example of a global tool bar button for my pocketcompletion feature
(setq global-tool-bar-map
(let ((map (make-sparse-keymap)))
(dolist (x '((pocketcompletion . "zoom-in"))
map)
(tool-bar-local-item
(cdr x) (car x) (car x) map))))
;redefinition of tool-bar-make-keymap-1
(defun tool-bar-make-keymap-1 ()
"Generate an actual keymap from `tool-bar-map', without caching."
(mapcar (lambda (bind)
(let (image-exp plist)
(when (and (eq (car-safe (cdr-safe bind)) 'menu-item)
;; For the format of menu-items, see node
;; `Extended Menu Items' in the Elisp manual.
(setq plist (nthcdr (if (consp (nth 4 bind)) 5 4)
bind))
(setq image-exp (plist-get plist :image))
(consp image-exp)
(not (eq (car image-exp) 'image))
(fboundp (car image-exp)))
(if (not (display-images-p))
(setq bind nil)
(let ((image (eval image-exp)))
(unless (and image (image-mask-p image))
(setq image (append image '(:mask heuristic))))
(setq bind (copy-sequence bind)
plist (nthcdr (if (consp (nth 4 bind)) 5 4)
bind))
(plist-put plist :image image))))
bind))
(cons 'keymap (append (cdr global-tool-bar-map)
(cdr tool-bar-map)))
))
--
Joakim Verona