+DEFUN ("current-pixel-column", Fcurrent_pixel_column, 0, 2, 0, /*
+Return the horizontal pixel position of POS in window.
+Beginning of line is column 0. This is calculated using the redisplay
+display tables. If WINDOW is nil, the current window is assumed.
+If POS is nil, point is assumed. Note that POS must be visible for
+a non-nil result to be returned.
+*/
+ (window, pos))
+{
+ struct window* w = decode_window (window);
+ display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
+
+ struct display_line *dl = 0;
+ struct display_block *db = 0;
+ struct rune* rb = 0;
+ int y = w->last_point_y[CURRENT_DISP];
+ int x = w->last_point_x[CURRENT_DISP];
+
+ if (MINI_WINDOW_P (w))
+ return Qnil;
+
+ if (y<0 || x<0 || y >= Dynarr_length (dla) || !NILP (pos))
+ {
+ int first_line, i;
+ Bufpos point;
+
+ if (NILP (pos))
+ pos = Fwindow_point (window);
+
+ CHECK_INT (pos);
+ point = XINT (pos);
+
+ if (Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
+ first_line = 1;
+ else
+ first_line = 0;
+
+ for (i = first_line; i < Dynarr_length (dla); i++)
+ {
+ dl = Dynarr_atp (dla, i);
+ /* find the vertical location first */
+ if (point >= dl->bufpos && point <= dl->end_bufpos)
+ {
+ db = get_display_block_from_line (dl, TEXT);
+ for (i = 0; i < Dynarr_length (db->runes); i++)
+ {
+ rb = Dynarr_atp (db->runes, i);
+ if (point <= rb->bufpos)
+ goto found_bufpos;
+ }
+ return Qnil;
+ }
+ }
+ return Qnil;
+ found_bufpos:
+ ;
+ }
+ else
+ {
+ /* optimized case */
+ dl = Dynarr_atp (dla, y);
+ db = get_display_block_from_line (dl, TEXT);
+
+ if (x >= Dynarr_length (db->runes))
+ return Qnil;
+
+ rb = Dynarr_atp (db->runes, x);
+ }
+
+ return make_int (rb->xpos - WINDOW_LEFT (w));
+}
+