[Top][All Lists]

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

Some problems in `add-log-current-defun'

From: Herbert Euler
Subject: Some problems in `add-log-current-defun'
Date: Wed, 27 Dec 2006 18:32:58 +0800

I encountered a problem in add-log.el, and solved it somehow (see
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

   ;; 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:

   f1 ()
     /* If point is here `add-log-current-defun' gets wrong result.  */
   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.

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

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:

   method_3 ()
     /* ...  */

The current implementation cannot handle this name correctly.

Guanpeng Xu

Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

reply via email to

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