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: Re: Some problems in `add-log-current-defun' Date: Fri, 29 Dec 2006 11:10:04 +0800 Message-ID: References: NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: sea.gmane.org 1167361834 4643 80.91.229.10 (29 Dec 2006 03:10:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 29 Dec 2006 03:10:34 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 29 04:10: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 1H088a-0002jF-OR for ged-emacs-devel@m.gmane.org; Fri, 29 Dec 2006 04:10:29 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H088a-0003y8-57 for ged-emacs-devel@m.gmane.org; Thu, 28 Dec 2006 22:10:28 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H088M-0003tB-QX for emacs-devel@gnu.org; Thu, 28 Dec 2006 22:10:14 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H088L-0003sE-3A for emacs-devel@gnu.org; Thu, 28 Dec 2006 22:10:14 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H088K-0003sB-V0 for emacs-devel@gnu.org; Thu, 28 Dec 2006 22:10:12 -0500 Original-Received: from [65.54.246.73] (helo=bay0-omc1-s1.bay0.hotmail.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1H088F-0005Cc-ND; Thu, 28 Dec 2006 22:10:08 -0500 Original-Received: from hotmail.com ([64.4.26.36]) by bay0-omc1-s1.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Thu, 28 Dec 2006 19:10:06 -0800 Original-Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 28 Dec 2006 19:10:05 -0800 Original-Received: from 64.4.26.200 by by112fd.bay112.hotmail.msn.com with HTTP; Fri, 29 Dec 2006 03:10:04 GMT X-Originating-IP: [216.145.54.158] X-Originating-Email: [herberteuler@hotmail.com] X-Sender: herberteuler@hotmail.com In-Reply-To: Original-To: rms@gnu.org, jet@gyve.org X-OriginalArrivalTime: 29 Dec 2006 03:10:05.0321 (UTC) FILETIME=[D68C9F90:01C72AF6] 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:64407 Archived-At: The simplest fix for I is *** add-log.el Thu Dec 28 20:49:44 2006 --- add-log.el.1 Fri Dec 29 10:27:20 2006 *************** (defun add-log-current-defun () *** 816,822 **** (beginning-of-line) ;; 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)) (or (eobp) (forward-char 1)) --- 816,822 ---- (beginning-of-line) ;; 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)) (or (eobp) (forward-char 1)) But I think this is still not very robust, and perhaps there is a more reliable way of moving point, working for all of I-III. Let me test whether this approach works... And for IV, I think the following changes make a complete solution. At least the changed version of `add-log-current-defun' passed all cases I can think of, including the ``not reasonably formatted'' C++ name in the beginning of this thread: void class_1 :: sub_class_2 :: method_3 () { /* ... */ } The patch is: *** add-log.el Thu Dec 28 20:49:44 2006 --- add-log.el.4 Fri Dec 29 10:23:42 2006 *************** (defun add-log-current-defun () *** 916,941 **** ;; Include certain keywords if they ;; precede the name. (setq middle (point)) ! ;; Single (forward-sexp -1) invocation is ! ;; not enough for C++ member function defined ! ;; as part of nested class and/or namespace ! ;; like: ! ;; ! ;; void ! ;; foo::bar::baz::bazz () ! ;; { ... ! ;; ! ;; Here we have to move the point to ! ;; the beginning of foo, not bazz. ! (while (not (looking-back "\\(^\\|[ \t]\\)")) (forward-sexp -1)) ;; Is this C++ method? (when (and (< 2 middle) ! (string= (buffer-substring (- middle 2) ! middle) ! "::")) ;; Include "classname::". ! (setq middle (point))) ;; Ignore these subparts of a class decl ;; and move back to the class name itself. (while (looking-at "public \\|private ") --- 916,939 ---- ;; Include certain keywords if they ;; precede the name. (setq middle (point)) ! ;; Move through C++ nested name ! (while (looking-back "::[ \t\n]*") (forward-sexp -1)) + (forward-sexp -1) ;; Is this C++ method? (when (and (< 2 middle) ! (save-excursion ! (goto-char middle) ! (looking-back "::[ \t\n]*"))) ;; Include "classname::". ! (save-excursion ! ;; The `forward-sexp' form after ! ;; the `while' form above moves ! ;; backward one more sexp, so we ! ;; move forward one. ! (forward-sexp 1) ! (re-search-forward "\\(\\s \\|\n\\)*") ! (setq middle (point)))) ;; Ignore these subparts of a class decl ;; and move back to the class name itself. (while (looking-at "public \\|private ") *************** (defun add-log-current-defun () *** 953,960 **** (forward-char -1) (skip-chars-backward " \t") (setq end (point))) ! (buffer-substring-no-properties ! middle end)))))))) ((memq major-mode add-log-tex-like-modes) (if (re-search-backward "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" --- 951,962 ---- (forward-char -1) (skip-chars-backward " \t") (setq end (point))) ! (let ((name (buffer-substring-no-properties ! middle end))) ! (setq name (replace-regexp-in-string ! "\n" "" name) ! name (replace-regexp-in-string ! "[ \t]*::[ \t]*" "::" name)))))))))) ((memq major-mode add-log-tex-like-modes) (if (re-search-backward "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" Because of the network status I cannot update my source, could somebody please tell me how the newest CC mode moves point with `beginning-of-defun'? And I didn't quite understand Richard's comment on II: > 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, > >That change in CC mode would clearly be a change for the better, but >it doesn't work for me. > >... > >I also find that C-M-a is bound to `beginning-of-defun' in C mode. >Wasn't it supposed to be `c-beginning-of-defun' nowadays? > >What is wrong here? > >... Some explain? Thanks. (I may not able to reply shortly, also because of the poor network status :-( ) Regards, Guanpeng Xu _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/