Show total count of chars/words in statusbar

pintassilgo
Posts: 24
Joined: 08.03.2023 07:48

Show total count of chars/words in statusbar

Post by pintassilgo »

Thanks.

If you don't mind, I plan to reuse this thread to some minor questions not worth a dedicated thread. Starting with this one:

Do you know if there is a config or plugin to add chars and lines counter to status bar (maybe words too)? The same when there is a selection (count of chars, lines and words of the selected text). Other editors have this feature, like Notepad++, Kate, SciTE...
main Alexey
Posts: 2308
Joined: 25.08.2021 18:15

Post by main Alexey »

Yes, read about options

ui_statusbar_str_sel
ui_statusbar_small_sel
ui_statusbar_no_sel
ui_statusbar_carets

they have about 20 _macros_.
main Alexey
Posts: 2308
Joined: 25.08.2021 18:15

Post by main Alexey »

Please make a new thread- name it like "Minor questions about editor usage"
pintassilgo
Posts: 24
Joined: 08.03.2023 07:48

Post by pintassilgo »

Please make a new thread- name it like "Minor questions about editor usage"
Right, I'll do it if new questions arise.
Yes, read about options

ui_statusbar_str_sel
ui_statusbar_small_sel
ui_statusbar_no_sel
ui_statusbar_carets

they have about 20 _macros_.
Thanks, but with the available _macros_ I was only able to add the total amount of lines (with {count}).

It seems to be no way to get the total amount of chars, the total amount of words and the position of the caret in terms of chars or words.

Look at Notepad++ statusbar as an example:

Code: Select all

length: 17.646	lines: 475	|	Ln: 44	Col: 28	Pos: 1.652
With CudaText, I can't retrieve "length" (total chars) or "Pos" (total chars from the beginning up to caret).

Other example, Kate statusbar:

Code: Select all

6/15:33, Words 18, Chars 242
Which means

Code: Select all

{current_line}/{total_lines}:{current_col}, Words {total_words}, Chars: {total_chars}
With CudaText, I can't retrieve total words or total chars.

Specially the total of chars is important to me to be able to do a very quick and simple check if two files may be identical.
main Alexey
Posts: 2308
Joined: 25.08.2021 18:15

Post by main Alexey »

>It seems to be no way to get the total amount of chars, the total amount of words and the position of the caret in terms of chars or words.

To get it we need _slower_code, so they are absent. plugin "Text Statistics" shows this in a message box.
counting of words is slow.
and counting of total chars is slow - this needs counting ALL text lines, and if file is huge (50K lines) this needs (50K) additions.
counting of words is even slower! it needs looping over ALL text. how it will work on 50K lines text?

But this all can be added via plugin! if it uses on_change_slow, then it must be fast. ops, not 'fast' but no slowdown of work.
pintassilgo
Posts: 24
Joined: 08.03.2023 07:48

Post by pintassilgo »

A possible optimization in this matter is to only count everything once: when loading the file. After that, it's cheap to just handle events. For instance, if a single char is typed with no deletion, just add +1 to char count, no need to count the entire text. If something was pasted, count just the pasted content and add its size to the counter...

Word might be a little more complex, but for me it's fine, I'm mostly interested in total chars.
main Alexey
Posts: 2308
Joined: 25.08.2021 18:15

Post by main Alexey »

oh, what you suggested here, is very hard to code (on simple typing - ok, on simple paste without selection - ok, but on more compex cases, with selection, with multi-carets with multi-selections - bad).
pintassilgo
Posts: 24
Joined: 08.03.2023 07:48

Post by pintassilgo »

OK, fair enough. In any case, the suggestion remains for future consideration. At least char count visible in statusbar is almost universal across editors.

I did a quick task in Notepad++: copied the content of a file with 475 lines and 18k chars over and over until it surpassed 50k lines, with almost 2kk chars. It looks fine. Typing fast on a file that big has a bit of delay, not to the point of being annoying. And my guess is that the counter is not at fault.
pintassilgo
Posts: 24
Joined: 08.03.2023 07:48

Post by pintassilgo »

Now I repeated the same task on SciTE and it's so smooth as if the file is empty. I can't notice any slowness, not even the minimal. And it has chars counter. The content of statusbar, for reference:

Code: Select all

Line 53558, Column 19 | 1940435 Chars, 53562 Lines | 0 chars, 0 lines | LF
(it means current | total | selection)

If I make a biiig selection involving half of the content or almost all of it, counters update instantly. Of course I don't know the internal code, but *looks* and *feels* cheap, without any performance impact.
Last edited by pintassilgo on 10.03.2023 08:21, edited 3 times in total.
main Alexey
Posts: 2308
Joined: 25.08.2021 18:15

Post by main Alexey »

Maybe you can ask at NP++/SciTE forums - how they count charrs/words. simple adding on each update? cache?
Post Reply