Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show word count on status bar #1136

Closed
abdekker opened this issue Nov 12, 2015 · 45 comments
Closed

Show word count on status bar #1136

abdekker opened this issue Nov 12, 2015 · 45 comments
Labels

Comments

@abdekker
Copy link

Using v6.3 here. Currently the status bar has a panel that says "length : 31003 lines : 507" (in my example). The number of bytes is interesting but in some circumstances not of interest, whereas the number of words might be. My suggestion is to be able to toggle between "file size" and "word count" in the status bar. The status bar would then appear as:

  • "length : 31003 lines : 507" [if File size (default) is selected]
  • "words: 4943 lines: 507" [if Word count is selected]

I realise there is the menu option View > Summary... gives some of this information, but that's a bit buried away and requires several clicks.

Great job on notepad++, love it!

@denis-bogdanas
Copy link

I subscribe to this request.

@joergneulist
Copy link

You can also access the Summary by double clicking on the status bar. Still, I would also love to see the word count without interacting!

@abdekker
Copy link
Author

abdekker commented Jun 12, 2017

@joergneulist: Thanks! Did not know about that. The original feature request is still valid, but this is useful (hidden) feature.

@jamesford42
Copy link

+1

1 similar comment
@vbasarkar
Copy link

+1

@stoptheinsanity
Copy link

I use the double click method, but for me, if I could just glance at the status bars and clearly see the word count it wouldn't break the flow of writing.

@laocoi
Copy link

laocoi commented Nov 28, 2017

Vote for this feature

@Aenadon
Copy link

Aenadon commented Nov 28, 2017

Absolutely! Please do this!

@bitseeker
Copy link

+1 from me. Would be very progressive in workflow.

@igavronski
Copy link

+1 -- or even better, a customizable status bar would be great.

@sasumner
Copy link
Contributor

Possibly relevant: https://notepad-plus-plus.org/community/topic/14889/footer-sel-to-include-word-count

@a4jp-com
Copy link

Can I request the number of words selected get counted and displayed automatically in the bottom info bar? Everything else I wanted has been fixed and this program is wonderful. This would be very useful for students submitting homework that need to be certain lengths. As well as university students and SEO (Search Engine Optimization) workers like me that need to also find text throughout multiple files.

Like this: selected count/total count

@sasumner
Copy link
Contributor

Maybe I'm off base here but perhaps an idea on why this hasn't been implemented is that it could be "expensive" to calculate the number of words in a really large document. The standard things currently shown on the status bar are all direct Scintilla calls to data items that are already maintained.

@a4jp-com
Copy link

Word and Open Office can easily do this. It can't be that taxing on a modern day PC to do a word count. The total count is already built in and counting selected words in text when being selected isn't millions of words. It's just the words selected.

@a4jp-com
Copy link

Where is the code for the summary word count and the toolbar currently?

@sasumner
Copy link
Contributor

