The default Emacs C++ mode (cc-mode
) still does not recognize many C++11 features.
One annoying issue is that it applies too much indentation to lambda functions used
as function parameters:
std::vector<int> ar(4);
std::generate_n(std::begin(ar), 4, [] {
static int g_i;
return g_i++;
});
std::for_each(std::begin(ar), std::end(ar), [](int i) {
std::cout << " " << i;
});
bool b = std::is_sorted(std::begin(ar), std::end(ar), [&](int l, int r) {
return l<r;
});
std::cout << " " << b << "\n";
Ideally, one would prefer:
std::vector<int> ar(4);
std::generate_n(std::begin(ar), 4, [] {
static int g_i;
return g_i++;
});
std::for_each(std::begin(ar), std::end(ar), [](int i) {
std::cout << " " << i;
});
bool b = std::is_sorted(std::begin(ar), std::end(ar), [&](int l, int r) {
return l<r;
});
std::cout << " " << b << "\n";
Are there good solutions for this?
In Emacs26, the accepted answer doesn't work for me anymore. I just set the 'inlambda' to 0.
(c-offsets-alist . ((case-label . 0)
(inline-open . 0)
(substatement-open . 0)
(inlambda . 0) ; no extra indent for lambda
(block-open . 0) ; no space before {
(knr-argdecl-intro . -)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With