From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Herbert Euler" Newsgroups: gmane.emacs.devel Subject: Some problems in `add-log-current-defun' Date: Wed, 27 Dec 2006 18:32:58 +0800 Message-ID: NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: sea.gmane.org 1167215616 18978 80.91.229.10 (27 Dec 2006 10:33:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 27 Dec 2006 10:33:36 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 27 11:33:33 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 1GzW6D-0007Xa-9c for ged-emacs-devel@m.gmane.org; Wed, 27 Dec 2006 11:33:29 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GzW69-0005eo-Uv for ged-emacs-devel@m.gmane.org; Wed, 27 Dec 2006 05:33:26 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GzW5q-0005eY-PA for emacs-devel@gnu.org; Wed, 27 Dec 2006 05:33:06 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GzW5p-0005dt-9v for emacs-devel@gnu.org; Wed, 27 Dec 2006 05:33:05 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GzW5p-0005dq-00 for emacs-devel@gnu.org; Wed, 27 Dec 2006 05:33:05 -0500 Original-Received: from [65.54.246.228] (helo=bay0-omc3-s28.bay0.hotmail.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GzW5o-00089Z-GP for emacs-devel@gnu.org; Wed, 27 Dec 2006 05:33:04 -0500 Original-Received: from hotmail.com ([64.4.26.44]) by bay0-omc3-s28.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Wed, 27 Dec 2006 02:33:03 -0800 Original-Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 27 Dec 2006 02:33:03 -0800 Original-Received: from 64.4.26.200 by by112fd.bay112.hotmail.msn.com with HTTP; Wed, 27 Dec 2006 10:32:58 GMT X-Originating-IP: [216.145.54.7] X-Originating-Email: [herberteuler@hotmail.com] X-Sender: herberteuler@hotmail.com Original-To: emacs-devel@gnu.org X-OriginalArrivalTime: 27 Dec 2006 10:33:03.0639 (UTC) FILETIME=[63A29A70:01C729A2] 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:64328 Archived-At: I encountered a problem in add-log.el, and solved it somehow (see http://lists.gnu.org/archive/html/emacs-devel/2006-09/msg00869.html). However, after re-reading the implementation of `add-log-current-defun', I found there are still many problems (bugs) in `add-log-current-defun' for the C like languages. I'm going to work on it, but before doing anything, I'd like to write them down. This message is intended to describe the problems I found, rather than talking about any proposal. Please help me find whether there are more problems not found yet. Please locate to the function `add-log-current-defun' in `add-log.el' before continuing reading. 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'. II. On the change of `beginning-of-defun' in CC mode When the point is in the docstring of Emacs C source code, the following forms are evaluated. (let (maybe-beg) ;; Try to find the containing defun. (beginning-of-defun) (end-of-defun) But I found the result is wrong with the newest CC mode. Consider the following Emacs C source code: DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0, doc: /* Eval BODY allowing nonlocal exits using `throw'. TAG is evalled to get the tag to use; it must not be nil. Then the BODY is executed. Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'. If no throw happens, `catch' returns the value of the last BODY form. If a throw happens, it specifies the value to return from `catch'. usage: (catch TAG BODY...) */) Now suppose the point is at the beginning of the second paragarph, i.e. before ``Then''. This is where the point will be before evaluating the forms given above if one invokes `add-log-current-defun' when the point is in the first paragraph of the docstring. In the past, CC mode does not consider the arguments of DEFUN as a defun, so `beginning-of-defun' will move point to the beginning of the function that appear before this DEFUN. With the forms in `add-log-current-defun', the result is correct. But I found in the newest CC mode considers the arguments (starting with ``("catch"'', ending with ``*/)'') as a defun, so that `beginning-of-defun' will move point to the beginning of the arguments, i.e. between the space that is after ``DEFUN'' and the left paren before ``"catch"''. As a result, one cannot produce correct change log entry when point is in the first paragraph of this function, for example, when point is between ``Eval'' and ``BODY'' in the first paragraph. 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. IV. On the C++ names 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. Regards, Guanpeng Xu _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/