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

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

Re: same data appears twice, interactive then function body


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

Yuri Khan wrote:

>> Oh, so there is a `window-text-width'!
>
> Depending on what you are trying to achieve, ‘fill-column’
> might fit better.

It works great! I realized you don't even need
`window-text-width' twice! [improved code last]

I use this with files like this:

  https://dataswamp.org/~incal/FILM

(defun insert-string-centered (string &optional width)
  (interactive
   (list (read-from-minibuffer "string: ")
         (string-to-number (read-from-minibuffer "width [window]: " ))))
  (let*((max         (if (< 0 width) width (window-text-width)))
        (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) ))
(defalias 'isc #'insert-string-centered)

-- 
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]