From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bob Newell Newsgroups: gmane.emacs.help Subject: Re: How to detect words being added and removed to a buffer in a minor mode? Date: Sat, 19 Nov 2022 17:10:31 -1000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38539"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: =?UTF-8?Q?Pravles_Redne=D1=81koff?= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 20 04:11:33 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1owak1-0009rl-HS for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 20 Nov 2022 04:11:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1owajJ-0002Gg-3O; Sat, 19 Nov 2022 22:10:49 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1owajH-0002GY-Kg for help-gnu-emacs@gnu.org; Sat, 19 Nov 2022 22:10:47 -0500 Original-Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1owajF-0002V1-2c for help-gnu-emacs@gnu.org; Sat, 19 Nov 2022 22:10:47 -0500 Original-Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-142b72a728fso2588110fac.9 for ; Sat, 19 Nov 2022 19:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bobnewell-net.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=iO2bJwmZxhBoGBCtsUWxuN3Omoft6SkoK8ybJUDzHzM=; b=NE2GeQQ95NkO9GjnMIexYZnLHPXIy8f4bCr453xcFDp3Sf3iqBtzWEQncZDfhlg2Pj OY34ujauZzoOw+T9Tlwe6G7FR5zxJd5y1VDmQH/o6RMICQ3WCKPUtm00CQ38ANggTa0y zdA5C/Ditn+OAlSmJCkU5ySi1se0j19mo4YONoCqphYwKOTZXNpA9Nnd6QsctjS90mrZ FBC8YofX6Nk8KIOhkpaZh21TcfqkE/KdjKfNFTDXgzB45Bfpd6KoTciI4TWGjO7zs4IT SIfrAdieJe+UHnsf7Udzmmnme6dH1RJgdZ3KjysKjY1BI16Sbg9jMLb7witDA6nma6/p 4DpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iO2bJwmZxhBoGBCtsUWxuN3Omoft6SkoK8ybJUDzHzM=; b=CTG5sPwkHXpvvlrZ6PAu9upbvb2rBysw11WxstKLy3T6rJ7VcckBxh8AUsiVSBSDcf 97CrHHq85QtVliNY37V5XN3DjYBLhP7ninF5YRBGNhhBrZiZOLVD413isG1iZ7d8wp4E +382e1JJNQ4HRf9pJuTfnLvMvqmWEqEzjft+w0VL9Zbibx65vKGSZwkEEwkYTr8dkFeB HvP+PV14uQCUQM+d/hyG7zNXTB/ucztPhoQofvXeRwFkQYut8PNRU9ukwG+6/KIWbBIX 2v7yrWtIVDX6PQj8nWYcSgi21cbiSL3MBWpvuK5UeAnXnJ/hluivWSp/WEXi+xMr2JLS zPRA== X-Gm-Message-State: ANoB5plYmPNM5e2cKKg6Vsp0C2hUL125vZM0KBK90S96mJfgYv+QF6nP rNU/mUtZAdNMfeoNsZoEmluEx275TAYYMHznRmdT7A== X-Google-Smtp-Source: AA0mqf4JoD4avbNLCTbF0NZrBY6QVn8irTiciwPOfIhNrP+BmB3aKTetxUPuu0uLimOa6LqyVuRsGqJlnqBvewk5gKU= X-Received: by 2002:a05:6870:b3a6:b0:13b:7e32:2dd5 with SMTP id w38-20020a056870b3a600b0013b7e322dd5mr7331562oap.242.1668913842953; Sat, 19 Nov 2022 19:10:42 -0800 (PST) In-Reply-To: Received-SPF: none client-ip=2001:4860:4864:20::2e; envelope-from=bobnewell@bobnewell.net; helo=mail-oa1-x2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:141062 Archived-At: This might provide some of what you want although perhaps not all. https://github.com/emacsmirror/nanowrimo On Sat, Nov 19, 2022, 10:46 Pravles Redne=D1=81koff via Users list for the = GNU Emacs text editor wrote: > 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 sho= wn > in some modes). > > Restrictions: > > 1. This minor mode should work for text (Org mode) buffers with up to 300= 0 > 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 begi= n > 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 als= o > 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 t= he > buffer? > 2. Are there existing functions that count the words in the current buffe= r > which I can reuse in my minor mode? > > Thanks in advance > > Pravles