From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Vorobiev Subject: Re: Help, I need to paste raw image from clipboard into emacs/orgmode Date: Wed, 6 Nov 2013 09:28:05 -0600 Message-ID: References: <87obbiferr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b6d7f54e1e24804ea83cc27 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve520-0006gK-FJ for emacs-orgmode@gnu.org; Wed, 06 Nov 2013 10:28:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ve51u-0007NZ-Pr for emacs-orgmode@gnu.org; Wed, 06 Nov 2013 10:28:32 -0500 Received: from mail-qa0-x22c.google.com ([2607:f8b0:400d:c00::22c]:41458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve51u-0007NU-KE for emacs-orgmode@gnu.org; Wed, 06 Nov 2013 10:28:26 -0500 Received: by mail-qa0-f44.google.com with SMTP id f11so2258448qae.17 for ; Wed, 06 Nov 2013 07:28:25 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Klaus-Dieter Bauer Cc: Vitalie Spinu , org-mode mailing list --047d7b6d7f54e1e24804ea83cc27 Content-Type: text/plain; charset=ISO-8859-1 Hi Klaus, I found the function very useful so I expanded it a little to have more flexible image file names. First, I use the base name of the file in the current buffer as a prefix to the image file name. Then I added an integer buffer-local variable to be the image file name's suffix (preceded by an underscore) which is incremented every time new image is pasted: #+begin_src emacs-lisp (defvar org-clipboard-image-suffix 0) (make-variable-buffer-local 'org-clipboard-image-suffix) (setq-default org-clipboard-image-suffix 0) (defun org-insert-clipboard-image () (interactive) (incf org-clipboard-image-suffix) (let* ((image-file (concat (file-name-base (buffer-file-name)) "_" (format "%d" org-clipboard-image-suffix) ".png")) (exit-status (call-process "convert" nil nil nil "clipboard:" image-file))) (org-insert-link nil (concat "file:" image-file) ""))) #+end_src It would be very convenient if there were a way to determine if the clipboard contains an image, then use defadvice to call this function with, say, org-yank. Unfortunately I couldn't find any emacs functions to query properties of the content of the (Windows) clipboard. I only see w32-get-clipboard-data which returns only text. Regards, Alex On Fri, Jun 7, 2013 at 1:15 PM, Klaus-Dieter Bauer < bauer.klaus.dieter@gmail.com> wrote: > (defun my-org-insert-clipboard () > (interactive) > (let* ((image-file "clipboard.png") > (exit-status > (call-process "convert" nil nil nil > "clipboard:" image-file))) > (org-insert-link nil (concat "file:" image-file) "") > (org-display-inline-images))) > > That works for me (Emacs 24.3, Windows 7) though for practical use some > more edge case handling ("don't insert on failure", "different name if file > exists") will be wanted. > > kind regards, Klaus > > > 2013/6/7 Vitalie Spinu > >> >> Thanks for the tip. Do you have an elisp piece that handles the image >> insertion into org buffers? >> >> Thanks, >> >> Vitalie >> >> >> Klaus-Dieter Bauer >> >> on Thu, 6 Jun 2013 19:16:26 +0200 wrote: >> >> > Dear All, >> > Please Help, >> > I need to paste raw image from clipboard into emacs/orgmode, I am a >> > microsoft onenote user and I got used to take a lot of snapshots >> and embed >> > it into my notes, I think if I could know how to embed images >> directly into >> > emacs/orgmode from clipboard, I will switch to emacs very easily. >> >> > I searched the internet but unfortunately I didn't find the answer, >> > Thanks a lot. >> > Dodo >> >> > Hello! >> >> > While the original poster probably long since has implemented one of >> the >> > previously suggested solutions (or given up) I thought I'd share a >> more general >> > solution I found [1]. >> >> > ImageMagick's `convert' can use clipboard: as input file (don't know >> if it works >> > as output file). >> >> > convert clipboard: FILENAME-WITH-EXTENSION >> >> > I tested it with the cygwin and native windows versions and both >> worked. >> >> > king regards, Klaus >> >> > PS1: On Windows `convert.exe' might be shadowed by another executable, >> > especially C:\Windows\System32\convert.exe. In that case the PATH >> variable >> > should be adjusted such that ImageMagick comes before >> C:\Windows\system32. To >> > check what shadows the executable, you can run "where convert" in the >> > Windows-commandline. >> > PS2: On Windows only basic image-displaying-support is included >> out-of-the-box. >> > To get full support, the easiest way is to install the full GnuWin32 >> tools >> > (which include the necessary image libraries) with the web-installer. >> >> > ------ >> >> > [1] User "magick" in >> > >> http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=7524&p=22859 >> . >> >> > --047d7b6d7f54e1e24804ea83cc27 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Klaus,

