emacs-devel
[Top][All Lists]
Advanced

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

Re: [patch] add interactive browse of revisions from vc *Annotate* buffe


From: Kim F. Storm
Subject: Re: [patch] add interactive browse of revisions from vc *Annotate* buffers
Date: 21 Jan 2004 12:26:27 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Richard Stallman <address@hidden> writes:

>     (defun line-at-pos (&optional pos)
>       "Return buffer line number and narrowed line number at position POS.
>     If POS is nil, use current buffer location.
>     Return value is line-number or a cons (line-number narrowed-line-number)."
> 
> I don't like that complex definition of the return value.
> It should be one or the other.

What about this version?

(defun line-at-pos (&optional pos)
  "Return buffer line number and narrowed line number at position POS.
If POS is nil, use current buffer location.
Return value is a cons (line-number . narrowed-line-number)."
  (let ((opoint (or pos (point))) start)
    (save-excursion
      (save-restriction
        (goto-char (point-min))
        (widen)
        (forward-line 0)
        (setq start (point))
        (goto-char opoint)
        (forward-line 0)
        (let ((l1 (count-lines (point-min) start))
              (l2 (count-lines start (point))))
          (cons (+ l1 l2 1) (1+ l2)))))))

(defun what-line ()
  "Print the current buffer line number and narrowed line number of point."
  (interactive)
  (let ((l (line-at-pos (point))))
    (if (/= (car l) (cdr l))
        (message "line %d (narrowed line %d)" (car l) (cdr l))
      (message "Line %d" (car l)))))


It actually works faster by not counting the lines between start and
point twice!


-- 
Kim F. Storm <address@hidden> http://www.cua.dk





reply via email to

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