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

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

Function to present few centered lines


From: Jean Louis
Subject: Function to present few centered lines
Date: Wed, 14 Apr 2021 16:03:45 +0300

I would like to show few lines in the center of whole monitor window
by using Emacs. And I miss probably knowledge of some built-in
functions.

In this below for now degraded function I do not know how to enlarge
the font so that the (window-width) and (window-height) also change,
so that I can get realistic numbers which I can use to center lines.

What does not work:

- enlarging font, I don't know how to enlarge it, so that width and
  height of window is adjusted to new enlarged font

- centering, I am trying to center line by using window-width and
  setting fill-column, it seem it does not center nicely.

(defun present-snippet (snippet)
  "This is expected to show few lines with large font in the middle
of maximized frame."
  (let* ((snippet (split-string snippet))
         (buffer (car snippet)))
    (switch-to-buffer-other-frame buffer)
    (set-frame-parameter nil 'fullscreen 'maximized)
    ;; (text-scale-adjust 3) ;; 
    (let* ((width (window-width))
           (height (window-height))
           (first-line (- height (length snippet))))
      (mapc 'insert (make-list first-line "\n"))
      (while snippet
        (let* ((line (pop snippet))
               (line-length (length line))
               (fill-column width)
               (place (- (/ width 2) (/ line-length 2))))
          (insert line)
          (center-line)
          (insert "\n"))))))

(present-snippet "Phone: +1234456578")





reply via email to

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