unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* `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 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 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-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

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 11:56 `posn-at-point' and `posn-at-x-y' not in manual David PONCE
2004-06-04 12:10 ` David Kastrup
2004-06-05 13:49 ` Richard Stallman
  -- strict thread matches above, loose matches on Subject: below --
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 14:37 David PONCE
2004-06-04 16:53 ` Masatake YAMATO
2004-06-04 17:11   ` Masatake YAMATO
2004-06-07 10:14 David PONCE

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).