From: Marcin Borkowski <mbork@mbork.pl>
To: Jean Louis <bugs@gnu.support>
Cc: Eric S Fraga <e.fraga@ucl.ac.uk>, help-gnu-emacs@gnu.org
Subject: Re: How to detect words being added and removed to a buffer in a minor mode?
Date: Mon, 21 Nov 2022 18:17:14 +0100 [thread overview]
Message-ID: <87tu2scjmt.fsf@mbork.pl> (raw)
In-Reply-To: <Y3tOHlm5pHhNhJyv@protected.localdomain>
On 2022-11-21, at 11:08, Jean Louis <bugs@gnu.support> wrote:
> * Eric S Fraga <e.fraga@ucl.ac.uk> [2022-11-21 12:40]:
>> On Saturday, 19 Nov 2022 at 20:44, Dmitrii Pisarenko wrote:
>> > 1. How can I create an "event listener" (sorry for the non-Emacsian
>> > terminology) which would be called whenever the user types something
>> > in the buffer?
>>
>> Naïvely (i.e. I may be totally ignorant of a proper solution), there is
>> post-command-hook which can be used to process every single key event.
>
> There are 2 conditions here, one is that user wish to see the number
> of words visualy, other is that one wants to compare that once editing
> is finished.
>
> One need not see every single word counted. What if user enters 500
> words at once, then it would be futil to slow down the process until
> every single word has been counted.
>
> It implies, one could invoke function with number of words each in a
> while.
>
> In that case, one could use this function:
>
> run-with-timer is an interactive byte-compiled Lisp function in
> ‘timer.el’.
>
> (run-with-timer SECS REPEAT FUNCTION &rest ARGS)
I would rather look at `run-with-idle-timer'.
Also, there are `count-words-region' and `count-words'. I'm not sure
what the differences are, you might want to look at their docstrings
and/or code.
Would a mode which displays the number of words in the current buffer
whenever you stop typing for a few seconds be enough? (I am not sure
how exactly you want to obtain the "number of words typed in today".)
Hth,
--
Marcin Borkowski
http://mbork.pl
next prev parent reply other threads:[~2022-11-21 17:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-19 20:44 How to detect words being added and removed to a buffer in a minor mode? Dmitrii Pisarenko
2022-11-21 9:39 ` Eric S Fraga
2022-11-21 10:08 ` Jean Louis
2022-11-21 10:34 ` Emanuel Berg
2022-11-21 11:27 ` Eric S Fraga
2022-11-21 12:40 ` Emanuel Berg
2022-11-21 17:17 ` Marcin Borkowski [this message]
2022-11-21 17:21 ` Marcin Borkowski
2022-11-21 18:56 ` [External] : " Drew Adams
2022-11-22 15:33 ` Emanuel Berg
2022-11-26 6:14 ` Marcin Borkowski
2022-11-26 14:51 ` Emanuel Berg
-- strict thread matches above, loose matches on Subject: below --
2022-11-19 20:45 Pravles Redneсkoff via Users list for the GNU Emacs text editor
2022-11-20 3:10 ` Bob Newell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tu2scjmt.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=bugs@gnu.support \
--cc=e.fraga@ucl.ac.uk \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).