@a4jp-com It is not advisable to compare Word or Open Office to Notepad++; apples and oranges. As a raw assignment (won't use the word "task" here), it's not "taxing on a modern day PC"--however it would have to be "architected" in. THAT part may or may not be "easy". It is certainly easy to say "just (count) the words".

@sasumner
Copy link
Contributor

sasumner commented Feb 16, 2018

@a4jp-com said "Where is the code for the summary word count and the toolbar currently?"

If you are a programmer it might occur to you to search the project for a string such as:
Characters (without
which should lead you very near the area you are asking about. Not sure, though, didn't try it...

@manjukefernando
Copy link

It would be great if the word count can be shown on the status bar

@ulrich-schroeders
Copy link

+1

@mdingemanse
Copy link

+1

Love Notepad++ and use it everyday, but it always bugs me to not have this simple feature

@DavidHansen-0x454d43
Copy link

I was just googling how to do this in Notepad++ a couple days ago...
I expected it to be on the status bar, and it wasn't obvious how to find that information.
I think this would be a great enhancement.

@a4jp-com
Copy link

It can't be too difficult to implement something like this. Anyone know a programmer that can help?

@DavidHansen-0x454d43
Copy link

@a4jp-com a straight forward implementation is probably not too difficult. However, I suspect it is quite challenging to make it efficient enough so that users don't notice any slowdown while editing.

@a4jp-com
Copy link

Is there any way to get a beta version of the program made? To see if it actually slows things down? I guess unless anything is made no one will actually know if the program is slow or be able to find out why it is slow.

Adding a selected word count feature into a left click menu after something is selected would be another way to deal with it if the status bar is no good. Or a popup that says this standard feature is turned on in options but you can turn it off to speed up the program if you like.

Even the plugin has no problems at all counting words or characters.

If a counter was slow, it could be set up so it doesn't interfere with the actual program too, right? Sorry if I'm looking at this in the wrong way, I'm only used to making web based things. What code has this program been made in? C++?

Here is some sample code for C/C++, Java, Python, C#, and PHP:
https://www.geeksforgeeks.org/count-words-in-a-given-string/

Optimizing GetStyleAt():
jacobslusser/ScintillaNET#32

Word Counting in C++: Implementing a Simple Word Counter:
https://www.fluentcpp.com/2018/10/12/word-counting-cpp-simple-word-counter/

I'm happy with the plugin I have now but it took ages to find it before and it would be great if a basic selected text word counter was added somehow. Even just having the plugin load in when the program loads would be cool. People can then disable it if they like.

@sasumner
Copy link
Contributor

So maybe the discussion of this issue is getting a little too bogged down in my early comment about it being slow. It is all a matter of scale. If you edit mainly small files, having something constantly counting all the words and presenting that on the status bar is no big deal. However, some people use Notepad++ to edit huge files (the largest it can handle), and in those cases having something constantly doing an action like this could be prohibitive. So these users would start crying "Why did N++ get so slow?!". I'm just saying this is a potential concern, not that it surely would happen. It all gets back to architecture and design concerns, rather than just saying "this surely must be easy to implement!". It is much better to be an on-demand feature that you summon up when needed, rather than always happening. So we already have it in View->Summary; it just needs to be implemented for a selection when a selection is active when invoked.

@suk79sin
Copy link

suk79sin commented Feb 5, 2019

+1

@donho
Copy link
Member

donho commented Apr 10, 2019

Double click on the "length/lines" zone of status bar will launch Summary.
There'll be no word count on status bar.

Edit: No word count on status bar due to the performance issue.

@donho donho closed this as completed Apr 10, 2019
@heresjolly
Copy link

I copy and pasted the entire Bee Movie script 105 times. It took approximately 3 seconds for the summary box to open on the resulting document as shown here: image

This is a very long time yes, however the summary opened instantaneously when the document was only a single instance of the script as shown here: image

My take away is that the potential CPU lag from tracking word counts on large documents in real time is a potential concern, however I have some recommendations.

  1. The word count doesn't haven't to be up to the millisecond. The consensus request that I've inferred seems to simply pertain to work flow and creative flow. If the same word counter used in summary were set to automatically kick in/refresh when the user stops interacting with the text, it would still serve the requested function.

  2. A maximum count for real time could also be implemented. The entire Lord of the Rings trilogy only contains 576,459 words and Stephen King's Under the Dome (a notoriously long read) only contains 299,280. Most people aren't going to require more than 200,000-300,000 even if they're writing exorbitantly long novels. Once the counter reaches a certain length, or if it's taking over a designated time to analyze, the function self disables, or switches to a longer sliding delay before refreshing. A color system can be utilized to designate when the count is up to date, for example: green = up to date, but then switches to red (out of date) once the user interacts with the text.

@abdekker
Copy link
Author

abdekker commented Aug 19, 2020 via email

@sasumner
Copy link
Contributor

There'll be no word count on status bar.

@KasunL
Copy link

KasunL commented Aug 29, 2020

Yes, it'll be nice if I could switch between Length / Word count on status bar. +1

@sasumner
Copy link
Contributor

There'll be no word count on status bar.

@a4jp-com
Copy link

a4jp-com commented Aug 31, 2020

Can you add the word count as an option in the right click menu (+ summary)? I would like to be able to select text and then right click bringing up and option to show details. Shortcuts only work when you can use both hands and the top menus aren't the best if you just wanna check the word count of different sections over and over. Any accessibility updates are greatly appreciated.

@sasumner
Copy link
Contributor

sasumner commented Sep 6, 2020

@a4jp-com said:

Can you add the word count as an option in the right click menu (+ summary)? I would like to be able to select text and then right click...

I attempted to add a change to the code for your need, but it was rejected. Thus I would suggest creating a macro for it, following these steps:

  1. Select some text to count the words in
  2. Open the Replace window by pressing Ctrl+h
  3. Set up the Replace window as follows:
    image
  4. Start macro recording via button on toolbar
  5. Press the Replace All button
  6. End macro recording via button on toolbar (then suggest testing the macro to make sure it is working!)
  7. Save and name the created macro (suggestion: Word count in selection )
  8. Add your macro to the N++ right-click context menu (this Community POSTING may be helpful), but maybe a simpler way is just adding this line to contextMenu.xml:
<Item MenuEntryName="Macro" MenuItemName="Word count in selection"/>

When you run your macro, you will see the results here (example for 5 counted words in some selected text):
image

Some limitations with this approach:

  • Requires that you have the Replace window open when you wish to get a count of words in a selection
  • Modifies your document (because it is doing a replacement operation)

If these limitations bother you, you can substitute the following, for the similarly numbered steps above:

2a. Open the Find window by pressing Ctrl+f
3a. Set up the Find window as follows:
image
5a. Press the Find All in Current Document button

When you run the "a" version of the macro, you will see the results here:

image

@a4jp-com
Copy link

a4jp-com commented Sep 7, 2020

I can't see why they would block the update unless the code was buggy. That gets around the complaints of slow counts if people have large blocks of text. Opening the file is gonna take a long time anyway if there are millions of characters, right? I'm okay even if the useful toolbar count can't be implemented as the coding engine of this program is super slow. I just never thought a text editor would be so slow. If the code is super slow, can it be ported to a better coding system then?

Thank you so much for your try @sasumner
Can you post the code here so we can work on it? This program is great but terrible when it comes to anything that needs a set number of words or characters. Like SEO work. Especially without a quick way of checking the numbers of words in a block of text quickly. Also checking files when they have to have paragraphs of a certain length. We just want a one or two click option if possible. @sasumner do you think your code could be made into a plugin?

@sasumner
Copy link
Contributor

sasumner commented Sep 7, 2020

@a4jp-com

I don't understand your first paragraph. Notepad++ is know for its "speed"; recently I saw a post where someone switched from VSCode to Notepad++ because VSCode was very slow. If N++ is slow for you, perhaps open an issue where you describe your circumstances.

Can you post the code here so we can work on it?

What code do you mean? The macro definition from shortcuts.xml?

do you think your code could be made into a plugin?

For this you mean the C++ code I did in the (rejected) PR?

@sasumner
Copy link
Contributor

sasumner commented Sep 7, 2020

Adding reject label to perhaps discourage people from re-requesting this feature.

@sasumner sasumner added the reject label Sep 7, 2020
@igavronski
Copy link

So... I need this feature as well and switched to vim.
Good luck with N++, @sasumner

@a4jp-com
Copy link

a4jp-com commented Sep 7, 2020

@igavronski what is Vim? I'm happy to switch apps if a proper word count isn't being added to Notepad Plus Plus.

I was told Notepad Plus Plus is slow and that is why they didn't want to add the count to the toolbar as an option or feature. I can't see why having it as an option that can be turned on or a plugin would be bad though.

@sasumner not the macro but the C++ code you made. I'm sure a it will help lots of people if it is available and working.
I'm happy to try another apps if something out there already does this though. I like Notepad Plus Plus but like Blender prefer stuff that can be made user friendly with components that make work quicker.

@sasumner
Copy link
Contributor

sasumner commented Sep 7, 2020

IMO something like this not being a native feature is an insane reason to switch away from Notepad++, when there are so many ways to "make it happen".

@a4jp-com said:

I was told Notepad Plus Plus is slow

Do you believe everything you hear, or do you make judgments for yourself?

not the macro but the C++ code you made
The C++ code I did is in PR #8791.

I'll work up yet another way to do this, using the Pythonscript plugin....

@sasumner
Copy link
Contributor

sasumner commented Sep 7, 2020

I said:

I'll work up yet another way to do this, using the Pythonscript plugin....

Oh wait, I already did that, over 2 years ago; see THIS from earlier in this thread.

@mdingemanse
Copy link

That Pythonscript plugin looks wonderful and just what I was looking for @sasumner. Thanks for your patient support here as people struggle to understand why this couldn't be a feature (conditional on filesize perhaps). Should the Pythonscript code still work? I've added it as a script in N++ 7.9 but it doesn't seem to show up on status bar when selecting text. (A first copy-paste gave me a Unicode error in the Python console, but after fixing the apostrophes it seems to run, yet displays nothing.)

@sasumner
Copy link
Contributor

@mdingemanse

The way that script was posted was poor, but it should still work once format and indentation problems are solved.
Here's a more properly formatted version of it that I tested:

# -*- coding: utf-8 -*-

from Npp import editor, notepad, SCINTILLANOTIFICATION
import re

def WCISAISB__callback_sci_UPDATEUI(args):
    if args['updated'] & UPDATE.SELECTION:
        text = editor.getSelText()
        notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, 'Word count in selection: {}'.format(len(re.findall(r'\w+', text))) if len(text) > 0 else ' ')

editor.callback(WCISAISB__callback_sci_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])

