Bug 185712 - Invalid indenting of code template
Summary: Invalid indenting of code template
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.0.1   Edit
Assignee: Anton Leherbauer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-05-07 00:05 EDT by Sergey Prigogin CLA
Modified: 2009-01-09 15:05 EST (History)
0 users

See Also:


Attachments
Proposed fix (6.33 KB, patch)
2007-05-19 22:39 EDT, Sergey Prigogin CLA
bjorn.freeman-benson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2007-05-07 00:05:17 EDT
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.
Comment 1 Anton Leherbauer CLA 2007-05-07 05:02:37 EDT
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.
Comment 2 Sergey Prigogin CLA 2007-05-07 12:38:46 EDT
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.
Comment 3 Anton Leherbauer CLA 2007-05-08 04:14:42 EDT
(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.
Comment 4 Sergey Prigogin CLA 2007-05-19 22:39:41 EDT
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.
Comment 5 Anton Leherbauer CLA 2007-05-21 03:38:03 EDT
Patch applied. Thanks, Sergey!
Comment 6 Anton Leherbauer CLA 2007-07-13 04:28:39 EDT
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?
Comment 7 Anton Leherbauer CLA 2007-07-13 07:33:23 EDT
Never mind, I fixed it myself.