[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: window-line and window-column

From: rgb
Subject: Re: window-line and window-column
Date: 10 Oct 2005 20:34:17 -0700
User-agent: G2/0.2

Hovav Shacham wrote:
> "rgb" <address@hidden> writes:
> > How can I tell where, within the current window, I am.
> Does any of the functions in windmove.el help?  In particular,
> `windmove-coordinates-of-position'?
Apparently that's not part of CVS Emacs.
I did find a copy elsewhere and yes it does give me exactly
what I was looking for.  Thanks.
Saddly, several hours after finishing my own version :(
Oh well.  I've got a better understanding of compute-motion.
I think I'll be suggesting some wording changes to it's
doc string ... as soon as I think of something that might
have helped me <:'

(defun window-position (&optional visible)
  "Returns the cons (screen-line . screen-column) of point.
When VISIBLE is non-nil a screen-column of 0 is returned when a
value would otherwise be returned such as after (scroll-left).
nil is returned if current-buffer is not in the current window."
  (if (eq (current-buffer) (window-buffer))
    (if (or truncate-lines (/= 0 (window-hscroll)))
        ;; Lines never wrap when horizontal scrolling is in effect.
        (let ((window-column (- (current-column)(window-hscroll)))
              (window-line (count-lines (window-start)(point))))
           ((= 0 (current-column))
            (cons window-line (if visible 0 window-column)))
           ((<= (current-column) (window-hscroll))
            (cons (1- window-line) (if visible 0 window-column)))
           (t (cons (1- window-line) window-column))))
      ;; When lines are not being truncated we deal with wrapping
      (let ((window-column (% (current-column)(window-width)))
            (window-line (count-screen-lines (window-start)(point))))
        (if (= 0 window-column)
            (cons window-line window-column)
          (cons (1- window-line) window-column))))))

reply via email to

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