Page 1 of 1

Disable highlighting on a file size limit

Posted: 06 May 2020 14:40
by lolo
Hello,

Is there a way to automatically disable highlighting on a file if this file is bigger than a specific size?

For example, I would like to open a big SQL file but without highlighting (for better performance at opening and parsing file)
I have had a look in "Options" and "Highlighting and margin" but without success.

Thanks in advance for your answer and have a nice day.

Re: Disable highlighting on a file size limit

Posted: 10 Jul 2020 16:14
by pjj
I don't know if you still need a hand here, but here's my solution: set this particular file format to simple text and run script posted below on file open:

Code: Select all

let threshold = 1000000;
let myExt = "xml";
let myHighlighter = "xml";

let len = length(Document.Text());
let filename = Document.FileName();
let ext = Copy(filename, length(filename) - 2, 3);

if ((ext == myExt) && (len < threshold)) {
    MainApp.SetHighlighter(myHighlighter);
}
If any file has the extension you want and is bigger than the threshold you set, appropriate highlighter will be switched on; otherwise, it will be displayed without any.

Re: Disable highlighting on a file size limit

Posted: 10 Jul 2020 19:09
by lolo
Hi pjj,

Thanks a lot for your answer.
I haven't thought about using a script when opening file and I have never used them before but I will have a look at these nice functionality.

RJ TextEd is so powerful :shock:

Re: Disable highlighting on a file size limit

Posted: 11 Jul 2020 09:21
by pjj
lolo wrote:
10 Jul 2020 19:09
RJ TextEd is so powerful :shock:
It truly is!

Please let me know if my script has worked for you. -- Btw it could be enhanced to accommodate files of all types (i.e. extensions), however I don't think it is the best idea to switch off native support for all highlighters and then switch them on via a script.