GNU bug report logs - #52129
29.0.50; Wish: Extend `:align-to center' to work on lines in buffer

Previous Next

Package: emacs;

Reported by: Arthur Miller <arthur.miller <at> live.com>

Date: Fri, 26 Nov 2021 20:22:01 UTC

Severity: normal

Tags: wontfix

Found in version 29.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 52129 in the body.
You can then email your comments to 52129 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Fri, 26 Nov 2021 20:22:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arthur Miller <arthur.miller <at> live.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 26 Nov 2021 20:22:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Arthur Miller <arthur.miller <at> live.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; Wish: Extend `:align-to center' to work on lines in buffer
Date: Fri, 26 Nov 2021 21:01:11 +0100
[Message part 1 (text/plain, inline)]
I am not sure if the title is descriptive enough, or even correct, but as seen
from attached code and image, I am trying to align two strings in a center of
each strings line.

It works now when string-pixel-width correctly calculates pixel widths. However,
I would prefer if I could just use :align-to center as a spec for a string as
property. Currently we have to use space as a spacer as we used to use
gif-spacers back in time.

I am not sure about how semantics would work, there are several cases to
consider, but generally if a string or a stretch of text in a string were given
text property 'display '(:align-to center), then Emacs would align that stretch
of text in the middle of the line that text occupies.

There would be cases where text dooes not fit the line, where there are multiple
such substring in same line maybe etc.

I don't know if it is possible or not, I am not familar with the display code,
nor am I sure about the syntax of proposal, but it would be nice and probably
useful to have some more declarative approach then what I had to do procedurally
in the attached example.

[aligned-clock.png (image/png, attachment)]
[emacs-vision-clock.el (text/plain, attachment)]
[Message part 4 (text/plain, inline)]



In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.17.4)
 of 2021-11-26 built on pascal
Repository revision: c32e8bdc23214793ffcb065ba8478570679c1f0a
Repository branch: alpha-patch
Windowing system distributor 'The X.Org Foundation', version 11.0.12101001
System Description: Arch Linux

Configured using:
 'configure --with-native-compilation 'CFLAGS=-O2 -mtune=native -march=native''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE
XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: sv_SE.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ELisp/l

Minor modes in effect:
  windmove-mode: t
  beacon-mode: t
  outshine-mode: t
  dired-async-mode: t
  outline-minor-mode: t
  yas-minor-mode: t
  page-break-lines-mode: t
  company-mode: t
  electric-pair-mode: t
  global-auto-revert-mode: t
  global-hl-line-mode: t
  global-subword-mode: t
  subword-mode: t
  auto-image-file-mode: t
  auto-insert-mode: t
  display-time-mode: t
  delete-selection-mode: t
  save-place-mode: t
  winner-mode: t
  which-key-mode: t
  wrap-region-global-mode: t
  wrap-region-mode: t
  helm-mode: t
  helm-adaptive-mode: t
  shell-dirtrack-mode: t
  helm-autoresize-mode: t
  helm--remap-mouse-mode: t
  async-bytecomp-package-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: yas--auto-fill
  transient-mark-mode: t
  abbrev-mode: t

Load-path shadows:
/home/arthur/repos/emacs/lisp/transient hides /home/arthur/.emacs.d/elpa/transient-20210723.1601/transient
/home/arthur/.emacs.d/elpa/lispy-20210914.1209/elpa hides /home/arthur/.emacs.d/elpa/ivy-20210930.1450/elpa
/home/arthur/repos/emacs/lisp/emacs-lisp/helper hides /home/arthur/.emacs.d/elpa/helper-0.5/helper
/home/arthur/.emacs.d/lisp/helm-git-branch hides /home/arthur/.emacs.d/elpa/helm-git-branch-0.1/helm-git-branch
/usr/local/share/emacs/site-lisp/emms/emms-cue hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-cue
/usr/local/share/emacs/site-lisp/emms/emms-info-ogginfo hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-info-ogginfo
/usr/local/share/emacs/site-lisp/emms/emms-mark hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-mark
/usr/local/share/emacs/site-lisp/emms/emms-last-played hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-last-played
/usr/local/share/emacs/site-lisp/emms/emms-player-mpg321-remote hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-player-mpg321-remote
/usr/local/share/emacs/site-lisp/emms/emms-score hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-score
/usr/local/share/emacs/site-lisp/emms/emms-player-mpd hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-player-mpd
/usr/local/share/emacs/site-lisp/emms/emms-show-all hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-show-all
/usr/local/share/emacs/site-lisp/emms/emms-setup hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-setup
/usr/local/share/emacs/site-lisp/emms/emms-playlist-sort hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-playlist-sort
/usr/local/share/emacs/site-lisp/emms/emms hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms
/usr/local/share/emacs/site-lisp/emms/emms-info-mp3info hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-info-mp3info
/usr/local/share/emacs/site-lisp/emms/emms-source-playlist hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-source-playlist
/usr/local/share/emacs/site-lisp/emms/emms-cache hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-cache
/usr/local/share/emacs/site-lisp/emms/emms-volume hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-volume
/usr/local/share/emacs/site-lisp/emms/emms-playing-time hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-playing-time
/usr/local/share/emacs/site-lisp/emms/emms-tag-editor hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-tag-editor
/usr/local/share/emacs/site-lisp/emms/emms-source-file hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-source-file
/usr/local/share/emacs/site-lisp/emms/emms-bookmarks hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-bookmarks
/usr/local/share/emacs/site-lisp/emms/emms-player-simple hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-player-simple
/usr/local/share/emacs/site-lisp/emms/emms-player-xine hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-player-xine
/usr/local/share/emacs/site-lisp/emms/emms-librefm-stream hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-librefm-stream
/usr/local/share/emacs/site-lisp/emms/emms-browser hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-browser
/usr/local/share/emacs/site-lisp/emms/emms-maint hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-maint
/usr/local/share/emacs/site-lisp/emms/emms-playlist-mode hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-playlist-mode
/usr/local/share/emacs/site-lisp/emms/emms-url hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-url
/usr/local/share/emacs/site-lisp/emms/emms-streams hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-streams
/usr/local/share/emacs/site-lisp/emms/emms-info-opusinfo hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-info-opusinfo
/usr/local/share/emacs/site-lisp/emms/emms-mode-line hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-mode-line
/usr/local/share/emacs/site-lisp/emms/emms-player-mplayer hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-player-mplayer
/usr/local/share/emacs/site-lisp/emms/emms-info hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-info
/usr/local/share/emacs/site-lisp/emms/emms-librefm-scrobbler hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-librefm-scrobbler
/usr/local/share/emacs/site-lisp/emms/emms-info-libtag hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-info-libtag
/usr/local/share/emacs/site-lisp/emms/emms-info-metaflac hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-info-metaflac
/usr/local/share/emacs/site-lisp/emms/emms-metaplaylist-mode hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-metaplaylist-mode
/usr/local/share/emacs/site-lisp/emms/emms-compat hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-compat
/usr/local/share/emacs/site-lisp/emms/emms-volume-pulse hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-volume-pulse
/usr/local/share/emacs/site-lisp/emms/emms-player-mpv hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-player-mpv
/usr/local/share/emacs/site-lisp/emms/emms-playlist-limit hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-playlist-limit
/usr/local/share/emacs/site-lisp/emms/emms-history hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-history
/usr/local/share/emacs/site-lisp/emms/emms-player-vlc hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-player-vlc
/usr/local/share/emacs/site-lisp/emms/emms-mode-line-icon hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-mode-line-icon
/usr/local/share/emacs/site-lisp/emms/emms-lyrics hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-lyrics
/usr/local/share/emacs/site-lisp/emms/emms-stream-info hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-stream-info
/usr/local/share/emacs/site-lisp/emms/emms-volume-amixer hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-volume-amixer
/usr/local/share/emacs/site-lisp/emms/emms-i18n hides /home/arthur/.emacs.d/elpa/emms-20210911.2031/emms-i18n
/home/arthur/.emacs.d/elpa/elisp-refs-20211009.1531/elisp-refs hides /home/arthur/.emacs.d/elpa/elisp-refs-1.4/elisp-refs
/home/arthur/.emacs.d/elpa/elisp-refs-20211009.1531/elisp-refs-autoloads hides /home/arthur/.emacs.d/elpa/elisp-refs-1.4/elisp-refs-autoloads
/home/arthur/.emacs.d/elpa/elisp-refs-20211009.1531/elisp-refs-pkg hides /home/arthur/.emacs.d/elpa/elisp-refs-1.4/elisp-refs-pkg
/home/arthur/.emacs.d/lisp/company-cmake hides /home/arthur/.emacs.d/elpa/company-20211002.1732/company-cmake

Features:
(shadow emacsbug sendmail mm-archive misearch multi-isearch gnus-fun smiley
mail-extr qp gnus-async gnus-ml gnus-topic cursor-sensor url-cache benchmark
nndraft nnmh nnhackernews anaphora request gnus-bcklg gnus-cite nnfolder utf-7
gnutls network-stream gnus-agent gnus-srvr gnus-score score-mode nnvirtual
gnus-msg nntp gnus-cache help-fns radix-tree cl-print debug helm-command
emacs-vision-clock windmove time-stamp vc-git diff-mode vc-dispatcher
org-pretty-table ol-eww eww xdg url-queue mm-url ol-rmail ol-mhe ol-irc ol-info
ol-gnus nnselect gnus-search eieio-opt speedbar ezimage dframe gnus-art mm-uu
mml2015 mm-view mml-smime smime dig gnus-sum shr kinsoku svg dom gnus-group
gnus-undo gnus-start gnus-dbus gnus-cloud nnimap nnmail mail-source utf7 netrc
nnoo gnus-spec gnus-int gnus-range message yank-media rfc822 mml mml-sec epa epg
rfc6068 epg-config mm-decode mm-bodies mm-encode mailabbrev gmm-utils mailheader
gnus-win ol-docview doc-view ol-bibtex ol-bbdb ol-w3m ol-doi org-link-doi
dired-auto-readme helm-external helm-net tramp-archive tramp-gvfs tramp-cache
zeroconf dbus ffap beacon emms-librefm-stream xml emms-librefm-scrobbler
emms-i18n emms-history emms-score emms-stream-info emms-metaplaylist-mode
emms-bookmarks emms-cue emms-mode-line-icon emms-browser sort emms-playlist-sort
emms-last-played emms-player-xine emms-player-mpd emms-lyrics emms-url
emms-streams emms-show-all emms-tag-editor emms-mark emms-cache
emms-info-opusinfo emms-info-ogginfo emms-info-mp3info emms-player-vlc
emms-player-mplayer emms-player-mpv emms-mode-line-cycle emms-mode-line
emms-playing-time emms-player-simple emms-info later-do emms-playlist-limit
emms-volume emms-volume-amixer emms-playlist-mode emms-source-playlist
emms-source-file locate emms-setup emms emms-compat c++-setup sv-kalender lunar
solar cal-dst holidays hol-loaddefs extras recentf tree-widget server overseer
pkg-info url-http url-auth url-gw nsm rmc puny epl f s outshine
outshine-org-cmds outorg org-protocol org-pdftools pdf-occur pdf-isearch
let-alist pdf-annot tablist tablist-filter semantic/wisent/comp semantic/wisent
semantic/wisent/wisent semantic/util-modes semantic/util semantic semantic/tag
semantic/lex semantic/fw mode-local cedet facemenu pdf-misc imenu pdf-tools
cus-edit cus-start cus-load pdf-view bookmark pp jka-compr pdf-cache pdf-info tq
pdf-util pdf-macs image-mode dired-extras dired-copy-paste dired-subtree
dired-hacks-utils openwith dired-x wdired dired-async dired-aux dired
dired-loaddefs exif org-noter org-element avl-tree org-refile org ob ob-tangle
ob-ref ob-lob ob-table ob-exp org-macro org-footnote org-src ob-comint
org-pcomplete org-list org-faces org-entities org-version ob-emacs-lisp ob-core
ob-eval org-table oc-basic bibtex ol org-keys oc org-compat org-macs
org-loaddefs cal-menu calendar cal-loaddefs noutline outline yasnippet-snippets
yasnippet derived disp-table page-break-lines company-yasnippet company-ispell
ispell company-clang company-elisp company-etags etags fileloop generator xref
project company-semantic company-template company-keywords company-files
company-capf company pcase elec-pair autorevert hl-line cap-words superword
subword image-file image-converter autoinsert time delsel saveplace winner
which-key advice solarized-dark-theme solarized solarized-faces color
wrap-region dash gnus nnheader gnus-util rmail rmail-loaddefs mail-utils
wid-edit helm-mode helm-adaptive helm-projectile projectile lisp-mnt mail-parse
rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr grep compile
text-property-search ibuf-ext ibuffer ibuffer-loaddefs thingatpt helm-eshell
helm-elisp helm-files filenotify tramp tramp-loaddefs trampver tramp-integration
files-x tramp-compat shell pcomplete comint ansi-color parse-time iso8601
time-date ls-lisp helm-buffers helm-occur helm-tags helm-locate helm-eval edebug
backtrace find-func helm-info ring helm-types helm-config diminish helm-pages
helm-grep helm-regexp helm-utils helm-help format-spec helm easy-mmode
async-bytecomp helm-global-bindings edmacro kmacro helm-source helm-multi-match
helm-lib async elisp-extras popup comp comp-cstr warnings rx cl-extra help-mode
helm-easymenu cl info package browse-url url url-proxy url-privacy url-expand
url-methods url-history url-cookie url-domsuf url-util mailcap url-handlers
url-parse auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json map url-vars seq gv subr-x byte-opt bytecomp byte-compile
cconv cl-loaddefs cl-lib iso-transl tooltip eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register page
tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse
jit-lock font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5
base64 format env code-pages mule custom widget keymap hashtable-print-readable
backquote threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo move-toolbar gtk x-toolkit x multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 730568 792838)
 (symbols 48 46135 895)
 (strings 32 166920 139329)
 (string-bytes 1 6499549)
 (vectors 16 97681)
 (vector-slots 8 1997619 1820891)
 (floats 8 1412 6559)
 (intervals 56 4846 6212)
 (buffers 992 47))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sat, 27 Nov 2021 06:00:02 GMT) Full text and rfc822 format available.

