all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* C++ name and add-log-current-defun
@ 2006-09-21 12:39 Herbert Euler
  2006-09-21 15:05 ` Kevin Rodgers
  0 siblings, 1 reply; 10+ messages in thread
From: Herbert Euler @ 2006-09-21 12:39 UTC (permalink / raw)


add-log-current-defun cannot handle C++ names well.  For
example, the current function:

    int some_class::some_method(int arg)
    {
        // ...
    }

If one invoke add-change-log-entry-other-window when point
is in this function, one would get

    * some_file.cpp (class::some_method):

rather than

    * some_file.cpp (some_class::some_method):

This is because add-log-current-defun in add-log.el calculates
the function name wrong.  Below is the code:

    ;; Now find the right beginning of the name.
    ;; Include certain keywords if they
    ;; precede the name.
    (setq middle (point))
    (forward-word -1)
    ;; Is this C++ method?
    ;; ...

(forward-word -1) wouldn't put point before `some_class',
but puts point before `c' in `some_class'.

How about changing it to like this?

    (while (not (looking-back "\\(^\\|[ \t]\\)"))
      (backward-word 1))

Regards,
Guanpeng Xu

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-09-21 12:39 C++ name and add-log-current-defun Herbert Euler
@ 2006-09-21 15:05 ` Kevin Rodgers
  2006-09-22  4:36   ` Masatake YAMATO
  0 siblings, 1 reply; 10+ messages in thread
From: Kevin Rodgers @ 2006-09-21 15:05 UTC (permalink / raw)


Herbert Euler wrote:
> add-log-current-defun cannot handle C++ names well.  For
> example, the current function:
> 
>    int some_class::some_method(int arg)
>    {
>        // ...
>    }
> 
> If one invoke add-change-log-entry-other-window when point
> is in this function, one would get
> 
>    * some_file.cpp (class::some_method):
> 
> rather than
> 
>    * some_file.cpp (some_class::some_method):
> 
> This is because add-log-current-defun in add-log.el calculates
> the function name wrong.  Below is the code:
> 
>    ;; Now find the right beginning of the name.
>    ;; Include certain keywords if they
>    ;; precede the name.
>    (setq middle (point))
>    (forward-word -1)
>    ;; Is this C++ method?
>    ;; ...
> 
> (forward-word -1) wouldn't put point before `some_class',
> but puts point before `c' in `some_class'.
> 
> How about changing it to like this?
> 
>    (while (not (looking-back "\\(^\\|[ \t]\\)"))
>      (backward-word 1))

How about making the intent clear:

(skip-syntax-backward "w_") ; word and symbol characters

-- 
Kevin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-09-21 15:05 ` Kevin Rodgers
@ 2006-09-22  4:36   ` Masatake YAMATO
  2006-09-22  7:30     ` Herbert Euler
  2006-12-20  2:26     ` Herbert Euler
  0 siblings, 2 replies; 10+ messages in thread
From: Masatake YAMATO @ 2006-09-22  4:36 UTC (permalink / raw)
  Cc: emacs-devel

Hi,

> Herbert Euler wrote:
> > add-log-current-defun cannot handle C++ names well.  For
> > example, the current function:
> > 
> >    int some_class::some_method(int arg)
> >    {
> >        // ...
> >    }
> > 
> > If one invoke add-change-log-entry-other-window when point
> > is in this function, one would get
> > 
> >    * some_file.cpp (class::some_method):
> > 
> > rather than
> > 
> >    * some_file.cpp (some_class::some_method):
> > 
> > This is because add-log-current-defun in add-log.el calculates
> > the function name wrong.  Below is the code:
> > 
> >    ;; Now find the right beginning of the name.
> >    ;; Include certain keywords if they
> >    ;; precede the name.
> >    (setq middle (point))
> >    (forward-word -1)
> >    ;; Is this C++ method?
> >    ;; ...
> > 
> > (forward-word -1) wouldn't put point before `some_class',
> > but puts point before `c' in `some_class'.
> > 
> > How about changing it to like this?
> > 
> >    (while (not (looking-back "\\(^\\|[ \t]\\)"))
> >      (backward-word 1))
> 
> How about making the intent clear:
> 
> (skip-syntax-backward "w_") ; word and symbol characters

