all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Cc: rms@gnu.org,  pogonyshev@gmx.net,  emacs-devel@gnu.org
Subject: Re: [pogonyshev@gmx.net: `c-indent-command' in a rare case]
Date: Fri, 08 Oct 2004 20:31:38 +0200	[thread overview]
Message-ID: <x5is9lf4dx.fsf@lola.goethe.zz> (raw)
In-Reply-To: <5b3c0pksfb.fsf@lister.roxen.com> (Martin Stjernholm's message of "Fri, 08 Oct 2004 19:53:28 +0200")

Martin Stjernholm <mast@lysator.liu.se> writes:

> Richard Stallman <rms@gnu.org> 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


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl


      reply	other threads:[~2004-10-08 18:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1CDv10-0004rX-Fw@fencepost.gnu.org>
2004-10-07 11:21 ` [pogonyshev@gmx.net: `c-indent-command' in a rare case] Martin Stjernholm
2004-10-08 16:05   ` Richard Stallman
2004-10-08 17:29     ` Stefan
2004-10-10 15:16       ` Richard Stallman
2004-10-10 22:38         ` Kim F. Storm
2004-10-08 17:53     ` Martin Stjernholm
2004-10-08 18:31       ` David Kastrup [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x5is9lf4dx.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=pogonyshev@gmx.net \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.