unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* I'm looking for a way to paste images directly from the clipboard into Emacs
@ 2024-11-11 19:26 Jean Louis
  2024-11-11 20:14 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Jean Louis @ 2024-11-11 19:26 UTC (permalink / raw)
  To: Help GNU Emacs

I'm looking for a way to paste images directly from the clipboard into Emacs. If an image is detected, I would like to perform various operations on it, such as saving it to a file or recording it. Is there an existing method or package in Emacs that can facilitate this functionality? Any guidance or tips would be greatly appreciated!

Jean Louis



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

* Re: I'm looking for a way to paste images directly from the clipboard into Emacs
  2024-11-11 19:26 I'm looking for a way to paste images directly from the clipboard into Emacs Jean Louis
@ 2024-11-11 20:14 ` Eli Zaretskii
  2024-11-12  0:37   ` Jean Louis
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2024-11-11 20:14 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Mon, 11 Nov 2024 22:26:39 +0300
> From: Jean Louis <bugs@gnu.support>
> 
> I'm looking for a way to paste images directly from the clipboard into Emacs. If an image is detected, I would like to perform various operations on it, such as saving it to a file or recording it. Is there an existing method or package in Emacs that can facilitate this functionality? Any guidance or tips would be greatly appreciated!

Emacs 30 and later has the new command yank-media for that purpose.



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

* Re: I'm looking for a way to paste images directly from the clipboard into Emacs
  2024-11-11 20:14 ` Eli Zaretskii
@ 2024-11-12  0:37   ` Jean Louis
  0 siblings, 0 replies; 3+ messages in thread
From: Jean Louis @ 2024-11-12  0:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2024-11-11 23:16]:
> > Date: Mon, 11 Nov 2024 22:26:39 +0300
> > From: Jean Louis <bugs@gnu.support>
> > 
> > I'm looking for a way to paste images directly from the clipboard into Emacs. If an image is detected, I would like to perform various operations on it, such as saving it to a file or recording it. Is there an existing method or package in Emacs that can facilitate this functionality? Any guidance or tips would be greatly appreciated!
> 
> Emacs 30 and later has the new command yank-media for that purpose.

That is very nice. I have done this and now it works well, I just need
to make more extensions. I can see multiple image MIME types being
offered from various programs.

(defun hyperscope-yank-media-handler (mime-type data)
  "HANDLER function to be registered with `yank-media-handler'."
  (let* ((extension (cond ((and (string-match "image" (symbol-name mime-type))
				(string-match "jpeg" (symbol-name mime-type)))
			   ".jpg")
			  ((and (string-match "image" (symbol-name mime-type))
				(string-match "png" (symbol-name mime-type)))
			   ".png")
			  (t (rcd-warning-message "No option for MIME type: %s" (symbol-name mime-type)))))
	 (data-file (concat (file-name-as-directory (getenv "TMPDIR")) "TEMP-IMAGE-" (rcd-timestamp-date-time) "-" (rcd-random-word 4) extension)))
    (string-to-file-force data data-file)
    (hyperscope-store-files nil (list data-file))
    (rcd-message "Stored %s as file %s" (symbol-name mime-type) data-file)))

(defun hyperscope-capture-clipboard-media ()
  "Capture any clipboard image into the Hyperscope Dynamic Knowledge Repository."
  (interactive)
  (with-temp-buffer
    (yank-media-handler "image/.*" 'hyperscope-yank-media-handler)
    (yank-media)))



Jean Louis












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

end of thread, other threads:[~2024-11-12  0:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-11 19:26 I'm looking for a way to paste images directly from the clipboard into Emacs Jean Louis
2024-11-11 20:14 ` Eli Zaretskii
2024-11-12  0:37   ` Jean Louis

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).