all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: dak@gnu.org, emacs-devel@gnu.org
Subject: Re: `posn-at-point' and `posn-at-x-y' not in manual
Date: 07 Jun 2004 12:47:57 +0200	[thread overview]
Message-ID: <m3u0xn4pb6.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <16878127.1086351352498.JavaMail.www@wwinf1002>

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

  parent reply	other threads:[~2004-06-07 10:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-04 12:15 `posn-at-point' and `posn-at-x-y' not in manual David PONCE
2004-06-04 12:23 ` Masatake YAMATO
2004-06-07 10:47 ` Kim F. Storm [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-06-07 10:14 David PONCE
2004-06-04 14:37 David PONCE
2004-06-04 16:53 ` Masatake YAMATO
2004-06-04 17:11   ` Masatake YAMATO
2004-06-04 11:56 David PONCE
2004-06-04 12:10 ` David Kastrup
2004-06-05 13:49 ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3u0xn4pb6.fsf@kfs-l.imdomain.dk \
    --to=storm@cua.dk \
    --cc=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.