From e29eef320cc1cfc8a853747def354fc280b22e7b Mon Sep 17 00:00:00 2001
From: MaxED <j.maxed@gmail.com>
Date: Fri, 29 Jan 2016 13:05:28 +0000
Subject: [PATCH] Preferences: moved Script Editor settings to a separate page,
 added a bunch of new Script Editor settings. Changed: Script Editor no longer
 converts typed constants to uppercase. Changed: when "Auto indent" is
 enabled, Script Editor no longer adds additional indentation to a line after
 closing brace.

---
 MakeSVNRelease.bat                            |   2 +-
 Source/Core/Builder.csproj                    |   9 +
 Source/Core/Config/ProgramConfiguration.cs    |  90 ++-
 Source/Core/Controls/ScriptEditorControl.cs   | 108 +--
 .../ScriptEditorPreviewControl.Designer.cs    |  68 ++
 .../Controls/ScriptEditorPreviewControl.cs    | 413 ++++++++++
 .../Controls/ScriptEditorPreviewControl.resx  | 120 +++
 Source/Core/Rendering/ColorCollection.cs      |  22 +-
 Source/Core/Resources/Lexers.cfg              |   8 +-
 .../Core/Windows/PreferencesForm.Designer.cs  | 709 ++++++++++++------
 Source/Core/Windows/PreferencesForm.cs        | 296 +++++---
 Source/Core/Windows/PreferencesForm.resx      |  12 +-
 12 files changed, 1428 insertions(+), 429 deletions(-)
 create mode 100644 Source/Core/Controls/ScriptEditorPreviewControl.Designer.cs
 create mode 100644 Source/Core/Controls/ScriptEditorPreviewControl.cs
 create mode 100644 Source/Core/Controls/ScriptEditorPreviewControl.resx

diff --git a/MakeSVNRelease.bat b/MakeSVNRelease.bat
index 45ba22787..f315e5786 100644
--- a/MakeSVNRelease.bat
+++ b/MakeSVNRelease.bat
@@ -160,7 +160,7 @@ ECHO.
 ECHO Packing release...
 ECHO.
 IF EXIST "SVN_Build\*.7z" DEL /F /Q "SVN_Build\*.7z" > NUL
-"%SEVENZIPDIR%\7z" a .\SVN_Build\gzdb.7z .\Build\* -xr!*.xml -xr!JetBrains.Profiler.Core.Api.dll -x!Setup
+"%SEVENZIPDIR%\7z" a .\SVN_Build\gzdb.7z .\Build\* -xr!*.xml -xr!JetBrains.Profiler.Core.Api.dll -xr!ScintillaNET.3.5.pdb -x!Setup
 IF %ERRORLEVEL% NEQ 0 GOTO PACKFAIL
 IF NOT EXIST .\SVN_Build\gzdb.7z GOTO FILEFAIL
 
diff --git a/Source/Core/Builder.csproj b/Source/Core/Builder.csproj
index 82e4ce1d6..798732e7c 100644
--- a/Source/Core/Builder.csproj
+++ b/Source/Core/Builder.csproj
@@ -694,6 +694,9 @@
     <EmbeddedResource Include="Controls\ScriptEditorControl.resx">
       <DependentUpon>ScriptEditorControl.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="Controls\ScriptEditorPreviewControl.resx">
+      <DependentUpon>ScriptEditorPreviewControl.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Resources\SkySphere.md3" />
     <None Include="Resources\ThingStatistics.png" />
     <None Include="Resources\Copy.png" />
@@ -767,6 +770,12 @@
     <Compile Include="Controls\ScriptEditorControl.designer.cs">
       <DependentUpon>ScriptEditorControl.cs</DependentUpon>
     </Compile>
+    <Compile Include="Controls\ScriptEditorPreviewControl.cs">
+      <SubType>UserControl</SubType>
+    </Compile>
+    <Compile Include="Controls\ScriptEditorPreviewControl.Designer.cs">
+      <DependentUpon>ScriptEditorPreviewControl.cs</DependentUpon>
+    </Compile>
     <Compile Include="Controls\SectorSlopeControl.cs">
       <SubType>UserControl</SubType>
     </Compile>
diff --git a/Source/Core/Config/ProgramConfiguration.cs b/Source/Core/Config/ProgramConfiguration.cs
index 6ef7a9913..48cb55802 100644
--- a/Source/Core/Config/ProgramConfiguration.cs
+++ b/Source/Core/Config/ProgramConfiguration.cs
@@ -61,15 +61,7 @@ namespace CodeImp.DoomBuilder.Config
 		private int movespeed;
 		private float viewdistance;
 		private bool invertyaxis;
-		private string scriptfontname;
-		private int scriptfontsize;
-		private bool scriptfontbold;
-		private bool scriptontop;
-		private bool scriptautoindent;
-		private bool scriptusetabs; //mxd
-		private bool snippetsallmanstyle; //mxd
 		private string screenshotspath; //mxd
-		private int scripttabwidth;
 		private int previewimagesize;
 		private int autoscrollspeed;
 		private int zoomfactor;
@@ -92,7 +84,21 @@ namespace CodeImp.DoomBuilder.Config
 		private float filteranisotropy;
 		private bool showtexturesizes;
 		private bool locatetexturegroup; //mxd
-		private SplitLineBehavior splitlinebehavior;	//mxd
+		private SplitLineBehavior splitlinebehavior; //mxd
+
+		//mxd. Script editor settings
+		private string scriptfontname;
+		private int scriptfontsize;
+		private bool scriptfontbold;
+		private bool scriptontop;
+		private bool scriptautoindent;
+		private bool scriptallmanstyle; //mxd
+		private bool scriptusetabs; //mxd
+		private int scripttabwidth;
+		private bool scriptautoclosebrackets; //mxd
+		private bool scriptshowlinenumbers; //mxd
+		private bool scriptshowfolding; //mxd
+		private bool scriptautoshowautocompletion; //mxd
 
 		//mxd
 		private ModelRenderMode gzDrawModelsMode;
@@ -154,19 +160,11 @@ namespace CodeImp.DoomBuilder.Config
 		public int MoveSpeed { get { return movespeed; } internal set { movespeed = value; } }
 		public float ViewDistance { get { return viewdistance; } internal set { viewdistance = value; } }
 		public bool InvertYAxis { get { return invertyaxis; } internal set { invertyaxis = value; } }
-		public string ScriptFontName { get { return scriptfontname; } internal set { scriptfontname = value; } }
-		public int ScriptFontSize { get { return scriptfontsize; } internal set { scriptfontsize = value; } }
-		public bool ScriptFontBold { get { return scriptfontbold; } internal set { scriptfontbold = value; } }
-		public bool ScriptOnTop { get { return scriptontop; } internal set { scriptontop = value; } }
 		public int PreviewImageSize { get { return previewimagesize; } internal set { previewimagesize = value; } }
 		public int AutoScrollSpeed { get { return autoscrollspeed; } internal set { autoscrollspeed = value; } }
 		public int ZoomFactor { get { return zoomfactor; } internal set { zoomfactor = value; } }
 		public bool ShowErrorsWindow { get { return showerrorswindow; } internal set { showerrorswindow = value; } }
 		public bool AnimateVisualSelection { get { return animatevisualselection; } internal set { animatevisualselection = value; } }
-		public bool ScriptUseTabs { get { return scriptusetabs; } internal set { scriptusetabs = value; } } //mxd
-		public int ScriptTabWidth { get { return scripttabwidth; } internal set { scripttabwidth = value; } }
-		public bool ScriptAutoIndent { get { return scriptautoindent; } internal set { scriptautoindent = value; } }
-		public bool SnippetsAllmanStyle { get { return snippetsallmanstyle; } internal set { snippetsallmanstyle = value; } } //mxd
 		internal string ScreenshotsPath { get { return screenshotspath; } set { screenshotspath = value; } } //mxd
 		internal int PreviousVersion { get { return previousversion; } }
 		internal PasteOptions PasteOptions { get { return pasteoptions; } set { pasteoptions = value; } }
@@ -187,6 +185,20 @@ namespace CodeImp.DoomBuilder.Config
 		public bool LocateTextureGroup { get { return locatetexturegroup; } internal set { locatetexturegroup = value; } } //mxd
 		public SplitLineBehavior SplitLineBehavior { get { return splitlinebehavior; } set { splitlinebehavior = value; } } //mxd
 
+		//mxd. Script editor settings
+		public string ScriptFontName { get { return scriptfontname; } internal set { scriptfontname = value; } }
+		public int ScriptFontSize { get { return scriptfontsize; } internal set { scriptfontsize = value; } }
+		public bool ScriptFontBold { get { return scriptfontbold; } internal set { scriptfontbold = value; } }
+		public bool ScriptOnTop { get { return scriptontop; } internal set { scriptontop = value; } }
+		public bool ScriptAutoIndent { get { return scriptautoindent; } internal set { scriptautoindent = value; } }
+		public bool ScriptAllmanStyle { get { return scriptallmanstyle; } internal set { scriptallmanstyle = value; } } //mxd
+		public bool ScriptUseTabs { get { return scriptusetabs; } internal set { scriptusetabs = value; } } //mxd
+		public int ScriptTabWidth { get { return scripttabwidth; } internal set { scripttabwidth = value; } }
+		public bool ScriptAutoCloseBrackets { get { return scriptautoclosebrackets; } internal set { scriptautoclosebrackets = value; } } //mxd
+		public bool ScriptShowLineNumbers { get { return scriptshowlinenumbers; } internal set { scriptshowlinenumbers = value; } } //mxd
+		public bool ScriptShowFolding { get { return scriptshowfolding; } internal set { scriptshowfolding = value; } } //mxd
+		public bool ScriptAutoShowAutocompletion { get { return scriptautoshowautocompletion; } internal set { scriptautoshowautocompletion = value; } } //mxd
+
 		//mxd 
 		public ModelRenderMode GZDrawModelsMode { get { return gzDrawModelsMode; } internal set { gzDrawModelsMode = value; } }
 		public LightRenderMode GZDrawLightsMode { get { return gzDrawLightsMode; } internal set { gzDrawLightsMode = value; } }
@@ -270,15 +282,7 @@ namespace CodeImp.DoomBuilder.Config
 				movespeed = cfg.ReadSetting("movespeed", 100);
 				viewdistance = cfg.ReadSetting("viewdistance", 3000.0f);
 				invertyaxis = cfg.ReadSetting("invertyaxis", false);
-				scriptfontname = cfg.ReadSetting("scriptfontname", "Courier New");
-				scriptfontsize = cfg.ReadSetting("scriptfontsize", 10);
-				scriptfontbold = cfg.ReadSetting("scriptfontbold", false);
-				scriptautoindent = cfg.ReadSetting("scriptautoindent", true);
-				snippetsallmanstyle = cfg.ReadSetting("snippetsallmanstyle", false); //mxd
 				screenshotspath = cfg.ReadSetting("screenshotspath", General.DefaultScreenshotsPath); //mxd
-				scriptontop = cfg.ReadSetting("scriptontop", true);
-				scriptusetabs = cfg.ReadSetting("scriptusetabs", true); //mxd
-				scripttabwidth = cfg.ReadSetting("scripttabwidth", 4);
 				previewimagesize = cfg.ReadSetting("previewimagesize", 1);
 				autoscrollspeed = cfg.ReadSetting("autoscrollspeed", 0);
 				zoomfactor = cfg.ReadSetting("zoomfactor", 3);
@@ -303,6 +307,20 @@ namespace CodeImp.DoomBuilder.Config
 				locatetexturegroup = cfg.ReadSetting("locatetexturegroup", true); //mxd
 				splitlinebehavior = (SplitLineBehavior) General.Clamp(cfg.ReadSetting("splitlinebehavior", 0), 0, 3); //mxd
 
+				//mxd. Script editor
+				scriptfontname = cfg.ReadSetting("scriptfontname", "Courier New");
+				scriptfontsize = cfg.ReadSetting("scriptfontsize", 10);
+				scriptfontbold = cfg.ReadSetting("scriptfontbold", false);
+				scriptontop = cfg.ReadSetting("scriptontop", true);
+				scriptautoindent = cfg.ReadSetting("scriptautoindent", true);
+				scriptallmanstyle = cfg.ReadSetting("scriptallmanstyle", false); //mxd
+				scriptusetabs = cfg.ReadSetting("scriptusetabs", true); //mxd
+				scripttabwidth = cfg.ReadSetting("scripttabwidth", 4);
+				scriptautoclosebrackets = cfg.ReadSetting("scriptautoclosebrackets", true); //mxd
+				scriptshowlinenumbers = cfg.ReadSetting("scriptshowlinenumbers", true); //mxd
+				scriptshowfolding = cfg.ReadSetting("scriptshowfolding", true); //mxd
+				scriptautoshowautocompletion = cfg.ReadSetting("scriptautoshowautocompletion", true); //mxd
+
 				//mxd 
 				gzDrawModelsMode = (ModelRenderMode)cfg.ReadSetting("gzdrawmodels", (int)ModelRenderMode.ALL);
 				gzDrawLightsMode = (LightRenderMode)cfg.ReadSetting("gzdrawlights", (int)LightRenderMode.ALL);
@@ -367,14 +385,6 @@ namespace CodeImp.DoomBuilder.Config
 			cfg.WriteSetting("movespeed", movespeed);
 			cfg.WriteSetting("viewdistance", viewdistance);
 			cfg.WriteSetting("invertyaxis", invertyaxis);
-			cfg.WriteSetting("scriptfontname", scriptfontname);
-			cfg.WriteSetting("scriptfontsize", scriptfontsize);
-			cfg.WriteSetting("scriptfontbold", scriptfontbold);
-			cfg.WriteSetting("scriptontop", scriptontop);
-			cfg.WriteSetting("scriptusetabs", scriptusetabs); //mxd
-			cfg.WriteSetting("scripttabwidth", scripttabwidth);
-			cfg.WriteSetting("scriptautoindent", scriptautoindent);
-			cfg.WriteSetting("snippetsallmanstyle", snippetsallmanstyle); //mxd
 			cfg.WriteSetting("screenshotspath", screenshotspath); //mxd
 			cfg.WriteSetting("previewimagesize", previewimagesize);
 			cfg.WriteSetting("autoscrollspeed", autoscrollspeed);
@@ -400,6 +410,20 @@ namespace CodeImp.DoomBuilder.Config
 			cfg.WriteSetting("locatetexturegroup", locatetexturegroup); //mxd
 			cfg.WriteSetting("splitlinebehavior", (int)splitlinebehavior); //mxd
 
+			//mxd. Script editor
+			cfg.WriteSetting("scriptfontname", scriptfontname);
+			cfg.WriteSetting("scriptfontsize", scriptfontsize);
+			cfg.WriteSetting("scriptfontbold", scriptfontbold);
+			cfg.WriteSetting("scriptontop", scriptontop);
+			cfg.WriteSetting("scriptusetabs", scriptusetabs); //mxd
+			cfg.WriteSetting("scripttabwidth", scripttabwidth);
+			cfg.WriteSetting("scriptautoindent", scriptautoindent);
+			cfg.WriteSetting("scriptallmanstyle", scriptallmanstyle); //mxd
+			cfg.WriteSetting("scriptautoclosebrackets", scriptautoclosebrackets); //mxd
+			cfg.WriteSetting("scriptshowlinenumbers", scriptshowlinenumbers); //mxd
+			cfg.WriteSetting("scriptshowfolding", scriptshowfolding); //mxd
+			cfg.WriteSetting("scriptautoshowautocompletion", scriptautoshowautocompletion); //mxd
+
 			//mxd
 			cfg.WriteSetting("gzdrawmodels", (int)gzDrawModelsMode);
 			cfg.WriteSetting("gzdrawlights", (int)gzDrawLightsMode);
