Add function for rendering sixel graphics in current buffer.
authorTim Vaughan <tgvaughan@gmail.com>
Tue, 21 May 2019 11:30:08 +0000 (13:30 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Tue, 21 May 2019 11:30:08 +0000 (13:30 +0200)
sixel.el

index 775bb58..5448ab4 100644 (file)
--- a/sixel.el
+++ b/sixel.el
@@ -194,4 +194,18 @@ Returns a sixel image object."
          (sixel-image-to-xpm-pixels sixel-image) "};")
       (error "Incorrecly formatted sixel string"))))
 
          (sixel-image-to-xpm-pixels sixel-image) "};")
       (error "Incorrecly formatted sixel string"))))
 
+(defun sixel-render-images-in-buffer ()
+  "Find and render any sixel images in the current buffer."
+  (interactive)
+  (save-excursion
+    (goto-char (point-min))
+    (while (re-search-forward "\eP[[:ascii:]]*\e\\\\" nil t)
+      (let ((sixel-string (match-string 0))
+            (inhibit-read-only t))
+        (delete-region (match-beginning 0)
+                       (match-end 0))
+        (insert-image
+         (create-image (sixel-to-xpm sixel-string) 'xpm t))
+        (insert "\n")))))
+
 ;;; sixel.el ends here
 ;;; sixel.el ends here