Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
fixes #144
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Oct 23, 2017
1 parent dc02eda commit ecabb08
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 21 deletions.
1 change: 1 addition & 0 deletions 3PA/3P.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
<Compile Include="Lib\ProcessIo.cs" />
<Compile Include="Lib\ProgressCopy.cs" />
<Compile Include="Lib\RecurentAction.cs" />
<Compile Include="MainFeatures\SyntaxHighlighting\SyntaxFolding.cs" />
<Compile Include="NppCore\NppLang.cs" />
<Compile Include="MainFeatures\HtmlHelper.cs" />
<Compile Include="MainFeatures\ModificationsTag\ModificationTag.cs" />
Expand Down
11 changes: 0 additions & 11 deletions 3PA/MainFeatures/Pro/ProCodeFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,9 @@ public static void CorrectCodeIndentation() {
StringBuilder x = new StringBuilder();
var indentWidth = Sci.TabWidth;
var i = 0;
var lastIdent = 0;
var dic = parser.LineInfo;
while (dic.ContainsKey(i)) {
var line = Sci.GetLine(i);
line.FoldLevel = (int)SciMsg.SC_FOLDLEVELBASE + dic[i].BlockDepth;
if (dic[i].BlockDepth > lastIdent) {
if (i > 0)
Sci.GetLine(i - 1).FoldLevelFlags = FoldLevelFlags.Header;
lastIdent = dic[i].BlockDepth;
} else {
if (dic[i].BlockDepth < lastIdent)
lastIdent = dic[i].BlockDepth;

}
line.Indentation = dic[i].BlockDepth * indentWidth;
if (!canIndentSafely)
x.AppendLine(i + 1 + " > " + dic[i].BlockDepth + " , " + dic[i].Scope.ScopeType + " , " + dic[i].Scope.Name);
Expand Down
56 changes: 56 additions & 0 deletions 3PA/MainFeatures/SyntaxHighlighting/SyntaxFolding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#region header
// ========================================================================
// Copyright (c) 2017 - Julien Caillon ([email protected])
// This file (SyntaxFolding.cs) is part of 3P.
//
// 3P is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 3P is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with 3P. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================
#endregion
using System.Collections.Generic;
using System.Threading.Tasks;
using _3PA.MainFeatures.Parser;
using _3PA.NppCore;

namespace _3PA.MainFeatures.SyntaxHighlighting {

internal class SyntaxFolding {

public static void OnParseEndParserItems(List<ParserError> arg1, Dictionary<int, LineInfo> lineInfos, List<ParsedItem> arg3) {
var lineInfoCopy = new Dictionary<int, LineInfo>(lineInfos);

Task.Factory.StartNew(() => {
UiThread.Invoke(() => SetFolding(lineInfoCopy));
});
}

public static void SetFolding(Dictionary<int, LineInfo> lineInfos) {
var i = 0;
var lastIdent = 0;
while (lineInfos.ContainsKey(i)) {
var line = Sci.GetLine(i);
line.SetFoldLevel(lineInfos[i].BlockDepth, FoldLevelFlags.None);
if (lineInfos[i].BlockDepth > lastIdent) {
if (i > 0)
Sci.GetLine(i - 1).FoldLevelFlags = FoldLevelFlags.Header;
lastIdent = lineInfos[i].BlockDepth;
} else {
if (lineInfos[i].BlockDepth < lastIdent)
lastIdent = lineInfos[i].BlockDepth;

}
i++;
}
}
}
}
18 changes: 13 additions & 5 deletions 3PA/MainFeatures/SyntaxHighlighting/SyntaxHighlightVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// along with 3P. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================
#endregion
using System;
using System.Linq;
using _3PA.MainFeatures.AutoCompletionFeature;
using _3PA.MainFeatures.Parser;
Expand All @@ -31,6 +32,8 @@ internal class SyntaxHighlightVisitor : ILexerVisitor {

private char[] _operatorChars = { '=', '+', '-', '/', '*', '^', '<', '>' };

private string[] _normedVariables = {"gc_", "gch_", "gda_", "gdt_", "gdz_", "gd_", "gh_", "gi_", "gl_", "glg_", "gm_", "grw_", "gr_", "gr_", "gwh_", "sc_", "gch_", "gda_", "gdt_", "gdz_", "gd_", "gh_", "gi_", "gl_", "glg_", "gm_", "grw_", "gr_", "gr_", "gwh_", "lc_", "lch_", "lda_", "ldt_", "ldz_", "ld_", "lh_", "li_", "ll_", "llg_", "lm_", "lrw_", "lr_", "lr_", "lwh_", "ipc_", "ipch_", "ipda_", "ipdt_", "ipdz_", "ipd_", "iph_", "ipi_", "ipl_", "iplg_", "ipm_", "iprw_", "ipr_", "ipr_", "ipwh_", "opc_", "opch_", "opda_", "opdt_", "opdz_", "opd_", "oph_", "opi_", "opl_", "oplg_", "opm_", "oprw_", "opr_", "opr_", "opwh_", "iop_", "iopc_", "iopch_", "iopda_", "iopdt_", "iopdz_", "iopd_", "ioph_", "iopi_", "iopl_", "ioplg_", "iopm_", "ioprw_", "iopr_", "iopr_", "iopwh_"};

public void PreVisit(Lexer lexer) {
var proLexer = lexer as ProLexer;
if (proLexer != null) {
Expand Down Expand Up @@ -101,12 +104,17 @@ public void Visit(TokenWord tok) {
if (existingKeywords != null && existingKeywords.Count > 0) {
style = existingKeywords.First().KeywordSyntaxStyle;
}
}

//NormedVariables, // variables prefix (gc_, li_...)
/*"gc_", "gch_", "gda_", "gdt_", "gdz_", "gd_", "gh_", "gi_", "gl_", "glg_", "gm_", "grw_", "gr_", "gr_", "gwh_", "sc_", "gch_", "gda_", "gdt_", "gdz_", "gd_", "gh_", "gi_", "gl_", "glg_", "gm_", "grw_", "gr_", "gr_", "gwh_", "lc_", "lch_", "lda_", "ldt_", "ldz_", "ld_", "lh_", "li_", "ll_", "llg_", "lm_", "lrw_", "lr_", "lr_", "lwh_", "ipc_", "ipch_", "ipda_", "ipdt_", "ipdz_", "ipd_", "iph_", "ipi_", "ipl_", "iplg_", "ipm_", "iprw_", "ipr_", "ipr_", "ipwh_", "opc_", "opch_", "opda_", "opdt_", "opdz_", "opd_", "oph_", "opi_", "opl_", "oplg_", "opm_", "oprw_", "opr_", "opr_", "opwh_", "iop_", "iopc_", "iopch_", "iopda_", "iopdt_", "iopdz_", "iopd_", "ioph_", "iopi_", "iopl_", "ioplg_", "iopm_", "ioprw_", "iopr_", "iopr_", "iopwh_",
*/

// normed variables
if (style == SciStyleId.Default) {
var pos = tok.Value.IndexOf("_", StringComparison.CurrentCultureIgnoreCase);
if (pos > 0 && tok.Value.Length >= pos + 1) {
var prefix = tok.Value.Substring(0, pos + 1);
if (_normedVariables.Contains(prefix))
style = SciStyleId.NormedVariables;
}
}
}
SetStyling(tok.EndPosition - tok.StartPosition, style);
}

Expand Down
1 change: 0 additions & 1 deletion 3PA/NppCore/NppFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with 3P. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================
#endregion

using System.Collections.Generic;
using System.Text;
using _3PA.Lib;
Expand Down
1 change: 0 additions & 1 deletion 3PA/NppCore/NppLang.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with 3P. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================
#endregion

using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down
3 changes: 3 additions & 0 deletions 3PA/NppCore/SciLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ public FoldLevelFlags FoldLevelFlags {
}
}

/// <summary>
/// Set fold level and flag in one go
/// </summary>
public void SetFoldLevel(int level, FoldLevelFlags flag) {
var bits = level + (int) SciMsg.SC_FOLDLEVELBASE;
if (flag != FoldLevelFlags.None)
Expand Down
1 change: 0 additions & 1 deletion 3PA/NppCore/SciMarkerHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with 3P. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================
#endregion

using System;

namespace _3PA.NppCore {
Expand Down
21 changes: 20 additions & 1 deletion 3PA/NppCore/SciMsg.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
using System;
#region header
// ========================================================================
// Copyright (c) 2017 - Julien Caillon ([email protected])
// This file (SciMsg.cs) is part of 3P.
//
// 3P is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 3P is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with 3P. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================
#endregion
using System;
// ReSharper disable InconsistentNaming

namespace _3PA.NppCore {
Expand Down
21 changes: 20 additions & 1 deletion 3PA/NppCore/SciMsgSub.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
using System;
#region header
// ========================================================================
// Copyright (c) 2017 - Julien Caillon ([email protected])
// This file (SciMsgSub.cs) is part of 3P.
//
// 3P is a free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 3P is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with 3P. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================
#endregion
using System;

namespace _3PA.NppCore {

Expand Down
1 change: 1 addition & 0 deletions 3PA/Plug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ internal static void DoPlugStart() {
ParserHandler.OnStart += CodeExplorer.Instance.OnStart;
ParserHandler.OnEndSendCompletionItems += AutoCompletion.SetDynamicItems;
ParserHandler.OnEndSendParserItems += CodeExplorer.Instance.OnParseEndParserItems;
ParserHandler.OnEndSendParserItems += SyntaxFolding.OnParseEndParserItems;
ParserHandler.OnEndSendCodeExplorerItems += CodeExplorer.Instance.OnParseEndCodeExplorerItems;
ParserHandler.OnEnd += CodeExplorer.Instance.OnParseEnd;

Expand Down
1 change: 1 addition & 0 deletions NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

- #178 : Creation of NppBackup folder near the file saved
- Now try to show the version log to the user until it has actually been seen
- #144 : Syntax definition error on Function Foward sentences

0 comments on commit ecabb08

Please sign in to comment.