all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Herbert Euler" <herberteuler@hotmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Some problems in `add-log-current-defun'
Date: Fri, 29 Dec 2006 11:10:04 +0800	[thread overview]
Message-ID: <BAY112-F26284CCA035EB427E95D38DAC60@phx.gbl> (raw)
In-Reply-To: <E1Gzg9G-0002nd-I6@fencepost.gnu.org>

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/

  parent reply	other threads:[~2006-12-29  3:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-27 10:32 Some problems in `add-log-current-defun' Herbert Euler
2006-12-27 10:45 ` David Kastrup
2006-12-27 11:48   ` Masatake YAMATO
2006-12-27 12:22     ` David Kastrup
2006-12-27 11:55 ` Masatake YAMATO
2006-12-27 13:46 ` Masatake YAMATO
2006-12-27 21:17 ` Richard Stallman
2006-12-28 12:41   ` Masatake YAMATO
2006-12-29 15:44     ` Richard Stallman
2006-12-30  4:55       ` Masatake YAMATO
2006-12-30 18:24         ` Richard Stallman
2006-12-28 12:47   ` Herbert Euler
2006-12-29 15:44     ` Richard Stallman
2006-12-29  3:10   ` Herbert Euler [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-12-31  8:28 Herbert Euler
2006-12-31 22:13 ` Richard Stallman
2007-01-01  1:27   ` Herbert Euler
2007-01-02 23:35   ` Stefan Monnier
2007-01-03 21:11     ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY112-F26284CCA035EB427E95D38DAC60@phx.gbl \
    --to=herberteuler@hotmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.