diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2012-09-02 03:26:28 +0200 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2012-09-02 03:26:28 +0200 |
commit | ad617198bf31238533b93e955ca9adb650ddc932 (patch) | |
tree | 844f3bfbb704aa27237dedbfc51b4ad9ef27f0b4 /elisp/geiser-image.el | |
parent | 1e61bc61bfb690747cc881d4938c0724b13db6ed (diff) | |
download | geiser-ad617198bf31238533b93e955ca9adb650ddc932.tar.gz geiser-ad617198bf31238533b93e955ca9adb650ddc932.tar.bz2 |
Image support: buttons and auto-display in the REPL
When geiser-repl-inline-images-p is false (or we're in a terminal),
the inserted text replacement is a button that calls the external
viewer on click. There's also a parameter controlling whether the
viewer should be invoked automatically upon insertion.
Diffstat (limited to 'elisp/geiser-image.el')
-rw-r--r-- | elisp/geiser-image.el | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/elisp/geiser-image.el b/elisp/geiser-image.el index 222e0d3..dd90f05 100644 --- a/elisp/geiser-image.el +++ b/elisp/geiser-image.el @@ -22,7 +22,6 @@ "Options for image displaying." :group 'geiser) - (geiser-custom--defcustom geiser-system-image-viewer "display" "Which system image viewer program to invoke upon M-x `geiser-view-last-image'." @@ -44,6 +43,9 @@ system wide tmp dir will be used." :type 'path :group 'geiser-image) +(geiser-custom--defface image-button + 'button geiser-image "image buttons in terminal buffers") + (defun geiser-image--list-cache () @@ -64,7 +66,18 @@ images in `geiser-image-cache-dir'." (dolist (f (butlast (geiser-image--list-cache) geiser-image-cache-keep-last)) (delete-file f))) -(defun geiser-image--replace-images (inline-images-p) +(defun geiser-image--display (file) + (start-process "Geiser image view" nil geiser-system-image-viewer file)) + +(defun geiser-image--button-action (button) + (let ((file (button-get button 'geiser-image-file))) + (when (file-exists-p file) (geiser-image--display file)))) + +(define-button-type 'geiser-image--button + 'action 'geiser-image--button-action + 'follow-link t) + +(defun geiser-image--replace-images (inline-images-p auto-p) "Replace all image patterns with actual images" (with-silent-modifications (save-excursion @@ -78,9 +91,13 @@ images in `geiser-image-cache-dir'." (delete-region begin end) (if (and inline-images-p (display-images-p)) (put-image (create-image file) begin "[image]") - (progn - (goto-char begin) - (insert "[image] ; use M-x geiser-view-last-image to view"))) + (goto-char begin) + (insert-text-button "[image]" + :type 'geiser-image--button + 'face 'geiser-font-lock-image-button + 'geiser-image-file file + 'help-echo "Click to display image") + (when auto-p (geiser-image--display file))) (setq geiser-image-cache-dir (file-name-directory file)) (geiser-image--clean-cache)))))) @@ -92,10 +109,7 @@ image viewer." (interactive "p") (let ((images (reverse (geiser-image--list-cache)))) (if (>= (length images) n) - (start-process "Geiser image view" - nil - geiser-system-image-viewer - (nth (- n 1) images)) + (geiser-image--display (nth (- n 1) images)) (error "There aren't %d recent images" n)))) |