]> git.eshelyaron.com Git - emacs.git/commitdiff
Small dunnet score file improvements
authorGlenn Morris <rgm@gnu.org>
Thu, 23 Feb 2017 18:22:31 +0000 (13:22 -0500)
committerGlenn Morris <rgm@gnu.org>
Thu, 23 Feb 2017 18:22:31 +0000 (13:22 -0500)
* lisp/play/dunnet.el (dun-log-file): Switch to per-user default.
(dun-do-logfile): Handle non-existing score file.

lisp/play/dunnet.el

index ae31dc56ffc16eee3d378c952acdaff3a88468b3..f0a1cf12003d9374ab3ed7d1d67f3a0182affe78 100644 (file)
 ;; This game can be run in batch mode.  To do this, use:
 ;;    emacs -batch -l dunnet
 
-;;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-;;;  The log file should be set for your system, and it must
-;;;  be writable by all.
-
 ;;; Code:
 
 (defgroup dunnet nil
   :prefix "dun-"
   :group 'games)
 
-(defcustom dun-log-file "/usr/local/dunnet.score"
+;; Cf gamegrid.  dunnet normally runs in batch mode, where
+;; locate-user-emacs-file doesn't create directories.
+(defcustom dun-log-file (expand-file-name "dunnet-scores"
+                                         (let (noninteractive)
+                                           (locate-user-emacs-file "games/")))
   "Name of file to store score information for dunnet."
+  :version "26.1"
   :type 'file
   :group 'dunnet)
 
@@ -3068,11 +3069,15 @@ File not found")))
        (setq dun-room 0)))))
 
 
+;; See gamegrid-add-score; but that only handles a single integer score.
 (defun dun-do-logfile (type how)
   (let (ferror)
     (with-temp-buffer
       (condition-case err
-          (insert-file-contents dun-log-file)
+          (if (file-exists-p dun-log-file)
+             (insert-file-contents dun-log-file)
+           (let ((dir (file-name-directory dun-log-file)))
+             (if dir (make-directory dir t))))
         (error
          (setq ferror t)
          (dun-mprincl (error-message-string err))))