* Function to present few centered lines
@ 2021-04-14 13:03 Jean Louis
2021-04-14 13:13 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Jean Louis @ 2021-04-14 13:03 UTC (permalink / raw
To: Help GNU Emacs
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")
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Function to present few centered lines
2021-04-14 13:03 Function to present few centered lines Jean Louis
@ 2021-04-14 13:13 ` Eli Zaretskii
2021-04-14 13:35 ` Jean Louis
0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2021-04-14 13:13 UTC (permalink / raw
To: help-gnu-emacs
> Date: Wed, 14 Apr 2021 16:03:45 +0300
> From: Jean Louis <bugs@gnu.support>
>
> - enlarging font, I don't know how to enlarge it, so that width and
> height of window is adjusted to new enlarged font
"Adjusted" in what way? to keep the same number of columns? I think
you need to manually enlarge the window.
> - centering, I am trying to center line by using window-width and
> setting fill-column, it seem it does not center nicely.
Why not use center-region?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Function to present few centered lines
2021-04-14 13:13 ` Eli Zaretskii
@ 2021-04-14 13:35 ` Jean Louis
2021-04-14 14:09 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Jean Louis @ 2021-04-14 13:35 UTC (permalink / raw
To: Eli Zaretskii; +Cc: help-gnu-emacs
* Eli Zaretskii <eliz@gnu.org> [2021-04-14 16:14]:
> > Date: Wed, 14 Apr 2021 16:03:45 +0300
> > From: Jean Louis <bugs@gnu.support>
> >
> > - enlarging font, I don't know how to enlarge it, so that width and
> > height of window is adjusted to new enlarged font
>
> "Adjusted" in what way? to keep the same number of columns? I think
> you need to manually enlarge the window.
If I do:
(window-width) ⇒ 103
(text-scale-increase 5) ⇒ t
(window-width) ⇒ 103
(progn (insert "Hello") (center-line)) --- it will not show centered
according to text scale increase
What I would like is to get a new (window-width) value adjusted to the
text increased as to calculate more from thre.
> > - centering, I am trying to center line by using window-width and
> > setting fill-column, it seem it does not center nicely.
>
> Why not use center-region?
OK that is good idea. In this example I wish to center vertically as
also horizontally, but I can calculate vertical centering, insert
lines, and use center-region, that is fine.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Function to present few centered lines
2021-04-14 13:35 ` Jean Louis
@ 2021-04-14 14:09 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2021-04-14 14:09 UTC (permalink / raw
To: help-gnu-emacs
> Date: Wed, 14 Apr 2021 16:35:45 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
>
> (window-width) ⇒ 103
> (text-scale-increase 5) ⇒ t
> (window-width) ⇒ 103
> (progn (insert "Hello") (center-line)) --- it will not show centered
> according to text scale increase
You need to scale back fill-column, because evidently you want the
text centered in pixel units, not in column units.
> What I would like is to get a new (window-width) value adjusted to the
> text increased as to calculate more from thre.
The problem here is that window-width returns value in canonical
column units, while fill-column measures in actual columns. So you
are comparing apples with oranges.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-14 14:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-14 13:03 Function to present few centered lines Jean Louis
2021-04-14 13:13 ` Eli Zaretskii
2021-04-14 13:35 ` Jean Louis
2021-04-14 14:09 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.