Message #8 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Arthur Miller <arthur.miller <at> live.com>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50;
 Wish: Extend `:align-to center' to work on lines in buffer
Date: Sat, 27 Nov 2021 07:59:33 +0200
> From: Arthur Miller <arthur.miller <at> live.com>
> Date: Fri, 26 Nov 2021 21:01:11 +0100
> 
> I am not sure if the title is descriptive enough, or even correct, but as seen
> from attached code and image, I am trying to align two strings in a center of
> each strings line.
> 
> It works now when string-pixel-width correctly calculates pixel widths. However,
> I would prefer if I could just use :align-to center as a spec for a string as
> property. Currently we have to use space as a spacer as we used to use
> gif-spacers back in time.
> 
> I am not sure about how semantics would work, there are several cases to
> consider, but generally if a string or a stretch of text in a string were given
> text property 'display '(:align-to center), then Emacs would align that stretch
> of text in the middle of the line that text occupies.

I don't understand what exactly are you asking for.  Is your problem
that you have to prepend some character to the string and put the
:align-to spec on that character?  Because AFAIU that simple measure
should achieve your goal.  If that's not what you want, or if what I
described doesn't work, please show some simple code to explain your
requests.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sat, 27 Nov 2021 08:49:02 GMT) Full text and rfc822 format available.

Message #11 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Arthur Miller <arthur.miller <at> live.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Sat, 27 Nov 2021 09:47:58 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Arthur Miller <arthur.miller <at> live.com>
>> Date: Fri, 26 Nov 2021 21:01:11 +0100
>> 
>> I am not sure if the title is descriptive enough, or even correct, but as seen
>> from attached code and image, I am trying to align two strings in a center of
>> each strings line.
>> 
>> It works now when string-pixel-width correctly calculates pixel widths. However,
>> I would prefer if I could just use :align-to center as a spec for a string as
>> property. Currently we have to use space as a spacer as we used to use
>> gif-spacers back in time.
>> 
>> I am not sure about how semantics would work, there are several cases to
>> consider, but generally if a string or a stretch of text in a string were given
>> text property 'display '(:align-to center), then Emacs would align that stretch
>> of text in the middle of the line that text occupies.
>
> I don't understand what exactly are you asking for.  Is your problem
> that you have to prepend some character to the string and put the
> :align-to spec on that character?  Because AFAIU that simple measure
> should achieve your goal.

You mean something like this:

#+begin_src emacs-lisp
(defun evc--time ()
  (propertize
   (time-stamp-string " %H:%M") 'face evc--time-face 'display '(space :align-to center)))

(defun evc--date ()
  (propertize
   (concat
    " "
    (capitalize (time-stamp-string "%A")) ". "
    (capitalize (time-stamp-string "%B %d"))) 'face evc--date-face 'display '(space :align-to center)))

(defun evc--update ()
  (let ((time (evc--time))
        (date (evc--date)))
    (when (frame-live-p evc--frame)
      (select-frame evc--frame))
    (with-current-buffer evc--buffer
      (erase-buffer)
      (insert time "\n" date))))
#+end_src

That "simple measure" does not achieve the goal of aligning involved strings to
center; or I don't know understand how you mean.

This does:

#+begin_src emacs-lisp
(defun evc--time ()
  (propertize
   (time-stamp-string " %H:%M") 'face evc--time-face))

(defun evc--date ()
  (propertize
   (concat
    (capitalize (time-stamp-string "%A")) ". "
    (capitalize (time-stamp-string "%B %d"))) 'face evc--date-face))

(let* ((tlen (* 0.5 (string-pixel-width time)))
             (dlen (* 0.5 (string-pixel-width date)))
             (spct (propertize " " 'display `(space :align-to (- center (,tlen)))))
             (spcd (propertize " " 'display `(space :align-to (- center (,dlen))))))
        (insert spct time "\n" spcd date))
#+end_src

>                         please show some simple code to explain your
> requests.

I hope above illustrates that it is not just to prepend a space, you have to
calculate how much it should extend to. This has to be done for each line.

Also, even if it would be just to prepend a spacer character, the goal is still
to align text in center of a line, so why can't we just renderer to do it for
us, instead of having such procedural way of telling it what to do. Why can we
not just tell:

(defun evc--time ()
  (propertize
   (time-stamp-string " %H:%M") 'face evc--time-face 'display '(line :align-to center)))

or something similar.

Also what if the text is longer then visual line? Would it be possible for the
rendering engine to center part of the tring with 'aligne-to center' property,
and cull extensive part on sides that are outside. That is not acheavable with a spacer.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sat, 27 Nov 2021 09:16:02 GMT) Full text and rfc822 format available.

Message #14 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Arthur Miller <arthur.miller <at> live.com>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Sat, 27 Nov 2021 11:15:16 +0200
> From: Arthur Miller <arthur.miller <at> live.com>
> Cc: 52129 <at> debbugs.gnu.org
> Date: Sat, 27 Nov 2021 09:47:58 +0100
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > I don't understand what exactly are you asking for.  Is your problem
> > that you have to prepend some character to the string and put the
> > :align-to spec on that character?  Because AFAIU that simple measure
> > should achieve your goal.
> 
> You mean something like this:
> 
> #+begin_src emacs-lisp
> (defun evc--time ()
>   (propertize
>    (time-stamp-string " %H:%M") 'face evc--time-face 'display '(space :align-to center)))
> 
> (defun evc--date ()
>   (propertize
>    (concat
>     " "
>     (capitalize (time-stamp-string "%A")) ". "
>     (capitalize (time-stamp-string "%B %d"))) 'face evc--date-face 'display '(space :align-to center)))

No, I mean to put this property:

    'display '(space :align-to center)

on a space character (or any other character, which will not be
displayed) that is prepended to the time-stamp-string you want to
display.

> (let* ((tlen (* 0.5 (string-pixel-width time)))
>              (dlen (* 0.5 (string-pixel-width date)))
>              (spct (propertize " " 'display `(space :align-to (- center (,tlen)))))
>              (spcd (propertize " " 'display `(space :align-to (- center (,dlen))))))
>         (insert spct time "\n" spcd date))
> 
> I hope above illustrates that it is not just to prepend a space, you have to
> calculate how much it should extend to.

So you want to center the string, not its first character?  OK, but
why is the above a problem?  It's simple enough code, I think.

> Also, even if it would be just to prepend a spacer character, the goal is still
> to align text in center of a line, so why can't we just renderer to do it for
> us, instead of having such procedural way of telling it what to do. Why can we
> not just tell:
> 
> (defun evc--time ()
>   (propertize
>    (time-stamp-string " %H:%M") 'face evc--time-face 'display '(line :align-to center)))
> 
> or something similar.

Because the Emacs display code examines buffer text one character at a
time, left to right, and produces the glyphs for display for each
character before it goes to the next.  You are asking the display
engine to know the display width of your string before it performs the
layout calculations for that string, and that cannot work.  The
display code cannot even assume that it will traverse all the
characters of a line, it could be forced to stop before it reaches the
end of the line, in which case it cannot know that width even
post-factum.

> Also what if the text is longer then visual line? Would it be possible for the
> rendering engine to center part of the tring with 'aligne-to center' property,
> and cull extensive part on sides that are outside. That is not acheavable with a spacer.

You want the display engine to decide where to break such a long line?
Or do you want to decide that up front and indicate that via the
portion of the text on which you put this hypothetical property?  IOW,
what exactly is the meaning of "cull" here?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sat, 27 Nov 2021 11:07:02 GMT) Full text and rfc822 format available.

Message #17 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Arthur Miller <arthur.miller <at> live.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Sat, 27 Nov 2021 12:06:19 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Arthur Miller <arthur.miller <at> live.com>
>> Cc: 52129 <at> debbugs.gnu.org
>> Date: Sat, 27 Nov 2021 09:47:58 +0100
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> > I don't understand what exactly are you asking for.  Is your problem
>> > that you have to prepend some character to the string and put the
>> > :align-to spec on that character?  Because AFAIU that simple measure
>> > should achieve your goal.
>> 
>> You mean something like this:
>> 
>> #+begin_src emacs-lisp
>> (defun evc--time ()
>>   (propertize
>>    (time-stamp-string " %H:%M") 'face evc--time-face 'display '(space :align-to center)))
>> 
>> (defun evc--date ()
>>   (propertize
>>    (concat
>>     " "
>>     (capitalize (time-stamp-string "%A")) ". "
>>     (capitalize (time-stamp-string "%B %d"))) 'face evc--date-face 'display '(space :align-to center)))
>
> No, I mean to put this property:
>
>     'display '(space :align-to center)
>
> on a space character (or any other character, which will not be
> displayed) that is prepended to the time-stamp-string you want to
> display.

Aha, like this?:

(defun evc--time ()
  (concat (propertize " " 'display '(space :align-to center))
          (propertize
           (time-stamp-string " %H:%M") 'face evc--time-face)))

That still seems to be dependanble on when the time string is inserted? Because
when I test to insert like this:

(defun evc--update ()
  (let ((time (evc--time))
        (date (evc--date)))
    (when (frame-live-p evc--frame)
      (select-frame evc--frame))
    (with-current-buffer evc--buffer
      (erase-buffer)
      (insert time "\n" date)
      (goto-char 1))))

the string is not centered correctly; there is ~70 pixels difference between
left and right margins.

Maybe if I inserted longer string first, fitted frame to buffer, and than
inserted time, but I don't think it is relevant if you say it is not possible to
do it due to renderer only looking at one char at a time.

> Because the Emacs display code examines buffer text one character at a
> time, left to right, and produces the glyphs for display for each
> character before it goes to the next.  You are asking the display
> engine to know the display width of your string before it performs the
> layout calculations for that string, and that cannot work.  The
> display code cannot even assume that it will traverse all the
> characters of a line, it could be forced to stop before it reaches the
> end of the line, in which case it cannot know that width even
> post-factum.
>
>> Also what if the text is longer then visual line? Would it be possible for the
>> rendering engine to center part of the tring with 'aligne-to center' property,
>> and cull extensive part on sides that are outside. That is not acheavable with a spacer.
>
> You want the display engine to decide where to break such a long line?
> Or do you want to decide that up front and indicate that via the
> portion of the text on which you put this hypothetical property?  IOW,

Meant mostly that display engine would keep marked portion of the string
centered on the display, for example if there is some more important of the
string or so, but at the second thought I don't see much use of such
feature.

Anyway, I understand now when you say that renderer only looks at one char at a
time.

Is there any way to make it aware of surrounding context, like entire line? Or
would that be too demanding computationally? I guess there is a reason why it is
made one char at a time.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sat, 27 Nov 2021 11:26:01 GMT) Full text and rfc822 format available.

Message #20 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Arthur Miller <arthur.miller <at> live.com>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Sat, 27 Nov 2021 13:25:13 +0200
> From: Arthur Miller <arthur.miller <at> live.com>
> Cc: 52129 <at> debbugs.gnu.org
> Date: Sat, 27 Nov 2021 12:06:19 +0100
> 
> > No, I mean to put this property:
> >
> >     'display '(space :align-to center)
> >
> > on a space character (or any other character, which will not be
> > displayed) that is prepended to the time-stamp-string you want to
> > display.
> 
> Aha, like this?:
> 
> (defun evc--time ()
>   (concat (propertize " " 'display '(space :align-to center))
>           (propertize
>            (time-stamp-string " %H:%M") 'face evc--time-face)))
> 
> That still seems to be dependanble on when the time string is inserted? Because
> when I test to insert like this:
> 
> (defun evc--update ()
>   (let ((time (evc--time))
>         (date (evc--date)))
>     (when (frame-live-p evc--frame)
>       (select-frame evc--frame))
>     (with-current-buffer evc--buffer
>       (erase-buffer)
>       (insert time "\n" date)
>       (goto-char 1))))
> 
> the string is not centered correctly; there is ~70 pixels difference between
> left and right margins.

That's because it centers the first character of the string, not its
middle character.

> Is there any way to make it aware of surrounding context, like entire line? Or
> would that be too demanding computationally?

I don't think I understand what you mean by "surrounding context", and
what would it mean for it to "be aware" of it?

> I guess there is a reason why it is made one char at a time.

Simplicity and speed, I guess.  But that's not for me to answer: I
wasn't there when this was designed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sat, 27 Nov 2021 23:41:02 GMT) Full text and rfc822 format available.

Message #23 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Arthur Miller <arthur.miller <at> live.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Sun, 28 Nov 2021 00:40:30 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Arthur Miller <arthur.miller <at> live.com>
>> Cc: 52129 <at> debbugs.gnu.org
>> Date: Sat, 27 Nov 2021 12:06:19 +0100
>> 
>> > No, I mean to put this property:
>> >
>> >     'display '(space :align-to center)
>> >
>> > on a space character (or any other character, which will not be
>> > displayed) that is prepended to the time-stamp-string you want to
>> > display.
>> 
>> Aha, like this?:
>> 
>> (defun evc--time ()
>>   (concat (propertize " " 'display '(space :align-to center))
>>           (propertize
>>            (time-stamp-string " %H:%M") 'face evc--time-face)))
>> 
>> That still seems to be dependanble on when the time string is inserted? Because
>> when I test to insert like this:
>> 
>> (defun evc--update ()
>>   (let ((time (evc--time))
>>         (date (evc--date)))
>>     (when (frame-live-p evc--frame)
>>       (select-frame evc--frame))
>>     (with-current-buffer evc--buffer
>>       (erase-buffer)
>>       (insert time "\n" date)
>>       (goto-char 1))))
>> 
>> the string is not centered correctly; there is ~70 pixels difference between
>> left and right margins.
>
> That's because it centers the first character of the string, not its
> middle character.

That too; so you see, it is not as simple to get it right by just prepending a
space with :align-to center property.

>> Is there any way to make it aware of surrounding context, like entire line? Or
>> would that be too demanding computationally?
>
> I don't think I understand what you mean by "surrounding context", and
> what would it mean for it to "be aware" of it?

With context I meant simply the line, or at least part of the line to be
displayed. To be aware of it = to take it into consideration when displaying
line, so things like suggested would be possible.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sun, 28 Nov 2021 07:49:01 GMT) Full text and rfc822 format available.

Message #26 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Arthur Miller <arthur.miller <at> live.com>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Sun, 28 Nov 2021 09:48:48 +0200
> From: Arthur Miller <arthur.miller <at> live.com>
> Cc: 52129 <at> debbugs.gnu.org
> Date: Sun, 28 Nov 2021 00:40:30 +0100
> 
> > That's because it centers the first character of the string, not its
> > middle character.
> 
> That too; so you see, it is not as simple to get it right by just prepending a
> space with :align-to center property.

We've been through this: you need to dynamically compute the pixel
coordinate to align-to, as function of the string width.

> >> Is there any way to make it aware of surrounding context, like entire line? Or
> >> would that be too demanding computationally?
> >
> > I don't think I understand what you mean by "surrounding context", and
> > what would it mean for it to "be aware" of it?
> 
> With context I meant simply the line, or at least part of the line to be
> displayed. To be aware of it = to take it into consideration when displaying
> line, so things like suggested would be possible.

The display engine considers the line as a whole only when the entire
screen line has been laid out, i.e. we get to a newline or the X
coordinate is at the right edge of the window.  Before that, there's
no information about the "line context".




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Sun, 28 Nov 2021 10:39:01 GMT) Full text and rfc822 format available.

Message #29 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Arthur Miller <arthur.miller <at> live.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Sun, 28 Nov 2021 11:38:18 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Arthur Miller <arthur.miller <at> live.com>
>> Cc: 52129 <at> debbugs.gnu.org
>> Date: Sun, 28 Nov 2021 00:40:30 +0100
>> 
>> > That's because it centers the first character of the string, not its
>> > middle character.
>> 
>> That too; so you see, it is not as simple to get it right by just prepending a
>> space with :align-to center property.
>
> We've been through this: you need to dynamically compute the pixel
> coordinate to align-to, as function of the string width.

Yes, I know. I just reflected further to say it wasn't "just" to add align-to
property but it needs more computations :).

But if you say it is one character at a time, and it is not much to do about it,
then it is not much more to be done about that.

>> >> Is there any way to make it aware of surrounding context, like entire line? Or
>> >> would that be too demanding computationally?
>> >
>> > I don't think I understand what you mean by "surrounding context", and
>> > what would it mean for it to "be aware" of it?
>> 
>> With context I meant simply the line, or at least part of the line to be
>> displayed. To be aware of it = to take it into consideration when displaying
>> line, so things like suggested would be possible.
>
> The display engine considers the line as a whole only when the entire
> screen line has been laid out, i.e. we get to a newline or the X
> coordinate is at the right edge of the window.  Before that, there's
> no information about the "line context".

So it would in principle mean, to render line twice, if such property would be
implemented, and that could be very expensive computation, so it is off the radar.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52129; Package emacs. (Mon, 29 Nov 2021 16:01:01 GMT) Full text and rfc822 format available.

Message #32 received at 52129 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Arthur Miller <arthur.miller <at> live.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 52129 <at> debbugs.gnu.org
Subject: Re: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on
 lines in buffer
Date: Mon, 29 Nov 2021 16:59:59 +0100
Arthur Miller <arthur.miller <at> live.com> writes:

> So it would in principle mean, to render line twice, if such property would be
> implemented, and that could be very expensive computation, so it is
> off the radar.

Yes, I think so, so I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 29 Nov 2021 16:01:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 52129 <at> debbugs.gnu.org and Arthur Miller <arthur.miller <at> live.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 29 Nov 2021 16:01:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 28 Dec 2021 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 118 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.