1

I am writing scripts and I need to separate actual text from comments by color. For example the code is in black, and the comments are in red.

**writeln('this one should be BLACK');**
*this is a commentary, which should be RED* 

Is there any software which would allow me to type text and switch current typing color by a matter of pressing a key? for example CAPSLOCK .. ?

3
  • 1
    You may need to detail (in the original question, please!) what you have tried already and why it didn't work and a bit more detail on what features you must have. Commented May 7, 2020 at 16:52
  • It depends on your editor. For example, in nano, vi, VSCode, BBEdit, etc, they all have “filters” that do this type of thing. What editor are you using?
    – Allan
    Commented May 7, 2020 at 17:00
  • I'm using sublime. But I don't even need a "text-editor-compiler". I just need a text editor in which you can easily change text color while typing Commented May 7, 2020 at 17:16

2 Answers 2

2

What you are looking for are Color Schemes, which automatically set the text color based on the context. Sublime supports them out of the box, see https://docs.sublimetext.io/guide/customization/color_schemes.html and https://www.sublimetext.com/docs/3/color_schemes.html.

2
  • thank you, but I don't want context to define my text color. I WANT to do it. I should be responsible for this. At any given moment, in any context, to change the color of the text. Commented May 7, 2020 at 17:58
  • @DimaWhite Feel free to edit your question to make this more clear. But for this to work you need to use somethink like Word or Pages who support text formatting embedded in the text. Color Schemes only show the color on the UI, the stored text doesn't contain color information.
    – nohillside
    Commented May 7, 2020 at 18:01
1

but I don't want context to define my text color. I WANT to do it. I should be responsible for this.

The issue with this is that good code editors ideally do not like to modify your source files.

For your use case the editor will have to store some extra information (metadata) somewhere so that it can keep track of, and display, the right colour to you in the editor. It can do this by storing this additional metadata in your source file itself or by storing it separately in its own database or a separate file.

Obviously adding this extra information in the source file may interfere with code execution, when you run your code. Storing the data separately is better but this data can be lost if you don't copy the metadata file / rules too when copying your source file and viewing it in a different system.

That's why most code editors display colours based on context, after analysing your code, as this way, they don't have to include any additional data in your source file.


Anyway, you can try the first approach by defining your own metadata and storing it in your source code using TextMate.

TextMate editor has a feature called Bundles (equivalent to macros or scripts).

You should be able to do what you want by creating your own bundle to search for some specific keywords in code comments (like NOTE, WARNING, TODO or RED, BLUE, GREEN etc.) and defining that when such keywords are encountered the text following them should be coloured with whatever colour you have defined for them.

Here's the documentation on TextMate Bundles.


Otherwise, just use Pages and write your code in that. And when you want to execute your code, manually copy and paste it to a text file and run it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .