From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sigmund Tzeng Subject: Re: [Orgmode] Extending paste to auto-archive a copied image Date: Fri, 1 Mar 2013 09:59:17 +0800 (CST) Message-ID: <1362103157.254.YahooMailNeo@web74401.mail.tp2.yahoo.com> Reply-To: Sigmund Tzeng Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:42788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBFFt-0006Ts-BH for emacs-orgmode@gnu.org; Thu, 28 Feb 2013 20:59:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBFFq-0006hy-On for emacs-orgmode@gnu.org; Thu, 28 Feb 2013 20:59:25 -0500 Received: from nm12-vm3.bullet.mail.tp2.yahoo.com ([203.188.200.98]:42896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBFFq-0006gc-6L for emacs-orgmode@gnu.org; Thu, 28 Feb 2013 20:59:22 -0500 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: "emacs-orgmode@gnu.org" , "bastien.guerry@wikimedia.fr" , "celoserpa@gmail.com" Hi,=0A=0AI wrote some code to fulfill the proposal you discussed two years = ago, using xclip and perl to yank image file in link format for org, and sa= ve the file named after the image's timestamp.=0A=0AWhich means it's workin= g for xwin clones, and I'm currently using Ubuntu 12.10.=0A=0AThe function = is named "x-selection-value2", attached at the end of this mail. I'm bindin= g it to C-v. =0A=0AThe naming of the yanked file is kind of casual. Please = feel free to change it.=0A=0A=0A>From: =A0=A0=A0=A0Bastien=0A>Subject: =A0= =A0=A0=A0Re: [Orgmode] Extending paste to auto-archive a copied image=0A>Da= te: =A0=A0=A0=A0Sat, 12 Feb 2011 12:25:43 +0100=0A>User-agent: =A0=A0=A0=A0= Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)=0A> =0A>Hi Marcelo,=0A> = =0A>Marcelo de Moraes Serpa writes:=0A> =0A>> What I am su= ggesting is, somehow hook into the moment the file is=0A>> pasted/dragged a= nd run some code.=0A> =0A>This would require code in Emacs.=A0=A0I'm not fa= miliar at all with Emacs=0A>ability to recognize drag'n droped files (as I = don't use drag'n drop)=0A>but perhaps other do and might suggest how to set= a hook when Emacs=0A>copies external content/files/whatever from X.=0A> = =0A>-- =0A> Bastien=0A=0A(defun x-selection-value2 ()=0A=A0 "using xclip an= d perl to yank image file in link format for org, and save the file named a= fter the image's timestamp"=0A=A0 (interactive)=0A=A0 (when (and (executabl= e-find "xclip") (getenv "DISPLAY"))=0A=A0=A0=A0 (let (clip-targets clip-tex= t)=0A=A0=A0=A0=A0=A0 (when t=0A=A0=A0=A0 (progn=0A=A0=A0=A0 =A0 (setq clip-= targets (shell-command-to-string "xclip -o -selection clipboard -t TARGETS|= perl -e '$ret=3D0;while(<>){if ($_ eq \"image/png\\n\"){$ret+=3D4 ;$result = =3D `xclip -o -selection clipboard -t TIMESTAMP`;}$ret=3D+1 if ($_ eq \"STR= ING\\n\") or ($_ eq \"UTF8_STRING\\n\");$ret+=3D2 if $_ eq \"text/html\\n\"= ;}if($ret eq 6){print \"webimg\"};if($ret eq 4){print \"clipboardimg\"};if(= $ret eq 1){print \"string\"};if($ret eq 0){print \"nothing\"};'"))=0A=A0=A0= =A0 =A0 (message (concat "type :" clip-targets))=0A=A0=A0=A0 =A0 (when (str= ing=3D "webimg"=A0 clip-targets)=0A=A0=A0=A0 =A0=A0=A0 (progn=A0=A0 =0A=A0= =A0=A0 =A0=A0=A0=A0=A0 (setq clip-text (shell-command-to-string (concat "pe= rl -e '$buffn=3D\"" (file-name-directory (buffer-file-name)) "\";$result = =3D `xclip -o -selection clipboard -t TIMESTAMP`;chomp($result);$fn =3D `xc= lip -o -selection clipboard -t text/html`;$fn=3D~/src=3D\"(.*?)\"/i;system(= \"xclip -o -selection clipboard -t image/png > $buffn$result.png\");print \= "[[file:\".$result.\".png]\".$1.\"]\";'")))=0A=A0=A0=A0 =A0=A0=A0=A0=A0 (in= sert clip-text)=0A=A0=A0=A0 =A0=A0=A0=A0=A0 )=0A=A0=A0=A0 =A0=A0=A0 )=0A=A0= =A0=A0 =A0 (when (string=3D "clipboardimg"=A0 clip-targets)=0A=A0=A0=A0 =A0= =A0=A0 (progn=A0 =0A=A0=A0=A0 =A0=A0=A0=A0=A0 (setq clip-text (shell-comman= d-to-string (concat "perl -e '$buffn=3D\"" (file-name-directory (buffer-fil= e-name)) "\";$result =3D `xclip -o -selection clipboard -t TIMESTAMP`;chomp= ($result);system(\"xclip -o -selection clipboard -t image/png > $buffn$resu= lt.png\");print \"[[file:\".$result.\".png]\".$result.\".png]$buffn\";'")))= =0A=A0=A0=A0 =A0=A0=A0=A0=A0 (insert clip-text)=0A=A0=A0=A0 =A0=A0=A0=A0=A0= )=0A=A0=A0=A0 =A0=A0=A0 )=0A=A0=A0=A0 =A0 )=0A=A0=A0=A0 ) =0A=A0=A0=A0=A0= =A0 ))=0A=A0 (or clip-text (x-selection-value))=A0 =0A)