diff --git a/Source/Core/Controls/ScriptEditorControl.cs b/Source/Core/Controls/ScriptEditorControl.cs
index d0e2d818e..2af871c8e 100644
--- a/Source/Core/Controls/ScriptEditorControl.cs
+++ b/Source/Core/Controls/ScriptEditorControl.cs
@@ -35,22 +35,22 @@ using ScintillaNET;
 
 namespace CodeImp.DoomBuilder.Controls
 {
+	internal enum ScriptStyleType
+	{
+		PlainText = 0,
+		Keyword = 1,
+		Constant = 2,
+		Comment = 3,
+		Literal = 4,
+		LineNumber = 5,
+		String = 6, //mxd
+		Include = 7, //mxd
+	}
+	
 	internal partial class ScriptEditorControl : UserControl
 	{
 		#region ================== Enums
 
-		private enum ScriptStyleType
-		{
-			PlainText = 0,
-			Keyword = 1,
-			Constant = 2,
-			Comment = 3,
-			Literal = 4,
-			LineNumber = 5,
-			String = 6, //mxd
-			Include = 7, //mxd
-		}
-
 		// Index for registered images
 		private enum ImageIndex
 		{
@@ -147,8 +147,11 @@ namespace CodeImp.DoomBuilder.Controls
 			scriptedit.Margins[0].Sensitive = true;
 			
 			// Line numbers margin
-			scriptedit.Margins[1].Type = MarginType.Number;
-			scriptedit.Margins[1].Width = 16;
+			if(General.Settings.ScriptShowLineNumbers)
+			{
+				scriptedit.Margins[1].Type = MarginType.Number;
+				scriptedit.Margins[1].Width = 16;
+			}
 			scriptedit.Margins[1].Mask = 0; // No markers here
 
 			// Spacing margin
@@ -354,10 +357,17 @@ namespace CodeImp.DoomBuilder.Controls
 
 			// Set style for linenumbers and margins
 			scriptedit.Styles[Style.LineNumber].BackColor = General.Colors.ScriptBackground.ToColor();
+			scriptedit.SetFoldMarginColor(true, General.Colors.ScriptFoldBackColor.ToColor());
+			scriptedit.SetFoldMarginHighlightColor(true, General.Colors.ScriptFoldBackColor.ToColor());
+			for(int i = 25; i < 32; i++)
+			{
+				scriptedit.Markers[i].SetForeColor(General.Colors.ScriptFoldBackColor.ToColor());
+				scriptedit.Markers[i].SetBackColor(General.Colors.ScriptFoldForeColor.ToColor());
+			}
  
 			//mxd. Set style for (mis)matching braces
-			scriptedit.Styles[Style.BraceLight].BackColor = General.Colors.ScriptBraceHighlight.ToColor(); //Color.Cyan;
-			scriptedit.Styles[Style.BraceBad].BackColor = General.Colors.ScriptBadBraceHighlight.ToColor(); //Color.Red;
+			scriptedit.Styles[Style.BraceLight].BackColor = General.Colors.ScriptBraceHighlight.ToColor();
+			scriptedit.Styles[Style.BraceBad].BackColor = General.Colors.ScriptBadBraceHighlight.ToColor();
 
 			//mxd. Set whitespace color
 			scriptedit.SetWhitespaceForeColor(true, General.Colors.ScriptWhitespace.ToColor());
@@ -399,9 +409,6 @@ namespace CodeImp.DoomBuilder.Controls
 					}
 
 					scriptedit.Styles[stylenum].ForeColor = General.Colors.Colors[colorindex].ToColor();
-					
-					//mxd. Display constants as uppercase
-					if(type == ScriptStyleType.Constant) scriptedit.Styles[stylenum].Case = StyleCase.Upper;
 				}
 			}
 			
@@ -470,7 +477,7 @@ namespace CodeImp.DoomBuilder.Controls
 			autocompletelist = new List<string>(autocompletedict.Values);
 
 			// Setup folding (https://github.com/jacobslusser/ScintillaNET/wiki/Automatic-Code-Folding)
