notepad-plus-plus / notepad-plus-plus

Notepad++ official repository

Home Page:https://notepad-plus-plus.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Ghost Comment Styling

CCS86 opened this issue · comments

commented

Is there an existing issue for this?

  • I have searched the existing issues

Description of the Issue

Even though my language is defined to only use ( ) for comments, I get comment styling randomly where it should not be. I can "chase" it and eventually get it to disappear without actually altering the content. Also, doing a compare seems to reset the bug as well.

Steps To Reproduce

I'm not sure the exact trigger for this behavior, but it happens to me regularly as of late.

Here is my language file:

EDM.xml.zip

Current Behavior

Comment.mp4

Expected Behavior

I expect comment styling only inside a pair of parenthesis.

Debug Information

Notepad++ v8.6.5   (64-bit)
Build time : Mar 29 2024 - 17:04:43
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line : "G:\Shared drives\Wolfram Engineering\W CAM\GCODE\TMA8-2\aaa.nc"
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
Periodic Backup : ON
OS Name : Windows 10 Pro (64-bit
OS Version : 22H2
OS Build : 19045.4291
Current ANSI codepage : 1252
Plugins : 
    ComparePlugin (2.0.2)
    mimeTools (3.1)
    NppConverter (4.6)
    NppExport (0.4)

Anything else?

I love the program, thank you!

commented

For G-code, there's already a collection of community-provided UDLs to choose from

Thank you for the suggestions, I appreciate it.

I checked them out and prefer a number of things about my own UDL.

One thing I noticed is that I am using "comment style" and those others are using "comment line style". That may have to do with the bug here.

I uploaded my UDL to the original post.

One thing I noticed is that I am using "comment style" and those others are using "comment line style". That may have to do with the bug here.

Tested with OP EDM.xml . Thanks for providing @CCS86

  • "comment style" ends at the ) even if exist on the next line.
  • "comment line style" ends at the ) or newline.

IMO, switch to "comment line style" if comments cannot be multiline else may need to use Auto-Insert ( ) to restrain the style.


https://github.com/NCalu/NCneticNpp
Plugin with builtin lexer and plotter. Unfortunately, the foreground colours are builtin so is not configurable by the user, though uncheck styling in the plugins menu to use custom UDL. If the plotter is closed then the styling is removed so may need to reactivate UDL. If the plotter is unwanted, then probably remain with just the UDL.

commented

One thing I noticed is that I am using "comment style" and those others are using "comment line style". That may have to do with the bug here.

Tested with OP EDM.xml . Thanks for providing @CCS86

  • "comment style" ends at the ) even if exist on the next line.
  • "comment line style" ends at the ) or newline.

IMO, switch to "comment line style" if comments cannot be multiline else may need to use Auto-Insert ( ) to restrain the style.

https://github.com/NCalu/NCneticNpp Plugin with builtin lexer and plotter. Unfortunately, the foreground colours are builtin so is not configurable by the user, though uncheck styling in the plugins menu to use custom UDL. If the plotter is closed then the styling is removed so may need to reactivate UDL. If the plotter is unwanted, then probably remain with just the UDL.

Thank you, I will give that a try. It isn't a huge deal to individually bracket multi-line comments in my code.

commented

The problem with this workaround of using "comment line style" is that it doesn't help me identify when I am missing close parenthesis, and the comment "spills" out. The styling ends at the new line, in NP++, but on the machine it causes issues.

@CCS86 The "comment line style" seems OK though no error style available which I tried and failed to get with the UDL if a closing parentheses was missing, I guess the cnc machine has no tolerance for the missing parentheses. It is basically a job for a syntax checker/linter though not sure where a good one exists. PythonScript plugin could check on save if the parentheses are paired.

# Validate file saved
# https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript/1
# https://github.com/notepad-plus-plus/notepad-plus-plus/issues/15046

from Npp import editor, notepad, MESSAGEBOXFLAGS, NOTIFICATION

if 'fileSavedValidatation' not in globals():
    def fileSavedValidatation(args):
        bufferID = args['bufferID']
        langType = notepad.getLangType(bufferID)
        langName = notepad.getLanguageName(langType)

        if langName == 'udf - EDM':
            warn = 0

            for line in range(editor.getLineCount()):
                text = editor.getLine(line)

                if '(' in text or ')' in text:
                    if text.count('(') != text.count(')'):
                        warn += 1
                        editor.eOLAnnotationSetText(line, '<--- WARNING: Parentheses not paired ')

            if warn:
                editor.eOLAnnotationSetVisible(0x112)
                msg = 'Warnings to resolve: {}'.format(warn)
                notepad.messageBox(msg, 'fileSavedValidatation', MESSAGEBOXFLAGS.ICONWARNING)
            else:
                editor.eOLAnnotationClearAll()


    notepad.callback(fileSavedValidatation, [NOTIFICATION.FILESAVED])

Could be set to imported in the users startup.py if cnc is a full time task. If imported, could put it in the plugins\Config\PythonScript\lib directory so is not listed to the plugins menu. Create the lib folder if not exist. Set PythonScript to initialize at ATSTARTUP in it's configuration.

Uses a callback which is triggered on a file saved and if it has the udf - EDM name, it will check if the parentheses are paired on each line. If not, warning eol annotations will be inserted into the document to point out where to solve with a fix and a messagebox will display at the end of the checked lines to catch your attention. Save the fixed document again which will clear the eol annotations.

cnc

Excerpt from test file to reproduce:

N0 (Filename: 10267.TAP)
N1 (Post processor: MachMotion Plasma by SigmaNEST)
N2 (Date: 6/1/2016)
N3 (Start Parameters)
N4 (Material: Type: MS, Thickness: 0.25)
N5 (Plasma: Pierce Height: .2, Pierce Time: .4)
N6 (Plasma: Cut Height: .15)
N7 (Plasma: Arc Voltage: , Amperage: 80)
N8 (End Parameters)
N9 G20 (Units:Inches)
N10 G90
N11 (Part: P52)
N12 M6 T1 (Plasma)
N13 G00 X1.1232 Y0.503 F100.
N14 M63 P60
N15 M3
N16 G01 X1.1585 Y0.4676 F100.
N17 G01 X1.2116 Y0.4146 F100. G09
N18 G01 X1.2116 Y1.3366 F100.
N19 G01 X0.2896 Y1.3366 F100.