org-download

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

commit 9058b8fea2ce62a5c6bc87f151a9bda6b1000982
parent 512998718e3d5ced04f15c386e6580a733bd4487
Author: Feng Shu <tumashu@163.com>
Date:   Fri, 24 May 2019 00:53:52 +0800

org-download.el (org-download--display-inline-images): Use posframe to preview image

Update org-download-posframe-show-params's comment

Don't require posframe at top level

org-download-thumbnail-default: use shell-command-to-string instead

Fix error width and height when first use

org-download-thumbnail-default: let copy-file over previous thumbnail-file

Fixes #103

Diffstat:
Morg-download.el | 46++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/org-download.el b/org-download.el @@ -177,9 +177,51 @@ For example: "When non-nil display inline images in org buffer after download." :type 'boolean) +(defvar org-download-posframe-show-params + '(;; Please do not remove :timeout or set it to large. + :timeout 1 + :internal-border-width 1 + :internal-border-color "red" + :min-width 40 + :min-height 10 + :poshandler posframe-poshandler-window-center) + "List of parameters passed to `posframe-show'.") + +(defcustom org-download-thumbnail-file + (expand-file-name "org-download-thumbnail.png" temporary-file-directory) + "The file to thumbnail of `org-download-path-last-file'." + :type 'file) + +(defcustom org-download-thumbnail-function + #'org-download-thumbnail-default + "The tool to create screenshot's thumbnail." + :type 'function) + +(defun org-download-thumbnail-default (image-file thumbnail-file) + "Create the THUMBNAIL of IMAGE" + (cond + ((executable-find "convert") + (shell-command-to-string (format "convert -resize 400 %s %s" + image-file thumbnail-file))) + (t + (message "org-download: fail to create thumbnail, use original image instead.") + (copy-file image-file thumbnail-file t)))) + (defun org-download--display-inline-images () - (when org-download-display-inline-images - (org-display-inline-images))) + (if org-download-display-inline-images + (org-display-inline-images) + (require 'posframe) + (when (posframe-workable-p) + (let ((buffer (get-buffer-create " *org-download-image"))) + (funcall org-download-thumbnail-function + org-download-path-last-file + org-download-thumbnail-file) + (with-current-buffer buffer + (erase-buffer) + (insert-image-file org-download-thumbnail-file)) + (apply #'posframe-show + buffer + org-download-posframe-show-params))))) (defun org-download-get-heading (lvl) "Return the heading of the current entry's LVL level parent."