-			if(scriptconfig.Lexer == Lexer.Cpp || scriptconfig.Lexer == Lexer.CppNoCase)
+			if(General.Settings.ScriptShowFolding && (scriptconfig.Lexer == Lexer.Cpp || scriptconfig.Lexer == Lexer.CppNoCase))
 			{
 				// Instruct the lexer to calculate folding
 				scriptedit.SetProperty("fold", "1");
@@ -482,13 +489,6 @@ namespace CodeImp.DoomBuilder.Controls
 				scriptedit.Margins[2].Sensitive = true;
 				scriptedit.Margins[2].Width = 12;
 
-				// Set colors for all folding markers
-				for(int i = 25; i < 32; i++)
-				{
-					scriptedit.Markers[i].SetForeColor(SystemColors.ControlLightLight);
-					scriptedit.Markers[i].SetBackColor(SystemColors.ControlDark);
-				}
-
 				// Configure folding markers with respective symbols
 				scriptedit.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
 				scriptedit.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
@@ -907,7 +907,7 @@ namespace CodeImp.DoomBuilder.Controls
 			{
 				if(line.IndexOf(separator[0], StringComparison.Ordinal) != -1) 
 				{
-					if(General.Settings.SnippetsAllmanStyle)
+					if(General.Settings.ScriptAllmanStyle)
 						result.AddRange(line.Split(separator, StringSplitOptions.RemoveEmptyEntries));
 					else
 						result.Add(line.Replace(separator[0], " "));
@@ -1097,27 +1097,35 @@ namespace CodeImp.DoomBuilder.Controls
 			}
 
 			// Auto-match braces
-			//TODO: Auto-match quotes
-			bool endpos = (scriptedit.CurrentPosition == scriptedit.TextLength);
-			if(!string.IsNullOrEmpty(scriptconfig.CodeBlockOpen) && e.Char == scriptconfig.CodeBlockOpen[0] && !string.IsNullOrEmpty(scriptconfig.CodeBlockClose) &&
-				(endpos || (char)scriptedit.GetCharAt(scriptedit.CurrentPosition + 1) != scriptconfig.CodeBlockClose[0]))
+			if(General.Settings.ScriptAutoCloseBrackets)
 			{
-				scriptedit.InsertText(scriptedit.CurrentPosition, scriptconfig.CodeBlockClose);
-			}
-			else if(!string.IsNullOrEmpty(scriptconfig.FunctionOpen) && e.Char == scriptconfig.FunctionOpen[0] && !string.IsNullOrEmpty(scriptconfig.FunctionClose) &&
-				(endpos || (char)scriptedit.GetCharAt(scriptedit.CurrentPosition + 1) != scriptconfig.FunctionClose[0]))
-			{
-				scriptedit.InsertText(scriptedit.CurrentPosition, scriptconfig.FunctionClose);
-			}
-			else if(!string.IsNullOrEmpty(scriptconfig.ArrayOpen) && e.Char == scriptconfig.ArrayOpen[0] && !string.IsNullOrEmpty(scriptconfig.ArrayClose) &&
-				(endpos || (char)scriptedit.GetCharAt(scriptedit.CurrentPosition + 1) != scriptconfig.ArrayClose[0]))
-			{
-				scriptedit.InsertText(scriptedit.CurrentPosition, scriptconfig.ArrayClose);
+				//TODO: Auto-match quotes
+				bool endpos = (scriptedit.CurrentPosition == scriptedit.TextLength);
+				if(!string.IsNullOrEmpty(scriptconfig.CodeBlockOpen) && e.Char == scriptconfig.CodeBlockOpen[0] && !string.IsNullOrEmpty(scriptconfig.CodeBlockClose) &&
+					(endpos || (char)scriptedit.GetCharAt(scriptedit.CurrentPosition + 1) != scriptconfig.CodeBlockClose[0]))
+				{
+					scriptedit.InsertText(scriptedit.CurrentPosition, scriptconfig.CodeBlockClose);
+					return;
+				}
+				
+				if(!string.IsNullOrEmpty(scriptconfig.FunctionOpen) && e.Char == scriptconfig.FunctionOpen[0] && !string.IsNullOrEmpty(scriptconfig.FunctionClose) &&
+					(endpos || (char)scriptedit.GetCharAt(scriptedit.CurrentPosition + 1) != scriptconfig.FunctionClose[0]))
+				{
+					scriptedit.InsertText(scriptedit.CurrentPosition, scriptconfig.FunctionClose);
+					return;
+				}
+				
+				if(!string.IsNullOrEmpty(scriptconfig.ArrayOpen) && e.Char == scriptconfig.ArrayOpen[0] && !string.IsNullOrEmpty(scriptconfig.ArrayClose) &&
+					(endpos || (char)scriptedit.GetCharAt(scriptedit.CurrentPosition + 1) != scriptconfig.ArrayClose[0]))
+				{
+					scriptedit.InsertText(scriptedit.CurrentPosition, scriptconfig.ArrayClose);
+					return;
+				}
 			}
-			else
+
+			if(General.Settings.ScriptAutoShowAutocompletion)
 			{
 				// Display the autocompletion list
-				// TODO: make this behaviour optional?
 				ShowAutoCompletionList();
 			}
 		}
@@ -1205,23 +1213,19 @@ namespace CodeImp.DoomBuilder.Controls
 
 				// Need to increase indentation? We do this when:
 				// 1. Line contains '{' and '}' and the cursor is between them
-				// 2. Line either doesn't contain '}', or it's before '{', it contains '{' and the cursor is after it 
-				// 3. Line doesn't contain ';', line contains ')' and the cursor is after it
+				// 2. Line either doesn't contain '}', or it's before '{', or the line contains '{' and the cursor is after it 
 				int blockopenpos = (string.IsNullOrEmpty(scriptconfig.CodeBlockOpen) ? -1 : linetext.LastIndexOf(scriptconfig.CodeBlockOpen, selectionpos, StringComparison.Ordinal));
 				int blockclosepos = (string.IsNullOrEmpty(scriptconfig.CodeBlockOpen) ? -1 : linetext.IndexOf(scriptconfig.CodeBlockClose, selectionpos, StringComparison.Ordinal));
-				int funcclosepos = (string.IsNullOrEmpty(scriptconfig.FunctionClose) ? -1 : linetext.LastIndexOf(scriptconfig.FunctionClose, StringComparison.Ordinal));
 
 				// Add indentation when the cursor is between { and }
 				bool addindent = (blockopenpos != -1 && blockopenpos < selectionpos) && (blockclosepos == -1 || (blockopenpos < blockclosepos && blockclosepos >= selectionpos));
-				bool isblockindent = addindent;
-				addindent |= funcclosepos != -1 && blockopenpos == -1 && funcclosepos < selectionpos && !linetext.Contains(scriptconfig.Terminator);
 				if(addindent) indent += scriptedit.TabWidth;
 
 				// Calculate indentation
 				string indentstr = GetIndentationString(indent);
 
-				// Move CodeBlockOpen to the new line (will be applied in scriptedit_CharAdded)?
-				expandcodeblock = (isblockindent && General.Settings.SnippetsAllmanStyle);
+				// Move CodeBlockOpen to the new line? (will be applied in scriptedit_CharAdded)
+				expandcodeblock = General.Settings.ScriptAllmanStyle;
 
 				// Offset closing block char?
 				if(addindent && blockclosepos != -1)
diff --git a/Source/Core/Controls/ScriptEditorPreviewControl.Designer.cs b/Source/Core/Controls/ScriptEditorPreviewControl.Designer.cs
new file mode 100644
index 000000000..baa722da6
--- /dev/null
+++ b/Source/Core/Controls/ScriptEditorPreviewControl.Designer.cs
@@ -0,0 +1,68 @@
+namespace CodeImp.DoomBuilder.Controls
+{
+	partial class ScriptEditorPreviewControl
+	{
+		/// <summary> 
+		/// Required designer variable.
+		/// </summary>
+		private System.ComponentModel.IContainer components = null;
+
+		/// <summary> 
+		/// Clean up any resources being used.
+		/// </summary>
+		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+		protected override void Dispose(bool disposing)
+		{
+			if(disposing && (components != null))
+			{
+				components.Dispose();
+			}
+			base.Dispose(disposing);
+		}
+
+		#region Component Designer generated code
+
+		/// <summary> 
+		/// Required method for Designer support - do not modify 
+		/// the contents of this method with the code editor.
+		/// </summary>
+		private void InitializeComponent()
+		{
+			this.scriptedit = new ScintillaNET.Scintilla();
+			this.SuspendLayout();
+			// 
+			// scriptedit
+			// 
+			this.scriptedit.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+			this.scriptedit.CaretWidth = 2;
+			this.scriptedit.Dock = System.Windows.Forms.DockStyle.Fill;
+			this.scriptedit.ExtraAscent = 1;
+			this.scriptedit.ExtraDescent = 1;
+			this.scriptedit.FontQuality = ScintillaNET.FontQuality.LcdOptimized;
+			this.scriptedit.Location = new System.Drawing.Point(0, 0);
+			this.scriptedit.Name = "scriptedit";
+			this.scriptedit.ScrollWidth = 200;
+			this.scriptedit.Size = new System.Drawing.Size(300, 150);
+			this.scriptedit.TabIndex = 1;
+			this.scriptedit.TabStop = false;
+			this.scriptedit.UseTabs = true;
+			this.scriptedit.ViewWhitespace = ScintillaNET.WhitespaceMode.VisibleAlways;
+			this.scriptedit.WhitespaceSize = 2;
+			this.scriptedit.UpdateUI += new System.EventHandler<ScintillaNET.UpdateUIEventArgs>(this.scriptedit_UpdateUI);
+			// 
+			// ScriptEditorPreviewControl
+			// 
+			this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
+			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
+			this.Controls.Add(this.scriptedit);
+			this.Name = "ScriptEditorPreviewControl";
+			this.Size = new System.Drawing.Size(300, 150);
+			this.ResumeLayout(false);
+
+		}
+
+		#endregion
+
+		private ScintillaNET.Scintilla scriptedit;
+	}
+}
diff --git a/Source/Core/Controls/ScriptEditorPreviewControl.cs b/Source/Core/Controls/ScriptEditorPreviewControl.cs
new file mode 100644
index 000000000..1e28fe87a
--- /dev/null
+++ b/Source/Core/Controls/ScriptEditorPreviewControl.cs
@@ -0,0 +1,413 @@
+#region ================== Namespaces
+
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Windows.Forms;
+using CodeImp.DoomBuilder.Rendering;
+using ScintillaNET;
+
+#endregion
+
+namespace CodeImp.DoomBuilder.Controls
+{
+	internal partial class ScriptEditorPreviewControl : UserControl
+	{
+		#region ================== Constants
+
+		private const int HIGHLIGHT_INDICATOR = 8;
+
+		#endregion
+
+		#region ================== Variables
+
+		private Dictionary<int, ScriptStyleType> styletranslation;
+		private string highlightedword;
+		private Color indicatorcolor;
+		private int lastcaretpos;
+		private readonly HashSet<char> bracechars; 
+
+		#endregion
+
+		#region ================== Properties
+
+		public string FontName { set { ApplyFont(value); } }
+		public int FontSize { set { ApplyFontSize(value); } }
+		public bool FontBold { set { ApplyFontBold(value); } }
+		public int TabWidth { set { scriptedit.TabWidth = value; } }
+		public bool ShowLineNumbers { set { UpdateLineNumbers(value); } }
+		public bool ShowFolding { set { UpdateFolding(value); } }
+
+		// Colors
+		public Color ScriptBackground 
+		{ 
+			set
+			{ 
+				scriptedit.Styles[Style.Default].BackColor = value;
+				scriptedit.CaretForeColor = PixelColor.FromColor(value).Inverse().ToColor();
+				scriptedit.Styles[Style.LineNumber].BackColor = value;
+				scriptedit.SetWhitespaceBackColor(true, value);
+
+				foreach(KeyValuePair<int, ScriptStyleType> group in styletranslation)
+					scriptedit.Styles[group.Key].BackColor = value;
+			} 
+		}
+
+		public Color FoldForeColor { set { for(int i = 25; i < 32; i++) scriptedit.Markers[i].SetBackColor(value); } }
+		public Color FoldBackColor
+		{
+			set
+			{
+				scriptedit.SetFoldMarginColor(true, value);
+				scriptedit.SetFoldMarginHighlightColor(true, value);
+				for(int i = 25; i < 32; i++) scriptedit.Markers[i].SetForeColor(value);
+			}
+		}
+
+		public Color LineNumbers { set { ApplyStyleColor(ScriptStyleType.LineNumber, value); } }
+		public Color PlainText { set { ApplyStyleColor(ScriptStyleType.PlainText, value); } }
+		public Color Comments { set { ApplyStyleColor(ScriptStyleType.Comment, value); } }
+		public Color Keywords { set { ApplyStyleColor(ScriptStyleType.Keyword, value); } }
+		public Color Literals { set { ApplyStyleColor(ScriptStyleType.Literal, value); } }
+		public Color Constants { set { ApplyStyleColor(ScriptStyleType.Constant, value); } }
+		public Color Strings { set { ApplyStyleColor(ScriptStyleType.String, value); } }
+		public Color Includes { set { ApplyStyleColor(ScriptStyleType.Include, value); } }
+
+		public Color SelectionForeColor { set { scriptedit.SetSelectionForeColor(true, value); } }
+		public Color SelectionBackColor { set { scriptedit.SetSelectionBackColor(true, value); } }
+		public Color WhitespaceColor { set { scriptedit.SetWhitespaceForeColor(true, value); } }
+		public Color BraceHighlight { set { scriptedit.Styles[Style.BraceLight].BackColor = value; } }
+		public Color BadBraceHighlight { set { scriptedit.Styles[Style.BraceBad].BackColor = value; } }
+		public Color ScriptIndicator { set { indicatorcolor = value; UpdateWordHighlight(); } }
+
+		#endregion
+
+		#region ================== Constructor / Setup
+
+		public ScriptEditorPreviewControl()
+		{
+			InitializeComponent();
+
+			if(LicenseManager.UsageMode != LicenseUsageMode.Designtime)
+			{
+				bracechars = new HashSet<char> { '{', '}', '(', ')', '[', ']' };
+				SetupStyles();
+			}
+		}
+
+		// This sets up the script editor with default settings
+		private void SetupStyles()
+		{
+			// Symbol margin
+			scriptedit.Margins[0].Type = MarginType.Symbol;
+			scriptedit.Margins[0].Width = 20;
+			scriptedit.Margins[0].Mask = 0; // No markers here
+			scriptedit.Margins[0].Cursor = MarginCursor.Arrow;
+			scriptedit.Margins[0].Sensitive = true;
+
+			// Line numbers margin
+			if(General.Settings.ScriptShowLineNumbers)
+			{
+				scriptedit.Margins[1].Type = MarginType.Number;
+				scriptedit.Margins[1].Width = 16;
+			}
+			scriptedit.Margins[1].Mask = 0; // No markers here
+
+			// Spacing margin
+			scriptedit.Margins[2].Type = MarginType.Symbol;
+			scriptedit.Margins[2].Width = 5;
+			scriptedit.Margins[2].Cursor = MarginCursor.Arrow;
+			scriptedit.Margins[2].Mask = 0; // No markers here
+
+			// Set lexer
+			scriptedit.Lexer = Lexer.CppNoCase;
+
+			// Set script editor preview text
+			scriptedit.Text = "#include \"zcommon.acs\"" + "\n" +
+							  "script 667 ENTER //A simple script example" + "\n" +
+							  "{" + "\n" +
+								"    int red = CR_RED;" + "\n" +
+								"\tPrint(s:\"Welcome!\");" + "\n" +
+								"\tThing_ChangeTID(0, 667);" + "\n" +
+			                  "} } // <- A spare brace!";
+
+			// No text editing beyond this point!
+			scriptedit.ReadOnly = true;
+
+			// Set keywords (0)
+			const string keywords = "script enter Print int HudMessageBold Thing_ChangeTID";
+			scriptedit.SetKeywords(0, keywords.ToLowerInvariant());
+
+			// Set constants (1);
+			const string constants = "CR_RED";
+			scriptedit.SetKeywords(1, constants.ToLowerInvariant());
+
+			// Reset document slyle
+			scriptedit.ClearDocumentStyle();
+			scriptedit.StyleResetDefault();
+
+			// Create style translation dictionary
+			styletranslation = new Dictionary<int, ScriptStyleType>
+			{
+				{ 0, ScriptStyleType.PlainText }, // End of line
+				{ 10, ScriptStyleType.PlainText }, // Operator
+				{ 11, ScriptStyleType.PlainText }, // Identifier
+				{ 33, ScriptStyleType.LineNumber },
+				{ 1, ScriptStyleType.Comment },
+				{ 2, ScriptStyleType.Comment },
+				{ 5, ScriptStyleType.Keyword },
+				{ 4, ScriptStyleType.Literal },
+				{ 7, ScriptStyleType.Literal },
+				{ 16, ScriptStyleType.Constant },
+				{ 37, ScriptStyleType.LineNumber },
+				{ 6, ScriptStyleType.String },
+				{ 9, ScriptStyleType.Include },
+			};
+
+			// Set the default style and settings
+			scriptedit.Styles[Style.Default].Font = General.Settings.ScriptFontName;
+			scriptedit.Styles[Style.Default].Size = General.Settings.ScriptFontSize;
+			scriptedit.Styles[Style.Default].Bold = General.Settings.ScriptFontBold;
+			scriptedit.Styles[Style.Default].Italic = false;
+			scriptedit.Styles[Style.Default].Underline = false;
+			scriptedit.Styles[Style.Default].Case = StyleCase.Mixed;
+			scriptedit.Styles[Style.Default].ForeColor = General.Colors.PlainText.ToColor();
+			scriptedit.Styles[Style.Default].BackColor = General.Colors.ScriptBackground.ToColor();
+			scriptedit.CaretPeriod = SystemInformation.CaretBlinkTime;
+			scriptedit.CaretForeColor = General.Colors.ScriptBackground.Inverse().ToColor();
+
+			// Set tabulation settings
+			scriptedit.UseTabs = General.Settings.ScriptUseTabs;
+			scriptedit.TabWidth = General.Settings.ScriptTabWidth;
+
+			// This applies the default style to all styles
+			scriptedit.StyleClearAll();
+
+			// Set style for linenumbers and margins
+			scriptedit.Styles[Style.LineNumber].BackColor = General.Colors.ScriptBackground.ToColor();
+			scriptedit.SetFoldMarginColor(true, General.Colors.ScriptFoldBackColor.ToColor());
+			scriptedit.SetFoldMarginHighlightColor(true, General.Colors.ScriptFoldBackColor.ToColor());
+			for(int i = 25; i < 32; i++)
+			{
+				scriptedit.Markers[i].SetForeColor(General.Colors.ScriptFoldBackColor.ToColor());
+				scriptedit.Markers[i].SetBackColor(General.Colors.ScriptFoldForeColor.ToColor());
+			}
+
+			// Set style for (mis)matching braces
+			scriptedit.Styles[Style.BraceLight].BackColor = General.Colors.ScriptBraceHighlight.ToColor();
+			scriptedit.Styles[Style.BraceBad].BackColor = General.Colors.ScriptBadBraceHighlight.ToColor();
+
+			// Set whitespace color
+			scriptedit.SetWhitespaceForeColor(true, General.Colors.ScriptWhitespace.ToColor());
+
+			// Set selection colors
+			scriptedit.SetSelectionForeColor(true, General.Colors.ScriptSelectionForeColor.ToColor());
+			scriptedit.SetSelectionBackColor(true, General.Colors.ScriptSelectionBackColor.ToColor());
+			indicatorcolor = General.Colors.ScriptIndicator.ToColor();
+
+			// Set words colors
+			foreach(KeyValuePair<int, ScriptStyleType> group in styletranslation)
+			{
+				// Apply color to style
+				int colorindex;
+				switch(group.Value)
+				{
+					case ScriptStyleType.PlainText: colorindex = ColorCollection.PLAINTEXT; break;
+					case ScriptStyleType.Comment: colorindex = ColorCollection.COMMENTS; break;
+					case ScriptStyleType.Constant: colorindex = ColorCollection.CONSTANTS; break;
+					case ScriptStyleType.Keyword: colorindex = ColorCollection.KEYWORDS; break;
+					case ScriptStyleType.LineNumber: colorindex = ColorCollection.LINENUMBERS; break;
+					case ScriptStyleType.Literal: colorindex = ColorCollection.LITERALS; break;
+					case ScriptStyleType.String: colorindex = ColorCollection.STRINGS; break;
+					case ScriptStyleType.Include: colorindex = ColorCollection.INCLUDES; break;
+					default: colorindex = ColorCollection.PLAINTEXT; break;
+				}
+
+				scriptedit.Styles[group.Key].ForeColor = General.Colors.Colors[colorindex].ToColor();
+				scriptedit.Styles[group.Key].BackColor = General.Colors.ScriptBackground.ToColor();
+			}
+
+			// Setup folding
+			UpdateFolding(General.Settings.ScriptShowFolding);
+
+			// Rearrange the layout
+			this.PerformLayout();
+		}
+
+		#endregion
+
+		#region ================== Methods
+
+		private void ApplyStyleColor(ScriptStyleType type, Color color)
+		{
+			foreach(KeyValuePair<int, ScriptStyleType> group in styletranslation)
+				if(group.Value == type) scriptedit.Styles[group.Key].ForeColor = color;
+		}
+
+		private void ApplyFont(string font)
+		{
+			foreach(KeyValuePair<int, ScriptStyleType> group in styletranslation)
+				scriptedit.Styles[group.Key].Font = font;
+		}
+
+		private void ApplyFontBold(bool bold)
+		{
+			foreach(KeyValuePair<int, ScriptStyleType> group in styletranslation)
+				scriptedit.Styles[group.Key].Bold = bold;
+		}
+
+		private void ApplyFontSize(int size)
+		{
+			foreach(KeyValuePair<int, ScriptStyleType> group in styletranslation)
+				scriptedit.Styles[group.Key].Size = size;
+		}
+
+		private void UpdateLineNumbers(bool show)
+		{
+			if(show)
+			{
+				scriptedit.Margins[1].Type = MarginType.Number;
+				scriptedit.Margins[1].Width = 16;
+			}
+			else
+			{
+				scriptedit.Margins[1].Type = MarginType.Symbol;
+				scriptedit.Margins[1].Width = 0;
+			}
+		}
+
+		private void UpdateFolding(bool show)
+		{
+			if(show)
+			{
+				// Instruct the lexer to calculate folding
+				scriptedit.SetProperty("fold", "1");
+				scriptedit.SetProperty("fold.compact", "1");
+
+				// Configure a margin to display folding symbols
+				scriptedit.Margins[2].Type = MarginType.Symbol;
+				scriptedit.Margins[2].Mask = Marker.MaskFolders;
+				scriptedit.Margins[2].Sensitive = true;
+				scriptedit.Margins[2].Width = 12;
+
+				// Configure folding markers with respective symbols
+				scriptedit.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
+				scriptedit.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
+				scriptedit.Markers[Marker.FolderEnd].Symbol = MarkerSymbol.BoxPlusConnected;
+				scriptedit.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
+				scriptedit.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
+				scriptedit.Markers[Marker.FolderSub].Symbol = MarkerSymbol.VLine;
+				scriptedit.Markers[Marker.FolderTail].Symbol = MarkerSymbol.LCorner;
+
+				// Enable automatic folding
+				scriptedit.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change);
+			}
+			else
+			{
+				// Disable folding
+				scriptedit.SetProperty("fold", "0");
+				scriptedit.SetProperty("fold.compact", "0");
+
+				scriptedit.Margins[2].Type = MarginType.Symbol;
+				scriptedit.Margins[2].Mask = 0; // No markers here
+				scriptedit.Margins[2].Sensitive = false;
+				scriptedit.Margins[2].Width = 5;
+
+				scriptedit.AutomaticFold = AutomaticFold.None;
+			}
+		}
+
+		private void UpdateWordHighlight()
+		{
+			// If a word is selected, highlight the same words
+			if(scriptedit.SelectedText != highlightedword)
+			{
+				// Highlight only when whole word is selected
+				if(!string.IsNullOrEmpty(scriptedit.SelectedText) && scriptedit.GetWordFromPosition(scriptedit.SelectionStart) == scriptedit.SelectedText) {
+					HighlightWord(scriptedit.SelectedText);
+				}
+				else
+				{
+					// Clear highlight
+					scriptedit.IndicatorCurrent = HIGHLIGHT_INDICATOR;
+					scriptedit.IndicatorClearRange(0, scriptedit.TextLength);
+				}
+
+				highlightedword = scriptedit.SelectedText;
+			}
+		}
+
+		private void HighlightWord(string text)
+		{
+			// Remove all uses of our indicator
+			scriptedit.IndicatorCurrent = HIGHLIGHT_INDICATOR;
+			scriptedit.IndicatorClearRange(0, scriptedit.TextLength);
+
+			// Update indicator appearance
+			scriptedit.Indicators[HIGHLIGHT_INDICATOR].Style = IndicatorStyle.RoundBox;
+			scriptedit.Indicators[HIGHLIGHT_INDICATOR].Under = true;
+			scriptedit.Indicators[HIGHLIGHT_INDICATOR].ForeColor = indicatorcolor;
+			scriptedit.Indicators[HIGHLIGHT_INDICATOR].OutlineAlpha = 50;
+			scriptedit.Indicators[HIGHLIGHT_INDICATOR].Alpha = 30;
+
+			// Search the document
+			scriptedit.TargetStart = 0;
+			scriptedit.TargetEnd = scriptedit.TextLength;
+			scriptedit.SearchFlags = SearchFlags.WholeWord;
+
+			while(scriptedit.SearchInTarget(text) != -1)
+			{
+				//mxd. Don't mark currently selected word
+				if(scriptedit.SelectionStart != scriptedit.TargetStart && scriptedit.SelectionEnd != scriptedit.TargetEnd)
+				{
+					// Mark the search results with the current indicator
+					scriptedit.IndicatorFillRange(scriptedit.TargetStart, scriptedit.TargetEnd - scriptedit.TargetStart);
+				}
+
+				// Search the remainder of the document
+				scriptedit.TargetStart = scriptedit.TargetEnd;
+				scriptedit.TargetEnd = scriptedit.TextLength;
+			}
+		}
+
+		#endregion
+
+		#region ================== Events
+
+		private void scriptedit_UpdateUI(object sender, UpdateUIEventArgs e)
+		{
+			UpdateWordHighlight();
+
+			// Has the caret changed position?
+			int caretpos = scriptedit.CurrentPosition;
+			if(lastcaretpos != caretpos)
+			{
+				lastcaretpos = caretpos;
+				int bracepos1 = -1;
+
+				// Is there a brace to the left or right?
+				if(caretpos > 0 && bracechars.Contains((char)scriptedit.GetCharAt(caretpos - 1)))
+					bracepos1 = (caretpos - 1);
+				else if(bracechars.Contains((char)(scriptedit.GetCharAt(caretpos))))
+					bracepos1 = caretpos;
+
+				if(bracepos1 > -1)
+				{
+					// Find the matching brace
+					int bracepos2 = scriptedit.BraceMatch(bracepos1);
+					if(bracepos2 == Scintilla.InvalidPosition)
+						scriptedit.BraceBadLight(bracepos1);
+					else
+						scriptedit.BraceHighlight(bracepos1, bracepos2);
+				}
+				else
+				{
+					// Turn off brace matching
+					scriptedit.BraceHighlight(Scintilla.InvalidPosition, Scintilla.InvalidPosition);
+				}
+			}
+		}
+
+		#endregion
+	}
+}
diff --git a/Source/Core/Controls/ScriptEditorPreviewControl.resx b/Source/Core/Controls/ScriptEditorPreviewControl.resx
new file mode 100644
index 000000000..ff31a6db5
--- /dev/null
+++ b/Source/Core/Controls/ScriptEditorPreviewControl.resx
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>
\ No newline at end of file
diff --git a/Source/Core/Rendering/ColorCollection.cs b/Source/Core/Rendering/ColorCollection.cs
index aaaa315e7..8ddf95854 100644
--- a/Source/Core/Rendering/ColorCollection.cs
+++ b/Source/Core/Rendering/ColorCollection.cs
@@ -37,7 +37,7 @@ namespace CodeImp.DoomBuilder.Rendering
 		private const float DARK_ADDITION = -0.2f;
 
 		// Palette size
-		private const int NUM_COLORS = 49;
+		private const int NUM_COLORS = 51;
 		public const int NUM_THING_COLORS = 20;
 		public const int THING_COLORS_OFFSET = 20;
 
@@ -91,6 +91,8 @@ namespace CodeImp.DoomBuilder.Rendering
 		public const int SCRIPTSELECTIONBACK = 46;
 		public const int STRINGS = 47;
 		public const int INCLUDES = 48;
+		public const int SCRIPTFOLDFORE = 49;
+		public const int SCRIPTFOLDBACK = 50;
 		
 		#endregion
 
@@ -131,18 +133,22 @@ namespace CodeImp.DoomBuilder.Rendering
 		public PixelColor Selection3D { get { return colors[SELECTION3D]; } internal set { colors[SELECTION3D] = value; } }
 		
 		public PixelColor ScriptBackground { get { return colors[SCRIPTBACKGROUND]; } internal set { colors[SCRIPTBACKGROUND] = value; } }
-		public PixelColor ScriptIndicator { get { return colors[SCRIPTINDICATOR]; } internal set { colors[SCRIPTINDICATOR] = value; } }
-		public PixelColor ScriptBraceHighlight { get { return colors[SCRIPTBRACEHIGHLIGHT]; } internal set { colors[SCRIPTBRACEHIGHLIGHT] = value; } }
-		public PixelColor ScriptBadBraceHighlight { get { return colors[SCRIPTBADBRACEHIGHLIGHT]; } internal set { colors[SCRIPTBADBRACEHIGHLIGHT] = value; } }
-		public PixelColor ScriptWhitespace { get { return colors[SCRIPTWHITESPACE]; } internal set { colors[SCRIPTWHITESPACE] = value; } }
-		public PixelColor ScriptSelectionForeColor { get { return colors[SCRIPTSELECTIONFORE]; } internal set { colors[SCRIPTSELECTIONFORE] = value; } }
-		public PixelColor ScriptSelectionBackColor { get { return colors[SCRIPTSELECTIONBACK]; } internal set { colors[SCRIPTSELECTIONBACK] = value; } }
+		public PixelColor ScriptIndicator { get { return colors[SCRIPTINDICATOR]; } internal set { colors[SCRIPTINDICATOR] = value; } } //mxd
+		public PixelColor ScriptBraceHighlight { get { return colors[SCRIPTBRACEHIGHLIGHT]; } internal set { colors[SCRIPTBRACEHIGHLIGHT] = value; } } //mxd
+		public PixelColor ScriptBadBraceHighlight { get { return colors[SCRIPTBADBRACEHIGHLIGHT]; } internal set { colors[SCRIPTBADBRACEHIGHLIGHT] = value; } } //mxd
+		public PixelColor ScriptWhitespace { get { return colors[SCRIPTWHITESPACE]; } internal set { colors[SCRIPTWHITESPACE] = value; } } //mxd
+		public PixelColor ScriptSelectionForeColor { get { return colors[SCRIPTSELECTIONFORE]; } internal set { colors[SCRIPTSELECTIONFORE] = value; } } //mxd
+		public PixelColor ScriptSelectionBackColor { get { return colors[SCRIPTSELECTIONBACK]; } internal set { colors[SCRIPTSELECTIONBACK] = value; } } //mxd
 		public PixelColor LineNumbers { get { return colors[LINENUMBERS]; } internal set { colors[LINENUMBERS] = value; } }
 		public PixelColor PlainText { get { return colors[PLAINTEXT]; } internal set { colors[PLAINTEXT] = value; } }
 		public PixelColor Comments { get { return colors[COMMENTS]; } internal set { colors[COMMENTS] = value; } }
 		public PixelColor Keywords { get { return colors[KEYWORDS]; } internal set { colors[KEYWORDS] = value; } }
 		public PixelColor Literals { get { return colors[LITERALS]; } internal set { colors[LITERALS] = value; } }
 		public PixelColor Constants { get { return colors[CONSTANTS]; } internal set { colors[CONSTANTS] = value; } }
+		public PixelColor Strings { get { return colors[STRINGS]; } internal set { colors[STRINGS] = value; } } //mxd
+		public PixelColor Includes { get { return colors[INCLUDES]; } internal set { colors[INCLUDES] = value; } } //mxd
+		public PixelColor ScriptFoldForeColor { get { return colors[SCRIPTFOLDFORE]; } internal set { colors[SCRIPTFOLDFORE] = value; } } //mxd
+		public PixelColor ScriptFoldBackColor { get { return colors[SCRIPTFOLDBACK]; } internal set { colors[SCRIPTFOLDBACK] = value; } } //mxd
 		
 		#endregion
 
@@ -217,6 +223,8 @@ namespace CodeImp.DoomBuilder.Rendering
 			if(colors[SCRIPTSELECTIONBACK].ToInt() == 0) colors[SCRIPTSELECTIONBACK] = PixelColor.FromInt(-13395457);
 			if(colors[STRINGS].ToInt() == 0) colors[STRINGS] = PixelColor.FromInt(-6089451);
 			if(colors[INCLUDES].ToInt() == 0) colors[INCLUDES] = PixelColor.FromInt(-9868951);
+			if(colors[SCRIPTFOLDFORE].ToInt() == 0) colors[SCRIPTFOLDFORE] = PixelColor.FromColor(SystemColors.ControlLightLight);
+			if(colors[SCRIPTFOLDBACK].ToInt() == 0) colors[SCRIPTFOLDBACK] = PixelColor.FromColor(SystemColors.ControlDark);
 			
 			// Create assist colors
 			CreateAssistColors();
diff --git a/Source/Core/Resources/Lexers.cfg b/Source/Core/Resources/Lexers.cfg
index 5cb1b9ce3..a91136d3f 100644
--- a/Source/Core/Resources/Lexers.cfg
+++ b/Source/Core/Resources/Lexers.cfg
@@ -23,13 +23,13 @@ lexer1	// None
 
 lexer3	// CPP-style, case-sensitive
 {
-	0 = 0;		// plain text
+	10 = 0;		// operator -> plain text
+	11 = 0;		// identifier -> plain text
 	33 = 5;	  // line numbers
 	1 = 3;		// comments
 	2 = 3;		// comments
 	5 = 1;		// keywords
 	4 = 4;		// literal
-	6 = 4;		// literal
 	7 = 4;		// literal
 	16 = 2;	  // constants
 	37 = 5;   // ident guides
@@ -79,13 +79,13 @@ lexer18	// Pascal-style
 
 lexer35	// CPP-style, case-insensitive
 {
-	0 = 0;		// plain text
+	10 = 0;		// operator -> plain text
+	11 = 0;		// identifier -> plain text
 	33 = 5;	  // line numbers
 	1 = 3;		// comments
 	2 = 3;		// comments
 	5 = 1;		// keywords
 	4 = 4;		// literal
-	6 = 4;		// literal
 	7 = 4;		// literal
 	16 = 2;	  // constants
 	37 = 5;   // ident guides
diff --git a/Source/Core/Windows/PreferencesForm.Designer.cs b/Source/Core/Windows/PreferencesForm.Designer.cs
index 58e4282ef..f47f11997 100644
--- a/Source/Core/Windows/PreferencesForm.Designer.cs
+++ b/Source/Core/Windows/PreferencesForm.Designer.cs
@@ -152,29 +152,49 @@ namespace CodeImp.DoomBuilder.Windows
 			this.classicbilinear = new System.Windows.Forms.CheckBox();
 			this.imagebrightnesslabel = new System.Windows.Forms.Label();
 			this.imagebrightness = new System.Windows.Forms.TrackBar();
-			this.colorsgroup3 = new System.Windows.Forms.GroupBox();
-			this.snippetsallmanstyle = new System.Windows.Forms.CheckBox();
-			this.scripttabwidth = new CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox();
-			this.scriptautoindent = new System.Windows.Forms.CheckBox();
+			this.tabscripteditor = new System.Windows.Forms.TabPage();
+			this.groupBox9 = new System.Windows.Forms.GroupBox();
+			this.scriptshowfolding = new System.Windows.Forms.CheckBox();
+			this.scriptshowlinenumbers = new System.Windows.Forms.CheckBox();
+			this.groupBox8 = new System.Windows.Forms.GroupBox();
+			this.scriptautoshowautocompletion = new System.Windows.Forms.CheckBox();
+			this.scriptautoclosebrackets = new System.Windows.Forms.CheckBox();
+			this.scriptusetabs = new System.Windows.Forms.CheckBox();
+			this.scriptallmanstyle = new System.Windows.Forms.CheckBox();
 			this.label10 = new System.Windows.Forms.Label();
-			this.fontpreview = new System.Windows.Forms.RichTextBox();
-			this.scriptfontsize = new System.Windows.Forms.ComboBox();
-			this.label8 = new System.Windows.Forms.Label();
-			this.scriptfontbold = new System.Windows.Forms.CheckBox();
-			this.scriptfontname = new System.Windows.Forms.ComboBox();
+			this.scriptautoindent = new System.Windows.Forms.CheckBox();
+			this.scripttabwidth = new CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox();
+			this.groupBox7 = new System.Windows.Forms.GroupBox();
 			this.label3 = new System.Windows.Forms.Label();
-			this.colorconstants = new CodeImp.DoomBuilder.Controls.ColorControl();
-			this.colorliterals = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.scriptfontname = new System.Windows.Forms.ComboBox();
+			this.scriptfontbold = new System.Windows.Forms.CheckBox();
+			this.label8 = new System.Windows.Forms.Label();
+			this.scriptfontsize = new System.Windows.Forms.ComboBox();
+			this.groupBox6 = new System.Windows.Forms.GroupBox();
+			this.colorindicator = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorwhitespace = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorbracebad = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorbrace = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorselectionback = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorselectionfore = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorincludes = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorstrings = new CodeImp.DoomBuilder.Controls.ColorControl();
 			this.colorscriptbackground = new CodeImp.DoomBuilder.Controls.ColorControl();
-			this.colorkeywords = new CodeImp.DoomBuilder.Controls.ColorControl();
-			this.colorlinenumbers = new CodeImp.DoomBuilder.Controls.ColorControl();
-			this.colorcomments = new CodeImp.DoomBuilder.Controls.ColorControl();
 			this.colorplaintext = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorcomments = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorlinenumbers = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorkeywords = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorliterals = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorconstants = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.previewgroup = new System.Windows.Forms.GroupBox();
+			this.scriptedit = new CodeImp.DoomBuilder.Controls.ScriptEditorPreviewControl();
 			this.tabpasting = new System.Windows.Forms.TabPage();
 			this.label16 = new System.Windows.Forms.Label();
 			this.pasteoptions = new CodeImp.DoomBuilder.Controls.PasteOptionsControl();
 			this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
 			this.browseScreenshotsFolderDialog = new System.Windows.Forms.FolderBrowserDialog();
+			this.colorfoldfore = new CodeImp.DoomBuilder.Controls.ColorControl();
+			this.colorfoldback = new CodeImp.DoomBuilder.Controls.ColorControl();
 			label7 = new System.Windows.Forms.Label();
 			label6 = new System.Windows.Forms.Label();
 			label5 = new System.Windows.Forms.Label();
@@ -210,7 +230,12 @@ namespace CodeImp.DoomBuilder.Windows
 			((System.ComponentModel.ISupportInitialize)(this.tbDynLightSize)).BeginInit();
 			((System.ComponentModel.ISupportInitialize)(this.tbDynLightCount)).BeginInit();
 			((System.ComponentModel.ISupportInitialize)(this.imagebrightness)).BeginInit();
-			this.colorsgroup3.SuspendLayout();
+			this.tabscripteditor.SuspendLayout();
+			this.groupBox9.SuspendLayout();
+			this.groupBox8.SuspendLayout();
+			this.groupBox7.SuspendLayout();
+			this.groupBox6.SuspendLayout();
+			this.previewgroup.SuspendLayout();
 			this.tabpasting.SuspendLayout();
 			this.SuspendLayout();
 			// 
@@ -797,6 +822,7 @@ namespace CodeImp.DoomBuilder.Windows
 			this.tabs.Controls.Add(this.tabinterface);
 			this.tabs.Controls.Add(this.tabkeys);
 			this.tabs.Controls.Add(this.tabcolors);
+			this.tabs.Controls.Add(this.tabscripteditor);
 			this.tabs.Controls.Add(this.tabpasting);
 			this.tabs.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
 			this.tabs.Location = new System.Drawing.Point(11, 13);
@@ -815,10 +841,10 @@ namespace CodeImp.DoomBuilder.Windows
 			this.tabinterface.Controls.Add(this.groupBox2);
 			this.tabinterface.Controls.Add(groupBox1);
 			this.tabinterface.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-			this.tabinterface.Location = new System.Drawing.Point(4, 23);
+			this.tabinterface.Location = new System.Drawing.Point(4, 22);
 			this.tabinterface.Name = "tabinterface";
 			this.tabinterface.Padding = new System.Windows.Forms.Padding(5);
-			this.tabinterface.Size = new System.Drawing.Size(682, 509);
+			this.tabinterface.Size = new System.Drawing.Size(682, 510);
 			this.tabinterface.TabIndex = 0;
 			this.tabinterface.Text = "Interface";
 			this.tabinterface.UseVisualStyleBackColor = true;
@@ -1230,10 +1256,10 @@ namespace CodeImp.DoomBuilder.Windows
 			this.tabkeys.Controls.Add(this.listactions);
 			this.tabkeys.Controls.Add(this.actioncontrolpanel);
 			this.tabkeys.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-			this.tabkeys.Location = new System.Drawing.Point(4, 23);
+			this.tabkeys.Location = new System.Drawing.Point(4, 22);
 			this.tabkeys.Name = "tabkeys";
 			this.tabkeys.Padding = new System.Windows.Forms.Padding(3);
-			this.tabkeys.Size = new System.Drawing.Size(682, 509);
+			this.tabkeys.Size = new System.Drawing.Size(682, 510);
 			this.tabkeys.TabIndex = 1;
 			this.tabkeys.Text = "Controls";
 			this.tabkeys.UseVisualStyleBackColor = true;
@@ -1409,13 +1435,12 @@ namespace CodeImp.DoomBuilder.Windows
 			// tabcolors
 			// 
 			this.tabcolors.Controls.Add(this.appearancegroup1);
-			this.tabcolors.Controls.Add(this.colorsgroup3);
 			this.tabcolors.Controls.Add(this.colorsgroup1);
 			this.tabcolors.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-			this.tabcolors.Location = new System.Drawing.Point(4, 23);
+			this.tabcolors.Location = new System.Drawing.Point(4, 22);
 			this.tabcolors.Name = "tabcolors";
 			this.tabcolors.Padding = new System.Windows.Forms.Padding(5);
-			this.tabcolors.Size = new System.Drawing.Size(682, 509);
+			this.tabcolors.Size = new System.Drawing.Size(682, 510);
 			this.tabcolors.TabIndex = 2;
 			this.tabcolors.Text = "Appearance";
 			this.tabcolors.UseVisualStyleBackColor = true;
@@ -1446,9 +1471,9 @@ namespace CodeImp.DoomBuilder.Windows
 			this.appearancegroup1.Controls.Add(this.classicbilinear);
 			this.appearancegroup1.Controls.Add(this.imagebrightnesslabel);
 			this.appearancegroup1.Controls.Add(this.imagebrightness);
-			this.appearancegroup1.Location = new System.Drawing.Point(217, 224);
+			this.appearancegroup1.Location = new System.Drawing.Point(217, 14);
 			this.appearancegroup1.Name = "appearancegroup1";
-			this.appearancegroup1.Size = new System.Drawing.Size(457, 277);
+			this.appearancegroup1.Size = new System.Drawing.Size(457, 487);
 			this.appearancegroup1.TabIndex = 24;
 			this.appearancegroup1.TabStop = false;
 			this.appearancegroup1.Text = " Additional Options ";
@@ -1618,45 +1643,131 @@ namespace CodeImp.DoomBuilder.Windows
 			this.imagebrightness.TickStyle = System.Windows.Forms.TickStyle.TopLeft;
 			this.imagebrightness.ValueChanged += new System.EventHandler(this.imagebrightness_ValueChanged);
 			// 
-			// colorsgroup3
+			// tabscripteditor
+			// 
+			this.tabscripteditor.Controls.Add(this.groupBox9);
+			this.tabscripteditor.Controls.Add(this.groupBox8);
+			this.tabscripteditor.Controls.Add(this.groupBox7);
+			this.tabscripteditor.Controls.Add(this.groupBox6);
+			this.tabscripteditor.Controls.Add(this.previewgroup);
+			this.tabscripteditor.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+			this.tabscripteditor.Location = new System.Drawing.Point(4, 22);
+			this.tabscripteditor.Name = "tabscripteditor";
+			this.tabscripteditor.Size = new System.Drawing.Size(682, 510);
+			this.tabscripteditor.TabIndex = 4;
+			this.tabscripteditor.Text = "Script Editor";
+			this.tabscripteditor.UseVisualStyleBackColor = true;
+			// 
+			// groupBox9
+			// 
+			this.groupBox9.Controls.Add(this.scriptshowfolding);
+			this.groupBox9.Controls.Add(this.scriptshowlinenumbers);
+			this.groupBox9.Location = new System.Drawing.Point(217, 260);
+			this.groupBox9.Name = "groupBox9";
+			this.groupBox9.Size = new System.Drawing.Size(457, 78);
+			this.groupBox9.TabIndex = 6;
+			this.groupBox9.TabStop = false;
+			this.groupBox9.Text = " Appearance ";
+			// 
+			// scriptshowfolding
+			// 
+			this.scriptshowfolding.AutoSize = true;
+			this.scriptshowfolding.Location = new System.Drawing.Point(19, 49);
+			this.scriptshowfolding.Name = "scriptshowfolding";
+			this.scriptshowfolding.Size = new System.Drawing.Size(120, 17);
+			this.scriptshowfolding.TabIndex = 38;
+			this.scriptshowfolding.Text = "Enable code folding";
+			this.scriptshowfolding.UseVisualStyleBackColor = true;
+			this.scriptshowfolding.CheckedChanged += new System.EventHandler(this.scriptshowfolding_CheckedChanged);
+			// 
+			// scriptshowlinenumbers
+			// 
+			this.scriptshowlinenumbers.AutoSize = true;
+			this.scriptshowlinenumbers.Location = new System.Drawing.Point(19, 26);
+			this.scriptshowlinenumbers.Name = "scriptshowlinenumbers";
+			this.scriptshowlinenumbers.Size = new System.Drawing.Size(115, 17);
+			this.scriptshowlinenumbers.TabIndex = 37;
+			this.scriptshowlinenumbers.Text = "Show line numbers";
+			this.scriptshowlinenumbers.UseVisualStyleBackColor = true;
+			this.scriptshowlinenumbers.CheckedChanged += new System.EventHandler(this.scriptshowlinenumbers_CheckedChanged);
+			// 
+			// groupBox8
+			// 
+			this.groupBox8.Controls.Add(this.scriptautoshowautocompletion);
+			this.groupBox8.Controls.Add(this.scriptautoclosebrackets);
+			this.groupBox8.Controls.Add(this.scriptusetabs);
+			this.groupBox8.Controls.Add(this.scriptallmanstyle);
+			this.groupBox8.Controls.Add(this.label10);
+			this.groupBox8.Controls.Add(this.scriptautoindent);
+			this.groupBox8.Controls.Add(this.scripttabwidth);
+			this.groupBox8.Location = new System.Drawing.Point(217, 104);
+			this.groupBox8.Name = "groupBox8";
+			this.groupBox8.Size = new System.Drawing.Size(457, 148);
+			this.groupBox8.TabIndex = 5;
+			this.groupBox8.TabStop = false;
+			this.groupBox8.Text = " Formatting ";
+			// 
+			// scriptautoshowautocompletion
+			// 
+			this.scriptautoshowautocompletion.AutoSize = true;
+			this.scriptautoshowautocompletion.Location = new System.Drawing.Point(19, 118);
+			this.scriptautoshowautocompletion.Name = "scriptautoshowautocompletion";
+			this.scriptautoshowautocompletion.Size = new System.Drawing.Size(169, 17);
+			this.scriptautoshowautocompletion.TabIndex = 37;
+			this.scriptautoshowautocompletion.Text = "Auto show auto-completion list";
+			this.scriptautoshowautocompletion.UseVisualStyleBackColor = true;
+			// 
+			// scriptautoclosebrackets
+			// 
+			this.scriptautoclosebrackets.AutoSize = true;
+			this.scriptautoclosebrackets.Location = new System.Drawing.Point(19, 72);
+			this.scriptautoclosebrackets.Name = "scriptautoclosebrackets";
+			this.scriptautoclosebrackets.Size = new System.Drawing.Size(120, 17);
+			this.scriptautoclosebrackets.TabIndex = 36;
+			this.scriptautoclosebrackets.Text = "Auto-close brackets";
+			this.toolTip1.SetToolTip(this.scriptautoclosebrackets, "When enabled, the editor will automatically\r\ninsert closing bracket if opening br" +
+					"acket was typed.");
+			this.scriptautoclosebrackets.UseVisualStyleBackColor = true;
+			// 
+			// scriptusetabs
+			// 
+			this.scriptusetabs.AutoSize = true;
+			this.scriptusetabs.Location = new System.Drawing.Point(19, 26);
+			this.scriptusetabs.Name = "scriptusetabs";
+			this.scriptusetabs.Size = new System.Drawing.Size(68, 17);
+			this.scriptusetabs.TabIndex = 35;
+			this.scriptusetabs.Text = "Use tabs";
+			this.scriptusetabs.UseVisualStyleBackColor = true;
+			// 
+			// scriptallmanstyle
+			// 
+			this.scriptallmanstyle.AutoSize = true;
+			this.scriptallmanstyle.Location = new System.Drawing.Point(19, 95);
+			this.scriptallmanstyle.Name = "scriptallmanstyle";
+			this.scriptallmanstyle.Size = new System.Drawing.Size(119, 17);
+			this.scriptallmanstyle.TabIndex = 34;
+			this.scriptallmanstyle.Text = "Allman-style bracing";
+			this.toolTip1.SetToolTip(this.scriptallmanstyle, resources.GetString("scriptallmanstyle.ToolTip"));
+			this.scriptallmanstyle.UseVisualStyleBackColor = true;
 			// 
-			this.colorsgroup3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-						| System.Windows.Forms.AnchorStyles.Right)));
-			this.colorsgroup3.Controls.Add(this.snippetsallmanstyle);
-			this.colorsgroup3.Controls.Add(this.scripttabwidth);
-			this.colorsgroup3.Controls.Add(this.scriptautoindent);
-			this.colorsgroup3.Controls.Add(this.label10);
-			this.colorsgroup3.Controls.Add(this.fontpreview);
-			this.colorsgroup3.Controls.Add(this.scriptfontsize);
-			this.colorsgroup3.Controls.Add(this.label8);
-			this.colorsgroup3.Controls.Add(this.scriptfontbold);
-			this.colorsgroup3.Controls.Add(this.scriptfontname);
-			this.colorsgroup3.Controls.Add(this.label3);
-			this.colorsgroup3.Controls.Add(this.colorconstants);
-			this.colorsgroup3.Controls.Add(this.colorliterals);
-			this.colorsgroup3.Controls.Add(this.colorscriptbackground);
-			this.colorsgroup3.Controls.Add(this.colorkeywords);
-			this.colorsgroup3.Controls.Add(this.colorlinenumbers);
-			this.colorsgroup3.Controls.Add(this.colorcomments);
-			this.colorsgroup3.Controls.Add(this.colorplaintext);
-			this.colorsgroup3.Location = new System.Drawing.Point(217, 8);
-			this.colorsgroup3.Name = "colorsgroup3";
-			this.colorsgroup3.Size = new System.Drawing.Size(457, 212);
-			this.colorsgroup3.TabIndex = 1;
-			this.colorsgroup3.TabStop = false;
-			this.colorsgroup3.Text = " Script editor ";
-			this.colorsgroup3.Visible = false;
-			// 
-			// snippetsallmanstyle
-			// 
-			this.snippetsallmanstyle.AutoSize = true;
-			this.snippetsallmanstyle.Location = new System.Drawing.Point(202, 187);
-			this.snippetsallmanstyle.Name = "snippetsallmanstyle";
-			this.snippetsallmanstyle.Size = new System.Drawing.Size(172, 17);
-			this.snippetsallmanstyle.TabIndex = 34;
-			this.snippetsallmanstyle.Text = "Allman-style bracing in snippets";
-			this.toolTip1.SetToolTip(this.snippetsallmanstyle, resources.GetString("snippetsallmanstyle.ToolTip"));
-			this.snippetsallmanstyle.UseVisualStyleBackColor = true;
+			// label10
+			// 
+			this.label10.AutoSize = true;
+			this.label10.Location = new System.Drawing.Point(121, 27);
+			this.label10.Name = "label10";
+			this.label10.Size = new System.Drawing.Size(57, 13);
+			this.label10.TabIndex = 30;
+			this.label10.Text = "Tab width:";
+			// 
+			// scriptautoindent
+			// 
+			this.scriptautoindent.AutoSize = true;
+			this.scriptautoindent.Location = new System.Drawing.Point(19, 49);
+			this.scriptautoindent.Name = "scriptautoindent";
+			this.scriptautoindent.Size = new System.Drawing.Size(80, 17);
+			this.scriptautoindent.TabIndex = 31;
+			this.scriptautoindent.Text = "Auto indent";
+			this.scriptautoindent.UseVisualStyleBackColor = true;
 			// 
 			// scripttabwidth
 			// 
@@ -1669,44 +1780,68 @@ namespace CodeImp.DoomBuilder.Windows
 			this.scripttabwidth.ButtonStepSmall = 0.1F;
 			this.scripttabwidth.ButtonStepsUseModifierKeys = false;
 			this.scripttabwidth.ButtonStepsWrapAround = false;
-			this.scripttabwidth.Location = new System.Drawing.Point(364, 157);
+			this.scripttabwidth.Location = new System.Drawing.Point(181, 22);
 			this.scripttabwidth.Name = "scripttabwidth";
 			this.scripttabwidth.Size = new System.Drawing.Size(71, 24);
 			this.scripttabwidth.StepValues = null;
 			this.scripttabwidth.TabIndex = 32;
+			this.scripttabwidth.WhenTextChanged += new System.EventHandler(this.scripttabwidth_WhenTextChanged);
 			// 
-			// scriptautoindent
+			// groupBox7
 			// 
-			this.scriptautoindent.AutoSize = true;
-			this.scriptautoindent.Location = new System.Drawing.Point(202, 161);
-			this.scriptautoindent.Name = "scriptautoindent";
-			this.scriptautoindent.Size = new System.Drawing.Size(80, 17);
-			this.scriptautoindent.TabIndex = 31;
-			this.scriptautoindent.Text = "Auto indent";
-			this.scriptautoindent.UseVisualStyleBackColor = true;
+			this.groupBox7.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+						| System.Windows.Forms.AnchorStyles.Right)));
+			this.groupBox7.Controls.Add(this.label3);
+			this.groupBox7.Controls.Add(this.scriptfontname);
+			this.groupBox7.Controls.Add(this.scriptfontbold);
+			this.groupBox7.Controls.Add(this.label8);
+			this.groupBox7.Controls.Add(this.scriptfontsize);
+			this.groupBox7.Location = new System.Drawing.Point(217, 8);
+			this.groupBox7.Name = "groupBox7";
+			this.groupBox7.Size = new System.Drawing.Size(457, 90);
+			this.groupBox7.TabIndex = 4;
+			this.groupBox7.TabStop = false;
+			this.groupBox7.Text = " Font ";
 			// 
-			// label10
+			// label3
 			// 
-			this.label10.AutoSize = true;
-			this.label10.Location = new System.Drawing.Point(304, 162);
-			this.label10.Name = "label10";
-			this.label10.Size = new System.Drawing.Size(57, 13);
-			this.label10.TabIndex = 30;
-			this.label10.Text = "Tab width:";
+			this.label3.AutoSize = true;
+			this.label3.Location = new System.Drawing.Point(16, 27);
+			this.label3.Name = "label3";
+			this.label3.Size = new System.Drawing.Size(31, 13);
+			this.label3.TabIndex = 24;
+			this.label3.Text = "Font:";
 			// 
-			// fontpreview
+			// scriptfontname
 			// 
-			this.fontpreview.Cursor = System.Windows.Forms.Cursors.Arrow;
-			this.fontpreview.DetectUrls = false;
-			this.fontpreview.Location = new System.Drawing.Point(202, 70);
-			this.fontpreview.Name = "fontpreview";
-			this.fontpreview.ReadOnly = true;
-			this.fontpreview.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
-			this.fontpreview.Size = new System.Drawing.Size(233, 80);
-			this.fontpreview.TabIndex = 33;
-			this.fontpreview.Text = "1 #include \"zcommon.acs\"\n2 script 0 (void) { //a comment\n3       CONSTANT_VALUE;\n" +
-				"4 }";
-			this.fontpreview.WordWrap = false;
+			this.scriptfontname.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+			this.scriptfontname.FormattingEnabled = true;
+			this.scriptfontname.Location = new System.Drawing.Point(53, 24);
+			this.scriptfontname.Name = "scriptfontname";
+			this.scriptfontname.Size = new System.Drawing.Size(199, 21);
+			this.scriptfontname.Sorted = true;
+			this.scriptfontname.TabIndex = 23;
+			this.scriptfontname.SelectedIndexChanged += new System.EventHandler(this.scriptfontname_SelectedIndexChanged);
+			// 
+			// scriptfontbold
+			// 
+			this.scriptfontbold.AutoSize = true;
+			this.scriptfontbold.Location = new System.Drawing.Point(165, 56);
+			this.scriptfontbold.Name = "scriptfontbold";
+			this.scriptfontbold.Size = new System.Drawing.Size(47, 17);
+			this.scriptfontbold.TabIndex = 26;
+			this.scriptfontbold.Text = "Bold";
+			this.scriptfontbold.UseVisualStyleBackColor = true;
+			this.scriptfontbold.CheckedChanged += new System.EventHandler(this.scriptfontbold_CheckedChanged);
+			// 
+			// label8
+			// 
+			this.label8.AutoSize = true;
+			this.label8.Location = new System.Drawing.Point(16, 56);
+			this.label8.Name = "label8";
+			this.label8.Size = new System.Drawing.Size(30, 13);
+			this.label8.TabIndex = 28;
+			this.label8.Text = "Size:";
 			// 
 			// scriptfontsize
 			// 
