help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

same data appears twice, interactive then function body


From: Emanuel Berg
Subject: same data appears twice, interactive then function body
Date: Wed, 16 Dec 2020 02:23:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Check out this code, how do you avoid having 80 appear twice?

(defun insert-string-centered (string &optional width)
  (interactive
   (list (read-from-minibuffer "string: ")
         (string-to-number (read-from-minibuffer "width [80]: "))) )
  (let*((max         (if (< 0 width) width 80))
        (str-len     (length string))
        (padding     (+ (/ (- max str-len) 2) (if (= 0 (mod str-len 2)) 1 0)))
        (padding-str (make-string padding ?\s)) )
    (insert padding-str string) ))

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]