Function: posn-col-row

posn-col-row is a byte-compiled function defined in subr.el.gz.

Signature

(posn-col-row POSITION)

Documentation

Return the nominal column and row in POSITION, measured in characters.

The column and row values are approximations calculated from the x and y coordinates in POSITION and the frame's default character width and default line height, including spacing. For a scroll-bar event, the result column is 0, and the row corresponds to the vertical position of the click in the scroll bar. POSITION should be a list of the form returned by the event-start and event-end functions.

Probably introduced at or before Emacs version 23.3.

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun posn-col-row (position)
  "Return the nominal column and row in POSITION, measured in characters.
The column and row values are approximations calculated from the x
and y coordinates in POSITION and the frame's default character width
and default line height, including spacing.
For a scroll-bar event, the result column is 0, and the row
corresponds to the vertical position of the click in the scroll bar.
POSITION should be a list of the form returned by the `event-start'
and `event-end' functions."
  (let* ((pair            (posn-x-y position))
         (frame-or-window (posn-window position))
         (frame           (if (framep frame-or-window)
                              frame-or-window
                            (window-frame frame-or-window)))
         (window          (when (windowp frame-or-window) frame-or-window))
         (area            (posn-area position)))
    (cond
     ((null frame-or-window)
      '(0 . 0))
     ((eq area 'vertical-scroll-bar)
      (cons 0 (scroll-bar-scale pair (1- (window-height window)))))
     ((eq area 'horizontal-scroll-bar)
      (cons (scroll-bar-scale pair (window-width window)) 0))
     (t
      ;; FIXME: This should take line-spacing properties on
      ;; newlines into account.
      (let* ((spacing (when (display-graphic-p frame)
                        (or (with-current-buffer
                                (window-buffer (frame-selected-window frame))
                              line-spacing)
                            (frame-parameter frame 'line-spacing)))))
	(cond ((floatp spacing)
	       (setq spacing (truncate (* spacing
					  (frame-char-height frame)))))
	      ((null spacing)
	       (setq spacing 0)))
	(cons (/ (car pair) (frame-char-width frame))
	      (/ (cdr pair) (+ (frame-char-height frame) spacing))))))))