From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.cc-mode.general,gmane.emacs.devel Subject: Re: [pogonyshev@gmx.net: `c-indent-command' in a rare case] Date: Fri, 08 Oct 2004 20:31:38 +0200 Sender: cc-mode-help-admin@lists.sourceforge.net Message-ID: References: <5bvfdmzscy.fsf@lister.roxen.com> <5b3c0pksfb.fsf@lister.roxen.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1097260692 25585 80.91.229.6 (8 Oct 2004 18:38:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 8 Oct 2004 18:38:12 +0000 (UTC) Cc: rms@gnu.org, pogonyshev@gmx.net, emacs-devel@gnu.org Original-X-From: cc-mode-help-admin@lists.sourceforge.net Fri Oct 08 20:38:03 2004 Return-path: Original-Received: from lists.sourceforge.net ([66.35.250.206] helo=sc8-sf-list1.sourceforge.net) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CFzcw-0000yO-00 for ; Fri, 08 Oct 2004 20:38:03 +0200 Original-Received: from localhost ([127.0.0.1] helo=projects.sourceforge.net) by sc8-sf-list1.sourceforge.net with esmtp (Exim 4.30) id 1CFzcu-0006EI-3c; Fri, 08 Oct 2004 11:38:00 -0700 Original-Received: from sc8-sf-mx2-b.sourceforge.net ([10.3.1.12] helo=sc8-sf-mx2.sourceforge.net) by sc8-sf-list1.sourceforge.net with esmtp (Exim 4.30) id 1CFzXC-0004dr-3y for cc-mode-help@lists.sourceforge.net; Fri, 08 Oct 2004 11:32:06 -0700 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by sc8-sf-mx2.sourceforge.net with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.41) id 1CFzX9-0002uC-Sv for cc-mode-help@lists.sourceforge.net; Fri, 08 Oct 2004 11:32:06 -0700 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1CFzWm-0003Xj-5J; Fri, 08 Oct 2004 14:31:41 -0400 Original-To: bug-cc-mode@gnu.org In-Reply-To: <5b3c0pksfb.fsf@lister.roxen.com> (Martin Stjernholm's message of "Fri, 08 Oct 2004 19:53:28 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) Errors-To: cc-mode-help-admin@lists.sourceforge.net X-BeenThere: cc-mode-help@lists.sourceforge.net X-Mailman-Version: 2.0.9-sf.net Precedence: bulk List-Unsubscribe: , List-Id: Bug reports, feature requests, and general talk about CC Mode. List-Post: List-Help: List-Subscribe: , List-Archive: X-Original-Date: Fri, 08 Oct 2004 20:31:38 +0200 Xref: main.gmane.org gmane.emacs.cc-mode.general:1846 gmane.emacs.devel:28102 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:28102 Martin Stjernholm writes: > Richard Stallman 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