[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Some problems in `add-log-current-defun'
From: |
Herbert Euler |
Subject: |
Re: Some problems in `add-log-current-defun' |
Date: |
Fri, 29 Dec 2006 11:10:04 +0800 |
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/
- Re: Some problems in `add-log-current-defun', (continued)
- Re: Some problems in `add-log-current-defun',
Herbert Euler <=
Re: Some problems in `add-log-current-defun', Herbert Euler, 2006/12/31