@a4jp-com
Copy link

@sasumner thanks for making that.

@molsonkiko
Copy link
Contributor

molsonkiko commented Apr 24, 2023

Thought I'd introduce a new take on this, one that gives both the wordcount in the selection and the wordcount in the entire document. As an added bonus, it only recomputes the count when a new buffer is activated or the user actually modifies the file, which should improve performance. It also doesn't overwrite the document type section.

image

from Npp import editor, notepad, STATUSBARSECTION
from Npp import SCINTILLANOTIFICATION as SCN
from Npp import NOTIFICATION as NPPN

wordcount = 0
selected_wordcount = 0

def on_match(m):
    global wordcount
    wordcount += 1
    
def on_selection_match(m):
    global selected_wordcount
    selected_wordcount += 1

def get_wordcount(args):
    global wordcount
    if args.get('modificationType') or args.get('bufferID'):
        # doc was modified or new doc was opened; refresh count
        wordcount = 0
        editor.research('\w+', on_match)
    # add wordcount to status bar along with other info
    doclen = editor.getLength()
    doc_bar_desc = 'length: %i  lines: %i  words: %i' % (
        doclen,
        editor.getLineCount(),
        wordcount
    )
    notepad.setStatusBar(STATUSBARSECTION.DOCSIZE, doc_bar_desc)
    sel_start, sel_end = editor.getUserCharSelection()
    curloc = editor.getCurrentPos()
    curline = editor.lineFromPosition(curloc) + 1 # 1-based indexing
    curcol = editor.getColumn(curloc) + 1
    sel_size = sel_end - sel_start
    if 0 < sel_size < doclen:
        # get wordcount in selection, add to status bar
        global selected_wordcount
        selected_wordcount = 0
        editor.research('\w+', on_selection_match, 0, sel_start, sel_end)
        start_line, end_line = editor.getUserLineSelection()
        selection_desc = 'Ln : %i  Col : %i  Sel : %i  Lines : %i  Words : %i' % (
            curline,
            curcol,
            sel_size,
            end_line - start_line + 1,
            selected_wordcount
        )
        notepad.setStatusBar(STATUSBARSECTION.CURPOS, selection_desc)

try:
    MODULE_ALREADY_INITIALIZED
except:
    MODULE_ALREADY_INITIALIZED = True
    try:
        CALLBACK_ALREADY_ADDED
    except:
        get_wordcount({"modificationType": 1})
        editor.callback(get_wordcount, [SCN.UPDATEUI, SCN.MODIFIED])
        notepad.callback(get_wordcount, [NPPN.BUFFERACTIVATED])
        CALLBACK_ALREADY_ADDED = True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests