Function: calendar-string-spread
calendar-string-spread is a byte-compiled function defined in
calendar.el.gz.
Signature
(calendar-string-spread STRINGS CHAR LENGTH)
Documentation
Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH.
The effect is like mapconcat but the separating pieces are as
balanced as possible. Each item of STRINGS is evaluated before
concatenation so it can actually be an expression that evaluates
to a string. If LENGTH is too short, the STRINGS are just
concatenated and the result truncated.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/calendar.el.gz
(defun calendar-string-spread (strings char length)
"Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH.
The effect is like `mapconcat' but the separating pieces are as
balanced as possible. Each item of STRINGS is evaluated before
concatenation so it can actually be an expression that evaluates
to a string. If LENGTH is too short, the STRINGS are just
concatenated and the result truncated."
;; The algorithm is based on equation (3.25) on page 85 of Concrete
;; Mathematics by Ronald L. Graham, Donald E. Knuth, and Oren Patashnik,
;; Addison-Wesley, Reading, MA, 1989.
(let* ((strings (mapcar #'eval
(if (< (length strings) 2)
(append (list "") strings (list ""))
strings)))
(n (- length (string-width (apply #'concat strings))))
(m (* (1- (length strings)) (char-width char)))
(s (car strings))
(strings (cdr strings))
(i 0))
(dolist (string strings)
(setq s (concat s
(make-string (max 0 (/ (+ n i) m)) char)
string)
i (1+ i)))
(truncate-string-to-width s length)))