Have been debugging a minor-mode I am writing. After much torture spend locating the problem, I have now narrowed things down to the following function. Still, I have not been able to fix the problem eval-buffer: Invalid read syntax: ")"
.
(defun word-count-analysis (rgn-beg rgn-end &optional skip-words mnlen)
"Count times each word is used in a region, ignoring punctuation.
RGN-BEG Start of region
RGN-END End of region
SKIP-WORDS Words to ignore
MNLEN Minimum length of word."
(interactive "rxp")
(let ( ($cur-table (syntax-table))
$words $word-str $word $cell )
(set-syntax-table word-count-analysis-syntax-table)
(save-excursion
(goto-char rgn-beg)
(while (re-search-forward "\\w+" rgn-end t)
(setq $word-str (downcase (match-string 0)))
;; Keep punctuation in words (e.g. 5.10 and 4,300) but not if
;; punctuation occurs at the end of a word.
(if (string-match "\\(.+\\)[,.]$" $word-str)
(setq $word-str (match-string 1 $word-str)))
(setq $word (intern $word-str))
(setq $cell (assq $word $words))
(if (and (not (eq $word ',)) ; ignore comma at end of words
(not (eq $word '.)) ; ignore period stop at end of words
(or (not mnlen) (> (length $word-str) mnlen))
(or (not skip-words) (not (memq $word skip-words))))
(if $cell
(setcdr $cell (1+ (cdr $cell)))
(setq $words (cons (cons $word 1) $words)))) ))
;; restore table
(set-syntax-table $cur-table)
(when (interactive-p)
(message "%S" $words))
$words))