I have stored in my clipboard a path to an image, which I want to paste inside emacs.
I would like to modify the path to change/postpone/prepone some stuff before yanking.
Following my previous question here, I tried
(defun replace-in-string (what with in)
(replace-regexp-in-string (regexp-quote what) with in nil 'literal))
(defun paste-image-link ()
(interactive)
(let ((tmp (car kill-ring))))
(setq tmp (replace-in-string "E:\\Dropbox\\JULIEN\\01.Emacs"
"../.."
tmp))
(setq tmp (concat "[[file:" tmp "]]"))
(setq kill-ring (cons tmp (cdr kill-ring)))
(yank)
)
(global-set-key (kbd "M-i") 'paste-image-link)
My goal is to change the absolute path to a relative path and add [[file:
before.
For example, this :
E:\Dropbox\JULIEN\01.Emacs\02.Emacs screenshots\2021-04-04_02-23-12_vivaldi.png
should become :
[[file:../..\02.Emacs screenshots\2021-04-04_02-23-12_vivaldi.png]]
I am obviously making trivial mistakes about let
and setq
statements because I get instead :
[[file:[[file:[[file:[[file:[[file:[[file:[[file:(car kill-ring)]]]]]]]]]]]]]]
and the number of [[file:
before is growing each time i try
what should I do ?
Addendum : besides i would like to add a line before to finally get
#+ATTR_ORG: :width 300px
[[file:../..\02.Emacs screenshots\2021-04-04_02-23-12_vivaldi.png]]