unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to detect words being added and removed to a buffer in a minor mode?
@ 2022-11-19 20:44 Dmitrii Pisarenko
  2022-11-21  9:39 ` Eric S Fraga
  0 siblings, 1 reply; 14+ messages in thread
From: Dmitrii Pisarenko @ 2022-11-19 20:44 UTC (permalink / raw)
  To: help-gnu-emacs

Hello!

I want to create a minor mode which allows you to see the number of words in a buffer.

I want it to work in the following way:

1. User enters "M-x pwc-set-counter" and sets the word counter to a particular number.
2. Whenever a word is added to a buffer, the word counter is incremented.
3. Whenever a word is removed from a buffer, the word counter is decremented.
4. As long as the minor mode is active, the value of the word counter is visible in the mode line (same place where current row and column are shown in some modes).

Restrictions:

1. This minor mode should work for text (Org mode) buffers with up to 3000 words (i. e. we are NOT talking gigabytes of text).
2. This minor mode must be compatible with the evil and Org mode.

How is the minor mode I want to develop different from existing solutions?

I want to be able to count words that I wrote on a particular day.

Imagine I have a goal of writing at least 1000 words per day. When I begin to write on a new day, I reset the word counter to zero. Then I write in one buffer and see the progress in the modeline. Then I may switch to a different buffer (a different chapter), manually change the word counter and continue to work.

What I want to implement is the word counter from Scrivener which shows you the number of words you wrote today across different chapters. It also shows you a visual representatio of the percentage of the daily quota.

As far as I know, none of the existing Emacs word counters offers this functionality (correct me if I'm wrong).

Questions:

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?
2. Are there existing functions that count the words in the current buffer which I can reuse in my minor mode?

Thanks in advance

Pravles

^ permalink raw reply	[flat|nested] 14+ messages in thread
* How to detect words being added and removed to a buffer in a minor mode?
@ 2022-11-19 20:45 Pravles Redneсkoff via Users list for the GNU Emacs text editor
  2022-11-20  3:10 ` Bob Newell
  0 siblings, 1 reply; 14+ messages in thread
From: Pravles Redneсkoff via Users list for the GNU Emacs text editor @ 2022-11-19 20:45 UTC (permalink / raw)
  To: help-gnu-emacs

Hello!

I want to create a minor mode which allows you to see the number of words in a buffer.

I want it to work in the following way:

1. User enters "M-x pwc-set-counter" and sets the word counter to a particular number.
2. Whenever a word is added to a buffer, the word counter is incremented.
3. Whenever a word is removed from a buffer, the word counter is decremented.
4. As long as the minor mode is active, the value of the word counter is visible in the mode line (same place where current row and column are shown in some modes).

Restrictions:

1. This minor mode should work for text (Org mode) buffers with up to 3000 words (i. e. we are NOT talking gigabytes of text).
2. This minor mode must be compatible with the evil and Org mode.

How is the minor mode I want to develop different from existing solutions?

I want to be able to count words that I wrote on a particular day.

Imagine I have a goal of writing at least 1000 words per day. When I begin to write on a new day, I reset the word counter to zero. Then I write in one buffer and see the progress in the modeline. Then I may switch to a different buffer (a different chapter), manually change the word counter and continue to work.

What I want to implement is the word counter from Scrivener which shows you the number of words you wrote today across different chapters. It also shows you a visual representatio of the percentage of the daily quota.

As far as I know, none of the existing Emacs word counters offers this functionality.

Questions:

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?
2. Are there existing functions that count the words in the current buffer which I can reuse in my minor mode?

Thanks in advance

Pravles

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-11-26 14:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).