Here I found a solution on how to copy an URL from an org-link
.
When applied to these two org-link
:
[[https://emacs.stackexchange.com/][Emacs StackExchange]]
[[./path/file.org][An org file]]
It will respectively copy these strings:
https://emacs.stackexchange.com/
file:./path/file.org
I would have liked to have the two following strings copied instead:
https://emacs.stackexchange.com/
./path/
How could I achieve this?
UPDATE:
As I didn't make explicit the solution I was referring to in the first line of the question, here it is:
(defun farynaio/org-link-copy (&optional arg)
"Extract URL from org-mode link and add it to kill ring."
(interactive "P")
(let* ((link (org-element-lineage (org-element-context) '(link) t))
(type (org-element-property :type link))
(url (org-element-property :path link))
(url (concat type ":" url)))
(kill-new url)
(message (concat "Copied URL: " url))))
(define-key org-mode-map (kbd "C-x C-l") 'farynaio/org-link-copy)