@@ -1730,75 +1865,135 @@ namespace CodeImp.DoomBuilder.Windows
             "36",
             "48",
             "72"});
-			this.scriptfontsize.Location = new System.Drawing.Point(236, 43);
+			this.scriptfontsize.Location = new System.Drawing.Point(53, 53);
 			this.scriptfontsize.Name = "scriptfontsize";
 			this.scriptfontsize.Size = new System.Drawing.Size(94, 21);
 			this.scriptfontsize.TabIndex = 25;
 			this.scriptfontsize.SelectedIndexChanged += new System.EventHandler(this.scriptfontsize_SelectedIndexChanged);
 			// 
-			// label8
-			// 
-			this.label8.AutoSize = true;
-			this.label8.Location = new System.Drawing.Point(199, 46);
-			this.label8.Name = "label8";
-			this.label8.Size = new System.Drawing.Size(30, 13);
-			this.label8.TabIndex = 28;
-			this.label8.Text = "Size:";
-			// 
-			// scriptfontbold
-			// 
-			this.scriptfontbold.AutoSize = true;
-			this.scriptfontbold.Location = new System.Drawing.Point(354, 45);
-			this.scriptfontbold.Name = "scriptfontbold";
-			this.scriptfontbold.Size = new System.Drawing.Size(47, 17);
-			this.scriptfontbold.TabIndex = 26;
-			this.scriptfontbold.Text = "Bold";
-			this.scriptfontbold.UseVisualStyleBackColor = true;
-			this.scriptfontbold.CheckedChanged += new System.EventHandler(this.scriptfontbold_CheckedChanged);
-			// 
-			// scriptfontname
-			// 
-			this.scriptfontname.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
-			this.scriptfontname.FormattingEnabled = true;
-			this.scriptfontname.Location = new System.Drawing.Point(236, 17);
-			this.scriptfontname.Name = "scriptfontname";
-			this.scriptfontname.Size = new System.Drawing.Size(199, 21);
-			this.scriptfontname.Sorted = true;
-			this.scriptfontname.TabIndex = 23;
-			this.scriptfontname.SelectedIndexChanged += new System.EventHandler(this.scriptfontname_SelectedIndexChanged);
-			// 
-			// label3
-			// 
-			this.label3.AutoSize = true;
-			this.label3.Location = new System.Drawing.Point(199, 20);
-			this.label3.Name = "label3";
-			this.label3.Size = new System.Drawing.Size(31, 13);
-			this.label3.TabIndex = 24;
-			this.label3.Text = "Font:";
-			// 
-			// colorconstants
-			// 
-			this.colorconstants.BackColor = System.Drawing.Color.Transparent;
-			this.colorconstants.Label = "Constants:";
-			this.colorconstants.Location = new System.Drawing.Point(15, 179);
-			this.colorconstants.MaximumSize = new System.Drawing.Size(10000, 23);
-			this.colorconstants.MinimumSize = new System.Drawing.Size(100, 23);
-			this.colorconstants.Name = "colorconstants";
-			this.colorconstants.Size = new System.Drawing.Size(150, 23);
-			this.colorconstants.TabIndex = 6;
-			this.colorconstants.ColorChanged += new System.EventHandler(this.scriptcolor_ColorChanged);
-			// 
-			// colorliterals
+			// groupBox6
 			// 
-			this.colorliterals.BackColor = System.Drawing.Color.Transparent;
-			this.colorliterals.Label = "Literals:";
-			this.colorliterals.Location = new System.Drawing.Point(15, 152);
-			this.colorliterals.MaximumSize = new System.Drawing.Size(10000, 23);
-			this.colorliterals.MinimumSize = new System.Drawing.Size(100, 23);
-			this.colorliterals.Name = "colorliterals";
-			this.colorliterals.Size = new System.Drawing.Size(150, 23);
-			this.colorliterals.TabIndex = 5;
-			this.colorliterals.ColorChanged += new System.EventHandler(this.scriptcolor_ColorChanged);
+			this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+						| System.Windows.Forms.AnchorStyles.Left)));
+			this.groupBox6.Controls.Add(this.colorfoldback);
+			this.groupBox6.Controls.Add(this.colorfoldfore);
+			this.groupBox6.Controls.Add(this.colorindicator);
+			this.groupBox6.Controls.Add(this.colorwhitespace);
+			this.groupBox6.Controls.Add(this.colorbracebad);
+			this.groupBox6.Controls.Add(this.colorbrace);
+			this.groupBox6.Controls.Add(this.colorselectionback);
+			this.groupBox6.Controls.Add(this.colorselectionfore);
+			this.groupBox6.Controls.Add(this.colorincludes);
+			this.groupBox6.Controls.Add(this.colorstrings);
+			this.groupBox6.Controls.Add(this.colorscriptbackground);
+			this.groupBox6.Controls.Add(this.colorplaintext);
+			this.groupBox6.Controls.Add(this.colorcomments);
+			this.groupBox6.Controls.Add(this.colorlinenumbers);
+			this.groupBox6.Controls.Add(this.colorkeywords);
+			this.groupBox6.Controls.Add(this.colorliterals);
+			this.groupBox6.Controls.Add(this.colorconstants);
+			this.groupBox6.Location = new System.Drawing.Point(8, 8);
+			this.groupBox6.Name = "groupBox6";
+			this.groupBox6.Size = new System.Drawing.Size(203, 493);
+			this.groupBox6.TabIndex = 3;
+			this.groupBox6.TabStop = false;
+			this.groupBox6.Text = " Colors ";
+			// 
+			// colorindicator
+			// 
+			this.colorindicator.BackColor = System.Drawing.Color.Transparent;
+			this.colorindicator.Label = "Matching word:";
+			this.colorindicator.Location = new System.Drawing.Point(15, 325);
+			this.colorindicator.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorindicator.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorindicator.Name = "colorindicator";
+			this.colorindicator.Size = new System.Drawing.Size(168, 23);
+			this.colorindicator.TabIndex = 14;
+			this.colorindicator.ColorChanged += new System.EventHandler(this.colorindicator_ColorChanged);
+			// 
+			// colorwhitespace
+			// 
+			this.colorwhitespace.BackColor = System.Drawing.Color.Transparent;
+			this.colorwhitespace.Label = "Whitespace:";
+			this.colorwhitespace.Location = new System.Drawing.Point(15, 409);
+			this.colorwhitespace.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorwhitespace.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorwhitespace.Name = "colorwhitespace";
+			this.colorwhitespace.Size = new System.Drawing.Size(168, 23);
+			this.colorwhitespace.TabIndex = 13;
+			this.colorwhitespace.ColorChanged += new System.EventHandler(this.colorwhitespace_ColorChanged);
+			// 
+			// colorbracebad
+			// 
+			this.colorbracebad.BackColor = System.Drawing.Color.Transparent;
+			this.colorbracebad.Label = "Mismatching brace:";
+			this.colorbracebad.Location = new System.Drawing.Point(15, 381);
+			this.colorbracebad.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorbracebad.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorbracebad.Name = "colorbracebad";
+			this.colorbracebad.Size = new System.Drawing.Size(168, 23);
+			this.colorbracebad.TabIndex = 12;
+			this.colorbracebad.ColorChanged += new System.EventHandler(this.colorbracebad_ColorChanged);
+			// 
+			// colorbrace
+			// 
+			this.colorbrace.BackColor = System.Drawing.Color.Transparent;
+			this.colorbrace.Label = "Matching brace:";
+			this.colorbrace.Location = new System.Drawing.Point(15, 353);
+			this.colorbrace.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorbrace.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorbrace.Name = "colorbrace";
+			this.colorbrace.Size = new System.Drawing.Size(168, 23);
+			this.colorbrace.TabIndex = 11;
+			this.colorbrace.ColorChanged += new System.EventHandler(this.colorbrace_ColorChanged);
+			// 
+			// colorselectionback
+			// 
+			this.colorselectionback.BackColor = System.Drawing.Color.Transparent;
+			this.colorselectionback.Label = "Selection BG:";
+			this.colorselectionback.Location = new System.Drawing.Point(15, 297);
+			this.colorselectionback.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorselectionback.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorselectionback.Name = "colorselectionback";
+			this.colorselectionback.Size = new System.Drawing.Size(168, 23);
+			this.colorselectionback.TabIndex = 10;
+			this.colorselectionback.ColorChanged += new System.EventHandler(this.colorselectionback_ColorChanged);
+			// 
+			// colorselectionfore
+			// 
+			this.colorselectionfore.BackColor = System.Drawing.Color.Transparent;
+			this.colorselectionfore.Label = "Selection:";
+			this.colorselectionfore.Location = new System.Drawing.Point(15, 269);
+			this.colorselectionfore.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorselectionfore.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorselectionfore.Name = "colorselectionfore";
+			this.colorselectionfore.Size = new System.Drawing.Size(168, 23);
+			this.colorselectionfore.TabIndex = 9;
+			this.colorselectionfore.ColorChanged += new System.EventHandler(this.colorselectionfore_ColorChanged);
+			// 
+			// colorincludes
+			// 
+			this.colorincludes.BackColor = System.Drawing.Color.Transparent;
+			this.colorincludes.Label = "Includes:";
+			this.colorincludes.Location = new System.Drawing.Point(15, 241);
+			this.colorincludes.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorincludes.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorincludes.Name = "colorincludes";
+			this.colorincludes.Size = new System.Drawing.Size(168, 23);
+			this.colorincludes.TabIndex = 8;
+			this.colorincludes.ColorChanged += new System.EventHandler(this.colorincludes_ColorChanged);
+			// 
+			// colorstrings
+			// 
+			this.colorstrings.BackColor = System.Drawing.Color.Transparent;
+			this.colorstrings.Label = "Strings:";
+			this.colorstrings.Location = new System.Drawing.Point(15, 157);
+			this.colorstrings.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorstrings.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorstrings.Name = "colorstrings";
+			this.colorstrings.Size = new System.Drawing.Size(168, 23);
+			this.colorstrings.TabIndex = 7;
+			this.colorstrings.ColorChanged += new System.EventHandler(this.colorstrings_ColorChanged);
 			// 
 			// colorscriptbackground
 			// 
@@ -1808,67 +2003,110 @@ namespace CodeImp.DoomBuilder.Windows
 			this.colorscriptbackground.MaximumSize = new System.Drawing.Size(10000, 23);
 			this.colorscriptbackground.MinimumSize = new System.Drawing.Size(100, 23);
 			this.colorscriptbackground.Name = "colorscriptbackground";
-			this.colorscriptbackground.Size = new System.Drawing.Size(150, 23);
+			this.colorscriptbackground.Size = new System.Drawing.Size(168, 23);
 			this.colorscriptbackground.TabIndex = 0;
-			this.colorscriptbackground.ColorChanged += new System.EventHandler(this.scriptcolor_ColorChanged);
+			this.colorscriptbackground.ColorChanged += new System.EventHandler(this.colorscriptbackground_ColorChanged);
 			// 
-			// colorkeywords
+			// colorplaintext
 			// 
-			this.colorkeywords.BackColor = System.Drawing.Color.Transparent;
-			this.colorkeywords.Label = "Keywords:";
-			this.colorkeywords.Location = new System.Drawing.Point(15, 125);
-			this.colorkeywords.MaximumSize = new System.Drawing.Size(10000, 23);
-			this.colorkeywords.MinimumSize = new System.Drawing.Size(100, 23);
-			this.colorkeywords.Name = "colorkeywords";
-			this.colorkeywords.Size = new System.Drawing.Size(150, 23);
-			this.colorkeywords.TabIndex = 4;
-			this.colorkeywords.ColorChanged += new System.EventHandler(this.scriptcolor_ColorChanged);
+			this.colorplaintext.BackColor = System.Drawing.Color.Transparent;
+			this.colorplaintext.Label = "Plain text:";
+			this.colorplaintext.Location = new System.Drawing.Point(15, 73);
+			this.colorplaintext.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorplaintext.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorplaintext.Name = "colorplaintext";
+			this.colorplaintext.Size = new System.Drawing.Size(168, 23);
+			this.colorplaintext.TabIndex = 2;
+			this.colorplaintext.ColorChanged += new System.EventHandler(this.colorplaintext_ColorChanged);
+			// 
+			// colorcomments
+			// 
+			this.colorcomments.BackColor = System.Drawing.Color.Transparent;
+			this.colorcomments.Label = "Comments:";
+			this.colorcomments.Location = new System.Drawing.Point(15, 101);
+			this.colorcomments.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorcomments.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorcomments.Name = "colorcomments";
+			this.colorcomments.Size = new System.Drawing.Size(168, 23);
+			this.colorcomments.TabIndex = 3;
+			this.colorcomments.ColorChanged += new System.EventHandler(this.colorcomments_ColorChanged);
 			// 
 			// colorlinenumbers
 			// 
 			this.colorlinenumbers.BackColor = System.Drawing.Color.Transparent;
 			this.colorlinenumbers.Label = "Line numbers:";
-			this.colorlinenumbers.Location = new System.Drawing.Point(15, 44);
+			this.colorlinenumbers.Location = new System.Drawing.Point(15, 45);
 			this.colorlinenumbers.MaximumSize = new System.Drawing.Size(10000, 23);
 			this.colorlinenumbers.MinimumSize = new System.Drawing.Size(100, 23);
 			this.colorlinenumbers.Name = "colorlinenumbers";
-			this.colorlinenumbers.Size = new System.Drawing.Size(150, 23);
+			this.colorlinenumbers.Size = new System.Drawing.Size(168, 23);
 			this.colorlinenumbers.TabIndex = 1;
-			this.colorlinenumbers.ColorChanged += new System.EventHandler(this.scriptcolor_ColorChanged);
+			this.colorlinenumbers.ColorChanged += new System.EventHandler(this.colorlinenumbers_ColorChanged);
 			// 
-			// colorcomments
+			// colorkeywords
 			// 
-			this.colorcomments.BackColor = System.Drawing.Color.Transparent;
-			this.colorcomments.Label = "Comments:";
-			this.colorcomments.Location = new System.Drawing.Point(15, 98);
-			this.colorcomments.MaximumSize = new System.Drawing.Size(10000, 23);
-			this.colorcomments.MinimumSize = new System.Drawing.Size(100, 23);
-			this.colorcomments.Name = "colorcomments";
-			this.colorcomments.Size = new System.Drawing.Size(150, 23);
-			this.colorcomments.TabIndex = 3;
-			this.colorcomments.ColorChanged += new System.EventHandler(this.scriptcolor_ColorChanged);
+			this.colorkeywords.BackColor = System.Drawing.Color.Transparent;
+			this.colorkeywords.Label = "Keywords:";
+			this.colorkeywords.Location = new System.Drawing.Point(15, 129);
+			this.colorkeywords.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorkeywords.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorkeywords.Name = "colorkeywords";
+			this.colorkeywords.Size = new System.Drawing.Size(168, 23);
+			this.colorkeywords.TabIndex = 4;
+			this.colorkeywords.ColorChanged += new System.EventHandler(this.colorkeywords_ColorChanged);
 			// 
-			// colorplaintext
+			// colorliterals
 			// 
