emacs-devel
[Top][All Lists]
Advanced

[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: Masatake YAMATO
Subject: Re: `posn-at-point' and `posn-at-x-y' not in manual
Date: Sat, 05 Jun 2004 01:53:18 +0900 (JST)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]