help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to detect words being added and removed to a buffer in a minor m


From: Marcin Borkowski
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
User-agent: mu4e 1.1.0; emacs 29.0.50

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]