[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: `posn-at-point' and `posn-at-x-y' not in manual
From: |
Kim F. Storm |
Subject: |
Re: `posn-at-point' and `posn-at-x-y' not in manual |
Date: |
07 Jun 2004 12:47:57 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
David PONCE <address@hidden> writes:
> >>About the `posn-at-point' function, any idea on how to convert the
> >>pixel coordinates it returns, which are relative to a window, into
> >>coordinates relative to the selected frame, to display a tool tip at
> >>point for example?
> >
> >
> > window-inside-pixel-edges or window-pixel-edges ?
>
> Of course! Thanks!
> As an example, here is an implementation of a `set-mouse-at-point'
> function that seems to work very well :-)
>
> (defun set-mouse-at-point ()
> "Move the mouse pointer to pixel position of point."
> (let* ((pos (posn-at-point))
> (x-y (posn-x-y pos))
> (wnd (posn-window pos))
> (frm (window-frame wnd))
> (edg (window-pixel-edges wnd)))
> (set-mouse-pixel-position
> frm
> (+ (car x-y) (car edg) (frame-char-width frm))
> (+ (cdr x-y) (cadr edg) (/ (frame-char-height frm) 2)))
> ))
Here are some other nice functions to play with -- maybe something
for line-move to use?
(defun posn-above-point (&optional pos window)
"Return position above POS in WINDOW."
(let ((posn (posn-at-point pos window)))
(if posn
(let ((x-y (posn-x-y posn)))
(posn-at-x-y (car x-y) (1- (cdr x-y)))))))
(defun posn-below-point (&optional pos window)
"Return position below POS in WINDOW."
(let ((posn (posn-at-point pos window)))
(if posn
(let ((x-y (posn-x-y posn))
(w-h (posn-object-width-height posn)))
(posn-at-x-y (car x-y) (+ (cdr x-y) (cdr w-h)))))))
Of course, the caller should check whether the returned posn is
in the same window as point, or that it doesn't hit the
modeline ...
--
Kim F. Storm <address@hidden> http://www.cua.dk