开发者

elisp: posn-at-point returns nil after goto-char. How to update the display before posn-at-point?

In e开发者_如何学编程macs lisp, posn-at-point is documented as:

posn-at-point is a built-in function in C source code.

(posn-at-point &optional POS WINDOW)

.

Return position information for buffer POS in WINDOW.

POS defaults to point in WINDOW; WINDOW defaults to the selected window.

.

Return nil if position is not visible in window. Otherwise,

the return value is similar to that returned by event-start for

a mouse click at the upper left corner of the glyph corresponding

to the given buffer position:

(WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)

IMAGE (DX . DY) (WIDTH . HEIGHT))

The posn- functions access elements of such lists.

ok, now I've got a function that looks something like this:

(defun my-move-and-popup-menu ()
  "move the point, then pop up a menu."
    (goto-char xxxx)
    (setq p (posn-at-point))
    (my-popup-menu p ...)
)

Basically, move the point, then retrieve the screen position at that point, and then popup a menu at that screen position.

But I am finding that posn-at-point returns non-nil, only if the xxxx character position (the after position) is visible in the window, before the call to goto-char. It seems that the position is not actually updated until exit from the function. If goto-char goes a long way, more than one screenful, then the retrieved position is always nil, and my code doesn't know where to popup the menu.

The reason I suggest that the position is not actually updated until exit from the function - when the menu successfully pops up, the cursor is clearly visible in its previous location while the popup menu is being displayed. When I dismiss the menu, the cursor moves to where I expected it to move, after the goto-char call.

How can I get the position to be really updated, between goto-char and posn-at-point, so that posn-at-point will not return nil?

In a Windows Forms application I would call Form.Update() or something similar to update the display in the middle of an event handler. What's the emacs version of that?


Try:

 (goto-char xxx)
 (redisplay)

to enforce displaying of the new position.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