Skip to content

Commit

Permalink
Fancy comments, part 2
Browse files Browse the repository at this point in the history
Started implementing the fancy formatter.  It currently doesn't do
anything fancy, just word-wrapping.

Moved the static DebugShowRuler field into Formatter, so that the
cached data is discarded when the setting changes.

Also, updated SourceNotes with instructions for publishing a release.
  • Loading branch information
fadden committed Jul 6, 2024
1 parent 83da0d9 commit 1c84357
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 92 deletions.
16 changes: 14 additions & 2 deletions Asm65/Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class FormatConfig {

/// <summary>Insert space after delimiter for long comments?</summary>
public bool AddSpaceLongComment { get; set; } = false;
/// <summary>Enable debug mode for long comments?</summary>
public bool DebugLongComments { get; set; } = false;

//
// Functional changes to assembly output.
Expand Down Expand Up @@ -163,6 +165,7 @@ public FormatConfig(FormatConfig src) {
UpperOperandXY = src.UpperOperandXY;

AddSpaceLongComment = src.AddSpaceLongComment;
DebugLongComments = src.DebugLongComments;

SuppressHexNotation = src.SuppressHexNotation;
SuppressImpliedAcc = src.SuppressImpliedAcc;
Expand Down Expand Up @@ -539,6 +542,13 @@ public string FullLineCommentDelimiterPlus {
get { return mFullLineCommentDelimiterPlus; }
}

/// <summary>
/// If true, enable debug mode when rendering long comments.
/// </summary>
public bool DebugLongComments {
get { return mFormatConfig.DebugLongComments; }
}

/// <summary>
/// Prefix for non-unique address labels.
/// </summary>
Expand All @@ -565,15 +575,17 @@ public int OperandWrapLen {

/// <summary>
/// Constructor. Initializes various fields based on the configuration. We want to
/// do as much work as possible here.
/// pre-compute as many things as possible, to speed up formatting.
/// </summary>
public Formatter(FormatConfig config) {
mFormatConfig = new FormatConfig(config); // make a copy

if (string.IsNullOrEmpty(mFormatConfig.NonUniqueLabelPrefix)) {
mFormatConfig.NonUniqueLabelPrefix = "@";
}

if (string.IsNullOrEmpty(mFormatConfig.FullLineCommentDelimiterBase)) {
mFormatConfig.FullLineCommentDelimiterBase = "!";
}
if (mFormatConfig.AddSpaceLongComment) {
mFullLineCommentDelimiterPlus = mFormatConfig.FullLineCommentDelimiterBase + " ";
} else {
Expand Down
21 changes: 15 additions & 6 deletions SourceGen/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ public void ApplyAppSettings() {
settings.GetString(AppSettings.FMT_LOCAL_VARIABLE_PREFIX, string.Empty);
mFormatterConfig.CommaSeparatedDense =
settings.GetBool(AppSettings.FMT_COMMA_SEP_BULK_DATA, true);
mFormatterConfig.DebugLongComments = DebugLongComments;

string chrDelCereal = settings.GetString(AppSettings.FMT_CHAR_DELIM, null);
if (chrDelCereal != null) {
Expand Down Expand Up @@ -4721,6 +4722,11 @@ public void ViewAddressMap() {

#region Debug features

/// <summary>
/// If set, show rulers and visible spaces in long comments.
/// </summary>
internal bool DebugLongComments { get; private set; } = false;

public void Debug_ExtensionScriptInfo() {
string info = mProject.DebugGetLoadedScriptInfo();

Expand Down Expand Up @@ -4793,12 +4799,15 @@ public void Debug_Refresh() {
}

public void Debug_ToggleCommentRulers() {
MultiLineComment.DebugShowRuler = !MultiLineComment.DebugShowRuler;
// Don't need to repeat the analysis, but we do want to save/restore the
// selection and top position when the comment fields change size.
UndoableChange uc =
UndoableChange.CreateDummyChange(UndoableChange.ReanalysisScope.DataOnly);
ApplyChanges(new ChangeSet(uc), false);
DebugLongComments = !DebugLongComments;
mFormatterConfig.DebugLongComments = DebugLongComments;
mFormatterConfig.AddSpaceLongComment = !DebugLongComments;
mFormatterCpuDef = null; // force mFormatter refresh on next analysis
if (CodeLineList != null) {
UndoableChange uc =
UndoableChange.CreateDummyChange(UndoableChange.ReanalysisScope.DisplayOnly);
ApplyChanges(new ChangeSet(uc), false);
}
}

public void Debug_ToggleKeepAliveHack() {
Expand Down
Loading

0 comments on commit 1c84357

Please sign in to comment.