From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Cl=c3=a9ment_Pit-Claudel?= Newsgroups: gmane.emacs.devel Subject: Re: SVG/PNG images in toolbars? Date: Sat, 18 Nov 2017 21:31:30 -0500 Message-ID: References: <5b6aaac8-6e10-4458-7947-3ac4bd40b47c@gmail.com> <831sm6jj79.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1511058700 27642 195.159.176.226 (19 Nov 2017 02:31:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 19 Nov 2017 02:31:40 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 19 03:31:35 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGFOP-0006jt-0H for ged-emacs-devel@m.gmane.org; Sun, 19 Nov 2017 03:31:33 +0100 Original-Received: from localhost ([::1]:51704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGFOW-00049T-CU for ged-emacs-devel@m.gmane.org; Sat, 18 Nov 2017 21:31:40 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGFOP-00049C-P1 for emacs-devel@gnu.org; Sat, 18 Nov 2017 21:31:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGFOO-00073d-NL for emacs-devel@gnu.org; Sat, 18 Nov 2017 21:31:33 -0500 Original-Received: from mail-qk0-x234.google.com ([2607:f8b0:400d:c09::234]:34533) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eGFOO-00073R-Jk; Sat, 18 Nov 2017 21:31:32 -0500 Original-Received: by mail-qk0-x234.google.com with SMTP id v137so3776822qkb.1; Sat, 18 Nov 2017 18:31:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=r92W4foTiwjYh1ofUDpfcFPtQ+3ETyFTKA5cDudMEMQ=; b=hMBIahrx792SWZ3J3NmWCcmraiRtBgRRkTSg7HpMS9M/dC5L6vgn3tOD++aiz+GOvc dX637g4fe7XmYVdq5IpGlVJ3t6DEknO0H1OsUDVzdHyriHBSZwKyJkDMuWetPfgUUlUV wXbzZBwzj3SzPH5tzIm86icz+cFJ5Fc+gwwjX96b+jgEsWRaS1vYGy3T3QlWQy9sHlkt ktHnTzXPFVAubbmC3G8f63KxgyTCof16z30/PG0OSyEtRDXmFfEFZgGSOKhhKXVfYITK GLTph3hh1Wki02ZNVTwdOKU2O2STihuIUdeZdqnJzdrhctOy04x2JxVL9L2eAkB+JODw os7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=r92W4foTiwjYh1ofUDpfcFPtQ+3ETyFTKA5cDudMEMQ=; b=Iw8LlG9raYw+Yj/GwIG/ektIKIDqO5jGp0VQOBQGAlmmIRvO4b3FW8lwtMhx1lj0ro e/JiDreKLKx5OA7DbTfB9uLBT+d+RGqJ6V4HPJ3FnXxVvkL5l5miH9MZhC1JzwQ5AtrV 2XSz5X8t6qE0Qrl2rFt4pZbfclxApeeTOe4qaP0yMuuu/52bBT4QrcqtAWAd50CEjSNe 2SKHkMbu38UjzOCMuzSMg9y1yeMDXGA8bFEVULdRwh5NqLgYU0r9XxZGd1gs9qKAR7py anpT83qFSNWlxGlQ4r2x0iuYvuKt/oExGY3VLm0RzgYLzDYn8ORhqAG09UuMQFXhVOqm 4yXA== X-Gm-Message-State: AJaThX7jM+iOayHpK7yiAXvAxcpXR1VHL4YjYwio0O80Zu92zr8m+7jo j9ofzfGV2dgSoCmKaWVFJVEEDgu6 X-Google-Smtp-Source: AGs4zMZM631EIUDpuGRd9e4FDFhkLj/PvDdB/4i1M21EoJRIc5tZjt0Q+FyKWn873Ccqp/Vk+MOxjw== X-Received: by 10.55.144.132 with SMTP id s126mr15621473qkd.309.1511058691586; Sat, 18 Nov 2017 18:31:31 -0800 (PST) Original-Received: from ?IPv6:2601:184:4180:66e7:91b1:9a76:6729:5fac? ([2601:184:4180:66e7:91b1:9a76:6729:5fac]) by smtp.gmail.com with ESMTPSA id v50sm4156490qta.0.2017.11.18.18.31.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Nov 2017 18:31:31 -0800 (PST) In-Reply-To: <831sm6jj79.fsf@gnu.org> Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::234 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:220272 Archived-At: On 2017-10-14 03:13, Eli Zaretskii wrote: >> From: Clément Pit-Claudel >> Date: Sat, 14 Oct 2017 04:15:15 +0200 >> >> Question: could we extend tool-bar--image-expression to return a form including references to SVGs and PNGs? I'd be happy to provide a patch. > > Please show the patch. Something along these lines, roughly: diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el index ee01a69..4bc7354 100644 --- a/lisp/tool-bar.el +++ b/lisp/tool-bar.el @@ -152,13 +152,17 @@ tool-bar--image-expression (pbm-spec (append (list :type 'pbm :file (concat icon ".pbm")) colors)) (xbm-spec (append (list :type 'xbm :file - (concat icon ".xbm")) colors))) + (concat icon ".xbm")) colors)) + (png-spec (append (list :type 'png :file + (concat icon ".png")) colors)) + (svg-spec (append (list :type 'svg :file + (concat icon ".svg")) colors))) `(find-image (cond ((not (display-color-p)) ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec)) ((< (display-color-cells) 256) ',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec)) (t - ',(list xpm-spec pbm-spec xbm-spec)))))) + ',(list svg-spec png-spec xpm-spec pbm-spec xbm-spec)))))) ;;;###autoload (defun tool-bar-local-item (icon def key map &rest props) > Though I admit I don't really understand the > purpose of such a patch: you can already provide an image spec for a > tool-bar button when you write the corresponding define-key > expression, and you can secify any images you like in that spec. > tool-bar--image-expression is for constructing tool-bar items from > menus, AFAIR. Yes, exactly. Sorry I was unclear. Let me try to explain better :) I already have a menu for my major mode, and I'm making a toolbar for it. tool-bar-local-item-from-menu is super convenient for that: (defvar mymode-tool-bar-map (let ((map (make-sparse-keymap))) (tool-bar-local-item-from-menu 'mymode-copy "mymode-copy" map mymode-map) (tool-bar-local-item-from-menu 'mymode-paste "mymode-paste" map mymode-map) (define-key-after map [mymode-sep] '(menu-item "--")) (tool-bar-local-item-from-menu 'mymode-reload "mymode-reload" map mymode-map) …)) … except this code only works if my icons (mymode-copy, mymode-paste, mymode-reload etc.) are in XPM, PBM, or XBM format. That's because tool-bar-local-item-from-menu calls tool-bar--image-expression to build the image spec of the new toolbar item, and unfortunately the resulting spec only references XPM, PBM, and XBM files (this is documented in tool-bar-add-item): > ICON is the base name of a file containing the image to use. The > function will first try to use low-color/ICON.xpm if `display-color-cells' > is less or equal to 256, then ICON.xpm, then ICON.pbm, and finally > ICON.xbm, using `find-image' Now suppose I want to use PNG or SVG images in my toolbar. I can either rebind tool-bar--image-expression to return an image spec including PNGs and SVGs, or duplicate tool-bar-item-from-menu and replace the call to tool-bar--image-expression in the copy, or post-process the keymap after calling tool-bar-item-from-menu. Neither of these are great, right? (I'm not super happy with the patch either; maybe it'd be better to introduce a variant of tool-bar-local-item-from-menu that takes an image expression instead of a string for the icon, and use that to implement tool-bar-local-item-from-menu; or maybe it would be better to make a dynamic variable that specifies which image formats to use; or maybe something else?). Thanks for your time! Clément.