Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / play / decipher.el
index d32e1aa..3de8ca3 100644 (file)
@@ -1,7 +1,6 @@
 ;;; decipher.el --- cryptanalyze monoalphabetic substitution ciphers
 ;;
-;; Copyright (C) 1995, 1996, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009  Free Software Foundation, Inc.
+;; Copyright (C) 1995-1996, 2001-2011  Free Software Foundation, Inc.
 ;;
 ;; Author: Christopher J. Madsen <chris_madsen@geocities.com>
 ;; Keywords: games
@@ -154,38 +153,37 @@ For example, to display ciphertext in the `bold' face, use
                             'bold)))
 in your `.emacs' file.")
 
-(defvar decipher-mode-map nil
+(defvar decipher-mode-map
+  (let ((map (make-keymap)))
+    (suppress-keymap map)
+    (define-key map "A" 'decipher-show-alphabet)
+    (define-key map "C" 'decipher-complete-alphabet)
+    (define-key map "D" 'decipher-digram-list)
+    (define-key map "F" 'decipher-frequency-count)
+    (define-key map "M" 'decipher-make-checkpoint)
+    (define-key map "N" 'decipher-adjacency-list)
+    (define-key map "R" 'decipher-restore-checkpoint)
+    (define-key map "U" 'decipher-undo)
+    (define-key map " " 'decipher-keypress)
+    (define-key map [remap undo] 'decipher-undo)
+    (define-key map [remap advertised-undo] 'decipher-undo)
+    (let ((key ?a))
+      (while (<= key ?z)
+       (define-key map (vector key) 'decipher-keypress)
+       (incf key)))
+    map)
   "Keymap for Decipher mode.")
-(if (not decipher-mode-map)
-    (progn
-      (setq decipher-mode-map (make-keymap))
-      (suppress-keymap decipher-mode-map)
-      (define-key decipher-mode-map "A" 'decipher-show-alphabet)
-      (define-key decipher-mode-map "C" 'decipher-complete-alphabet)
-      (define-key decipher-mode-map "D" 'decipher-digram-list)
-      (define-key decipher-mode-map "F" 'decipher-frequency-count)
-      (define-key decipher-mode-map "M" 'decipher-make-checkpoint)
-      (define-key decipher-mode-map "N" 'decipher-adjacency-list)
-      (define-key decipher-mode-map "R" 'decipher-restore-checkpoint)
-      (define-key decipher-mode-map "U" 'decipher-undo)
-      (define-key decipher-mode-map " " 'decipher-keypress)
-      (define-key decipher-mode-map [remap undo] 'decipher-undo)
-      (define-key decipher-mode-map [remap advertised-undo] 'decipher-undo)
-      (let ((key ?a))
-        (while (<= key ?z)
-          (define-key decipher-mode-map (vector key) 'decipher-keypress)
-          (incf key)))))
-
-(defvar decipher-stats-mode-map nil
-  "Keymap for Decipher-Stats mode.")
-(if (not decipher-stats-mode-map)
-    (progn
-      (setq decipher-stats-mode-map (make-keymap))
-      (suppress-keymap decipher-stats-mode-map)
-      (define-key decipher-stats-mode-map "D" 'decipher-digram-list)
-      (define-key decipher-stats-mode-map "F" 'decipher-frequency-count)
-      (define-key decipher-stats-mode-map "N" 'decipher-adjacency-list)
-      ))
+
+
+(defvar decipher-stats-mode-map
+  (let ((map (make-keymap)))
+    (suppress-keymap map)
+    (define-key map "D" 'decipher-digram-list)
+    (define-key map "F" 'decipher-frequency-count)
+    (define-key map "N" 'decipher-adjacency-list)
+    map)
+"Keymap for Decipher-Stats mode.")
+
 
 (defvar decipher-mode-syntax-table nil
   "Decipher mode syntax table")
@@ -488,7 +486,7 @@ The most useful commands are:
       (let ((font-lock-fontify-region-function 'ignore))
         ;; insert-and-inherit will pick the right face automatically
         (while (search-forward-regexp "^:" nil t)
-          (setq bound (save-excursion (end-of-line) (point)))
+          (setq bound (point-at-eol))
           (while (search-forward cipher-string bound 'end)
             (decipher-insert plain-char)))))))
 
@@ -681,8 +679,7 @@ ciphertext."
   (interactive (list (upcase (following-char))))
   (decipher-analyze)
   (let (start end)
-    (save-excursion
-      (set-buffer (decipher-stats-buffer))
+    (with-current-buffer (decipher-stats-buffer)
       (goto-char (point-min))
       (or (re-search-forward (format "^%c: " cipher-char) nil t)
           (error "Character `%c' is not used in ciphertext" cipher-char))
@@ -730,8 +727,7 @@ START-REGEXP matches the first line to display.
 END-REGEXP matches the line after that which ends the display.
 The ending line is included in the display unless it is blank."
   (let (start end)
-    (save-excursion
-      (set-buffer (decipher-stats-buffer))
+    (with-current-buffer (decipher-stats-buffer)
       (goto-char (point-min))
       (re-search-forward start-regexp)
       (beginning-of-line)
@@ -926,9 +922,8 @@ Creates the statistics buffer if it doesn't exist."
                                                   (aref decipher--after  i)))
                     freq-list)
               total-chars (+ total-chars (aref decipher--freqs i)))))
-    (save-excursion
-      ;; Switch to statistics buffer, creating it if necessary:
-      (set-buffer (decipher-stats-buffer t))
+    ;; Switch to statistics buffer, creating it if necessary:
+    (with-current-buffer (decipher-stats-buffer t)
       ;; This can't happen, but it never hurts to double-check:
       (or (eq major-mode 'decipher-stats-mode)
           (error "Buffer %s is not in Decipher-Stats mode" (buffer-name)))
@@ -1024,8 +1019,7 @@ if it can't, it signals an error."
    ;; See if decipher-stats-buffer exists:
    ((and (bufferp decipher-stats-buffer)
          (buffer-name decipher-stats-buffer))
-    (or (save-excursion
-          (set-buffer decipher-stats-buffer)
+    (or (with-current-buffer decipher-stats-buffer
           (eq major-mode 'decipher-stats-mode))
         (error "Buffer %s is not in Decipher-Stats mode"
                (buffer-name decipher-stats-buffer)))
@@ -1041,8 +1035,7 @@ if it can't, it signals an error."
                 ;; We just lost track of the statistics buffer:
                 (get-buffer stats-name)
               (generate-new-buffer stats-name))))
-    (save-excursion
-      (set-buffer decipher-stats-buffer)
+    (with-current-buffer decipher-stats-buffer
       (decipher-stats-mode))
     decipher-stats-buffer)
    ;; Give up:
@@ -1052,22 +1045,20 @@ if it can't, it signals an error."
 
 (provide 'decipher)
 
-;;;(defun decipher-show-undo-list ()
-;;;  "Display the undo list (for debugging purposes)."
-;;;  (interactive)
-;;;  (with-output-to-temp-buffer "*Decipher Undo*"
-;;;    (let ((undo-list decipher-undo-list)
-;;;          undo-rec undo-map)
-;;;      (save-excursion
-;;;        (set-buffer "*Decipher Undo*")
-;;;        (while (setq undo-rec (pop undo-list))
-;;;          (or (consp (car undo-rec))
-;;;              (setq undo-rec (list undo-rec)))
-;;;          (insert ?\()
-;;;          (while (setq undo-map (pop undo-rec))
-;;;            (insert (cdr undo-map) (car undo-map) ?\ ))
-;;;          (delete-backward-char 1)
-;;;          (insert ")\n"))))))
-
-;; arch-tag: 8f094d88-ffe1-4f99-afe3-a5e81dd939d9
+;;(defun decipher-show-undo-list ()
+;;  "Display the undo list (for debugging purposes)."
+;;  (interactive)
+;;  (with-output-to-temp-buffer "*Decipher Undo*"
+;;    (let ((undo-list decipher-undo-list)
+;;          undo-rec undo-map)
+;;      (with-current-buffer "*Decipher Undo*"
+;;        (while (setq undo-rec (pop undo-list))
+;;          (or (consp (car undo-rec))
+;;              (setq undo-rec (list undo-rec)))
+;;          (insert ?\()
+;;          (while (setq undo-map (pop undo-rec))
+;;            (insert (cdr undo-map) (car undo-map) ?\ ))
+;;          (delete-char -1)
+;;          (insert ")\n"))))))
+
 ;;; decipher.el ends here