From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Masatake YAMATO Newsgroups: gmane.emacs.devel Subject: Re: Some problems in `add-log-current-defun' Date: Wed, 27 Dec 2006 20:55:34 +0900 (JST) Message-ID: <20061227.205534.82897855.jet@gyve.org> References: NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1167220584 31424 80.91.229.10 (27 Dec 2006 11:56:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 27 Dec 2006 11:56:24 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 27 12:56:24 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by dough.gmane.org with esmtp (Exim 4.50) id 1GzXOI-0007ay-Di for ged-emacs-devel@m.gmane.org; Wed, 27 Dec 2006 12:56:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GzXOH-0002RE-Rz for ged-emacs-devel@m.gmane.org; Wed, 27 Dec 2006 06:56:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GzXO6-0002R7-2h for emacs-devel@gnu.org; Wed, 27 Dec 2006 06:56:02 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GzXO1-0002PL-HO for emacs-devel@gnu.org; Wed, 27 Dec 2006 06:56:00 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GzXO1-0002Oz-Cn for emacs-devel@gnu.org; Wed, 27 Dec 2006 06:55:57 -0500 Original-Received: from [66.187.233.31] (helo=mx1.redhat.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GzXO0-0005K3-VB for emacs-devel@gnu.org; Wed, 27 Dec 2006 06:55:57 -0500 Original-Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id kBRBtu5o023626; Wed, 27 Dec 2006 06:55:56 -0500 Original-Received: from pobox.tokyo.redhat.com (pobox.tokyo.redhat.com [172.16.33.225]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id kBRBtt5g031392; Wed, 27 Dec 2006 06:55:55 -0500 Original-Received: from localhost (dhcp92.tokyo.redhat.com [172.16.33.92]) by pobox.tokyo.redhat.com (8.12.8/8.12.8) with ESMTP id kBRBtnvU016191; Wed, 27 Dec 2006 20:55:53 +0900 Original-To: herberteuler@hotmail.com In-Reply-To: X-Mailer: Mew version 4.2.53 on Emacs 22.0.51 / Mule 5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:64332 Archived-At: About II. I'd like to hear a comment from David. > I. The end of a function > > The point is moved to the start position of a function or an empty > line (lines consist of only white space characters) with the following > code. > > ;; See if we are in the beginning part of a function, > ;; before the open brace. If so, advance forward. > (while (not (looking-at "{\\|\\(\\s *$\\)")) > (forward-line 1)) > > But this is not reliable. If someone forgets to put a newline after a > function, `add-log-current-defun' will report wrong name. Please > consider the following example: > > int > f1 () > { > /* If point is here `add-log-current-defun' gets wrong result. */ > } > int > f2 () > { > /* ... */ > } > > When the point is inside the body of `f1', invoking > `add-log-current-defun' will get `f2', rather than `f1'. Reproduced. I think this is case that `add-log-current-defun' cannot handle reasonably formatted C++ code. > III. Different styles > > The function skips typedefs and arglist with the following forms. > > ;; Skip back over typedefs and arglist. > ;; Stop at the function definition itself > ;; or at the line that follows end of function doc string. > (forward-line -1) > (while (and (not (bobp)) > (looking-at "[ \t\n]") > (not (looking-back "[*]/)\n" (- (point) 4)))) > (forward-line -1)) > > This is not general: it cannot process programs in some style. In > section 7.7 of the 3rd edition of The C++ Programming Language by > Bjarne Stroustrup, there is a shell sort implementation: > > void ssort(void * base, size_t n, size_t sz, CFT cmp) > /* > Sort the "n" elements of vector "base" into increasing order > using the comparison function pointed to by "cmp". > The elements are of size "sz". > > Shell sort (Knuth, Vol3, pg84) > */ > { > /* ... */ > } > > The current implementation cannot handle programs in this style > correctly. The book is very famous. However, in my experience this code is not reasonably formatted. > And what I tried to fix is not general too. My fix is > > (while (not (looking-back "\\(^\\|[ \t]\\)")) > (forward-sexp -1)) > > This is not general too: C++ permits the nested name to be put in many > lines. For example, the following name is valid: > > void > class_1 > :: > sub_class_2 > :: > method_3 () > { > /* ... */ > } > > The current implementation cannot handle this name correctly. I think this is also not reasonably formatted. Masatake YAMATO