Community
Participate
Working Groups
CDT HEAD: 1. Create an editor template called "forit": for (${type}::const_iterator ${it} = ${collection}begin(); ${it} != ${collection}end(); ++${it}) { ${cursor} } Don't check the Use code formatter box. 2. Insert the template in a C++ file. It gets inserted as: for (type::const_iterator it = collectionbegin(); it != collectionend(); ++it) { } instead of expected: for (type::const_iterator it = collectionbegin(); it != collectionend(); ++it) { } BTW, it would make sense to include this template in the default set.
That's probably related to bug 181139. The indenter simply does not handle continuation lines correctly. E.g. Ctrl+I does not fix the indentation, either.
One possibility is to work around the underlying problem by applying insertion point indentation to the template as a whole instead of trying to reindent it.
(In reply to comment #2) > One possibility is to work around the underlying problem by applying insertion > point indentation to the template as a whole instead of trying to reindent it. Makes sense.
Created attachment 67908 [details] Proposed fix Apart from the indenting problem reported earlier this patch fixes two additional problems with template insertion: 1. Indenting of template in the suggestion popup (see CContext.evaluate). 2. Replacement of tabs with spaces if code style requires it (see CFormatter.convertTabs). Toni, please review and apply. Thanks.
Patch applied. Thanks, Sergey!
The patch breaks indentation of templates around multi-line selection. E.g. select two lines > Ctrl+Space > select for loop The first line of the selection is shifted too far to the right. Sergey, could you look into this?
Never mind, I fixed it myself.