[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 16efea3 2/2: Small dunnet score file improvements
From: |
Glenn Morris |
Subject: |
[Emacs-diffs] master 16efea3 2/2: Small dunnet score file improvements |
Date: |
Thu, 23 Feb 2017 13:22:40 -0500 (EST) |
branch: master
commit 16efea3a883ebf633946ee9b9d0681eb55437878
Author: Glenn Morris <address@hidden>
Commit: Glenn Morris <address@hidden>
Small dunnet score file improvements
* lisp/play/dunnet.el (dun-log-file): Switch to per-user default.
(dun-do-logfile): Handle non-existing score file.
---
lisp/play/dunnet.el | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/lisp/play/dunnet.el b/lisp/play/dunnet.el
index ae31dc5..f0a1cf1 100644
--- a/lisp/play/dunnet.el
+++ b/lisp/play/dunnet.el
@@ -27,10 +27,6 @@
;; 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
@@ -38,8 +34,13 @@
: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))))