From: David Reitter <david.reitter@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Nathaniel Cunningham <nathaniel.cunningham@gmail.com>,
Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: width of propertized string
Date: Fri, 6 Jun 2008 09:40:05 +0100 [thread overview]
Message-ID: <51DA7565-36FD-4700-903B-DE0E41DB34EA@gmail.com> (raw)
In-Reply-To: <jwviqwnacz6.fsf-monnier+emacs@gnu.org>
On 5 Jun 2008, at 20:47, Stefan Monnier wrote:
>> Given a propertized string, how would one find out what its (pixel)
>> dimensions are going to be?
>
> Display it, measure its size.
Tried that (see code below). This is too slow because we need to
switch to the temporary buffer.
All of my use cases concern displaying things in the echo area or the
header line. Thus, I would want to ignore any font locking and other
automatically applied properties.
My use cases are:
- adding appropriate spacing and justifying buttons in the header line
- word-wrapping text, primarily in the echo area before displaying it.
(defun visual-pixel-col-at-point ()
(or
(car-safe (pos-visible-in-window-p (point) nil 'partial))
0))
(defun string-pixel-width (text)
(let ((width))
(let ((old-buffer (current-buffer)))
(with-temp-buffer ;; should be in fundamental-mode
;; this is way too slow.
(switch-to-buffer (current-buffer) t)
(let ((buffer-undo-list nil) (start (point))
(truncate-lines t) (after-change-functions nil))
(let ((left (visual-pixel-col-at-point)))
(insert text)
(setq width (- (visual-pixel-col-at-point) left)))
(delete-region start (point)))
(switch-to-buffer old-buffer t)))
width))
next prev parent reply other threads:[~2008-06-06 8:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20ecf6c70806050537k1d343af9r7a05240b5558ea10@mail.gmail.com>
2008-06-05 12:53 ` width of propertized string David Reitter
2008-06-05 19:47 ` Stefan Monnier
2008-06-06 8:40 ` David Reitter [this message]
2008-06-06 19:16 ` Stefan Monnier
2008-06-06 19:03 ` Richard M Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51DA7565-36FD-4700-903B-DE0E41DB34EA@gmail.com \
--to=david.reitter@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=nathaniel.cunningham@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.