Skip to content

Instantly share code, notes, and snippets.

@daviderestivo
Created August 30, 2017 12:07
Show Gist options
  • Save daviderestivo/ad3dfa38d3f7266d014ce469aafd18dc to your computer and use it in GitHub Desktop.
Save daviderestivo/ad3dfa38d3f7266d014ce469aafd18dc to your computer and use it in GitHub Desktop.
This is an helper function for org-download. It creates an \"./image\" folder within the same directory of the org file. Images are separated inside that image folder by additional folders one per org file.
(defun drestivo/org-download-method (link)
"This is an helper function for org-download.
It creates an \"./image\" folder within the same directory of the org file.
Images are separated inside that image folder by additional folders one per
org file.
More info can be found here: https://github.com/abo-abo/org-download/issues/40.
See the commit message for an example:
https://github.com/abo-abo/org-download/commit/137c3d2aa083283a3fc853f9ecbbc03039bf397b"
(let ((filename
(file-name-nondirectory
(car (url-path-and-query
(url-generic-parse-url link)))))
(dir (concat
(file-name-directory (buffer-file-name))
(format "%s/%s/%s"
"images"
(file-name-base (buffer-file-name))
(org-download--dir-2)))))
(progn
(setq filename-with-timestamp (format "%s%s.%s"
(file-name-sans-extension filename)
(format-time-string org-download-timestamp)
(file-name-extension filename)))
;; Check if directory exists otherwise creates it
(unless (file-exists-p dir)
(make-directory dir t))
(message (format "Image: %s saved!" (expand-file-name filename-with-timestamp dir)))
(expand-file-name filename-with-timestamp dir))))
(setq org-download-method 'drestivo/org-download-method)
@AtomicNess123
Copy link

Great function! However, it doesn't then work with the renaming functions such as org-download-rename-at-point. Have you noticed this? It would be critical that it works with such functions.

@daviderestivo
Copy link
Author

@AtomicNess123 thanks for spotting this. I can have a look and check if I can make it compatible with org-download-rename-at-point. But I already foreseen that it might not be so easy …

@AtomicNess123
Copy link

I thought so too. Thanks if you have some time for it though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment