emacs-bug-tracker
[Top][All Lists]
Advanced

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

bug#46301: closed (28.0.50; cc-mode: add support for c++ lambda expressi


From: GNU bug Tracking System
Subject: bug#46301: closed (28.0.50; cc-mode: add support for c++ lambda expression)
Date: Mon, 01 Mar 2021 19:35:02 +0000

Your message dated Mon, 1 Mar 2021 19:34:27 +0000
with message-id <YD1Bw9rjcAKkqLS8@ACM>
and subject line Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda 
expression
has caused the debbugs.gnu.org bug report #46301,
regarding 28.0.50; cc-mode: add support for c++ lambda expression
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
46301: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=46301
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: 28.0.50; cc-mode: add support for c++ lambda expression Date: Thu, 04 Feb 2021 21:17:22 +0530
Hi,

This bugs only occurs when we assign lambda expression as default
arguments in C++.  I know there are better ways of using lambda but I
was just playing with both C++ and Emacs on a hobby project.

Consider this C++ code:

template <typename T>
void bubble_sort(std :: vector<T> &v, bool cmp(T, T)=[](T a, T b){return a < 
b;})
{
    bool swapped = true;
    for(size_t i = 0; i < v.size() && swapped; i++) {
        swapped = false;
        for(size_t j = 0; j < v.size()-i; j++){
            if(cmp(v[j+1], v[j])) {
                std::swap(v[j], v[j+1]);
                swapped=true;
            }
        }
    }
}

Here cmp takes a lambda as default argument and if in c++-mode if we try
using C-M-e(c-end-of-defun) it will get trapped into lambda.

To solve this is added c-forward-to-nth

((memq where '(at-function-end outwith-function at-header in-header))
    (when (c-syntactic-re-search-forward "{" nil 'eob)
      (backward-char)
      (forward-sexp)

      ;; continue to move sexp if we are looking ) and ,
      (while (looking-at ")\\|,")
        (c-syntactic-re-search-forward "{" nil 'eob)
        (backward-char)
        (forward-sexp))

      (setq n (1- n))))

By this I am trying to move forward lambda's which are separated by ','
or ended with ')'.  I will also attaching the necessary diff to support
the issue.
--
Utkarsh Singh

Attachment: cc-cmds.el.diff
Description: support c++ lambda

Attachment: signature.asc
Description: PGP signature


--- End Message ---
--- Begin Message --- Subject: Re: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression Date: Mon, 1 Mar 2021 19:34:27 +0000
Hello, Utkarsh.

On Sat, Feb 27, 2021 at 21:17:11 +0530, Utkarsh Singh wrote:
> Alan Mackenzie <acm@muc.de> writes:

> > I've spent the last couple of days fixing the handling of C-M-a/e in
> > cc-cmds.el.  It took rather more than the four line patch you proposed.
> > ;-)  Could I ask you, please, to apply the following patch (which should
> > apply cleanly to the Emacs master branch), byte compile cc-cmds.el, load
> > it into Emacs, and test it for me on your real source code.  Then please
> > report back whether the bug is in fact fixed, and if not, what is still
> > wrong.  In the event you would like help with the patching or byte
> > compiling, feel free to send me private email.

> Thanks now issue is fixed and code itself looks pretty solid.

Thanks for doing the testing.  I've committed the patch to all the
relevant places, and I'm closing the bug with this post.

> Due to my in-experience in Elisp and comprehensive cc-mode library I was
> unable to deep dive into the patch but I have a questions about it:

> Why non-interactive functions of cc-mode doesn't provide doc-string?

Quite a lot of functions, even non-interactive ones, and variables have
a doc string.  This means that those functions/variables are available
to modes derived from CC Mode, and their interfaces are fixed.  The ones
without doc strings are regarded as "internal" to CC Mode, and their
interfaces can (and do) change at any time.  There's a comment to this
effect burried in the first few hundred lines of cc-engine.el.

A few years ago, an alternative convention started being adopted by
Emacs, where a double hypen is used to indicate an "internal" function
or variable.

> --
> Utkarsh Singh

-- 
Alan Mackenzie (Nuremberg, Germany).


--- End Message ---

reply via email to

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