all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#74044: 31.0.50; yank-media filters out svg files
@ 2024-10-27 10:38 Cecilio Pardo
  2024-10-27 12:04 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Cecilio Pardo @ 2024-10-27 10:38 UTC (permalink / raw)
  To: 74044

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

yank-media filters out image formats that are not supported by emacs.

To do that is passes the second part of the mime type (png, jpeg, etc.)
to (image-type-available-p).  This is ok for other image types, but not
for SVG, because its mime type is image/svg+xml. For example, InkScape
(a free vector drawing program) uses image/svg+xml to copy vector data
into the clipbard.

This patch fixes that filtering. Also changes the function
mailcap-mime-type-to-extension, used by org-mode to choose an extension
for the file it saves. It nees to be svg, not svg+xml.



[-- Attachment #2: 0001-Fix-yank-media-to-allow-SVG-files.patch --]
[-- Type: text/plain, Size: 2168 bytes --]

From 5564a67e2899d507b0d35e9eaf7053ad9c3f0024 Mon Sep 17 00:00:00 2001
From: Cecilio Pardo <cpardo@imayhem.com>
Date: Sun, 27 Oct 2024 11:02:45 +0100
Subject: [PATCH] Fix yank media to allow SVG files.

* lisp/net/mailcap.el (mailcap-mime-type-to-extension): Return "svg"
for mime type image/svg+xml. Org-mode uses this.
* lisp/yank-media.el (yank-media--find-matching-media): If svg is
supported, don't filter out image/svg+xml
---
 lisp/net/mailcap.el | 12 ++++++++----
 lisp/yank-media.el  |  3 ++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
index 3e847c758c2..698d59ce36a 100644
--- a/lisp/net/mailcap.el
+++ b/lisp/net/mailcap.el
@@ -1084,10 +1084,14 @@ mailcap-file-name-to-mime-type
 (defun mailcap-mime-type-to-extension (mime-type)
   "Return a file name extension based on a MIME-TYPE.
 For instance, `image/png' will result in `png'."
-  (intern (cadr (split-string (if (symbolp mime-type)
-                                  (symbol-name mime-type)
-                                mime-type)
-                              "/"))))
+  (intern
+   (let ((e (cadr (split-string (if (symbolp mime-type)
+                                    (symbol-name mime-type)
+                                  mime-type)
+                                "/"))))
+     (if (string= e "svg+xml")
+         "svg"
+       e))))
 
 (defun mailcap-mime-types ()
   "Return a list of MIME media types."
diff --git a/lisp/yank-media.el b/lisp/yank-media.el
index 6655bb705ef..cfc888e9f7f 100644
--- a/lisp/yank-media.el
+++ b/lisp/yank-media.el
@@ -67,7 +67,8 @@ yank-media--find-matching-media
    (lambda (type)
      (pcase-let ((`(,major ,minor) (split-string (symbol-name type) "/")))
        (if (and (equal major "image")
-                (not (image-type-available-p (intern minor))))
+                (not (image-type-available-p
+                      (intern (if (string= minor "svg+xml") "svg" minor)))))
            ;; Just filter out all the image types that Emacs doesn't
            ;; support, because the clipboard is full of things like
            ;; `image/x-win-bitmap'.
-- 
2.35.1.windows.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#74044: 31.0.50; yank-media filters out svg files
  2024-10-27 10:38 bug#74044: 31.0.50; yank-media filters out svg files Cecilio Pardo
@ 2024-10-27 12:04 ` Eli Zaretskii
  2024-10-27 13:45   ` Cecilio Pardo
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-10-27 12:04 UTC (permalink / raw)
  To: Cecilio Pardo; +Cc: 74044

> Date: Sun, 27 Oct 2024 11:38:14 +0100
> From: Cecilio Pardo <cpardo@imayhem.com>
> 
> yank-media filters out image formats that are not supported by emacs.
> 
> To do that is passes the second part of the mime type (png, jpeg, etc.)
> to (image-type-available-p).  This is ok for other image types, but not
> for SVG, because its mime type is image/svg+xml. For example, InkScape
> (a free vector drawing program) uses image/svg+xml to copy vector data
> into the clipbard.
> 
> This patch fixes that filtering. Also changes the function
> mailcap-mime-type-to-extension, used by org-mode to choose an extension
> for the file it saves. It nees to be svg, not svg+xml.

Please add comments that explain why we treat svg+xml spercially.

Thanks.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#74044: 31.0.50; yank-media filters out svg files
  2024-10-27 12:04 ` Eli Zaretskii
@ 2024-10-27 13:45   ` Cecilio Pardo
  2024-10-31 10:37     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Cecilio Pardo @ 2024-10-27 13:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74044

[-- Attachment #1: Type: text/plain, Size: 736 bytes --]

On 27/10/2024 13:04, Eli Zaretskii wrote:
>> yank-media filters out image formats that are not supported by emacs.
>>
>> To do that is passes the second part of the mime type (png, jpeg, etc.)
>> to (image-type-available-p).  This is ok for other image types, but not
>> for SVG, because its mime type is image/svg+xml. For example, InkScape
>> (a free vector drawing program) uses image/svg+xml to copy vector data
>> into the clipbard.
>>
>> This patch fixes that filtering. Also changes the function
>> mailcap-mime-type-to-extension, used by org-mode to choose an extension
>> for the file it saves. It nees to be svg, not svg+xml.
> 
> Please add comments that explain why we treat svg+xml spercially.

Patch attached.

Thank you.

[-- Attachment #2: 0001-Fix-yank-media-to-allow-SVG-files.patch --]
[-- Type: text/plain, Size: 2625 bytes --]

From bd1f30291bc332cc65decff5c766c81457e2d0d8 Mon Sep 17 00:00:00 2001
From: Cecilio Pardo <cpardo@imayhem.com>
Date: Sun, 27 Oct 2024 14:39:34 +0100
Subject: [PATCH] Fix yank media to allow SVG files.

* lisp/net/mailcap.el (mailcap-mime-type-to-extension): Return "svg"
for mime type image/svg+xml. Org-mode uses this.
* lisp/yank-media.el (yank-media--find-matching-media): If svg is
supported, don't filter out image/svg+xml
---
 lisp/net/mailcap.el | 15 +++++++++++----
 lisp/yank-media.el  |  7 ++++++-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
index 3e847c758c2..d3ca899216a 100644
--- a/lisp/net/mailcap.el
+++ b/lisp/net/mailcap.el
@@ -1084,10 +1084,17 @@ mailcap-file-name-to-mime-type
 (defun mailcap-mime-type-to-extension (mime-type)
   "Return a file name extension based on a MIME-TYPE.
 For instance, `image/png' will result in `png'."
-  (intern (cadr (split-string (if (symbolp mime-type)
-                                  (symbol-name mime-type)
-                                mime-type)
-                              "/"))))
+  (intern
+   (let ((e (cadr (split-string (if (symbolp mime-type)
+                                    (symbol-name mime-type)
+                                  mime-type)
+                                "/"))))
+     ;; Usually, the normal extension is the same as the MIME subtype.
+     ;; But for SVG files, the extension is "svg" and the MIME type is
+     ;; "svg+xml".
+     (if (string= e "svg+xml")
+         "svg"
+       e))))
 
 (defun mailcap-mime-types ()
   "Return a list of MIME media types."
diff --git a/lisp/yank-media.el b/lisp/yank-media.el
index 6655bb705ef..17981c37c0e 100644
--- a/lisp/yank-media.el
+++ b/lisp/yank-media.el
@@ -67,7 +67,12 @@ yank-media--find-matching-media
    (lambda (type)
      (pcase-let ((`(,major ,minor) (split-string (symbol-name type) "/")))
        (if (and (equal major "image")
-                (not (image-type-available-p (intern minor))))
+                (not (image-type-available-p
+                      ;; Usually, MIME subtype is the same as Emacs'
+                      ;; identifier for an image type.  But for SVG, the
+                      ;; identifier is 'svg, while the MIME type is
+                      ;; image/svg+xml. So we make the exception here.
+                      (intern (if (string= minor "svg+xml") "svg" minor)))))
            ;; Just filter out all the image types that Emacs doesn't
            ;; support, because the clipboard is full of things like
            ;; `image/x-win-bitmap'.
-- 
2.35.1.windows.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#74044: 31.0.50; yank-media filters out svg files
  2024-10-27 13:45   ` Cecilio Pardo
@ 2024-10-31 10:37     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-10-31 10:37 UTC (permalink / raw)
  To: Cecilio Pardo; +Cc: 74044-done

> Date: Sun, 27 Oct 2024 14:45:45 +0100
> Cc: 74044@debbugs.gnu.org
> From: Cecilio Pardo <cpardo@imayhem.com>
> 
> On 27/10/2024 13:04, Eli Zaretskii wrote:
> >> yank-media filters out image formats that are not supported by emacs.
> >>
> >> To do that is passes the second part of the mime type (png, jpeg, etc.)
> >> to (image-type-available-p).  This is ok for other image types, but not
> >> for SVG, because its mime type is image/svg+xml. For example, InkScape
> >> (a free vector drawing program) uses image/svg+xml to copy vector data
> >> into the clipbard.
> >>
> >> This patch fixes that filtering. Also changes the function
> >> mailcap-mime-type-to-extension, used by org-mode to choose an extension
> >> for the file it saves. It nees to be svg, not svg+xml.
> > 
> > Please add comments that explain why we treat svg+xml spercially.
> 
> Patch attached.

Thanks, installed on master, and closing the bug.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-31 10:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-27 10:38 bug#74044: 31.0.50; yank-media filters out svg files Cecilio Pardo
2024-10-27 12:04 ` Eli Zaretskii
2024-10-27 13:45   ` Cecilio Pardo
2024-10-31 10:37     ` Eli Zaretskii

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.