|
From: | Jean Louis |
Subject: | Re: same data appears twice, interactive then function body |
Date: | Wed, 16 Dec 2020 07:16:40 +0300 |
User-agent: | Mutt/2.0 (3d08634) (2020-11-07) |
* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2020-12-16 07:03]: > Stefan Monnier wrote: > > > Here's my take on it: > > > > (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 (+ 42 42 -4))) > > [...] > > > > Now the question is how to avoid having 42 appear twice, > > I guess I remember from micro computers that we used division in this way to find the center. (defun insert-centered-text (text &optional width) (interactive "MText: ") (let* ((width (or width (window-text-width))) (length (length (string-trim text))) (pos (/ (- width length) 2))) (move-to-column pos t) (insert text) (insert "\n")))
[Prev in Thread] | Current Thread | [Next in Thread] |