-			this.colorplaintext.BackColor = System.Drawing.Color.Transparent;
-			this.colorplaintext.Label = "Plain text:";
-			this.colorplaintext.Location = new System.Drawing.Point(15, 71);
-			this.colorplaintext.MaximumSize = new System.Drawing.Size(10000, 23);
-			this.colorplaintext.MinimumSize = new System.Drawing.Size(100, 23);
-			this.colorplaintext.Name = "colorplaintext";
-			this.colorplaintext.Size = new System.Drawing.Size(150, 23);
-			this.colorplaintext.TabIndex = 2;
-			this.colorplaintext.ColorChanged += new System.EventHandler(this.scriptcolor_ColorChanged);
+			this.colorliterals.BackColor = System.Drawing.Color.Transparent;
+			this.colorliterals.Label = "Numbers:";
+			this.colorliterals.Location = new System.Drawing.Point(15, 185);
+			this.colorliterals.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorliterals.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorliterals.Name = "colorliterals";
+			this.colorliterals.Size = new System.Drawing.Size(168, 23);
+			this.colorliterals.TabIndex = 5;
+			this.colorliterals.ColorChanged += new System.EventHandler(this.colorliterals_ColorChanged);
+			// 
+			// colorconstants
+			// 
+			this.colorconstants.BackColor = System.Drawing.Color.Transparent;
+			this.colorconstants.Label = "Constants:";
+			this.colorconstants.Location = new System.Drawing.Point(15, 213);
+			this.colorconstants.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorconstants.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorconstants.Name = "colorconstants";
+			this.colorconstants.Size = new System.Drawing.Size(168, 23);
+			this.colorconstants.TabIndex = 6;
+			this.colorconstants.ColorChanged += new System.EventHandler(this.colorconstants_ColorChanged);
+			// 
+			// previewgroup
+			// 
+			this.previewgroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+						| System.Windows.Forms.AnchorStyles.Right)));
+			this.previewgroup.Controls.Add(this.scriptedit);
+			this.previewgroup.Location = new System.Drawing.Point(217, 344);
+			this.previewgroup.Name = "previewgroup";
+			this.previewgroup.Size = new System.Drawing.Size(457, 157);
+			this.previewgroup.TabIndex = 2;
+			this.previewgroup.TabStop = false;
+			this.previewgroup.Text = " Preview ";
+			// 
+			// scriptedit
+			// 
+			this.scriptedit.Location = new System.Drawing.Point(6, 19);
+			this.scriptedit.Name = "scriptedit";
+			this.scriptedit.Size = new System.Drawing.Size(445, 132);
+			this.scriptedit.TabIndex = 0;
 			// 
 			// tabpasting
 			// 
 			this.tabpasting.Controls.Add(this.label16);
 			this.tabpasting.Controls.Add(this.pasteoptions);
 			this.tabpasting.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
-			this.tabpasting.Location = new System.Drawing.Point(4, 23);
+			this.tabpasting.Location = new System.Drawing.Point(4, 22);
 			this.tabpasting.Name = "tabpasting";
 			this.tabpasting.Padding = new System.Windows.Forms.Padding(5);
-			this.tabpasting.Size = new System.Drawing.Size(682, 509);
+			this.tabpasting.Size = new System.Drawing.Size(682, 510);
 			this.tabpasting.TabIndex = 3;
 			this.tabpasting.Text = "Pasting ";
 			this.tabpasting.UseVisualStyleBackColor = true;
@@ -1899,6 +2137,30 @@ namespace CodeImp.DoomBuilder.Windows
 			// 
 			this.browseScreenshotsFolderDialog.Description = "Select a Folder to Save Screenshots Into";
 			// 
+			// colorfoldfore
+			// 
+			this.colorfoldfore.BackColor = System.Drawing.Color.Transparent;
+			this.colorfoldfore.Label = "Fold:";
+			this.colorfoldfore.Location = new System.Drawing.Point(15, 437);
+			this.colorfoldfore.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorfoldfore.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorfoldfore.Name = "colorfoldfore";
+			this.colorfoldfore.Size = new System.Drawing.Size(168, 23);
+			this.colorfoldfore.TabIndex = 15;
+			this.colorfoldfore.ColorChanged += new System.EventHandler(this.colorfoldfore_ColorChanged);
+			// 
+			// colorfoldback
+			// 
+			this.colorfoldback.BackColor = System.Drawing.Color.Transparent;
+			this.colorfoldback.Label = "Fold BG:";
+			this.colorfoldback.Location = new System.Drawing.Point(15, 465);
+			this.colorfoldback.MaximumSize = new System.Drawing.Size(10000, 23);
+			this.colorfoldback.MinimumSize = new System.Drawing.Size(100, 23);
+			this.colorfoldback.Name = "colorfoldback";
+			this.colorfoldback.Size = new System.Drawing.Size(168, 23);
+			this.colorfoldback.TabIndex = 16;
+			this.colorfoldback.ColorChanged += new System.EventHandler(this.colorfoldback_ColorChanged);
+			// 
 			// PreferencesForm
 			// 
 			this.AcceptButton = this.apply;
@@ -1956,8 +2218,15 @@ namespace CodeImp.DoomBuilder.Windows
 			((System.ComponentModel.ISupportInitialize)(this.tbDynLightSize)).EndInit();
 			((System.ComponentModel.ISupportInitialize)(this.tbDynLightCount)).EndInit();
 			((System.ComponentModel.ISupportInitialize)(this.imagebrightness)).EndInit();
-			this.colorsgroup3.ResumeLayout(false);
-			this.colorsgroup3.PerformLayout();
+			this.tabscripteditor.ResumeLayout(false);
+			this.groupBox9.ResumeLayout(false);
+			this.groupBox9.PerformLayout();
+			this.groupBox8.ResumeLayout(false);
+			this.groupBox8.PerformLayout();
+			this.groupBox7.ResumeLayout(false);
+			this.groupBox7.PerformLayout();
+			this.groupBox6.ResumeLayout(false);
+			this.previewgroup.ResumeLayout(false);
 			this.tabpasting.ResumeLayout(false);
 			this.ResumeLayout(false);
 
@@ -1984,14 +2253,6 @@ namespace CodeImp.DoomBuilder.Windows
 		private CodeImp.DoomBuilder.Controls.ColorControl colorlinedefs;
 		private CodeImp.DoomBuilder.Controls.ColorControl colorvertices;
 		private CodeImp.DoomBuilder.Controls.ColorControl colorbackcolor;
-		private System.Windows.Forms.GroupBox colorsgroup3;
-		private CodeImp.DoomBuilder.Controls.ColorControl colorscriptbackground;
-		private CodeImp.DoomBuilder.Controls.ColorControl colorkeywords;
-		private CodeImp.DoomBuilder.Controls.ColorControl colorlinenumbers;
-		private CodeImp.DoomBuilder.Controls.ColorControl colorcomments;
-		private CodeImp.DoomBuilder.Controls.ColorControl colorplaintext;
-		private CodeImp.DoomBuilder.Controls.ColorControl colorliterals;
-		private CodeImp.DoomBuilder.Controls.ColorControl colorconstants;
 		private CodeImp.DoomBuilder.Controls.ColorControl colorindication;
 		private CodeImp.DoomBuilder.Controls.ColorControl colorgrid64;
 		private CodeImp.DoomBuilder.Controls.ColorControl colorgrid;
@@ -2043,14 +2304,6 @@ namespace CodeImp.DoomBuilder.Windows
 		private System.Windows.Forms.Label zoomfactorlabel;
 		private System.Windows.Forms.Label label19;
 		private System.Windows.Forms.GroupBox groupBox5;
-		private CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox scripttabwidth;
-		private System.Windows.Forms.CheckBox scriptautoindent;
-		private System.Windows.Forms.Label label10;
-		private System.Windows.Forms.ComboBox scriptfontsize;
-		private System.Windows.Forms.Label label8;
-		private System.Windows.Forms.CheckBox scriptfontbold;
-		private System.Windows.Forms.ComboBox scriptfontname;
-		private System.Windows.Forms.Label label3;
 		private System.Windows.Forms.CheckBox scriptontop;
 		private System.Windows.Forms.CheckBox toolbar_script;
 		private System.Windows.Forms.CheckBox toolbar_copy;
@@ -2083,12 +2336,10 @@ namespace CodeImp.DoomBuilder.Windows
 		private System.Windows.Forms.Label label24;
 		private CodeImp.DoomBuilder.Controls.ColorControl color3dFloors;
 		private System.Windows.Forms.TextBox actiondescription;
-		private System.Windows.Forms.RichTextBox fontpreview;
 		private System.Windows.Forms.CheckBox cbMarkExtraFloors;
 		private System.Windows.Forms.TrackBar recentFiles;
 		private System.Windows.Forms.Label labelRecentFiles;
 		private System.Windows.Forms.Label label25;
-		private System.Windows.Forms.CheckBox snippetsallmanstyle;
 		private System.Windows.Forms.CheckBox capitalizetexturenames;
 		private System.Windows.Forms.GroupBox groupBox3;
 		private System.Windows.Forms.Button browsescreenshotsdir;
@@ -2101,5 +2352,43 @@ namespace CodeImp.DoomBuilder.Windows
 		private System.Windows.Forms.CheckBox locatetexturegroup;
 		private System.Windows.Forms.CheckBox cbStoreEditTab;
 		private System.Windows.Forms.CheckBox checkforupdates;
+		private System.Windows.Forms.TabPage tabscripteditor;
+		private System.Windows.Forms.GroupBox previewgroup;
+		private System.Windows.Forms.CheckBox scriptallmanstyle;
+		private CodeImp.DoomBuilder.Controls.ButtonsNumericTextbox scripttabwidth;
+		private System.Windows.Forms.CheckBox scriptautoindent;
+		private System.Windows.Forms.Label label10;
+		private System.Windows.Forms.ComboBox scriptfontsize;
+		private System.Windows.Forms.Label label8;
+		private System.Windows.Forms.CheckBox scriptfontbold;
+		private System.Windows.Forms.ComboBox scriptfontname;
+		private System.Windows.Forms.Label label3;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorconstants;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorliterals;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorscriptbackground;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorkeywords;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorlinenumbers;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorcomments;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorplaintext;
+		private System.Windows.Forms.GroupBox groupBox7;
+		private System.Windows.Forms.GroupBox groupBox6;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorstrings;
+		private System.Windows.Forms.GroupBox groupBox8;
+		private System.Windows.Forms.CheckBox scriptusetabs;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorwhitespace;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorbracebad;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorbrace;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorselectionback;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorselectionfore;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorincludes;
+		private System.Windows.Forms.CheckBox scriptautoclosebrackets;
+		private System.Windows.Forms.GroupBox groupBox9;
+		private System.Windows.Forms.CheckBox scriptshowfolding;
+		private System.Windows.Forms.CheckBox scriptshowlinenumbers;
+		private System.Windows.Forms.CheckBox scriptautoshowautocompletion;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorindicator;
+		private CodeImp.DoomBuilder.Controls.ScriptEditorPreviewControl scriptedit;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorfoldback;
+		private CodeImp.DoomBuilder.Controls.ColorControl colorfoldfore;
 	}
 }
\ No newline at end of file
diff --git a/Source/Core/Windows/PreferencesForm.cs b/Source/Core/Windows/PreferencesForm.cs
index 49b844d9e..9bde86f15 100644
--- a/Source/Core/Windows/PreferencesForm.cs
+++ b/Source/Core/Windows/PreferencesForm.cs
@@ -38,8 +38,8 @@ namespace CodeImp.DoomBuilder.Windows
 		private bool allowapplycontrol;
 		private bool disregardshift;
 		private bool disregardcontrol;
-		private List<ListViewItem> actionListItems; //mxd
-		private List<int> actionListItemsGroupIndices; //mxd
+		private readonly List<ListViewItem> actionListItems; //mxd
+		private readonly List<int> actionListItemsGroupIndices; //mxd
 
 		private bool reloadresources;
 		
@@ -69,11 +69,6 @@ namespace CodeImp.DoomBuilder.Windows
 			vertexScale3D.Value = General.Clamp((int)(General.Settings.GZVertexScale3D * 10), vertexScale3D.Minimum, vertexScale3D.Maximum); //mxd
 			viewdistance.Value = General.Clamp((int)(General.Settings.ViewDistance / 200.0f), viewdistance.Minimum, viewdistance.Maximum);
 			invertyaxis.Checked = General.Settings.InvertYAxis;
-			scriptfontbold.Checked = General.Settings.ScriptFontBold;
-			scriptontop.Checked = General.Settings.ScriptOnTop;
-			scripttabwidth.Text = General.Settings.ScriptTabWidth.ToString();
-			scriptautoindent.Checked = General.Settings.ScriptAutoIndent;
-			snippetsallmanstyle.Checked = General.Settings.SnippetsAllmanStyle; //mxd
 			previewsize.Value = General.Clamp(General.Settings.PreviewImageSize, previewsize.Minimum, previewsize.Maximum);
 			autoscrollspeed.Value = General.Clamp(General.Settings.AutoScrollSpeed, autoscrollspeed.Minimum, autoscrollspeed.Maximum);
 			zoomfactor.Value = General.Clamp(General.Settings.ZoomFactor, zoomfactor.Minimum, zoomfactor.Maximum);
@@ -90,6 +85,7 @@ namespace CodeImp.DoomBuilder.Windows
 			toolbar_geometry.Checked = General.Settings.ToolbarGeometry;
 			toolbar_testing.Checked = General.Settings.ToolbarTesting;
 			showtexturesizes.Checked = General.Settings.ShowTextureSizes;
+
 			//mxd
 			locatetexturegroup.Checked = General.Settings.LocateTextureGroup;
 			cbStoreEditTab.Checked = General.Settings.StoreSelectedEditTab;
@@ -111,8 +107,20 @@ namespace CodeImp.DoomBuilder.Windows
 			screenshotsfolderpath.Text = General.Settings.ScreenshotsPath;
 			if(Directory.Exists(General.Settings.ScreenshotsPath))
 				browseScreenshotsFolderDialog.SelectedPath = General.Settings.ScreenshotsPath;
-			
-			// Fill fonts list
+
+			//mxd. Script editor
+			scriptfontbold.Checked = General.Settings.ScriptFontBold;
+			scriptontop.Checked = General.Settings.ScriptOnTop;
+			scriptusetabs.Checked = General.Settings.ScriptUseTabs;
+			scripttabwidth.Text = General.Settings.ScriptTabWidth.ToString();
+			scriptautoindent.Checked = General.Settings.ScriptAutoIndent;
+			scriptallmanstyle.Checked = General.Settings.ScriptAllmanStyle; //mxd
+			scriptautoclosebrackets.Checked = General.Settings.ScriptAutoCloseBrackets; //mxd
+			scriptshowfolding.Checked = General.Settings.ScriptShowFolding; //mxd
+			scriptshowlinenumbers.Checked = General.Settings.ScriptShowLineNumbers; //mxd
+			scriptautoshowautocompletion.Checked = General.Settings.ScriptAutoShowAutocompletion; //mxd
+
+			// Fill script fonts list
 			scriptfontname.BeginUpdate();
 			foreach(FontFamily ff in FontFamily.Families)
 				scriptfontname.Items.Add(ff.Name);
@@ -177,6 +185,7 @@ namespace CodeImp.DoomBuilder.Windows
 			colorInfo.Color = General.Colors.InfoLine;
 			color3dFloors.Color = General.Colors.ThreeDFloor;
 
+			// Script editor colors
 			colorscriptbackground.Color = General.Colors.ScriptBackground;
 			colorlinenumbers.Color = General.Colors.LineNumbers;
 			colorplaintext.Color = General.Colors.PlainText;
@@ -184,6 +193,17 @@ namespace CodeImp.DoomBuilder.Windows
 			colorkeywords.Color = General.Colors.Keywords;
 			colorliterals.Color = General.Colors.Literals;
 			colorconstants.Color = General.Colors.Constants;
+			colorstrings.Color = General.Colors.Strings; //mxd
+			colorincludes.Color = General.Colors.Includes; //mxd
+			colorselectionfore.Color = General.Colors.ScriptSelectionForeColor; //mxd
+			colorselectionback.Color = General.Colors.ScriptSelectionBackColor; //mxd
+			colorindicator.Color = General.Colors.ScriptIndicator; //mxd
+			colorbrace.Color = General.Colors.ScriptBraceHighlight; //mxd
+			colorbracebad.Color = General.Colors.ScriptBadBraceHighlight; //mxd
+			colorwhitespace.Color = General.Colors.ScriptWhitespace; //mxd
+			colorfoldfore.Color = General.Colors.ScriptFoldForeColor; //mxd
+			colorfoldback.Color = General.Colors.ScriptFoldBackColor; //mxd
+
 			blackbrowsers.Checked = General.Settings.BlackBrowsers;
 			capitalizetexturenames.Checked = General.Settings.CapitalizeTextureNames; //mxd
 			classicbilinear.Checked = General.Settings.ClassicBilinear;
