unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: joakim@verona.se
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: Emacs Development <emacs-devel@gnu.org>
Subject: Re: making a toolbar button globaly available
Date: Thu, 29 Jan 2009 20:56:50 +0100	[thread overview]
Message-ID: <m38wot998d.fsf@verona.se> (raw)
In-Reply-To: <jwv7i4qh8tm.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 20 Jan 2009 00:04:13 -0500")

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




      reply	other threads:[~2009-01-29 19:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m38wot998d.fsf@verona.se \
    --to=joakim@verona.se \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).