From: Alan M. <ac...@mu...> - 2013-05-26 14:00:50
|
Hi, Sezaru. On Wed, May 22, 2013 at 09:08:37PM +0000, Sezaru wrote: > cc-mode sometimes loose the indentation when working with c++ header files, > there is another thread with some similar problem here but the workaround > shown there does not work and it was said that in emacs-24.3 it was fixed, > which is the version I'm using and it still have the problem, so I decided > to create a new thread as it look like a diferent issue is causing the > problem. > I've tested this problem in my gentoo emacs 24.3 build and in a vanilla one > download from the official website. The bug persists in both even when > using the built-in cc-mode or the lastest direct from the repositories. It > also persistis when using -q option, so it is not another mode conflicting > with cc-mode. > I've made a little example to reproduce the problem: > #ifndef TEST_H_ > #define TEST_H_ > > > > class Test > { > public: > Test(void); > > Foo(void); > Bar(void); > }; > #endif // TEST_H_ > Save this code as test.hpp, now open it, and there will be 3 empty lines > between #define TEST_H and class Test, in the second empty line paste this: > #include <iostream> > Now the indentation will fail and every line you try to indentate will not. > Beware that you need to paste the #include <iostream> in the code and not > simply write it, if you write character by character the indentation will > still works as it should, it only breaks when you paste it (or at least it > was the only way I've found to reproduce it) Thanks for taking the trouble to report this, and thanks even more for such an accurate description. I think I've tracked this down, it's an ugly (mis)feature in the innards of Emacs's `yank' which messes around with text properties. Would you please try out the following patch, and let me know whether or not it fixes the problem fully. diff -r 10c9ed75910b cc-mode.el --- a/cc-mode.el Thu May 02 11:03:15 2013 +0000 +++ b/cc-mode.el Sun May 26 13:47:14 2013 +0000 @@ -1100,13 +1100,14 @@ (setq beg end))) ;; C-y is capable of spuriously converting category properties - ;; c-</>-as-paren-syntax into hard syntax-table properties. Remove - ;; these when it happens. + ;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table + ;; properties. Remove these when it happens. (when (memq 'category-properties c-emacs-features) (c-clear-char-property-with-value beg end 'syntax-table c-<-as-paren-syntax) (c-clear-char-property-with-value beg end 'syntax-table - c->-as-paren-syntax)) + c->-as-paren-syntax) + (c-clear-char-property-with-value beg end 'syntax-table nil)) (c-trim-found-types beg end old-len) ; maybe we don't need all of these. (c-invalidate-sws-region-after beg end) > Thanks! -- Alan Mackenzie (Nuremberg, Germany). |