emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sigmund Tzeng <herculus6502@yahoo.com.tw>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>,
	"bastien.guerry@wikimedia.fr" <bastien.guerry@wikimedia.fr>,
	"celoserpa@gmail.com" <celoserpa@gmail.com>
Subject: Re: [Orgmode] Extending paste to auto-archive a copied image
Date: Fri, 1 Mar 2013 09:59:17 +0800 (CST)	[thread overview]
Message-ID: <1362103157.254.YahooMailNeo@web74401.mail.tp2.yahoo.com> (raw)

Hi,

I 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 save the file named after the image's timestamp.

Which means it's working for xwin clones, and I'm currently using Ubuntu 12.10.

The function is named "x-selection-value2", attached at the end of this mail. I'm binding it to C-v. 

The naming of the yanked file is kind of casual. Please feel free to change it.


>From:     Bastien
>Subject:     Re: [Orgmode] Extending paste to auto-archive a copied image
>Date:     Sat, 12 Feb 2011 12:25:43 +0100
>User-agent:     Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)
> 
>Hi Marcelo,
> 
>Marcelo de Moraes Serpa <address@hidden> writes:
> 
>> What I am suggesting is, somehow hook into the moment the file is
>> pasted/dragged and run some code.
> 
>This would require code in Emacs.  I'm not familiar at all with Emacs
>ability to recognize drag'n droped files (as I don't use drag'n drop)
>but perhaps other do and might suggest how to set a hook when Emacs
>copies external content/files/whatever from X.
> 
>-- 
> Bastien

(defun x-selection-value2 ()
  "using xclip and perl to yank image file in link format for org, and save the file named after the image's timestamp"
  (interactive)
  (when (and (executable-find "xclip") (getenv "DISPLAY"))
    (let (clip-targets clip-text)
      (when t
    (progn
      (setq clip-targets (shell-command-to-string "xclip -o -selection clipboard -t TARGETS|perl -e '$ret=0;while(<>){if ($_ eq \"image/png\\n\"){$ret+=4 ;$result = `xclip -o -selection clipboard -t TIMESTAMP`;}$ret=+1 if ($_ eq \"STRING\\n\") or ($_ eq \"UTF8_STRING\\n\");$ret+=2 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\"};'"))
      (message (concat "type :" clip-targets))
      (when (string= "webimg"  clip-targets)
        (progn   
          (setq clip-text (shell-command-to-string (concat "perl -e '$buffn=\"" (file-name-directory (buffer-file-name)) "\";$result = `xclip -o -selection clipboard -t TIMESTAMP`;chomp($result);$fn = `xclip -o -selection clipboard -t text/html`;$fn=~/src=\"(.*?)\"/i;system(\"xclip -o -selection clipboard -t image/png > $buffn$result.png\");print \"[[file:\".$result.\".png]\".$1.\"]\";'")))
          (insert clip-text)
          )
        )
      (when (string= "clipboardimg"  clip-targets)
        (progn  
          (setq clip-text (shell-command-to-string (concat "perl -e '$buffn=\"" (file-name-directory (buffer-file-name)) "\";$result = `xclip -o -selection clipboard -t TIMESTAMP`;chomp($result);system(\"xclip -o -selection clipboard -t image/png > $buffn$result.png\");print \"[[file:\".$result.\".png]\".$result.\".png]$buffn\";'")))
          (insert clip-text)
          )
        )
      )
    ) 
      ))
  (or clip-text (x-selection-value))  
)

             reply	other threads:[~2013-03-01  1:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-01  1:59 Sigmund Tzeng [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-01-10 16:38 Extending paste to auto-archive a copied image Marcelo de Moraes Serpa
2011-02-11 11:50 ` Bastien
2011-02-11 19:57   ` Marcelo de Moraes Serpa
2011-02-12 11:25     ` Bastien
2011-02-12 22:22       ` Marcelo de Moraes Serpa
2011-10-04 18:46         ` [Orgmode] " Marcelo de Moraes Serpa

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=1362103157.254.YahooMailNeo@web74401.mail.tp2.yahoo.com \
    --to=herculus6502@yahoo.com.tw \
    --cc=bastien.guerry@wikimedia.fr \
    --cc=celoserpa@gmail.com \
    --cc=emacs-orgmode@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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