Search code examples
regextextg-codekate

Kate Text Editor regexp for CNC code alteration on PC


When using some CAM software, the CNC code is usually generated properly with spaces. But for example when moved to "Citizen Cincom L20" machine via USB or network and edited there it lose spaces and also lose semicolons while preserving new lines which does work as semicolons anyway.

But since editing of CNC program happens in 3 places: CAM Software(ESPRIT in this case), CNC machine controller and also via text editor on the computer as postprocessor in ESPRIT is garbage.I've come up with this regex


([0-9]{1,2})([A-Z])

\1 \2

so


G1G99X5.4Z-.5F.12

Becomes


G1 G99 X5.4 Z-.5 F.12

that works in Kate to space everything back again for clearer reviwing of code. The only issue about it is that I need to do that manually for every file and I would like to automate it, preferably via Kate, so it would happen upon opening any ????.PRG plain text files.

But I do not exactly know how such happening should be called is it like macro or what ? I'm looking for some suggestions to accomplish this. Or maybe some alternative solutions


Solution

  • First, go to View -> Tool Views -> Show Search and Replace. You will see

    enter image description here

    Make sure you:

    • Enable {} regex option on the right as you are using a regex
    • Enable "AB" option on the right that enables case sensitive matching
    • Select In Folder value from the dropdown on the right
    • Fill out the regex, replacement, Folder and the Filter fields with the appropriate values
    • Click Search button.

    You will see the results in a separate pane and Replace / Replace Checked buttons will become enabled.

    Review the replacements and click Replace Checked:

    enter image description here

    Then you may check the updated file contents, and if you are satisifed with the results, use Save All, also by pressing CTRL+L.