emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Extending paste to auto-archive a copied image
@ 2011-01-10 16:38 Marcelo de Moraes Serpa
  2011-01-12 20:09 ` Marcelo de Moraes Serpa
  2011-02-11 11:50 ` Bastien
  0 siblings, 2 replies; 8+ messages in thread
From: Marcelo de Moraes Serpa @ 2011-01-10 16:38 UTC (permalink / raw)
  To: Org Mode

Hi list,

So, I'm usign an emacs extension that renders links to image as the
image itself, it's a minor mode called iimage.el. It works great, but
the fact that I need to copy the image somewhere first is a time and
flow - killer. Is it possible to hook up to the paste command and, if
it's a image in the clipboard, auto-archive somewhere in the
filesystem it and then return its URL?

Thanks,

Marcelo.

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

* Re: Extending paste to auto-archive a copied image
  2011-01-10 16:38 Extending paste to auto-archive a copied image Marcelo de Moraes Serpa
@ 2011-01-12 20:09 ` Marcelo de Moraes Serpa
  2011-02-11 11:50 ` Bastien
  1 sibling, 0 replies; 8+ messages in thread
From: Marcelo de Moraes Serpa @ 2011-01-12 20:09 UTC (permalink / raw)
  To: Org Mode

*bump* -- no ideas?

On Mon, Jan 10, 2011 at 10:38 AM, Marcelo de Moraes Serpa
<celoserpa@gmail.com> wrote:
> Hi list,
>
> So, I'm usign an emacs extension that renders links to image as the
> image itself, it's a minor mode called iimage.el. It works great, but
> the fact that I need to copy the image somewhere first is a time and
> flow - killer. Is it possible to hook up to the paste command and, if
> it's a image in the clipboard, auto-archive somewhere in the
> filesystem it and then return its URL?
>
> Thanks,
>
> Marcelo.
>

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

* Re: Extending paste to auto-archive a copied image
  2011-01-10 16:38 Extending paste to auto-archive a copied image Marcelo de Moraes Serpa
  2011-01-12 20:09 ` Marcelo de Moraes Serpa
@ 2011-02-11 11:50 ` Bastien
  2011-02-11 19:57   ` Marcelo de Moraes Serpa
  1 sibling, 1 reply; 8+ messages in thread
From: Bastien @ 2011-02-11 11:50 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: Org Mode

Hi Marcelo,

Marcelo de Moraes Serpa <celoserpa@gmail.com> writes:

> So, I'm usign an emacs extension that renders links to image as the
> image itself, it's a minor mode called iimage.el. It works great, but
> the fact that I need to copy the image somewhere first is a time and
> flow - killer. Is it possible to hook up to the paste command and, if
> it's a image in the clipboard, auto-archive somewhere in the
> filesystem it and then return its URL?

Sorry I don't understand.  Can you give an example?  When you say
"paste", is it pasting from X or from Emacs?

Thanks,

-- 
 Bastien

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

* Re: Extending paste to auto-archive a copied image
  2011-02-11 11:50 ` Bastien
@ 2011-02-11 19:57   ` Marcelo de Moraes Serpa
  2011-02-12 11:25     ` Bastien
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo de Moraes Serpa @ 2011-02-11 19:57 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode

Hi Bastien,

Let's say I copy a file from my desktop. If I copy it (C-c) and then
yank into emacs, the filename is pasted.

Now, if I drag and drop it into an emacs buffer, emacs inserts the
contents of the file.

These two scenarios sum up something I think would be an awesome
addition to org, if only we could handle them differently.

For example, when taking notes in org, I often have different
reference sources open (web pages, word documents, pdfs etc), and
would like to insert images. I can already do that manually, and emacs
will even render them. But it takes too much time, and gets me out of
my productive zone.

What I am suggesting is, somehow hook into the moment the file is
pasted/dragged and run some code. This code would get a reference to
the file/contents of the file, save it in a org data directory and
return a URL to it, which would then be pasted in the document like a
regular link, and then iimage-mode would come into action and render
it.

Thanks,

Marcelo.

On Fri, Feb 11, 2011 at 5:50 AM, Bastien <bastien.guerry@wikimedia.fr> wrote:
> Hi Marcelo,
>
> Marcelo de Moraes Serpa <celoserpa@gmail.com> writes:
>
>> So, I'm usign an emacs extension that renders links to image as the
>> image itself, it's a minor mode called iimage.el. It works great, but
>> the fact that I need to copy the image somewhere first is a time and
>> flow - killer. Is it possible to hook up to the paste command and, if
>> it's a image in the clipboard, auto-archive somewhere in the
>> filesystem it and then return its URL?
>
> Sorry I don't understand.  Can you give an example?  When you say
> "paste", is it pasting from X or from Emacs?
>
> Thanks,
>
> --
>  Bastien
>

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

* Re: Extending paste to auto-archive a copied image
  2011-02-11 19:57   ` Marcelo de Moraes Serpa
@ 2011-02-12 11:25     ` Bastien
  2011-02-12 22:22       ` Marcelo de Moraes Serpa
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien @ 2011-02-12 11:25 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: Org Mode

Hi Marcelo,

Marcelo de Moraes Serpa <celoserpa@gmail.com> 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

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

* Re: Extending paste to auto-archive a copied image
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo de Moraes Serpa @ 2011-02-12 22:22 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode

It'd be an awesome feature IMO :)

Thanks!

Marcelo.

On Sat, Feb 12, 2011 at 5:25 AM, Bastien <bastien.guerry@wikimedia.fr> wrote:
> Hi Marcelo,
>
> Marcelo de Moraes Serpa <celoserpa@gmail.com> 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
>

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

* Re: [Orgmode] Extending paste to auto-archive a copied image
  2011-02-12 22:22       ` Marcelo de Moraes Serpa
@ 2011-10-04 18:46         ` Marcelo de Moraes Serpa
  0 siblings, 0 replies; 8+ messages in thread
From: Marcelo de Moraes Serpa @ 2011-10-04 18:46 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1440 bytes --]

*bump*

I think this would be an awesome feature. Some of us use highly-graphic OSes
such as OSX and Windows (or maybe Linux with Gnome), and being able to
interact with the desktop is a great feature. Imagine being able to drag and
drop a file directly to emacs and delegate the attachment to org, besides,
optionally, an icon could be shown (not really needed).

Copying and pasting an image would also be nice. Right now, I can't do this.
I can drag and drop files but emacs will just insert the contents of the
file inline. There must be a way to tell emacs to run a custom piece of
elisp code with the basic event information gathered from the paste/drag and
drop... or there isn't?

Cheers,

- Marcelo.

On Sat, Feb 12, 2011 at 4:22 PM, Marcelo de Moraes Serpa <
celoserpa@gmail.com> wrote:

> It'd be an awesome feature IMO :)
>
> Thanks!
>
> Marcelo.
>
> On Sat, Feb 12, 2011 at 5:25 AM, Bastien <bastien.guerry@wikimedia.fr>
> wrote:
> > Hi Marcelo,
> >
> > Marcelo de Moraes Serpa <celoserpa@gmail.com> 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
> >
>

[-- Attachment #2: Type: text/html, Size: 2091 bytes --]

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

* Re: [Orgmode] Extending paste to auto-archive a copied image
@ 2013-03-01  1:59 Sigmund Tzeng
  0 siblings, 0 replies; 8+ messages in thread
From: Sigmund Tzeng @ 2013-03-01  1:59 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org, bastien.guerry@wikimedia.fr,
	celoserpa@gmail.com

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

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

end of thread, other threads:[~2013-03-01  1:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-10 16:38 Extending paste to auto-archive a copied image Marcelo de Moraes Serpa
2011-01-12 20:09 ` 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
  -- strict thread matches above, loose matches on Subject: below --
2013-03-01  1:59 Sigmund Tzeng

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