unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* count all ispell(flyspell) errors in a buffer
@ 2023-11-25 13:57 Uwe Brauer
  2023-11-26 23:53 ` Emanuel Berg
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Uwe Brauer @ 2023-11-25 13:57 UTC (permalink / raw)
  To: help-gnu-emacs



Hi 

I usually use flyspell on most of my buffers, but sometimes are
interested to run ispell-region.

Is there any way to find out how many errors ispell finds when the
program starts, if I run it interactive, how many corrections of errors
I accepted?

I googled a bit but could not find anything.

Any ideas?

Thanks and regards

Uwe Brauer 
-- 
I strongly condemn Hamas heinous atrocities on Israel, especially the despicable pogroms.
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the EU and NATO membership of Ukraine. 





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

* Re: count all ispell(flyspell) errors in a buffer
  2023-11-25 13:57 count all ispell(flyspell) errors in a buffer Uwe Brauer
@ 2023-11-26 23:53 ` Emanuel Berg
  2023-11-27  0:36 ` Emanuel Berg
  2023-11-27  0:53 ` Emanuel Berg
  2 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2023-11-26 23:53 UTC (permalink / raw)
  To: help-gnu-emacs

Uwe Brauer wrote:

> I usually use flyspell on most of my buffers, but sometimes
> are interested to run ispell-region.
>
> Is there any way to find out how many errors ispell finds
> when the program starts

You can use this

(condition-case nil
    (not (ispell-word))
  (error nil) )

It returns t if the word is correct, otherwise nil.

Put in a loop that iterates all the words in the region with
`forward-word'.

For every word that is nil, do `cl-incf' on some error
variable that is initiated to 0.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: count all ispell(flyspell) errors in a buffer
  2023-11-25 13:57 count all ispell(flyspell) errors in a buffer Uwe Brauer
  2023-11-26 23:53 ` Emanuel Berg
@ 2023-11-27  0:36 ` Emanuel Berg
  2023-11-27  0:53 ` Emanuel Berg
  2 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2023-11-27  0:36 UTC (permalink / raw)
  To: help-gnu-emacs

Uwe Brauer wrote:

> I usually use flyspell on most of my buffers, but sometimes
> are interested to run ispell-region.
>
> Is there any way to find out how many errors ispell finds
> when the program starts, if I run it interactive, how many
> corrections of errors I accepted?
>
> I googled a bit but could not find anything.

(require 'cl-lib)
(require 'ispell)

(defun ispell-count (&optional beg end)
  (interactive
    (when (use-region-p)
      (list (region-beginning) (region-end)) ))
  (or beg (setq beg (point-min)))
  (or end (setq end (point-max)))
  (save-mark-and-excursion
    (goto-char beg)
    (backward-word)
    (forward-to-word)
    (cl-loop
      with errors = 0
      while (< (point) end)
      do (let ((word (thing-at-point 'word t)))
           (unless (ispell-lookup-words word) ; inefficient
             (cl-incf errors) )
           (forward-to-word) )
      finally (message "errors: %s" errors)) ))

;; this is a region wiht two
;; worsd spelled incorrectly

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: count all ispell(flyspell) errors in a buffer
  2023-11-25 13:57 count all ispell(flyspell) errors in a buffer Uwe Brauer
  2023-11-26 23:53 ` Emanuel Berg
  2023-11-27  0:36 ` Emanuel Berg
@ 2023-11-27  0:53 ` Emanuel Berg
  2 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2023-11-27  0:53 UTC (permalink / raw)
  To: help-gnu-emacs

Check out the below file URL, and this one

  https://dataswamp.org/~incal/emacs-init/dwim.el

for some further minor improvements of this program.

But the one I posted works fine and does not need the
dwim.el file.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/spell.el

(require 'cl-lib)
(require 'dwim)
(require 'ispell)

(defun ispell-count (&optional beg end)
  (interactive (use-region))
  (or beg (setq beg (point-min)))
  (or end (setq end (point-max)))
  (save-mark-and-excursion
    (goto-char beg)
    (backward-word)
    (cl-loop
      with words  = 0
      with errors = 0
      while (< (point) end)
      do (let ((word (thing-at-point 'word t)))
           (cl-incf words)
           (unless (ispell-lookup-words word)
             (cl-incf errors) )
           (forward-to-word) )
      finally (message "%s words checked, %s errors" words errors) )))

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2023-11-27  0:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-25 13:57 count all ispell(flyspell) errors in a buffer Uwe Brauer
2023-11-26 23:53 ` Emanuel Berg
2023-11-27  0:36 ` Emanuel Berg
2023-11-27  0:53 ` Emanuel Berg

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