Problem
Stopped using wc-mode
as it is not snappy anymore (as text writing usually is) with text document of 10k words. It appears that it counts the whole buffer after every change which seems to make it slow as logged here. A recent change was made to speed it up, but still produces considerable lag.
Partial Solution
There is a "solution" here, but it is so hard for me to implement it as I am not familiar with Lisp and inner workings of Emacs. There are two functions wc-buffer
and wc-region
, which are empty in the answer (below), for which I have no clue what should be in the function.
;; Function that counts words in buffer
(defun wc-buffer ()
...)
;; Function that counts words in a region
(defun wc-region (rbeg rend)
...)
(defvar-local a1 nil)
(defvar-local a2 nil)
(defvar-local curr-wc nil)
(defun init-function ()
(interactive)
(save-excursion
(setq curr-wc (wc-buffer))))
(defun wc-update-before (change-beg change-end)
(setq pos1 (max 1 (1- change-beg)))
(setq pos2 (min (point-max) (1+ change-end)))
(setq a1 (wc-region pos1 pos2)))
(defun wc-update-after (change-beg change-end prev-len)
(if (bound-and-true-p a1)
(progn
(setq pos1 (max 1 (1- change-beg)))
(setq pos2 (min (point-max) (1+ change-end)))
(setq a2 (wc-region pos1 pos2))
(setq curr-wc (+ curr-wc (- a2 a1))))
nil))
(init-function)
(add-hook 'before-change-functions #'wc-update-before nil t)
(add-hook 'after-change-functions #'wc-update-after nil t)
(setq inhibit-modification-hooks nil)
Help
I ask for someone either to tell me explicitly what goes in these functions or suggest alternatives for counting words and not having lag while displaying them in the mode-line.
Reproducing
You can reproduce this by: installing wc-mode
and enabling it and then when you have more than 10k words, you can expect (depending on your PC) quite some lag while typing. It's not snappy.