I found the function ve= ry useful so I expanded it a little to have more flexible image file names.= First, I use the base name of the file in the current buffer as a prefix t= o the image file name. Then I added an integer buffer-local variable to be = the image file name's suffix (preceded by an underscore) which is incre= mented every time new image is pasted:

=A0 =A0#+begin_src emacs-lisp
=A0 =A0 =A0(def= var org-clipboard-image-suffix 0)
=A0 =A0 =A0(make-variable-buffe= r-local 'org-clipboard-image-suffix)
=A0 =A0 =A0(setq-default= org-clipboard-image-suffix 0)
=A0 =A0 =A0
=A0 =A0 =A0(defun org-insert-clipboard-image ()<= /div>
=A0 =A0 =A0 =A0(interactive)
=A0 =A0 =A0 =A0(incf org-c= lipboard-image-suffix)
=A0 =A0 =A0 =A0(let* ((image-file
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(concat (file-name-base (buffer-file-name)= )
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"_"
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(format "%d" org-= clipboard-image-suffix)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0".png"))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (exit-statu= s=A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(call-process "convert" nil n= il nil=A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0"clipboard:" image-file)))
=A0 =A0 =A0 =A0 =A0(org-= insert-link nil (concat "file:" image-file) "")))
=A0 =A0 =A0#+end_src

It would be very c= onvenient if there were a way to determine if the clipboard contains an ima= ge, then use defadvice to call this function with, say, org-yank. Unfortuna= tely I couldn't find any emacs functions to query properties of the con= tent of the (Windows) clipboard. I only see w32-get-clipboard-data which re= turns only text.

Regards,
Alex


On Fri, Jun 7, 2013 at 1:15 PM, K= laus-Dieter Bauer <bauer.klaus.dieter@gmail.com> = wrote:
(defun my-org-ins= ert-clipboard ()
=A0 (interactive)
=A0 (let* ((image-fi= le "clipboard.png")
(exit-status=A0
=A0(call-process "conver= t" nil nil nil=A0
"clipboard:" image-file)))
=A0 =A0 (org-insert-lin= k nil (concat "file:" image-file) "")
=A0 =A0 (org-display-inline-images)))

T= hat works for me (Emacs 24.3, Windows 7) though for practical use some more= edge case handling ("don't insert on failure", "differe= nt name if file exists") will be wanted.=A0

kind regards, Klaus


2013/6/7 Vitali= e Spinu <spinuvit@gmail.com>

Thanks for the tip. Do you have an elisp piece that handles the image
insertion into org buffers?

Thanks,

=A0 =A0 Vitalie

=A0>> Klaus-Dieter Bauer <bauer.klaus.dieter@gmail.com>
=A0>> on Thu, 6 Jun 2013 19:16:26 +0200 wrote:

=A0> =A0 =A0 Dear All,
=A0> =A0 =A0 Please Help,
=A0> =A0 =A0 I need to paste raw image from clipboard into emacs/orgmode= , I am a
=A0> =A0 =A0 microsoft onenote user and I got used to take a lot of snap= shots and embed
=A0> =A0 =A0 it into my notes, I think if I could know how to embed imag= es directly into
=A0> =A0 =A0 emacs/orgmode from clipboard, I will switch to emacs very e= asily.

=A0> =A0 =A0 I searched the internet but unfortunately I didn't find= the answer,
=A0> =A0 =A0 Thanks a lot.
=A0> =A0 =A0 Dodo

=A0> Hello!

=A0> While the original poster probably long since has implemented one o= f the
=A0> previously suggested solutions (or given up) I thought I'd shar= e a more general
=A0> solution I found [1].

=A0> ImageMagick's `convert' can use clipboard: as input file (d= on't know if it works
=A0> as output file).

=A0> convert clipboard: FILENAME-WITH-EXTENSION

=A0> I tested it with the cygwin and native windows versions and both wo= rked.

=A0> king regards, Klaus

=A0> PS1: On Windows `convert.exe' might be shadowed by another exec= utable,
=A0> especially C:\Windows\System32\convert.exe. In that case the PATH v= ariable
=A0> should be adjusted such that ImageMagick comes before C:\Windows\sy= stem32. To
=A0> check what shadows the executable, you can run "where convert&= quot; in the
=A0> Windows-commandline.
=A0> PS2: On Windows only basic image-displaying-support is included out= -of-the-box.
=A0> To get full support, the easiest way is to install the full GnuWin3= 2 tools
=A0> (which include the necessary image libraries) with the web-installe= r.

=A0> ------

=A0> [1] User "magick" in
=A0> http://www.imagemagic= k.org/discourse-server/viewtopic.php?f=3D1&t=3D7524&p=3D22859.<= br>


--047d7b6d7f54e1e24804ea83cc27--