Function: animate-string

animate-string is an autoloaded and byte-compiled function defined in animate.el.gz.

Signature

(animate-string STRING VPOS &optional HPOS)

Documentation

Display STRING animations starting at position VPOS, HPOS.

The characters start at randomly chosen places, and all slide in parallel to their final positions, passing through animate-n-steps positions before the final ones. If HPOS is nil (or omitted), center the string horizontally in the current window.

Probably introduced at or before Emacs version 21.1.

Source Code

;; Defined in /usr/src/emacs/lisp/play/animate.el.gz
;;;###autoload
(defun animate-string (string vpos &optional hpos)
  "Display STRING animations starting at position VPOS, HPOS.
The characters start at randomly chosen places,
and all slide in parallel to their final positions,
passing through `animate-n-steps' positions before the final ones.
If HPOS is nil (or omitted), center the string horizontally
in the current window."
  (let ((characters
	 (animate-initialize string vpos
			     (or hpos
				 ;; HPOS unspecified, so compute
				 ;; it so as to center the string.
				 (max 0 (/ (- (window-width) (length string)) 2)))))
	(show-trailing-whitespace nil)
	;; Make sure indentation does not use tabs.
	;; They would confuse things.
	(indent-tabs-mode nil))
    (dotimes (i animate-n-steps)
      ;; Bind buffer-undo-list so it will be unchanged when we are done.
      ;; (We're going to undo all our changes anyway.)
      (let (buffer-undo-list
	    list-to-undo)
	;; Display the characters at the Ith position.
	;; This inserts them in the buffer.
	(animate-step characters (/ i 1.0 animate-n-steps))
	;; Make sure buffer is displayed starting at the beginning.
	(set-window-start nil 1)
	;; Display it, and wait just a little while.
        (sit-for (/ (float animate-total-added-delay) (max animate-n-steps 1)))
	;; Now undo the changes we made in the buffer.
	(setq list-to-undo buffer-undo-list)
	(while list-to-undo
	  (let ((undo-in-progress t))
	    (setq list-to-undo (primitive-undo 1 list-to-undo))))))
    ;; Insert the characters in their final positions.
    (animate-step characters 1)
    ;; Put the cursor at the end of the text on the line.
    (end-of-line)
    ;; Redisplay so they appear on the screen there.
    (sit-for 0)
    ;; This is so that the undo command, used afterwards,
    ;; will undo the "animate" calls one by one.
    (undo-boundary)))