How about this one?

*** add-log.el	31  5月 2006 16:12:48 +0900	1.177
--- add-log.el	22  9月 2006 13:32:30 +0900	
***************
*** 914,920 ****
  			       ;; Include certain keywords if they
  			       ;; precede the name.
  			       (setq middle (point))
! 			       (forward-word -1)
  			       ;; Is this C++ method?
  			       (when (and (< 2 middle)
  					  (string= (buffer-substring (- middle 2)
--- 914,920 ----
  			       ;; Include certain keywords if they
  			       ;; precede the name.
  			       (setq middle (point))
! 			       (forward-sexp -1)
  			       ;; Is this C++ method?
  			       (when (and (< 2 middle)
  					  (string= (buffer-substring (- middle 2)

Masatake YAMATO

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-09-22  4:36   ` Masatake YAMATO
@ 2006-09-22  7:30     ` Herbert Euler
  2006-09-22 10:55       ` Masatake YAMATO
  2006-12-20  2:26     ` Herbert Euler
  1 sibling, 1 reply; 10+ messages in thread
From: Herbert Euler @ 2006-09-22  7:30 UTC (permalink / raw)
  Cc: emacs-devel

All of these methods, Kevin's, Masatake's and mine,
work.

Regards,
Guanpeng Xu


>From: Masatake YAMATO <jet@gyve.org>
>To: ihs_4664@yahoo.com, "Herbert Euler" <herberteuler@hotmail.com>
>CC: emacs-devel@gnu.org
>Subject: Re: C++ name and add-log-current-defun
>Date: Fri, 22 Sep 2006 13:36:08 +0900 (JST)
>
>Hi,
>
> > Herbert Euler wrote:
> > > add-log-current-defun cannot handle C++ names well.  For
> > > example, the current function:
> > >
> > >    int some_class::some_method(int arg)
> > >    {
> > >        // ...
> > >    }
> > >
> > > If one invoke add-change-log-entry-other-window when point
> > > is in this function, one would get
> > >
> > >    * some_file.cpp (class::some_method):
> > >
> > > rather than
> > >
> > >    * some_file.cpp (some_class::some_method):
> > >
> > > This is because add-log-current-defun in add-log.el calculates
> > > the function name wrong.  Below is the code:
> > >
> > >    ;; Now find the right beginning of the name.
> > >    ;; Include certain keywords if they
> > >    ;; precede the name.
> > >    (setq middle (point))
> > >    (forward-word -1)
> > >    ;; Is this C++ method?
> > >    ;; ...
> > >
> > > (forward-word -1) wouldn't put point before `some_class',
> > > but puts point before `c' in `some_class'.
> > >
> > > How about changing it to like this?
> > >
> > >    (while (not (looking-back "\\(^\\|[ \t]\\)"))
> > >      (backward-word 1))
> >
> > How about making the intent clear:
> >
> > (skip-syntax-backward "w_") ; word and symbol characters
>
>How about this one?
>
>*** add-log.el	31  5ŒŽ 2006 16:12:48 +0900	1.177
>--- add-log.el	22  9ŒŽ 2006 13:32:30 +0900
>***************
>*** 914,920 ****
>   			       ;; Include certain keywords if they
>   			       ;; precede the name.
>   			       (setq middle (point))
>! 			       (forward-word -1)
>   			       ;; Is this C++ method?
>   			       (when (and (< 2 middle)
>   					  (string= (buffer-substring (- middle 2)
>--- 914,920 ----
>   			       ;; Include certain keywords if they
>   			       ;; precede the name.
>   			       (setq middle (point))
>! 			       (forward-sexp -1)
>   			       ;; Is this C++ method?
>   			       (when (and (< 2 middle)
>   					  (string= (buffer-substring (- middle 2)
>
>Masatake YAMATO
>
>
>
>_______________________________________________
>Emacs-devel mailing list
>Emacs-devel@gnu.org
>http://lists.gnu.org/mailman/listinfo/emacs-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-09-22  7:30     ` Herbert Euler
@ 2006-09-22 10:55       ` Masatake YAMATO
  2006-09-22 14:01         ` Herbert Euler
  0 siblings, 1 reply; 10+ messages in thread
From: Masatake YAMATO @ 2006-09-22 10:55 UTC (permalink / raw)
  Cc: ihs_4664, emacs-devel

> All of these methods, Kevin's, Masatake's and mine,
> work.
> 
> Regards,
> Guanpeng Xu

Viewed at size of code differential, mine is the best:-P
If you agree with me, I'll install my fix.
If not, I'll install your fix.

Give me ack.

Masatake

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-09-22 10:55       ` Masatake YAMATO
@ 2006-09-22 14:01         ` Herbert Euler
  0 siblings, 0 replies; 10+ messages in thread
From: Herbert Euler @ 2006-09-22 14:01 UTC (permalink / raw)
  Cc: ihs_4664, emacs-devel

Of course I agree with you. :-)  Thank you very much.

Regards,
Guanpeng Xu


>From: Masatake YAMATO <jet@gyve.org>
>To: herberteuler@hotmail.com
>CC: ihs_4664@yahoo.com, emacs-devel@gnu.org
>Subject: Re: C++ name and add-log-current-defun
>Date: Fri, 22 Sep 2006 19:55:14 +0900 (JST)
>
> > All of these methods, Kevin's, Masatake's and mine,
> > work.
> >
> > Regards,
> > Guanpeng Xu
>
>Viewed at size of code differential, mine is the best:-P
>If you agree with me, I'll install my fix.
>If not, I'll install your fix.
>
>Give me ack.
>
>Masatake
>
>
>_______________________________________________
>Emacs-devel mailing list
>Emacs-devel@gnu.org
>http://lists.gnu.org/mailman/listinfo/emacs-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-09-22  4:36   ` Masatake YAMATO
  2006-09-22  7:30     ` Herbert Euler
@ 2006-12-20  2:26     ` Herbert Euler
  2006-12-22 20:50       ` Kevin Rodgers
  1 sibling, 1 reply; 10+ messages in thread
From: Herbert Euler @ 2006-12-20  2:26 UTC (permalink / raw)
  Cc: emacs-devel

I found this not complete yet, since only going back one sexp
sometimes cannot reach the beginning of a name.  Please take
``class_1::sub_class_2::method'' as an example.  A complete
solution could be

*** add-log.el.~1.146.2.22.~    Mon Nov 13 10:58:16 2006
--- add-log.el  Wed Dec 20 10:13:47 2006
*************** (defun add-log-current-defun ()
*** 916,922 ****
                               ;; Include certain keywords if they
                               ;; precede the name.
                               (setq middle (point))
!                              (forward-sexp -1)
                               ;; Is this C++ method?
                               (when (and (< 2 middle)
                                          (string= (buffer-substring (- 
middle 2)
--- 916,923 ----
                               ;; Include certain keywords if they
                               ;; precede the name.
                               (setq middle (point))
!                              (while (not (looking-back "\\(^\\| 
\\|\t\\)"))
!                                (forward-sexp -1))
                               ;; Is this C++ method?
                               (when (and (< 2 middle)
                                          (string= (buffer-substring (- 
middle 2)

Regards,
Guanpeng Xu


>From: Masatake YAMATO <jet@gyve.org>
>To: ihs_4664@yahoo.com, "Herbert Euler" <herberteuler@hotmail.com>
>CC: emacs-devel@gnu.org
>Subject: Re: C++ name and add-log-current-defun
>Date: Fri, 22 Sep 2006 13:36:08 +0900 (JST)
>
>Hi,
>
> > Herbert Euler wrote:
> > > add-log-current-defun cannot handle C++ names well.  For
> > > example, the current function:
> > >
> > >    int some_class::some_method(int arg)
> > >    {
> > >        // ...
> > >    }
> > >
> > > If one invoke add-change-log-entry-other-window when point
> > > is in this function, one would get
> > >
> > >    * some_file.cpp (class::some_method):
> > >
> > > rather than
> > >
> > >    * some_file.cpp (some_class::some_method):
> > >
> > > This is because add-log-current-defun in add-log.el calculates
> > > the function name wrong.  Below is the code:
> > >
> > >    ;; Now find the right beginning of the name.
> > >    ;; Include certain keywords if they
> > >    ;; precede the name.
> > >    (setq middle (point))
> > >    (forward-word -1)
> > >    ;; Is this C++ method?
> > >    ;; ...
> > >
> > > (forward-word -1) wouldn't put point before `some_class',
> > > but puts point before `c' in `some_class'.
> > >
> > > How about changing it to like this?
> > >
> > >    (while (not (looking-back "\\(^\\|[ \t]\\)"))
> > >      (backward-word 1))
> >
> > How about making the intent clear:
> >
> > (skip-syntax-backward "w_") ; word and symbol characters
>
>How about this one?
>
>*** add-log.el	31  5ŒŽ 2006 16:12:48 +0900	1.177
>--- add-log.el	22  9ŒŽ 2006 13:32:30 +0900
>***************
>*** 914,920 ****
>   			       ;; Include certain keywords if they
>   			       ;; precede the name.
>   			       (setq middle (point))
>! 			       (forward-word -1)
>   			       ;; Is this C++ method?
>   			       (when (and (< 2 middle)
>   					  (string= (buffer-substring (- middle 2)
>--- 914,920 ----
>   			       ;; Include certain keywords if they
>   			       ;; precede the name.
>   			       (setq middle (point))
>! 			       (forward-sexp -1)
>   			       ;; Is this C++ method?
>   			       (when (and (< 2 middle)
>   					  (string= (buffer-substring (- middle 2)
>
>Masatake YAMATO
>
>
>
>_______________________________________________
>Emacs-devel mailing list
>Emacs-devel@gnu.org
>http://lists.gnu.org/mailman/listinfo/emacs-devel

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-12-20  2:26     ` Herbert Euler
@ 2006-12-22 20:50       ` Kevin Rodgers
  2006-12-23  3:27         ` Herbert Euler
  0 siblings, 1 reply; 10+ messages in thread
From: Kevin Rodgers @ 2006-12-22 20:50 UTC (permalink / raw)


Herbert Euler wrote:
> I found this not complete yet, since only going back one sexp
> sometimes cannot reach the beginning of a name.  Please take
> ``class_1::sub_class_2::method'' as an example.  A complete
> solution could be
> 
> *** add-log.el.~1.146.2.22.~    Mon Nov 13 10:58:16 2006
> --- add-log.el  Wed Dec 20 10:13:47 2006
> *************** (defun add-log-current-defun ()
> *** 916,922 ****
>                               ;; Include certain keywords if they
>                               ;; precede the name.
>                               (setq middle (point))
> !                              (forward-sexp -1)
>                               ;; Is this C++ method?
>                               (when (and (< 2 middle)
>                                          (string= (buffer-substring (- 
> middle 2)
> --- 916,923 ----
>                               ;; Include certain keywords if they
>                               ;; precede the name.
>                               (setq middle (point))
> !                              (while (not (looking-back "\\(^\\| 
> \\|\t\\)"))
> !                                (forward-sexp -1))
>                               ;; Is this C++ method?
>                               (when (and (< 2 middle)
>                                          (string= (buffer-substring (- 
> middle 2)

Once again, I propose:

(skip-syntax-backward "w_") ; word and symbol characters

-- 
Kevin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-12-22 20:50       ` Kevin Rodgers
@ 2006-12-23  3:27         ` Herbert Euler
  2006-12-27  7:50           ` Kevin Rodgers
  0 siblings, 1 reply; 10+ messages in thread
From: Herbert Euler @ 2006-12-23  3:27 UTC (permalink / raw)


Hmmm, I think the choice of ``skip-syntax-backward'' or
``forward-sexp'' is not more important than adding a
``while'' form; both the two functions work, but without
a ``while'' form, there is a bug.

Regards,
Guanpeng Xu


>From: Kevin Rodgers <ihs_4664@yahoo.com>
>To: emacs-devel@gnu.org
>Subject: Re: C++ name and add-log-current-defun
>Date: Fri, 22 Dec 2006 13:50:53 -0700
>
>Herbert Euler wrote:
>>I found this not complete yet, since only going back one sexp
>>sometimes cannot reach the beginning of a name.  Please take
>>``class_1::sub_class_2::method'' as an example.  A complete
>>solution could be
>>
>>*** add-log.el.~1.146.2.22.~    Mon Nov 13 10:58:16 2006
>>--- add-log.el  Wed Dec 20 10:13:47 2006
>>*************** (defun add-log-current-defun ()
>>*** 916,922 ****
>>                               ;; Include certain keywords if they
>>                               ;; precede the name.
>>                               (setq middle (point))
>>!                              (forward-sexp -1)
>>                               ;; Is this C++ method?
>>                               (when (and (< 2 middle)
>>                                          (string= (buffer-substring (- 
>>middle 2)
>>--- 916,923 ----
>>                               ;; Include certain keywords if they
>>                               ;; precede the name.
>>                               (setq middle (point))
>>!                              (while (not (looking-back "\\(^\\| 
>>\\|\t\\)"))
>>!                                (forward-sexp -1))
>>                               ;; Is this C++ method?
>>                               (when (and (< 2 middle)
>>                                          (string= (buffer-substring (- 
>>middle 2)
>
>Once again, I propose:
>
>(skip-syntax-backward "w_") ; word and symbol characters
>
>--
>Kevin
>
>
>
>_______________________________________________
>Emacs-devel mailing list
>Emacs-devel@gnu.org
>http://lists.gnu.org/mailman/listinfo/emacs-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: C++ name and add-log-current-defun
  2006-12-23  3:27         ` Herbert Euler
@ 2006-12-27  7:50           ` Kevin Rodgers
  0 siblings, 0 replies; 10+ messages in thread
From: Kevin Rodgers @ 2006-12-27  7:50 UTC (permalink / raw)


Herbert Euler wrote:
> Hmmm, I think the choice of ``skip-syntax-backward'' or
> ``forward-sexp'' is not more important than adding a
> ``while'' form; both the two functions work, but without
> a ``while'' form, there is a bug.

Yes, you're right.  Somehow I forgot to actually check that in a C++ 
buffer (vs. Emacs Lisp).

But I think your while condition

	(not (looking-back "\\(^\\| \\|\t\\)"))

could be improved by specifying a LIMIT arg to looking-back

	(1- (point))

and/or by anchoring the regexp with \=.

-- 
Kevin Rodgers
Denver, Colorado, USA

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-12-27  7:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-21 12:39 C++ name and add-log-current-defun Herbert Euler
2006-09-21 15:05 ` Kevin Rodgers
2006-09-22  4:36   ` Masatake YAMATO
2006-09-22  7:30     ` Herbert Euler
2006-09-22 10:55       ` Masatake YAMATO
2006-09-22 14:01         ` Herbert Euler
2006-12-20  2:26     ` Herbert Euler
2006-12-22 20:50       ` Kevin Rodgers
2006-12-23  3:27         ` Herbert Euler
2006-12-27  7:50           ` Kevin Rodgers

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.