org-download

a fork of abo-abo's org-download
git clone https://git.trogloxene.org/org-download.git
Log | Files | Refs | README

commit af07ea88debd1d9e6c5199070525651831c55b54
parent 6735717752d1ecfdb44745fff62a82d613cb8f26
Author: Oleh Krehel <ohwoeowho@gmail.com>
Date:   Mon, 14 Jan 2019 16:53:52 +0100

org-download.el (org-download-insert-link): Return inserted text as a string

Fixes #67

This code will download the image currently stored in the kill ring:

```elisp
(defun org-download-capture (url)
  (let* ((org-download-image-dir (expand-file-name "~/Pictures/org-download"))
         (org-download-abbreviate-filename-function #'expand-file-name)
         (str (org-download-image url)))
    (sit-for 0.01)
    str))

(setq org-capture-templates
      '(("i"
         "Image"
         entry
         (file+olp+datetree
          "~/Dropbox/org/wiki/images.org")
         "* %?\n%(org-download-capture (current-kill 0))\n")))
```

Diffstat:
Morg-download.el | 40+++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/org-download.el b/org-download.el @@ -396,25 +396,27 @@ It's inserted before the image link and is used to annotate it.") (const :tag "absolute" expand-file-name))) (defun org-download-insert-link (link filename) - (if (looking-back "^[ \t]+" (line-beginning-position)) - (delete-region (match-beginning 0) (match-end 0)) - (newline)) - (insert (funcall org-download-annotate-function link)) - (insert "\n") - (insert (if (= org-download-image-html-width 0) - "" - (format "#+attr_html: :width %dpx\n" org-download-image-html-width))) - (insert (if (= org-download-image-latex-width 0) - "" - (format "#+attr_latex: :width %dcm\n" org-download-image-latex-width))) - (insert (if (= org-download-image-org-width 0) - "" - (format "#+attr_org: :width %dpx\n" org-download-image-org-width))) - (insert - (format org-download-link-format - (org-link-escape - (funcall org-download-abbreviate-filename-function filename)))) - (org-display-inline-images)) + (let ((beg (point))) + (if (looking-back "^[ \t]+" (line-beginning-position)) + (delete-region (match-beginning 0) (match-end 0)) + (newline)) + (insert (funcall org-download-annotate-function link)) + (insert "\n") + (insert (if (= org-download-image-html-width 0) + "" + (format "#+attr_html: :width %dpx\n" org-download-image-html-width))) + (insert (if (= org-download-image-latex-width 0) + "" + (format "#+attr_latex: :width %dcm\n" org-download-image-latex-width))) + (insert (if (= org-download-image-org-width 0) + "" + (format "#+attr_org: :width %dpx\n" org-download-image-org-width))) + (insert + (format org-download-link-format + (org-link-escape + (funcall org-download-abbreviate-filename-function filename)))) + (org-display-inline-images) + (buffer-substring-no-properties beg (point)))) (defun org-download--at-comment-p () "Check if current line begins with #+DOWLOADED:."