From: Kimball T. <kd...@gm...> - 2012-01-10 21:12:51
|
On Tue, Jan 10, 2012 at 2:45 AM, Alan Mackenzie <ac...@mu...> wrote: > >> I've been having a common, but not consistent that I can lock it >> down, problem with cc-mode. I've tried checking out the latest head >> revision of the source tree, and it still persists. > > How often does it happen? Nearly every time, or about half the time, or > about 10% of the time or hardly ever? oh, I'd have to say it's nearly every time I edit something with "complex" c++ syntax - be that namespaces or templates. > >> Basically, as I'm typing, say something like: > >> namespace Foo >> { > >> template <class T> void doSomething( const std::vector<Bar::X> &v, const T &y ) > > > >> the template arguments (i.e. Bar::X, or class T) will not recognize >> that the template block has closed, and so indent will continue from >> there on the next line indented to say, underneath the Bar::X in the >> above example. > > Does this happen in exactly the fragment you've typed above? it has, although I did change the variable names, I also noticed yesterday that it happens with the function blocks (i.e. with the parens), so I suspect that the parser is somehow getting confused with an incorrect number of braces, and then that state gets "stuck" when the appropriate closing is added. It doesn't happen if I take the above text into it's own file, it's always in the context of a larger file. Take the attached file (Cache.h), and at line 80, add the following text. I'm not sure if you have to type it in, or if you can just paste it... ------------------------- begin snippet ------------------------- template <typename T> inline T retrieve( const std::unique_ptr<SerializerBase> &v, const Core::Checksum &csum ) { std::vector< std::unique_ptr<Core::Serializer> > foo; ----------------- end snippet ----------------------- for me, the indention ends up underneath the Core::Serializer (i.e. it thinks it's still in the std::unique_ptr template block). > >> Sometimes if I reload the file once I've finished typing, it will fix >> itself, sometimes it's more persistent. In either case, the incorrect >> only continues until the next major block (i.e. {}), so if I manually >> update the indenting, and get into the main code, it's usually fine, >> until the next time I declare a variable with template arguments. > > When I load that file fragment in emacs -Q, the indentation on the next > line after "template ..." goes to under the 'm' of "template", which is > correct. The same thing happens when I type it in from scratch. > >> Can someone give me pointers on where to look, or things to provide to >> help debug this? It's fairly annoying. > > Does the bug still happen if you start emacs with -Q? In any case, would > you please do C-c C-b in your buffer to dump your configuration, then > send it to the mailing list. it does not happen with -Q, but then it's loading the old version (5.31.7) of cc-mode (I have the new version in my home folder and it's not loading that version since it's not in the normal emacs load path). I've attached the output of C-c C-b, as I'm not able to mail directly from my machine. > >> Additionally, I'd like to make sure that C++11 template notation >> functions (template <class std::vector<X>> where there is no space >> between the right angle brackets)... > > I'm afraid C++11 support isn't there yet, in particular the use of "shift > right" to close two template brackets. :-( well, I would be willing to help contribute support, but was looking for a general overview of places to start looking, as I know cc-mode is used for other languages, so didn't want to start hacking and break support for a language I don't ever use. And of course, in C++11 you can have as many template arguments as you want to close :) thanks so much, Kimball |