Subject: Re: bug#36678: 27.0.50; imenu not working in C++ (maybe because of namespace)

From: Ergus <[email-masked]>
Date: Wed, 31 Jul 2019 17:56:13 +0200

Hi Alan:

Sorry for the long delay replying this.

I have been thinking on this for a while because this issue affects me
constantly as I use most of the time C++ now.

Maybe this is a stupid suggestion, but I was thinking that if the issue
is performance (for ii) we could add a special function to implement the
expensive part for the functional search in C and use the C regexps.

Maybe it could be restrictive somehow, but if this solves a problem,
could be good enough and important for C++-mode. Because namespace use
is becoming more and more extended in C++ with the new standards. And
the most common indentations are the 

Probably:

1) For example it could do a first filtration for the buffer in a C
function using C regexp (with fake positives) and then filter again in
the Lisp side?

2) Or, we could just iterate the file by lines in C and then modify the
regex for the next line conditionally (which is cheaper than in
Lisp). This could create a list in C that we can then use in the Lisp
side more efficiently.

In case we figure out a nice method for that. Does it makes sense?

On Wed, Jul 17, 2019 at 04:34:27PM -0000, Alan Mackenzie wrote:
>Hello again, Ergus.
>
>In article <[email-masked]> you wrote:
>> [-- text/plain, encoding 7bit, charset: us-ascii, 91 lines --]
>
>> --text follows this line--
>
>> In the example code (attachement) imenu does not recognizes the
>> functions. So it shows that there are not candidates when there are.
>
>[ .... ]
>
>> Major mode: C++//l
>
>The problem is that the function names are not at column zero.  If they
>were, they'd get recognised properly.  If CC Mode's imenu were to
>recognise indented functions there'd be too many false positives.
>
>This problem has actually come up before (on 2016-11-25, in a post to the
>CC Mode list by Jens Kjerrstr?m), and I then hacked up three defuns which
>would search for functions functionally rather than by regexp.  This
>wasn't wholly satisfactory since (i) this searching was slow; and (ii) if
>there were two functions of the same name (e.g., in different
>namespaces), imenu would only find the first one in the buffer.
>
>If you are interested, I could send you this hack, which is not all that
>big.  Maybe you could play around with it and make it work well.
>
>Maybe it would be possible to bring this approach up to a usable part of
>CC Mode - possibly solving (ii) by constructing a hierarchical menu, but
>problem (i) would remain.  In any case this would be a substantial
>enhancement rather than a simple bug fix.
>
>[ .... ]
>
>> [-- text/plain, encoding 7bit, charset: us-ascii, 45 lines, name: make_local_matrix.hpp --]
>
>> #ifndef _make_local_matrix_hpp_
>> #define _make_local_matrix_hpp_
>
>> #include <vector>
>> #include <map>
>
>> #include <cassert>
>> #include <cstdio>
>
>> #include <fstream>
>
>
>> namespace miniFE {
>
>
>>         void get_recv_info_task(CSRMatrix *A, size_t id, size_t numboxes
>>                                 const size_t *nrows_array,
>>                                 size_t Annz, size_t Anrows)
>>         {
>
>>         }
>
>
>>         void get_send_info_task(CSRMatrix *A, size_t id,
>>                 size_t numboxes,
>>                 int *send_length_local)
>>         {
>>         }
>
>
>>         void set_send_info_task(CSRMatrix *A_array, size_t id,
>>                                 size_t numboxes,
>>                                 int nelements_to_send_local,
>>                                 int *elements_to_send_local)
>>         {
>>         }
>
>>         void make_local_matrix(CSRMatrix *A_array, singleton *sing, size_t numboxes)
>>         {
>>         }
>
>> }//namespace miniFE
>
>> #endif
>
>-- 
>Alan Mackenzie (Nuremberg, Germany).
>