all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Point to Pixel
@ 2005-06-08 20:15 Patrick
  0 siblings, 0 replies; 4+ messages in thread
From: Patrick @ 2005-06-08 20:15 UTC (permalink / raw)


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)))
	(top (cadr (window-edges)))
	(point-left (- (point) (point-at-bol)))
	(point-top  (point)))
    (let ((x (+ (* (frame-char-width) left)  ; x =
		(* (frame-char-width) point-left)
		(get-param-safe 'left)))
	  (y (+ (* (frame-char-height)       ; y =
		   (+ top
		      (count-lines (window-start) (point))))
		(get-param-safe 'top))))
      (cons x y))))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Point to Pixel
       [not found] <mailman.3948.1118262081.25862.help-gnu-emacs@gnu.org>
@ 2005-06-08 21:50 ` Stefan Monnier
  2005-06-13 16:15   ` Patrick
       [not found]   ` <mailman.4555.1118680889.25862.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Monnier @ 2005-06-08 21:50 UTC (permalink / raw)


> 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! ;)

The problem with your code is that it doesn't correctly handle hidden text,
display properties (stretchable spaces, images, ...), proportional fonts,
faces that change the font size, line wrapping, ...

Emacs-CVS has a function that works correctly even in the face of the
above thingies.  It's called posn-at-point.


        Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Point to Pixel
  2005-06-08 21:50 ` Point to Pixel Stefan Monnier
@ 2005-06-13 16:15   ` Patrick
       [not found]   ` <mailman.4555.1118680889.25862.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Patrick @ 2005-06-13 16:15 UTC (permalink / raw)


Yes, it's just a quick hack.

Anyone know where this posn-at-point is in the CVS tree? 

On 6/8/05, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> > 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! ;)
> 
> The problem with your code is that it doesn't correctly handle hidden text,
> display properties (stretchable spaces, images, ...), proportional fonts,
> faces that change the font size, line wrapping, ...
> 
> Emacs-CVS has a function that works correctly even in the face of the
> above thingies.  It's called posn-at-point.
> 
> 
>         Stefan
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Point to Pixel
       [not found]   ` <mailman.4555.1118680889.25862.help-gnu-emacs@gnu.org>
@ 2005-06-15  4:32     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2005-06-15  4:32 UTC (permalink / raw)


> Anyone know where this posn-at-point is in the CVS tree? 

Compile Emacs-CVS, then do C-h f posn-at-point, then middle-click on
the link (it's in the C source code).


        Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-06-15  4:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3948.1118262081.25862.help-gnu-emacs@gnu.org>
2005-06-08 21:50 ` Point to Pixel Stefan Monnier
2005-06-13 16:15   ` Patrick
     [not found]   ` <mailman.4555.1118680889.25862.help-gnu-emacs@gnu.org>
2005-06-15  4:32     ` Stefan Monnier
2005-06-08 20:15 Patrick

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.