@@ -192,12 +212,10 @@ namespace CodeImp.DoomBuilder.Windows
 			
 			// Paste options
 			pasteoptions.Setup(General.Settings.PasteOptions.Copy());
-			UpdateScriptFontPreview(); //mxd
 
 			// Allow plugins to add tabs
 			this.SuspendLayout();
-			controller = new PreferencesController(this);
-			controller.AllowAddTab = true;
+			controller = new PreferencesController(this) { AllowAddTab = true };
 			General.Plugins.OnShowPreferences(controller);
 			controller.AllowAddTab = false;
 			this.ResumeLayout(true);
@@ -237,12 +255,6 @@ namespace CodeImp.DoomBuilder.Windows
 			General.Settings.GZVertexScale3D = vertexScale3D.Value * 0.1f; //mxd
 			General.Settings.ViewDistance = viewdistance.Value * 200.0f;
 			General.Settings.InvertYAxis = invertyaxis.Checked;
-			General.Settings.ScriptFontBold = scriptfontbold.Checked;
-			General.Settings.ScriptFontName = scriptfontname.Text;
-			General.Settings.ScriptOnTop = scriptontop.Checked;
-			General.Settings.ScriptTabWidth = scripttabwidth.GetResult(General.Settings.ScriptTabWidth);
-			General.Settings.ScriptAutoIndent = scriptautoindent.Checked;
-			General.Settings.SnippetsAllmanStyle = snippetsallmanstyle.Checked; //mxd
 			General.Settings.PreviewImageSize = previewsize.Value;
 			General.Settings.AutoScrollSpeed = autoscrollspeed.Value;
 			General.Settings.ZoomFactor = zoomfactor.Value;
@@ -265,6 +277,19 @@ namespace CodeImp.DoomBuilder.Windows
 			General.Settings.LocateTextureGroup = locatetexturegroup.Checked; //mxd
 			General.Settings.MaxRecentFiles = recentFiles.Value; //mxd
 			General.Settings.ScreenshotsPath = screenshotsfolderpath.Text.Trim(); //mxd
+
+			// Script settings
+			General.Settings.ScriptFontBold = scriptfontbold.Checked;
+			General.Settings.ScriptFontName = scriptfontname.Text;
+			General.Settings.ScriptOnTop = scriptontop.Checked;
+			General.Settings.ScriptUseTabs = scriptusetabs.Checked;
+			General.Settings.ScriptTabWidth = scripttabwidth.GetResult(General.Settings.ScriptTabWidth);
+			General.Settings.ScriptAutoIndent = scriptautoindent.Checked;
+			General.Settings.ScriptAllmanStyle = scriptallmanstyle.Checked; //mxd
+			General.Settings.ScriptAutoCloseBrackets = scriptautoclosebrackets.Checked; //mxd
+			General.Settings.ScriptShowFolding = scriptshowfolding.Checked; //mxd
+			General.Settings.ScriptShowLineNumbers = scriptshowlinenumbers.Checked; //mxd
+			General.Settings.ScriptAutoShowAutocompletion = scriptautoshowautocompletion.Checked; //mxd
 			
 			// Script font size
 			int fontsize;
@@ -286,6 +311,8 @@ namespace CodeImp.DoomBuilder.Windows
 			General.Colors.Indication = colorindication.Color;
 			General.Colors.Grid = colorgrid.Color;
 			General.Colors.Grid64 = colorgrid64.Color;
+
+			// Script editor colors
 			General.Colors.ScriptBackground = colorscriptbackground.Color;
 			General.Colors.LineNumbers = colorlinenumbers.Color;
 			General.Colors.PlainText = colorplaintext.Color;
@@ -293,6 +320,17 @@ namespace CodeImp.DoomBuilder.Windows
 			General.Colors.Keywords = colorkeywords.Color;
 			General.Colors.Literals = colorliterals.Color;
 			General.Colors.Constants = colorconstants.Color;
+			General.Colors.Strings = colorstrings.Color; //mxd
+			General.Colors.Includes = colorincludes.Color; //mxd
+			General.Colors.ScriptSelectionForeColor = colorselectionfore.Color; //mxd
+			General.Colors.ScriptSelectionBackColor = colorselectionback.Color; //mxd
+			General.Colors.ScriptIndicator = colorindicator.Color; //mxd
+			General.Colors.ScriptBraceHighlight = colorbrace.Color; //mxd
+			General.Colors.ScriptBadBraceHighlight = colorbracebad.Color; //mxd
+			General.Colors.ScriptWhitespace = colorwhitespace.Color; //mxd
+			General.Colors.ScriptFoldForeColor = colorfoldfore.Color; //mxd
+			General.Colors.ScriptFoldBackColor = colorfoldback.Color; //mxd
+			
 			//mxd
 			General.Colors.ModelWireframe = colorMD3.Color;
 			General.Colors.InfoLine = colorInfo.Color;
@@ -372,7 +410,7 @@ namespace CodeImp.DoomBuilder.Windows
 			}
 			
 			colorsgroup1.Visible = (tabs.SelectedTab == tabcolors);
-			colorsgroup3.Visible = (tabs.SelectedTab == tabcolors);
+			previewgroup.Visible = (tabs.SelectedTab == tabscripteditor);
 		}
 
 		#endregion
@@ -440,89 +478,6 @@ namespace CodeImp.DoomBuilder.Windows
 			labelRecentFiles.Text = recentFiles.Value.ToString();
 		}
 
-		// This updates the script font preview label
-		private void UpdateScriptFontPreview()
-		{
-			if((scriptfontname.SelectedIndex > -1) &&
-			   (scriptfontsize.SelectedIndex > -1))
-			{
-				FontFamily ff = new FontFamily(scriptfontname.Text);
-				FontStyle style = FontStyle.Regular;
-				if(scriptfontbold.Checked)
-				{
-					// Prefer bold over regular
-					if(ff.IsStyleAvailable(FontStyle.Bold))
-						style = FontStyle.Bold;
-					else if(ff.IsStyleAvailable(FontStyle.Regular))
-						style = FontStyle.Regular;
-					else if(ff.IsStyleAvailable(FontStyle.Italic))
-						style = FontStyle.Italic;
-					else if(ff.IsStyleAvailable(FontStyle.Underline))
-						style = FontStyle.Underline;
-					else if(ff.IsStyleAvailable(FontStyle.Strikeout))
-						style = FontStyle.Strikeout;
-				}
-				else
-				{
-					// Prefer regular over bold
-					if(ff.IsStyleAvailable(FontStyle.Regular))
-						style = FontStyle.Regular;
-					else if(ff.IsStyleAvailable(FontStyle.Bold))
-						style = FontStyle.Bold;
-					else if(ff.IsStyleAvailable(FontStyle.Italic))
-						style = FontStyle.Italic;
-					else if(ff.IsStyleAvailable(FontStyle.Underline))
-						style = FontStyle.Underline;
-					else if(ff.IsStyleAvailable(FontStyle.Strikeout))
-						style = FontStyle.Strikeout;
-				}
-				int fontsize;
-				if(!int.TryParse(scriptfontsize.Text, out fontsize)) fontsize = 8;
-				if(ff.IsStyleAvailable(style))
-					fontpreview.Font = new Font(scriptfontname.Text, fontsize, style); //mxd
-
-				//mxd. Update preview colors
-				fontpreview.BackColor = colorscriptbackground.Color.ToColor();
-				fontpreview.ForeColor = colorplaintext.Color.ToColor();
-
-				//1
-				fontpreview.Select(0, 1);
-				fontpreview.SelectionColor = colorlinenumbers.Color.ToColor();
-
-				//2
-				fontpreview.Select(25, 1);
-				fontpreview.SelectionColor = colorlinenumbers.Color.ToColor();
-
-				//script
-				fontpreview.Select(27, 6);
-				fontpreview.SelectionColor = colorkeywords.Color.ToColor();
-
-				//0
-				fontpreview.Select(34, 1);
-				fontpreview.SelectionColor = colorliterals.Color.ToColor();
-
-				//void
-				fontpreview.Select(37, 4);
-				fontpreview.SelectionColor = colorkeywords.Color.ToColor();
-
-				//a comment
-				fontpreview.Select(45, 11);
-				fontpreview.SelectionColor = colorcomments.Color.ToColor();
-
-				//3
-				fontpreview.Select(57, 1);
-				fontpreview.SelectionColor = colorlinenumbers.Color.ToColor();
-
-				//CONSTANT_VALUE
-				fontpreview.Select(65, 14);
-				fontpreview.SelectionColor = colorconstants.Color.ToColor();
-
-				//4
-				fontpreview.Select(81, 1);
-				fontpreview.SelectionColor = colorlinenumbers.Color.ToColor();
-			}
-		}
-
 		#endregion
 		
 		#region ================== Controls Panel
@@ -545,7 +500,7 @@ namespace CodeImp.DoomBuilder.Windows
 						// Don't count the selected action
 						if(item != listactions.SelectedItems[0])
 						{
-							Actions.Action a = General.Actions[item.Name];
+							Action a = General.Actions[item.Name];
 							int akey = (int)item.SubItems[1].Tag;
 
 							// Check if the key combination matches
@@ -573,7 +528,7 @@ namespace CodeImp.DoomBuilder.Windows
 		}
 		
 		// This fills the list of available controls for the specified action
-		private void FillControlsList(Actions.Action a)
+		private void FillControlsList(Action a)
 		{
 			actioncontrol.Items.Clear();
 			
@@ -810,9 +765,9 @@ namespace CodeImp.DoomBuilder.Windows
 				actioncontrol.SelectedIndex = -1;
 				
 				// Apply the key combination
-				listactions.SelectedItems[0].SubItems[1].Text = Actions.Action.GetShortcutKeyDesc(key);
+				listactions.SelectedItems[0].SubItems[1].Text = Action.GetShortcutKeyDesc(key);
 				listactions.SelectedItems[0].SubItems[1].Tag = key;
-				actionkey.Text = Actions.Action.GetShortcutKeyDesc(key);
+				actionkey.Text = Action.GetShortcutKeyDesc(key);
 				
 				// Show actions with same key
 				UpdateKeyUsedActions();
@@ -841,7 +796,7 @@ namespace CodeImp.DoomBuilder.Windows
 				KeyControl key = (KeyControl)actioncontrol.SelectedItem;
 
 				// Apply the key combination
-				listactions.SelectedItems[0].SubItems[1].Text = Actions.Action.GetShortcutKeyDesc(key.key);
+				listactions.SelectedItems[0].SubItems[1].Text = Action.GetShortcutKeyDesc(key.key);
 				listactions.SelectedItems[0].SubItems[1].Tag = key.key;
 				
 				// Show actions with same key
@@ -966,28 +921,133 @@ namespace CodeImp.DoomBuilder.Windows
 			labelDynLightIntensity.Text = ((float)tbDynLightIntensity.Value / 10).ToString();
 		}
 
-		//mxd
-		private void scriptfontbold_CheckedChanged(object sender, EventArgs e) 
+		#endregion
+
+		#region ================== Script Editor Panel (mxd)
+
+		private void scriptfontbold_CheckedChanged(object sender, EventArgs e)
 		{
-			UpdateScriptFontPreview();
+			if(allowapplycontrol) scriptedit.FontBold = scriptfontbold.Checked;
 		}
 
-		//mxd
 		private void scriptfontsize_SelectedIndexChanged(object sender, EventArgs e) 
 		{
-			UpdateScriptFontPreview();
+			if(allowapplycontrol)
+			{
+				int fontsize;
+				if(int.TryParse(scriptfontsize.Text, out fontsize))
+					scriptedit.FontSize = fontsize;
+			}
 		}
 
-		//mxd
-		private void scriptfontname_SelectedIndexChanged(object sender, EventArgs e) 
+		private void scripttabwidth_WhenTextChanged(object sender, EventArgs e)
 		{
-			UpdateScriptFontPreview();
+			if(allowapplycontrol)
+			{
+				int tabwidth;
+				if(int.TryParse(scripttabwidth.Text, out tabwidth))
+					scriptedit.TabWidth = tabwidth;
+			}
 		}
 
-		//mxd
-		private void scriptcolor_ColorChanged(object sender, EventArgs e) 
+		private void scriptfontname_SelectedIndexChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.FontName = scriptfontname.Text;
+		}
+
+		private void scriptshowlinenumbers_CheckedChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.ShowLineNumbers = scriptshowlinenumbers.Checked;
+		}
+
+		private void scriptshowfolding_CheckedChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.ShowFolding = scriptshowfolding.Checked;
+		}
+
+		private void colorscriptbackground_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.ScriptBackground = colorscriptbackground.Color.ToColor();
+		}
+
+		private void colorlinenumbers_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.LineNumbers = colorlinenumbers.Color.ToColor();
+		}
+
+		private void colorplaintext_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.PlainText = colorplaintext.Color.ToColor();
+		}
+
+		private void colorcomments_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.Comments = colorcomments.Color.ToColor();
+		}
+
+		private void colorkeywords_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.Keywords = colorkeywords.Color.ToColor();
+		}
+
+		private void colorstrings_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.Strings = colorstrings.Color.ToColor();
+		}
+
+		private void colorliterals_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.Literals = colorliterals.Color.ToColor();
+		}
+
+		private void colorconstants_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.Constants = colorconstants.Color.ToColor();
+		}
+
+		private void colorincludes_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.Includes = colorincludes.Color.ToColor();
+		}
+
+		private void colorselectionfore_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.SelectionForeColor = colorselectionfore.Color.ToColor();
+		}
+
+		private void colorselectionback_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.SelectionBackColor = colorselectionback.Color.ToColor();
+		}
+
+		private void colorindicator_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.ScriptIndicator = colorindicator.Color.ToColor();
+		}
+
+		private void colorbrace_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.BraceHighlight = colorbrace.Color.ToColor();
+		}
+
+		private void colorbracebad_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.BadBraceHighlight = colorbracebad.Color.ToColor();
+		}
+
+		private void colorwhitespace_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.WhitespaceColor = colorwhitespace.Color.ToColor();
+		}
+
+		private void colorfoldfore_ColorChanged(object sender, EventArgs e)
+		{
+			if(allowapplycontrol) scriptedit.FoldForeColor = colorfoldfore.Color.ToColor();
+		}
+
+		private void colorfoldback_ColorChanged(object sender, EventArgs e)
 		{
-			UpdateScriptFontPreview();
+			if(allowapplycontrol) scriptedit.FoldBackColor = colorfoldback.Color.ToColor();
 		}
 
 		#endregion
diff --git a/Source/Core/Windows/PreferencesForm.resx b/Source/Core/Windows/PreferencesForm.resx
index eba560cbc..acc38253f 100644
--- a/Source/Core/Windows/PreferencesForm.resx
+++ b/Source/Core/Windows/PreferencesForm.resx
@@ -144,15 +144,19 @@
   <metadata name="label21.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>False</value>
   </metadata>
-  <data name="snippetsallmanstyle.ToolTip" xml:space="preserve">
+  <metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <data name="scriptallmanstyle.ToolTip" xml:space="preserve">
     <value>When enabled, the opening brace 
-will be placed on a new line.
+will be placed on a new line when
+inserting a snippet or reformatting
+the text.
 
 Technical side: when enabled, $LB
 markers in snippets will be replaced 
 with newline characters, otherwise 
-they will be replaced with spaces
-</value>
+they will be replaced with tabs/spaces.</value>
   </data>
   <metadata name="browseScreenshotsFolderDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>114, 17</value>
-- 
GitLab