all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Eli Zaretskii <eliz@gnu.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: I'm looking for a way to paste images directly from the clipboard into Emacs
Date: Tue, 12 Nov 2024 03:37:52 +0300	[thread overview]
Message-ID: <ZzKjYKu_V0OwQDli@lco2> (raw)
In-Reply-To: <86v7wtil31.fsf@gnu.org>

* 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












      reply	other threads:[~2024-11-12  0:37 UTC|newest]

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

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

  git send-email \
    --in-reply-to=ZzKjYKu_V0OwQDli@lco2 \
    --to=bugs@gnu.support \
    --cc=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /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 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.