emacs-devel
[Top][All Lists]
Advanced

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

line-number-at-pos


From: Sam Steingold
Subject: line-number-at-pos
Date: Wed, 03 Mar 2010 14:06:45 -0500
User-agent: Thunderbird 2.0.0.22 (X11/20090625)

in simple.el:

(defun line-number-at-pos (&optional pos)
  "Return (narrowed) buffer line number at position POS.
If POS is nil, use current buffer location.
Counting starts at (point-min), so the value refers
to the contents of the accessible portion of the buffer."
  (let ((opoint (or pos (point))) start)
    (save-excursion
      (goto-char (point-min))
      (setq start (point))
      (goto-char opoint)
      (forward-line 0)
      (1+ (count-lines start (point))))))

why not just

(count-lines (point-min) (or pos (point)))





reply via email to

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