[Bf-committers] Patch for auto-identation in text editor

Bart bf-committers@blender.org
Thu, 08 Jul 2004 23:04:58 +0200


That's sounds good! But there are much problems with text editor:

- no way to type special characters: < > § |
- no way for: ä ö ü Ä Ö Ü ß
- a doubleclick on a word between spaces or special characters should
	select the word
- enter on numpad doesn't work
- sometimes it slows
- using find works only if you pressing the ok button; entering the
	search word and pressing just works after pressing it twice
	again
- you must click in the Textfield of search to before
	you can type a word
- May primitive syntax highlighting for Python would be great


Stephane SOPPERA wrote:
> Hi,
> 
> I've made this little patch (attached file) to add auto-identation to 
> the text editor.
> With this patch, spaces and tabulations at the beginning of the previous 
> line will automatically be added at the beginning of a newline when the 
> user press Enter in the text editor.
> That makes typing python source in blender much easier.
> 
> Thanks in advance,
> 
> 
> ------------------------------------------------------------------------
> 
> Index: source/blender/blenkernel/intern/text.c
> ===================================================================
> RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/text.c,v
> retrieving revision 1.9
> diff -r1.9 text.c
> 1809a1810,1811
> 
>>    int right_len;
>>    int left_spaces;
> 
> 1822,1824c1824,1840
> < 	right= MEM_mallocN(text->curl->len - text->curc+1, "textline_string");
> < 	if (text->curl->len - text->curc) memcpy(right, text->curl->line+text->curc, text->curl->len-text->curc);
> < 	right[text->curl->len - text->curc]=0;
> ---
> 
>>      /* Insert the spaces and tabulations that are at the begin of the line to the
>>       * begin of the new line. 
>>       *
>>       * 1. find the number of spaces'n'tabulations at the begin of the line */
>>    left_spaces=0;
>>    while ( left[left_spaces]==' ' || left[left_spaces]=='\t' ) 
>>        ++left_spaces;
>>      /* 2. Compute the new line length */
>>    right_len=text->curl->len - text->curc + left_spaces;
>>      /* 3. Allocate the memory for the new line */
>>	right= MEM_mallocN(right_len+1, "textline_string");
>>      /* 4. Copy the spaces from the first line to the new line */
>>    if (left_spaces) memcpy(right, text->curl->line, left_spaces);
>>      /* 5. Copy the content of the end of the splitted line after those spaces'n'tabulations */
>>	if (text->curl->len - text->curc) memcpy(right+left_spaces, text->curl->line+text->curc, text->curl->len-text->curc);
>>      /* 6. Add 0 for the last character of the string */
>>    right[right_len]=0;
> 
> 1835c1851
> < 	text->curl->len= text->curl->len - text->curc;
> ---
> 
>>	text->curl->len= right_len;
> 
> 1839c1855,1856
> < 	text->curc=0;
> ---
> 
>>      /* 7. Set the new cursor position after the spaces'n'tabulations */
>>	text->curc=left_spaces;


-- 
|\/\/\/|
|      |
| (O)(O)        Bart.
C      _)       bart@neeneenee.de
|   ,_/
|   /    - Ich bin nicht berechtigt Aushilfslehrer zu feuern -
/   \
                 http://www.neeneenee.de