Bug 65740

Summary: no word count function
Product: [Applications] kate Reporter: David Pashley <kde-bugs>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: a.j.ball, andy, bernd.mullet, bugs.kde.org, bugzilla, cruzki123, djjkotze, jessefrgsmith, litimetal, martin.ruessler, matija, mintlars, norbert.lindlbauer, pete, sridhar+bugs, walch.martin
Priority: NOR    
Version: 3.14.0   
Target Milestone: ---   
Platform: Debian testing   
OS: Linux   
Latest Commit: Version Fixed In: 5.8.0
Sentry Crash Report:
Attachments: external tool word count script
New Kate word count script for KDE 4

Description David Pashley 2003-10-09 12:12:05 UTC
Version:            (using KDE KDE 3.1.3)
Installed from:    Debian testing/unstable Packages
Compiler:          gcc 3.3 

it owuld be usefyul to have a word count function. Iyt would be nice if you could do a worj=k count of hte current selection.
Comment 1 Jeroen Wijnhout 2003-10-09 12:19:53 UTC
Subject: Re:  New: no word count function

On Thursday 09 October 2003 12:12, David Pashley wrote:
> Version:            (using KDE KDE 3.1.3)
> Installed from:    Debian testing/unstable Packages
> Compiler:          gcc 3.3
>
> it owuld be usefyul to have a word count function. Iyt would be nice if you
> could do a worj=k count of hte current selection.

What is a word? Seriously, I've been implementing a word count feature for 
Kile (LaTeX editor), it is pretty difficult to count words.

Just an example, how would you count the following?
K\"ahler (= K
Comment 2 Paul Hudson 2003-12-12 12:15:02 UTC
Hi there,

David kindly submitted this bug on my behalf at the Linux Expo in London, and since nothing much has happened with it, I thought I'd add my own comments.

Both myself and Nick (I'm Reviews Editor, he's the Editor of Linux Format magazine) use Kate to write all our articles, and we both miss having a word count function in there.  I fully understand what Joroen has said - word counting isn't an easy thing to do because of the inherent complexity of the words we use.

Right now I use wc to count the words, and even though the word count is probably off by about 5% it's a good enough estimate for me to use when submitting copy.  However, what I really want is to be able to select a chunk of text, hit Word Count, and have it only count /those/ words.  To do this in wc I usually copy the text, open a new document, copy the text in, save it somewhere temporary, then run wc.  Even OOo doesn't have "word count selection", which is quite frustrating!

I realise that this is probably a really niche request that would only benefit a few, so I understand why little movement has been made on this request.  However, I hope this has helped you understand why it would be helpful to have a built-in word count function - even one that is as rough as wc - for Kate.

Thanks,


Paul
Comment 3 Anders Lund 2004-02-29 00:34:49 UTC
Isn't it also a question of using the correct locale? in the case of ``k
Comment 4 Wilbert Berendsen 2004-05-11 11:56:00 UTC
I wrote this (in Dutch:) as a tutorial of how to embed scripts in Kate, and it provides a word count function: http://www.kde.nl/doc/kate-scripting/
Comment 5 jamethknorth 2005-11-22 04:26:00 UTC
I think this would be best implemented by added a 'word' definition (in some regex format or another) in the definition for file types. In theory, that would mean I could even do word-counting in HTML and get the word-count for the resulting page, not the markup, if the definition were designed to do that. This would be wonderful for those of us that use tex and the like for word-processing. In the meantime, the main app could just do the lazy word definition that wc uses if nothing was defined, and the system would be useable from day one.

If this allowed me to get word-counts of selected text, I would be completely sold, as right now I use Kate for all of my writing, but need to cat text through wc in a console to get a word-count for my work.
Comment 6 Thilo Bangert 2005-11-22 04:48:44 UTC
this is OT, sorry:

> To do this in wc I usually copy the text, open a new document, copy the text in, 
> save it somewhere temporary, then run wc.

just a hint: instead of creating a new file, just call wc an drag an drop the text into wc. then press <CTRL+d> ...

hhm, perhaps one can even make a desktop file.... but how does one tell it to accept text for dropping and what it should do with it....
Comment 7 Andy Goss 2005-11-23 06:06:27 UTC
If Gedit can have a wordcount, then Kate should too. As a journalist I am not too fussy about the accuracy of the count as words vary in length, so an additional character count including spaces would be good. I unearthed a KDE scripts solution but it does not work in Kubuntu or Fedora Core 4 KDE - Kate can't find the shell script. But that is a different bug.
Comment 8 Anders Lund 2005-11-23 20:48:01 UTC
Someone ought to write a plugin for katepart. Me, probably :)

Meanwhile, kates 'external tools' feature provides you with a easy way to do this. Here is a very simple implementation, note though that this does not work with non-local files, and that it saves the document if it has changes. The next version (3.0) of kate will allow to pipe text into commands used for external tools. But adding the following to $KDEHOME/share/apps/kate/externaltools would provide you with a command "Tools->External tools->Word count" that will work with local files:

[externaltool_Wordcount]
acname=externaltool_Wordcount
cmdname=
command=url=`echo %URL|sed -r 's,^\\w+\\:/+,/,'`\nkdialog --msgbox "Word count for\\n%URL:\\n$(wc -lwm $url|sed -r 's,\\s*(\\w+)\\s+(\\w+)\\s+(\\w+).*,Lines: \\1\\nWords: \\2\\nCharacters: \\3,')"
executable=wc
icon=
mimetypes=
name=Word count
save=1
Comment 9 Andy Goss 2005-11-24 03:18:57 UTC
Brilliant. Thanks. 

Andy Goss

On Wed, 2005-11-23 at 19:48 +0000, Anders Lund wrote:
[bugs.kde.org quoted mail]
Comment 10 Dominik Haumann 2006-04-28 19:15:04 UTC
For the this worked (two lines): 
url=`echo %URL|sed -r 's,^\\w+\\:/+,/,'`
kdialog --msgbox "Word count for\n%URL:\n$(wc -lwm $url|sed -r 's,\s*(\w+)\s+(\w+)\s+(\w+).*,Lines: \1\nWords: \2\nCharacters: \3,')" 
Comment 11 Andreas Kling 2006-09-16 20:51:39 UTC
*** Bug 134177 has been marked as a duplicate of this bug. ***
Comment 12 Andreas Kling 2006-09-16 20:51:57 UTC
*** Bug 121992 has been marked as a duplicate of this bug. ***
Comment 13 Dominik Haumann 2006-09-16 23:20:13 UTC
Created attachment 17798 [details]
external tool word count script

Step by step howto for Kate Application:
- Settings > Configure Kate...
- 'External Tools' page
- Create new external tool
Label: Word Count
Script: copy&paste from attached file.
Executable: wc
Mime Types: leave blank
Save: Current Document
Command Line Name: leave blank or type 'word-count'
- Save & Apply

Use: Tools > External Tools > Word Count
Comment 14 Dirk Kotze 2006-09-17 10:17:21 UTC
Dominik Haumann wrote:
[bugs.kde.org quoted mail]
Thanks for you speedy reply! However, you have forgotten to attach the
attachment you refer to :-))

Thanks again.

God bless,
Comment 15 Dominik Haumann 2006-09-17 11:39:34 UTC
The attachement resides in our bug tracking system. It's not attached to your mail, you have to follow the link.
Comment 16 Helge Hielscher 2007-01-17 14:04:27 UTC
Could this be used to have an up-to-date word count in the status bar as well or would that be a different RFE?
Comment 17 Sridhar Dhanapalan 2007-10-11 05:04:57 UTC
There is a solution at http://muzso.hu/node/3979

However, it only works when there is _one_ kate instance open. If you have multiple kates open (e.g. if you use different sessions), it will not work.
Comment 18 Milian Wolff 2010-01-21 18:22:59 UTC
*** Bug 216721 has been marked as a duplicate of this bug. ***
Comment 19 Milian Wolff 2010-01-21 18:34:52 UTC
With KDE 4.4 we now have inline spell-checking which only applies to areas marked in the highlight files. Now we could use these ranges and only do the word count in them. This would also probably fix bug 149955 and greatly improve the accuracy overall.

I'll see what I can do, but I hope to implement it for 4.5.
Comment 20 Jesse 2010-01-21 20:34:30 UTC
I agree that a word count wouldn't have to be overly accurate, as long as it gives an estimate. 

I'm fine with "rail-road" being counted as one or two words, for example.

