I'd like to obtain the absolute pixel position of the point (i.e. the cursor, not the mouse pointer) in the current buffer in a GUI frame, to pass it onwards to an external program.

I don't mind where the pixel position is anchored, e.g. whether to the frame or to the display, as I can easily convert between these, but I haven't found a way to obtain either position within Emacs.

What did I miss? What function can I use to get the pixel position of the point?


You can use window-absolute-pixel-position:

window-absolute-pixel-position is a compiled Lisp function in `window.el'.

(window-absolute-pixel-position &optional POSITION WINDOW)

Return display coordinates of POSITION in WINDOW. If the buffer position POSITION is visible in window WINDOW, return the display coordinates of the upper/left corner of the glyph at POSITION. The return value is a cons of the X- and Y-coordinates of that corner, relative to an origin at (0, 0) of WINDOW's display. Return nil if POSITION is not visible in WINDOW.

WINDOW must be a live window and defaults to the selected window. POSITION defaults to the value of `window-point' of WINDOW.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy