From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Reitter Newsgroups: gmane.emacs.devel Subject: Re: width of propertized string Date: Fri, 6 Jun 2008 09:40:05 +0100 Message-ID: <51DA7565-36FD-4700-903B-DE0E41DB34EA@gmail.com> References: <20ecf6c70806050537k1d343af9r7a05240b5558ea10@mail.gmail.com> <8122960A-4AF5-439B-91CB-F2E51D4E88C5@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v924) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1212741660 10898 80.91.229.12 (6 Jun 2008 08:41:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Jun 2008 08:41:00 +0000 (UTC) Cc: Nathaniel Cunningham , Emacs-Devel devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 06 10:41:42 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K4XVr-0007Ek-Qb for ged-emacs-devel@m.gmane.org; Fri, 06 Jun 2008 10:41:32 +0200 Original-Received: from localhost ([127.0.0.1]:52089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K4XV5-0006n7-0C for ged-emacs-devel@m.gmane.org; Fri, 06 Jun 2008 04:40:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K4XUZ-0006d0-7B for emacs-devel@gnu.org; Fri, 06 Jun 2008 04:40:11 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K4XUX-0006bJ-CV for emacs-devel@gnu.org; Fri, 06 Jun 2008 04:40:10 -0400 Original-Received: from [199.232.76.173] (port=51133 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K4XUW-0006az-R6 for emacs-devel@gnu.org; Fri, 06 Jun 2008 04:40:09 -0400 Original-Received: from ug-out-1314.google.com ([66.249.92.174]:29348) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K4XUW-0006Rs-A0 for emacs-devel@gnu.org; Fri, 06 Jun 2008 04:40:08 -0400 Original-Received: by ug-out-1314.google.com with SMTP id l31so671344ugc.48 for ; Fri, 06 Jun 2008 01:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:cc:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=OyDg58bTicDdOGTlktly1BHWhy0ZyEc2tter3PLDn5E=; b=o4lVkvy7Gx3QgNlWydMqtfmthkmLiAKH7w2ABpi1aiwuqqnXUlqW6DqybeNYTPMysd a1xs+XDGFvt4lHR3zMxQuVlYqETAUeicM7u1w5oehfzWAZRJ0tBnDBpOcZ7F3l5GbJk9 ZPxJQKmsxGA+DQiRbgw0dDdITLqbZjsOSjdwE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=w2c0iKgLeYN8KXyTmPTw9Cs9PJwO0bMmNY2SBFY7j96M/hxFM5EtWRt9DT9a8ooF/Q yFaf+8eQ86fY52Di7RU/Dvqc88v5F3Sy46giahvOjmPikcf/doEmpFFXJtFM4Copszmj Fr16FeLnCmPVzAlj6u8rSiQbh+rdemsL828EY= Original-Received: by 10.67.87.18 with SMTP id p18mr996638ugl.43.1212741607412; Fri, 06 Jun 2008 01:40:07 -0700 (PDT) Original-Received: from scarlett.lan ( [93.96.127.15]) by mx.google.com with ESMTPS id b39sm17341968ugf.39.2008.06.06.01.40.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 06 Jun 2008 01:40:06 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.924) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:98505 Archived-At: 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))