emacs-devel
[Top][All Lists]
Advanced

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

Re: address@hidden: `c-indent-command' in a rare case]


From: David Kastrup
Subject: Re: address@hidden: `c-indent-command' in a rare case]
Date: Fri, 08 Oct 2004 20:31:38 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

Martin Stjernholm <address@hidden> writes:

> Richard Stallman <address@hidden> wrote:
>
>> It seems logical to me.  The decrease in the number of lines remaining
>> to be moved is zero.
>
> Yes, I also think the number of lines remaining to be moved hasn't
> decreased. Therefore a return value of 1 is in order if forward-line
> was called with 1 since that number hasn't decreased.

simple.el:

(defun count-lines (start end)
  "Return number of lines between START and END.
This is usually the number of newlines between them,
but can be one more if START is not equal to END
and the greater of them is not at the start of a line."
  (save-excursion
    (save-restriction
      (narrow-to-region start end)
      (goto-char (point-min))
      (if (eq selective-display t)
          (save-match-data
            (let ((done 0))
              (while (re-search-forward "[\n\C-m]" nil t 40)
                (setq done (+ 40 done)))
              (while (re-search-forward "[\n\C-m]" nil t 1)
                (setq done (+ 1 done)))
              (goto-char (point-max))
              (if (and (/= start end)
                       (not (bolp)))
                  (1+ done)
                done)))
        (- (buffer-size) (forward-line (buffer-size)))))))

count-lines is used a few times, and the idioms in here may have
spread to other code, too.  In particular, we have

(defun line-number-at-pos (&optional pos)
  "Return (narrowed) buffer line number at position POS.
If POS is nil, use current buffer location."
  (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))))))

I am not sure about the implications of those, but I wanted to point
out that the return value of forward-line is used _very_ often in the
current operation of Emacs, so one should be careful to let it do the
right thing, whatever that may happen to be.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




reply via email to

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