unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / 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

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).