As someone else pointed out, Gedit does something along these lines where it gives a count of words, characters and character excluding spaces. That would be really handy to have in Kate/Kwrite.
Comment 21 Dominik Haumann 2011-08-30 14:52:56 UTC
*** Bug 264082 has been marked as a duplicate of this bug. ***
Comment 22 Andy Goss 2011-12-11 09:22:57 UTC
Created attachment 66615 [details]
New Kate word count script for KDE 4

I found this solution at http://www.linuxquestions.org/questions/showthread.php?p=4546996#post4546996
It works for Kate 3.5.3 in Mepis 11.
Comment 23 Andy Goss 2012-07-03 03:16:32 UTC
The version (3.8.4) of Kate that comes with Netrunner 4.2 (KDE 4.8.4) has lost External Tools, so I can't use Kate until another solution is found.
Maybe with KDE 4.9 the Python plugins will provide one. Meanwhile I am stuck with the inferior Gedit.
Better start learning Python :)
Comment 24 Andy Goss 2012-07-03 03:18:33 UTC
The version (3.8.4) of Kate that comes with Netrunner 4.2 (KDE 4.8.4) has lost External Tools, so I can't use Kate until another solution is found.
Maybe with KDE 4.9 the Python plugins will provide one. Meanwhile I am stuck with the inferior Gedit.
Better start learning Python :)
Comment 25 Janet 2013-08-16 13:13:28 UTC
IMHO this should be a default feature in an advanced editor like kate. Are there any plans to implement word counting? I'd expect it to be in the status bar as an option or a default script you could optionally turn on/put in the bar below the status bar.
Comment 26 Lars Karlsson 2013-11-27 17:59:53 UTC
I would also like to see this as a default feature or script. Kate is extremely useful for me as a journalist since it's completely unformatted text (e.g. easy to send to editors without having to bother about compatability issues). The only thing missing is character/word count.
Comment 27 Michal Humpula 2015-02-20 15:52:28 UTC
Git commit 97a1fc436f9810c6ba1c35ed42080ef1829871aa by Michal Humpula.
Committed on 14/02/2015 at 19:01.
Pushed by michalhumpula into branch 'master'.

add word count statistics in statusbar

This option is disabled by default, because it adds some nontrivial CPU and
memory overhead, though the implementation tries to keep it as minimal
as possible.

Whenewer the change in document is triggered, the timer is fired to wait
for 500ms of inactivity. The trigger is reseted every time the change
happens so as long as she keeps changing the document every 500ms
or so, the counting wont stall the editor and her experience.

Longer reculculations are done in batches of size 100 with the help of
500ms trigger. Which means 10000 lines long document will take 20s to
compute. Subsequent counting of changes will be much faster because of
the internal computation cache.

Interface changes includes adding signal KTextEditor::DocumentPrivate::loaded
to monitor document reload.

GUI: menu: View -> Show Word Count
REVIEW: 122571
FIXED-IN: 5.8.0

M  +2    -1    src/CMakeLists.txt
M  +2    -1    src/data/katepartui.rc
M  +9    -8    src/document/katedocument.cpp
M  +6    -3    src/document/katedocument.h
M  +22   -0    src/utils/kateconfig.cpp
M  +4    -0    src/utils/kateconfig.h
M  +44   -0    src/view/katestatusbar.cpp
M  +14   -2    src/view/katestatusbar.h
M  +11   -0    src/view/kateview.cpp
M  +2    -0    src/view/kateview.h
A  +189  -0    src/view/wordcounter.cpp     [License: LGPL (v2)]
A  +63   -0    src/view/wordcounter.h     [License: LGPL (v2)]

http://commits.kde.org/ktexteditor/97a1fc436f9810c6ba1c35ed42080ef1829871aa
Comment 28 Erik Quaeghebeur 2017-01-24 16:02:49 UTC
(In reply to Michal Humpula from comment #27)
> 
> add word count statistics in statusbar
> 
> This option is disabled by default, because it adds some nontrivial CPU and
> memory overhead, though the implementation tries to keep it as minimal
> as possible.

How do I activate this? (16.08.3)
Comment 29 Andy Goss 2017-01-25 00:33:35 UTC
(In reply to Erik Quaeghebeur from comment #28)
> (In reply to Michal Humpula from comment #27)
> > 
> > add word count statistics in statusbar
> > 
> > This option is disabled by default, because it adds some nontrivial CPU and
> > memory overhead, though the implementation tries to keep it as minimal
> > as possible.
> 
> How do I activate this? (16.08.3)

Second last item on the View menu.