emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [FR] yank media: allow customization of absolute path a filter for type candidates
@ 2024-09-16  4:56 pinmacs
  2024-09-16 17:10 ` Visuwesh
  0 siblings, 1 reply; 5+ messages in thread
From: pinmacs @ 2024-09-16  4:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

So I was using org-download, and I would like to replace it entirely 
with yank-media

and what I am missisng is:

1. do a variable for selecting absolute path: to be able to have a file 
link that works with absolute path; and the reason is that being 
relative, this, does not combine good when you move your latex export 
somewhere else (in my case, I usually move it to /tmp/, and from there I 
decide when I want to save something persistently), hence it fails, and 
I got tired on fixing the links, in fact, the absolute path sometimes is 
smaller than the relative one 
=file:/tmp/clipboard-20240916T013308.png]]= vs 
=[[file:../../../tmp/clipboard-20240916T011913.png]]=

2. do a variable that allow a list that would filter and reduce the type 
candidates of yank-media. In org-download, everything was png so I was 
not having the "Several types available, choose one" with 7 options. But 
then is like, oh, maybe I would like to be able to switch between png 
(synthetic image), jpg (natural image)... anyway, I hope you see 
customizing this is interesting for the users.

What I did to solve the absolute path meanwhile the discussion and 
development happens is defining on my own the entire function 
=org--image-yank-media-handler= just changing this:

#+begin_src diff
-(setq link (org-link-make-string (concat "file:" (file-relative-name 
absname))))
+(setq link (org-link-make-string (concat "file:" absname)))
#+end_src

source (sorry, this link is slow to open):
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/org.el?id=cdcde091b9bdc14fc2254b0e594d8e0da6c4e6c6#n20895

and here is the equivalent to the org-download
#+begin_src emacs-lisp
(defun my/yank-media ()
   "org-download replacement"
   (interactive)
   (let ((org-yank-image-save-method "/tmp/")
         (org-yank-dnd-method 'file-link))
     (yank-media))
     ;; facilitate image size on preview
     (save-excursion
       (previous-line)
       (insert "\n#+attr_org: :width 350px")))
;; thanks for all the fish, org-download
;; (global-set-key (kbd "C-M-y") 'org-download-clipboard)
(global-set-key (kbd "C-M-y") 'my/yank-media)
#+end_src

Thanks for your attention,
pinmacs


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

* Re: [FR] yank media: allow customization of absolute path a filter for type candidates
  2024-09-16  4:56 [FR] yank media: allow customization of absolute path a filter for type candidates pinmacs
@ 2024-09-16 17:10 ` Visuwesh
  2024-09-22 11:38   ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Visuwesh @ 2024-09-16 17:10 UTC (permalink / raw)
  To: pinmacs; +Cc: emacs-orgmode

[திங்கள் செப்டம்பர் 16, 2024] pinmacs wrote:

> Hi,
>
> So I was using org-download, and I would like to replace it entirely 
> with yank-media
>
> and what I am missisng is:
>
> 1. do a variable for selecting absolute path: to be able to have a file 
> link that works with absolute path; and the reason is that being 
> relative, this, does not combine good when you move your latex export 
> somewhere else (in my case, I usually move it to /tmp/, and from there I 
> decide when I want to save something persistently), hence it fails, and 
> I got tired on fixing the links, in fact, the absolute path sometimes is 
> smaller than the relative one 
> =file:/tmp/clipboard-20240916T013308.png]]= vs 
> =[[file:../../../tmp/clipboard-20240916T011913.png]]=

This can be done in the org side.  I guess adding another defcustom
would be the way to go? I don't see how it is possible to make
org-yank-image-save-method accept another option.

> 2. do a variable that allow a list that would filter and reduce the type 
> candidates of yank-media. In org-download, everything was png so I was 
> not having the "Several types available, choose one" with 7 options. But 
> then is like, oh, maybe I would like to be able to switch between png 
> (synthetic image), jpg (natural image)... anyway, I hope you see 
> customizing this is interesting for the users.

This needs to be done in the Emacs side.  The querying is done in
yank-media and nothing much can be done from org-mode.


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

* Re: [FR] yank media: allow customization of absolute path a filter for type candidates
  2024-09-16 17:10 ` Visuwesh
@ 2024-09-22 11:38   ` Ihor Radchenko
  2024-09-22 13:01     ` Visuwesh
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2024-09-22 11:38 UTC (permalink / raw)
  To: Visuwesh; +Cc: pinmacs, emacs-orgmode


Visuwesh <visuweshm@gmail.com> writes:
>> 1. do a variable for selecting absolute path: to be able to have a file 
>> link that works with absolute path; and the reason is that being 
>> relative, this, does not combine good when you move your latex export 
>> somewhere else (in my case, I usually move it to /tmp/, and from there I 
>> decide when I want to save something persistently), hence it fails, and 
>> I got tired on fixing the links, in fact, the absolute path sometimes is 
>> smaller than the relative one 
>> =file:/tmp/clipboard-20240916T013308.png]]= vs 
>> =[[file:../../../tmp/clipboard-20240916T011913.png]]=
>
> This can be done in the org side.  I guess adding another defcustom
> would be the way to go? I don't see how it is possible to make
> org-yank-image-save-method accept another option.

We can re-use `org-link-file-path-type'.
Probably, simply by factoring out the cond from `org-insert-link' and
then reusing it in yank handler.

>> 2. do a variable that allow a list that would filter and reduce the type 
>> candidates of yank-media. In org-download, everything was png so I was 
>> not having the "Several types available, choose one" with 7 options. But 
>> then is like, oh, maybe I would like to be able to switch between png 
>> (synthetic image), jpg (natural image)... anyway, I hope you see 
>> customizing this is interesting for the users.
>
> This needs to be done in the Emacs side.  The querying is done in
> yank-media and nothing much can be done from org-mode.

That's one option - we can ask Emacs devs to provide a customization for
`yank-media' to auto-select specific type once it is available.

Another possibility is making "image/.*" customizable in
(yank-media-handler "image/.*" #'org--image-yank-media-handler)

Then, users may limit image types that can be inserted into Org by
setting that regexp to something like "image/png".

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: [FR] yank media: allow customization of absolute path a filter for type candidates
  2024-09-22 11:38   ` Ihor Radchenko
@ 2024-09-22 13:01     ` Visuwesh
  2024-09-22 17:04       ` Pedro
  0 siblings, 1 reply; 5+ messages in thread
From: Visuwesh @ 2024-09-22 13:01 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: pinmacs, emacs-orgmode

[ஞாயிறு செப்டம்பர் 22, 2024] Ihor Radchenko wrote:

> Visuwesh <visuweshm@gmail.com> writes:
>>> 1. do a variable for selecting absolute path: to be able to have a file 
>>> link that works with absolute path; and the reason is that being 
>>> relative, this, does not combine good when you move your latex export 
>>> somewhere else (in my case, I usually move it to /tmp/, and from there I 
>>> decide when I want to save something persistently), hence it fails, and 
>>> I got tired on fixing the links, in fact, the absolute path sometimes is 
>>> smaller than the relative one 
>>> =file:/tmp/clipboard-20240916T013308.png]]= vs 
>>> =[[file:../../../tmp/clipboard-20240916T011913.png]]=
>>
>> This can be done in the org side.  I guess adding another defcustom
>> would be the way to go? I don't see how it is possible to make
>> org-yank-image-save-method accept another option.
>
> We can re-use `org-link-file-path-type'.
> Probably, simply by factoring out the cond from `org-insert-link' and
> then reusing it in yank handler.

I think this will indeed be the best.  We can reuse this everywhere we
insert the link in yank-media+DND code (which IIRC uses the same
function at the very end).

>>> 2. do a variable that allow a list that would filter and reduce the type 
>>> candidates of yank-media. In org-download, everything was png so I was 
>>> not having the "Several types available, choose one" with 7 options. But 
>>> then is like, oh, maybe I would like to be able to switch between png 
>>> (synthetic image), jpg (natural image)... anyway, I hope you see 
>>> customizing this is interesting for the users.
>>
>> This needs to be done in the Emacs side.  The querying is done in
>> yank-media and nothing much can be done from org-mode.
>
> That's one option - we can ask Emacs devs to provide a customization for
> `yank-media' to auto-select specific type once it is available.
>
> Another possibility is making "image/.*" customizable in
> (yank-media-handler "image/.*" #'org--image-yank-media-handler)
>
> Then, users may limit image types that can be inserted into Org by
> setting that regexp to something like "image/png".

I am leaning towards doing it in the Emacs side since it would get rid
of similar annoyance(s) in other yank-media handlers, not just Org.

If no one beats me to it before the end of this week, I will propose a
patch to take care of (1).  It would be preferable pinmacs if can take
care of (2) if we decide to take care of it from the Emacs side since I
will probably not be able to describe the situation well.


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

* Re: [FR] yank media: allow customization of absolute path a filter for type candidates
  2024-09-22 13:01     ` Visuwesh
@ 2024-09-22 17:04       ` Pedro
  0 siblings, 0 replies; 5+ messages in thread
From: Pedro @ 2024-09-22 17:04 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: visuweshm, yantar92


[-- Attachment #1.1.1.1: Type: text/plain, Size: 570 bytes --]

On 2024-09-22 10:01, Visuwesh wrote:
> I am leaning towards doing it in the Emacs side since it would get rid
> of similar annoyance(s) in other yank-media handlers, not just Org.
>
> If no one beats me to it before the end of this week, I will propose a
> patch to take care of (1).  It would be preferable pinmacs if can take
> care of (2) if we decide to take care of it from the Emacs side since I
> will probably not be able to describe the situation well.

Took care of 2. Done, see 
https://lists.gnu.org/archive/html/emacs-devel/2024-09/msg00685.html

[-- Attachment #1.1.1.2: Type: text/html, Size: 1032 bytes --]

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3323 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

end of thread, other threads:[~2024-09-22 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-16  4:56 [FR] yank media: allow customization of absolute path a filter for type candidates pinmacs
2024-09-16 17:10 ` Visuwesh
2024-09-22 11:38   ` Ihor Radchenko
2024-09-22 13:01     ` Visuwesh
2024-09-22 17:04       ` Pedro

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