feat(org): add #+STARTUP inlinegifs playgifs
- #+STARTUP: inlinegifs = play inline gif previews when point is on them. - #+STARTUP: playgifs = play all gifs in the visible buffer (super, super slow; use at your own risk). - Add +org-startup-with-animated-gifs for changing the global default (nil). Can be set to 'at-point (inlinegifs) or t (playgifs)
This commit is contained in:
parent
348ff3f65d
commit
83171ac554
2 changed files with 71 additions and 1 deletions
|
@ -84,6 +84,50 @@ exist, and `org-link' otherwise."
|
|||
(message "Download of image \"%s\" failed" link)
|
||||
nil)))
|
||||
|
||||
(defvar +org--gif-timers nil)
|
||||
;;;###autoload
|
||||
(defun +org-play-gif-at-point-h ()
|
||||
"Play the gif at point, while the cursor remains there (looping)."
|
||||
(dolist (timer +org--gif-timers (setq +org--gif-timers nil))
|
||||
(when (timerp (cdr timer))
|
||||
(cancel-timer (cdr timer)))
|
||||
(image-animate (car timer) nil 0))
|
||||
(when-let* ((ov (cl-find-if
|
||||
(lambda (it) (overlay-get it 'org-image-overlay))
|
||||
(overlays-at (point))))
|
||||
(dov (overlay-get ov 'display))
|
||||
(pt (point)))
|
||||
(when (image-animated-p dov)
|
||||
(push (cons
|
||||
dov (run-with-idle-timer
|
||||
0.5 nil
|
||||
(lambda (dov)
|
||||
(when (equal
|
||||
ov (cl-find-if
|
||||
(lambda (it) (overlay-get it 'org-image-overlay))
|
||||
(overlays-at (point))))
|
||||
(message "playing gif")
|
||||
(image-animate dov nil t)))
|
||||
dov))
|
||||
+org--gif-timers))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org-play-all-gifs-h ()
|
||||
"Continuously play all gifs in the visible buffer."
|
||||
(dolist (ov (overlays-in (point-min) (point-max)))
|
||||
(when-let* (((overlay-get ov 'org-image-overlay))
|
||||
(dov (overlay-get ov 'display))
|
||||
((image-animated-p dov))
|
||||
(w (selected-window)))
|
||||
(while-no-input
|
||||
(run-with-idle-timer
|
||||
0.3 nil
|
||||
(lambda (dov)
|
||||
(when (pos-visible-in-window-p (overlay-start ov) w nil)
|
||||
(unless (plist-get (cdr dov) :animate-buffer)
|
||||
(image-animate dov))))
|
||||
dov)))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Commands
|
||||
|
@ -100,3 +144,13 @@ exist, and `org-link' otherwise."
|
|||
(org-link-unescape (match-string-no-properties 1)))))
|
||||
(delete-region (match-beginning 0) (match-end 0))
|
||||
(insert label))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/play-gif-at-point ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(unless (eq 'org-mode major-mode)
|
||||
(user-error "Not in org-mode"))
|
||||
(or (+org-play-gif-at-point-h)
|
||||
(user-error "No gif at point")))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue