From 9fca19ffcb31cf940fd8deaa93583ac27e505f1e Mon Sep 17 00:00:00 2001 From: yamaoka Date: Mon, 14 Oct 2002 22:51:37 +0000 Subject: [PATCH] Synch with Oort Gnus. --- lisp/ChangeLog | 7 +++++++ lisp/spam-stat.el | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 06ee2ce..24e8324 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2002-10-14 Katsumi Yamaoka + + * spam-stat.el: Require cl for the functions gethash, + hash-table-count, make-hash-table and mapc for Emacs 20. + (puthash): Alias to cl-puthash for Emacs 20. + (with-syntax-table): New macro for Emacs 20. + 2002-10-12 Jesper harder * gnus-spec.el (gnus-pad-form): Use gnus-string-width-function. diff --git a/lisp/spam-stat.el b/lisp/spam-stat.el index 38fd9b7..e348c2a 100644 --- a/lisp/spam-stat.el +++ b/lisp/spam-stat.el @@ -1,6 +1,6 @@ ;;; spam-stat.el --- detecting spam based on statistics -;; Copyright (C) 2002 Alex Schroeder +;; Copyright (C) 2002 Alex Schroeder ;; Author: Alex Schroeder ;; Maintainer: Alex Schroeder @@ -69,7 +69,7 @@ ;; the rule (: spam-stat-split-fancy) to `nnmail-split-fancy' ;; ;; This requires the following in your ~/.gnus file: -;; +;; ;; (require 'spam-stat) ;; (spam-stat-load) @@ -178,6 +178,35 @@ This is set by hooking into Gnus.") (defvar spam-stat-buffer-name " *spam stat buffer*" "Name of the `spam-stat-buffer'.") +;; Functions missing in Emacs 20 + +(eval-and-compile + (when (and (not (featurep 'xemacs)) + (= emacs-major-version 20)) + ;; gethash, hash-table-count, make-hash-table, mapc + (require 'cl) + (defalias 'puthash 'cl-puthash))) + +(eval-when-compile + (unless (fboundp 'with-syntax-table) + ;; Imported from Emacs 21.2 + (defmacro with-syntax-table (table &rest body) "\ +Evaluate BODY with syntax table of current buffer set to a copy of TABLE. +The syntax table of the current buffer is saved, BODY is evaluated, and the +saved table is restored, even in case of an abnormal exit. +Value is what BODY returns." + (let ((old-table (make-symbol "table")) + (old-buffer (make-symbol "buffer"))) + `(let ((,old-table (syntax-table)) + (,old-buffer (current-buffer))) + (unwind-protect + (progn + (set-syntax-table (copy-syntax-table ,table)) + ,@body) + (save-current-buffer + (set-buffer ,old-buffer) + (set-syntax-table ,old-table)))))))) + ;; Hooking into Gnus (defun spam-stat-store-current-buffer () @@ -313,12 +342,12 @@ Use `spam-stat-ngood', `spam-stat-nbad', `spam-stat-good', (lambda (word count) (let ((entry (gethash word spam-stat))) (if entry - (spam-stat-set-good entry (+ count (spam-stat-good entry))) + (spam-stat-set-good entry (+ count (spam-stat-good entry))) (setq entry (spam-stat-make-entry count 0))) (spam-stat-set-score entry (spam-stat-compute-score entry)) (puthash word entry spam-stat))) (spam-stat-buffer-words))) - + (defun spam-stat-buffer-change-to-spam () "Consider current buffer no longer normal mail but spam." (setq spam-stat-nbad (1+ spam-stat-nbad) @@ -404,7 +433,7 @@ This deletes all the statistics." The default score for unknown words is stored in `spam-stat-unknown-word-score'." (spam-stat-score (gethash word spam-stat))) - + (defun spam-stat-buffer-words-with-scores () "Process current buffer, return the 15 most conspicuous words. -- 1.7.10.4