emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [emacs-wiki-discuss] word count note


From: Seth Falcon
Subject: Re: [emacs-wiki-discuss] word count note
Date: Sun, 07 May 2006 11:53:12 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)

"thomas knoll" <address@hidden> 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))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]