* `posn-at-point' and `posn-at-x-y' not in manual
@ 2004-06-04 11:56 David PONCE
2004-06-04 12:10 ` David Kastrup
2004-06-05 13:49 ` Richard Stallman
0 siblings, 2 replies; 10+ messages in thread
From: David PONCE @ 2004-06-04 11:56 UTC (permalink / raw)
Hello,
FYI, I noticed that the functions `posn-at-point' and `posn-at-x-y'
are not documented in the Emacs Lisp Reference Manual.
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?
Thanks!
David
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
2004-06-04 11:56 David PONCE
@ 2004-06-04 12:10 ` David Kastrup
2004-06-05 13:49 ` Richard Stallman
1 sibling, 0 replies; 10+ messages in thread
From: David Kastrup @ 2004-06-04 12:10 UTC (permalink / raw)
Cc: emacs-devel
David PONCE <david.ponce@wanadoo.fr> writes:
> FYI, I noticed that the functions `posn-at-point' and `posn-at-x-y'
> are not documented in the Emacs Lisp Reference Manual.
>
> 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 ?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
@ 2004-06-04 12:15 David PONCE
2004-06-04 12:23 ` Masatake YAMATO
2004-06-07 10:47 ` Kim F. Storm
0 siblings, 2 replies; 10+ messages in thread
From: David PONCE @ 2004-06-04 12:15 UTC (permalink / raw)
Cc: emacs-devel
>>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)))
))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
2004-06-04 12:15 David PONCE
@ 2004-06-04 12:23 ` Masatake YAMATO
2004-06-07 10:47 ` Kim F. Storm
1 sibling, 0 replies; 10+ messages in thread
From: Masatake YAMATO @ 2004-06-04 12:23 UTC (permalink / raw)
Cc: dak, emacs-devel
> Of course! Thanks!
> As an example, here is an implementation of a `set-mouse-at-point'
> function that seems to work very well :-)
How about tooltip?
Doctor, please show a sample. People wish your epiphany:-)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
@ 2004-06-04 14:37 David PONCE
2004-06-04 16:53 ` Masatake YAMATO
0 siblings, 1 reply; 10+ messages in thread
From: David PONCE @ 2004-06-04 14:37 UTC (permalink / raw)
Cc: emacs-devel
Masatake YAMATO wrote:
>>Of course! Thanks!
>>As an example, here is an implementation of a `set-mouse-at-point'
>>function that seems to work very well :-)
>
>
> How about tooltip?
> Doctor, please show a sample. People wish your epiphany:-)
>
Here it is:
(defun tooltip-show-at-point (text)
"Display a tooltip with TEXT near cursor."
(let* ((oP (mouse-pixel-position))
(tooltip-x-offset 0)
(tooltip-y-offset (- (frame-char-height))))
(set-mouse-at-point)
(tooltip-show text)
(set-mouse-pixel-position (nth 0 oP) (nth 1 oP) (nthcdr 2 oP))
))
David
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
2004-06-04 14:37 `posn-at-point' and `posn-at-x-y' not in manual David PONCE
@ 2004-06-04 16:53 ` Masatake YAMATO
2004-06-04 17:11 ` Masatake YAMATO
0 siblings, 1 reply; 10+ messages in thread
From: Masatake YAMATO @ 2004-06-04 16:53 UTC (permalink / raw)
Cc: emacs-devel
> >>Of course! Thanks!
> >>As an example, here is an implementation of a `set-mouse-at-point'
> >>function that seems to work very well :-)
> >
> >
> > How about tooltip?
> > Doctor, please show a sample. People wish your epiphany:-)
> >
>
> Here it is:
Thank you, sir.
However, I'd like not to move the mouse cursor if possible.
I've implemented `point-pixel-position' based on your code.
Maybe this code is applicable to popup menu.
(defun point-pixel-position ()
"Same as `mouse-pixel-position' but for 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)))
(cons
frm
(cons (+ (car x-y) (car edg) (frame-char-width frm))
(+ (cdr x-y) (cadr edg) (/ (frame-char-height frm) 2))))))
(defun tooltip-show-at-point (text)
"Display a tooltip with TEXT near cursor without moving mouse cursor."
(let* ((oP (mouse-pixel-position))
(nP (point-pixel-position))
(tooltip-x-offset tooltip-x-offset)
(tooltip-y-offset tooltip-y-offset))
;; The current mouse position is out of range.
;; Do dirty thing here.
(if (or (null (cadr oP))
(null (cddr oP)))
(set-mouse-pixel-position (nth 0 nP)
(nth 1 nP) (nthcdr 2 nP))
(setq tooltip-x-offset (+ (if tooltip-x-offset tooltip-x-offset 5)
(- (cadr nP) (cadr oP)))
tooltip-y-offset (+ (if tooltip-y-offset tooltip-y-offset -10)
(- (cddr nP)(cddr oP)))))
(tooltip-show text)
))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
2004-06-04 16:53 ` Masatake YAMATO
@ 2004-06-04 17:11 ` Masatake YAMATO
0 siblings, 0 replies; 10+ messages in thread
From: Masatake YAMATO @ 2004-06-04 17:11 UTC (permalink / raw)
Cc: emacs-devel
> Thank you, sir.
> However, I'd like not to move the mouse cursor if possible.
> I've implemented `point-pixel-position' based on your code.
> Maybe this code is applicable to popup menu.
Here is the example:
(let* ((pos (posn-at-point))
(x-y (posn-x-y pos))
(wnd (posn-window pos)))
(popup-menu (list nil "eval-after-load" "eval-and-compile" "eval-buffer" "eval-current-buffer" "eval-defun")
(list (list (car x-y)
(cdr x-y))
wnd)))
May be useful to show completion candidate.
Masatake YAMATO
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
2004-06-04 11:56 David PONCE
2004-06-04 12:10 ` David Kastrup
@ 2004-06-05 13:49 ` Richard Stallman
1 sibling, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2004-06-05 13:49 UTC (permalink / raw)
Cc: emacs-devel
FYI, I noticed that the functions `posn-at-point' and `posn-at-x-y'
are not documented in the Emacs Lisp Reference Manual.
Would someone like to write text for the manual about them?
Explaining explicitly that using window-inside-pixel-edges
is the way to turn this into frame-relative would be useful.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
@ 2004-06-07 10:14 David PONCE
0 siblings, 0 replies; 10+ messages in thread
From: David PONCE @ 2004-06-07 10:14 UTC (permalink / raw)
Cc: emacs-devel
Richard Stallman wrote:
> FYI, I noticed that the functions `posn-at-point' and `posn-at-x-y'
> are not documented in the Emacs Lisp Reference Manual.
>
> Would someone like to write text for the manual about them?
>
> Explaining explicitly that using window-inside-pixel-edges
> is the way to turn this into frame-relative would be useful.
Hi,
Here is a text I wrote that could serve as a starting point. I am not
sure in which file to add it. Feel free to proof read it, and use a
better English than mine ;-)
Sincerely,
David
------------------------- [ cut here ] ------------------------------
These functions return position information similar to that returned
by @code{event-start}, from a visible position on the display.
@defun posn-at-point &optional pos window
Return position information for buffer @var{pos} in @var{window}.
@var{pos} defaults to point in @var{window}; @var{window} defaults to
the selected window.
Return @code{nil} if position is not visible in window. Otherwise,
the return value is similar to that returned by @code{event-start} for
a mouse click at the upper left corner of the glyph corresponding to
the given buffer position:
@example
(@var{window} @var{area-or-pos} (@var{x} . @var{y}) @var{timestamp}
@var{object} @var{text-pos} (@var{col} . @var{row})
@var{image} (@var{dx} . @var{dy}) (@var{width} . @var{height}))
@end example
The @code{posn-} functions access elements of such lists.
@end defun
@defun posn-at-x-y x y &optional frame-or-window
Return position information for pixel coordinates @var{x} and @var{y}.
By default, @var{x} and @var{y} are relative to text area of the
selected window. Optional third arg @var{frame_or_window}
non-@code{nil} specifies frame or window.
The return value is similar to a mouse click position:
@example
(@var{window} @var{area-or-pos} (@var{x} . @var{y}) @var{timestamp}
@var{object} @var{text-pos} (@var{col} . @var{row})
@var{image} (@var{dx} . @var{dy}) (@var{width} . @var{height}))
@end example
The @code{posn-} functions access elements of such lists.
@end defun
The following sample function illustrates how the function
@code{window-inside-pixel-edges} can be used to convert
window-relative coordinates, like those returned by the
@code{posn-at-} functions, into frame-relative coordinates:
@example
(defun frame-relative-coordinates (position)
"Return frame-relative coordinates from POSITION."
(let* ((x-y (posn-x-y position))
(window (posn-window position))
(edges (window-inside-pixel-edges window)))
(cons (+ (car x-y) (car edges))
(+ (cdr x-y) (cadr edges)))))
@end example
------------------------- [ cut here ] ------------------------------
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: `posn-at-point' and `posn-at-x-y' not in manual
2004-06-04 12:15 David PONCE
2004-06-04 12:23 ` Masatake YAMATO
@ 2004-06-07 10:47 ` Kim F. Storm
1 sibling, 0 replies; 10+ messages in thread
From: Kim F. Storm @ 2004-06-07 10:47 UTC (permalink / raw)
Cc: dak, emacs-devel
David PONCE <david.ponce@wanadoo.fr> 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 <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-06-07 10:47 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-04 14:37 `posn-at-point' and `posn-at-x-y' not in manual David PONCE
2004-06-04 16:53 ` Masatake YAMATO
2004-06-04 17:11 ` Masatake YAMATO
-- strict thread matches above, loose matches on Subject: below --
2004-06-07 10:14 David PONCE
2004-06-04 12:15 David PONCE
2004-06-04 12:23 ` Masatake YAMATO
2004-06-07 10:47 ` Kim F. Storm
2004-06-04 11:56 David PONCE
2004-06-04 12:10 ` David Kastrup
2004-06-05 13:49 ` Richard Stallman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).