(defun count-words (&optional silent)
"Counts the number of words in the buffer.
If silent is t, then does not print message."
(interactive)
(save-excursion
(goto-char 0)
(let ((inhibit-field-text-motion t)
(count 0))
(while (forward-word 1)
(setq count (1+ count)))
(if (not silent)
(message (format "There are %d words in current buffer." count)))
count)))
(defun html2text-clean-sup (p1 p2 p3 p4)
(html2text-delete-tags p1 p2 p3 p4)
(goto-char p1)
(insert "^"))
(defun html2text-clean-hr-mod (p1 p2)
(html2text-delete-single-tag p1 p2))
(defun emacs-wiki-html-to-text-html2text ()
"Converts html in current buffer to text using html2text"
(interactive)
(let ((html2text-format-single-element-list
'(("hr" . html2text-clean-hr-mod)))
(html2text-replace-list
'((" " . " ") (" " . " ") (">" . ">")
("<" . "<") (""" . "\"") ("&" . "&")))
(html2text-remove-tag-list
'("h3" "html" "body" "p" "a" "center" "b" "blockquote"
"u" "i" "img" "dir" "head" "div" "br" "font" "title"
"meta" "span" "code" "em"))
(html2text-format-tag-list
'(("sup" . html2text-clean-sup)
("ul" . html2text-clean-ul)
("ol" . html2text-clean-ol)
("dl" . html2text-clean-dl))) tempreg)
(html2text)))
(defun emacs-wiki-count-words ()
"Counts total words in entry filename"
(interactive)
(let ((kill-whole-line t)
(inhibit-read-only t)
(text (buffer-substring (point-min) (point-max)))
(wordcnt 0))
(with-current-buffer (get-buffer-create "*Wiki Word Counter*")
(insert text)
(let ((emacs-wiki-publishing-header "")
(emacs-wiki-publishing-footer ""))
(emacs-wiki-maybe)
(emacs-wiki-replace-markup))
(emacs-wiki-html-to-text-html2text)
(setq wordcnt (count-words t)))
(kill-buffer "*Wiki Word Counter*")
(message (format "There are %d words in current Wiki buffer" wordcnt))
wordcnt
))
(define-key emacs-wiki-mode-map
[(control ?x) (?w)]
'emacs-wiki-count-words)