Re: word count note
Seth Falcon <[email protected]> Sun, 07 May 2006 11:53:12 -0700
| Newsgroups | gmane.emacs.wiki.general |
|---|---|
| Message-ID | <[email protected]> |
"thomas knoll" <[email protected]> writes: > Can someone help me figure out how to tweak the function below that > will count the words in the current note? (i.e. between .# 's) > > (defun count-words (start end) > "Print number of words in the region." > (interactive "r") > (save-excursion > (save-restriction > (narrow-to-region start end) > (goto-char (point-min)) > (count-matches "\\sw+")))) > (defalias 'word-count 'count-words) Here's a blind stab... (defun syf/planner-get-note-range () "Return (start end) positions for current planner note or nil if not in a note." (let* ((planner-note-regex "\\.\\(#[0-9]+\\)\\s-+\\(.*\\)") (start nil) (end nil)) (re-search-backward planner-note-regex nil t) (setq start (match-end 2)) (if start (progn (forward-line) (setq end (re-search-forward planner-note-regex nil t)) (if (not end) (setq end (point-max)) (goto-char (match-beginning 1)) (forward-line -1) (setq end (point))) (list start end))))) (defun syf/planner-count-words-in-note () "Count the words in the current planner note." (interactive) (let ((range (syf/planner-get-note-range)) (count nil)) (if (not range) (message "No planner note found.") (setq count (count-words (car range) (cadr range))) (message "This note has %d words" count))))