* making a toolbar button globaly available
@ 2009-01-19 17:13 joakim
2009-01-20 5:04 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: joakim @ 2009-01-19 17:13 UTC (permalink / raw)
To: Emacs Development
I've tried these two aproaches, none seem to work.
Is it a bug or just me?
(define-minor-mode pocketcompletion-mode
"Toggle pocketcompletion mode"
;; The initial value.
:init-value nil
;; The indicator for the mode line.
:lighter " pocketcompletion"
;; The minor mode bindings.
:group 'pocketcompletion
:global t
:keymap
'(([tool-bar pocketcompletion] .
(menu-item "pocketcompletion" pocketcompletion
:image (image :type xpm :file "zoom-in.xpm"))))
(message "pocketcompletion minor body %s" pocketcompletion-mode)
;(pocketcompletion-enable-toolbar-button);2nd aproach, uncomment
; this and comment out :keymap
)
(defun pocketcompletion-enable-toolbar-button ()
(define-key global-map [tool-bar pocketcompletion]
'(menu-item "pocketcompletion" pocketcompletion
:image (image :type xpm :file "zoom-in.xpm")))
)
--
Joakim Verona
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: making a toolbar button globaly available
2009-01-19 17:13 making a toolbar button globaly available joakim
@ 2009-01-20 5:04 ` Stefan Monnier
2009-01-29 19:56 ` joakim
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2009-01-20 5:04 UTC (permalink / raw)
To: joakim; +Cc: Emacs Development
> I've tried these two aproaches, none seem to work.
> Is it a bug or just me?
> (define-minor-mode pocketcompletion-mode
> "Toggle pocketcompletion mode"
> ;; The initial value.
> :init-value nil
> ;; The indicator for the mode line.
> :lighter " pocketcompletion"
> ;; The minor mode bindings.
> :group 'pocketcompletion
> :global t
> :keymap
> '(([tool-bar pocketcompletion] .
> (menu-item "pocketcompletion" pocketcompletion
> :image (image :type xpm :file "zoom-in.xpm"))))
> (message "pocketcompletion minor body %s" pocketcompletion-mode)
> ;(pocketcompletion-enable-toolbar-button);2nd aproach, uncomment
> ; this and comment out :keymap
> )
> (defun pocketcompletion-enable-toolbar-button ()
> (define-key global-map [tool-bar pocketcompletion]
> '(menu-item "pocketcompletion" pocketcompletion
> :image (image :type xpm :file "zoom-in.xpm")))
> )
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: making a toolbar button globaly available
2009-01-20 5:04 ` Stefan Monnier
@ 2009-01-29 19:56 ` joakim
0 siblings, 0 replies; 3+ messages in thread
From: joakim @ 2009-01-29 19:56 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Emacs Development
Stefan Monnier <monnier@IRO.UMontreal.CA> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-01-29 19:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-19 17:13 making a toolbar button globaly available joakim
2009-01-20 5:04 ` Stefan Monnier
2009-01-29 19:56 ` joakim
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.