From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Patrick Newsgroups: gmane.emacs.help,gmane.emacs.sources Subject: Point to Pixel Date: Wed, 8 Jun 2005 15:15:55 -0500 Message-ID: <4f1b14d905060813156e6a9cdf@mail.gmail.com> Reply-To: Patrick NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1118261836 22606 80.91.229.2 (8 Jun 2005 20:17:16 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 8 Jun 2005 20:17:16 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 08 22:17:12 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Dg6wt-0007ws-Tc for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Jun 2005 22:14:52 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dg73g-00045Q-BP for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Jun 2005 16:21:52 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Dg738-0003xg-8W for help-gnu-emacs@gnu.org; Wed, 08 Jun 2005 16:21:18 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Dg735-0003wY-LW for help-gnu-emacs@gnu.org; Wed, 08 Jun 2005 16:21:15 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dg735-0003vF-DR for help-gnu-emacs@gnu.org; Wed, 08 Jun 2005 16:21:15 -0400 Original-Received: from [64.233.184.195] (helo=wproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Dg724-0007KR-S2 for help-gnu-emacs@gnu.org; Wed, 08 Jun 2005 16:20:12 -0400 Original-Received: by wproxy.gmail.com with SMTP id 50so74054wri for ; Wed, 08 Jun 2005 13:16:26 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=SLhvW9Wjb3bnmhr2uxFLi8kuT/PeEyDTErYsrcU4Hpvp0j3YOwWJoovxKNBu+x03tvremZpCas2AHPc8S3mTOXYTVhkkrQXoeRAi30TXUBtt4vjw6oTBBM+nS/o3dLFTo8tZv01wek+NH1HUF5r7O47cWX6K6H0ZmHwInRLdKgM= Original-Received: by 10.54.142.12 with SMTP id p12mr4744187wrd; Wed, 08 Jun 2005 13:15:55 -0700 (PDT) Original-Received: by 10.54.73.16 with HTTP; Wed, 8 Jun 2005 13:15:55 -0700 (PDT) Original-To: gnu-emacs-sources@gnu.org, help-gnu-emacs@gnu.org Content-Disposition: inline X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:27364 gmane.emacs.sources:1479 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:27364 On windows gnu emacs (~21.3) this code will return the pixel-position of the current point! (or at least, within a few pixels) Returns values in form (x . y). I wanted this feature and couldn't find it... all I found were posts in lists also asking for the feature, with people denying it could be done in elisp. Well, that is not true! ;) I believe this should work in Xemacs and on other operating systems and recent emacs versions. I am currently using it to display an "intellisense"-like tooltip. Which, on windows, gnu emacs has no tooltip, so I am executing a little python app instead which handles the tooltip for me (via wx libraries). Works very nice. ; helper func (defun get-param-safe (s) "Sometimes frame-paramater returns values of (+ -4)" (let ((left (frame-parameter nil s))) (if (listp left) (cadr left) left))) ; this is it (defun point-to-pixel () "Converts the position of the current point to pixel coordinates relative to the screen (i.e. window manager)." (let ((left (car (window-edges))) =09(top (cadr (window-edges))) =09(point-left (- (point) (point-at-bol))) =09(point-top (point))) (let ((x (+ (* (frame-char-width) left) ; x =3D =09=09(* (frame-char-width) point-left) =09=09(get-param-safe 'left))) =09 (y (+ (* (frame-char-height) ; y =3D =09=09 (+ top =09=09 (count-lines (window-start) (point)))) =09=09(get-param-safe 'top)))) (cons x y))))