[Bf-committers] Patch for auto-identation in text editor
Stephane SOPPERA
bf-committers@blender.org
Thu, 08 Jul 2004 22:39:51 +0000
This is a multi-part message in MIME format.
--------------010604070206050305050002
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
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,
--
Stephane SOPPERA
http://perso.wanadoo.fr/stephane.soppera
--------------010604070206050305050002
Content-Type: text/plain;
name="patch_text_editor_indent.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="patch_text_editor_indent.txt"
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;
--------------010604070206050305050002--