diff options
author | Mark Oteiza <mvoteiza@udel.edu> | 2017-02-20 13:53:41 -0500 |
---|---|---|
committer | Mark Oteiza <mvoteiza@udel.edu> | 2017-02-20 13:53:41 -0500 |
commit | 27a76829fe71efcb048686a3c42221aec1020f10 (patch) | |
tree | 4ae99afca3144301dc9a3dd43c190a7a4e91b182 /lisp/play | |
parent | e546d3d967e12741394774f2d3aeadc07cf78483 (diff) | |
download | emacs-27a76829fe71efcb048686a3c42221aec1020f10.tar.gz |
Do not use switch-to-buffer for working in a temp buffer
* lisp/play/dunnet.el (dunnet): Use pop-to-buffer-same-window instead,
cf. Bug#22244.
(dun-load-d, dun-eval, dun-save-game, dun-do-logfile): Use
with-temp-buffer instead.
Diffstat (limited to 'lisp/play')
-rw-r--r-- | lisp/play/dunnet.el | 189 |
1 files changed, 83 insertions, 106 deletions
diff --git a/lisp/play/dunnet.el b/lisp/play/dunnet.el index e7f45659e9b..d13c967dad5 100644 --- a/lisp/play/dunnet.el +++ b/lisp/play/dunnet.el @@ -1176,7 +1176,7 @@ treasures for points?" "4" "four") (defun dunnet () "Switch to *dungeon* buffer and start game." (interactive) - (switch-to-buffer "*dungeon*") + (pop-to-buffer-same-window "*dungeon*") (dun-mode) (setq dun-dead nil) (setq dun-room 0) @@ -2343,20 +2343,16 @@ for a moment, then straighten yourself up. ;;; Load an encrypted file, and eval it. (defun dun-load-d (filename) - (let ((old-buffer (current-buffer)) - (result t)) - (switch-to-buffer (get-buffer-create "*loadc*")) - (erase-buffer) - (condition-case nil - (insert-file-contents filename) - (error (setq result nil))) - (when result + (let ((result t)) + (with-temp-buffer (condition-case nil - (dun-rot13) - (error (yank))) - (eval-buffer) - (kill-buffer (current-buffer))) - (switch-to-buffer old-buffer) + (insert-file-contents filename) + (error (setq result nil))) + (when result + (condition-case nil + (dun-rot13) + (error (yank))) + (eval-buffer))) result)) ;;; Functions to remove an object either from a room, or from inventory. @@ -2466,23 +2462,11 @@ for a moment, then straighten yourself up. (dun-eval varname value))))) (defun dun-eval (varname value) - (let (eval-error) - (switch-to-buffer (get-buffer-create "*dungeon-eval*")) - (erase-buffer) - (insert "(setq ") - (insert varname) - (insert " ") - (insert value) - (insert ")") - (setq eval-error nil) + (with-temp-buffer + (insert "(setq " varname " " value ")") (condition-case nil - (eval-buffer) - (error (setq eval-error t))) - (kill-buffer (current-buffer)) - (switch-to-buffer "*dungeon*") - (if eval-error - (dun-mprincl "Invalid syntax.")))) - + (eval-buffer) + (error (dun-mprincl "Invalid syntax."))))) (defun dun-unix-interface () (dun-login) @@ -3012,49 +2996,43 @@ File not found"))) (defun dun-save-game (filename) (if (not (setq filename (car filename))) (dun-mprincl "You must supply a filename for the save.") - (if (file-exists-p filename) - (delete-file filename)) + (when (file-exists-p filename) (delete-file filename)) (setq dun-numsaves (1+ dun-numsaves)) - (dun-make-save-buffer) - (dun-save-val "dun-current-room") - (dun-save-val "dun-computer") - (dun-save-val "dun-combination") - (dun-save-val "dun-visited") - (dun-save-val "dun-diggables") - (dun-save-val "dun-key-level") - (dun-save-val "dun-floppy") - (dun-save-val "dun-numsaves") - (dun-save-val "dun-numcmds") - (dun-save-val "dun-logged-in") - (dun-save-val "dungeon-mode") - (dun-save-val "dun-jar") - (dun-save-val "dun-lastdir") - (dun-save-val "dun-black") - (dun-save-val "dun-nomail") - (dun-save-val "dun-unix-verbs") - (dun-save-val "dun-hole") - (dun-save-val "dun-uncompressed") - (dun-save-val "dun-ethernet") - (dun-save-val "dun-sauna-level") - (dun-save-val "dun-room-objects") - (dun-save-val "dun-room-silents") - (dun-save-val "dun-inventory") - (dun-save-val "dun-endgame-questions") - (dun-save-val "dun-endgame") - (dun-save-val "dun-cdroom") - (dun-save-val "dun-cdpath") - (dun-save-val "dun-correct-answer") - (dun-save-val "dun-inbus") - (if (dun-compile-save-out filename) - (dun-mprincl "Error saving to file.") - (dun-do-logfile 'save nil) - (switch-to-buffer "*dungeon*") - (princ "") - (dun-mprincl "Done.")))) - -(defun dun-make-save-buffer () - (switch-to-buffer (get-buffer-create "*save-dungeon*")) - (erase-buffer)) + (with-temp-buffer + (dun-save-val "dun-current-room") + (dun-save-val "dun-computer") + (dun-save-val "dun-combination") + (dun-save-val "dun-visited") + (dun-save-val "dun-diggables") + (dun-save-val "dun-key-level") + (dun-save-val "dun-floppy") + (dun-save-val "dun-numsaves") + (dun-save-val "dun-numcmds") + (dun-save-val "dun-logged-in") + (dun-save-val "dungeon-mode") + (dun-save-val "dun-jar") + (dun-save-val "dun-lastdir") + (dun-save-val "dun-black") + (dun-save-val "dun-nomail") + (dun-save-val "dun-unix-verbs") + (dun-save-val "dun-hole") + (dun-save-val "dun-uncompressed") + (dun-save-val "dun-ethernet") + (dun-save-val "dun-sauna-level") + (dun-save-val "dun-room-objects") + (dun-save-val "dun-room-silents") + (dun-save-val "dun-inventory") + (dun-save-val "dun-endgame-questions") + (dun-save-val "dun-endgame") + (dun-save-val "dun-cdroom") + (dun-save-val "dun-cdpath") + (dun-save-val "dun-correct-answer") + (dun-save-val "dun-inbus") + (if (dun-compile-save-out filename) + (dun-mprincl "Error saving to file.") + (dun-do-logfile 'save nil))) + (princ "") + (dun-mprincl "Done."))) (defun dun-compile-save-out (filename) (let (ferror) @@ -3100,40 +3078,39 @@ File not found"))) (defun dun-do-logfile (type how) (let (ferror) - (setq ferror nil) - (switch-to-buffer (get-buffer-create "*score*")) - (erase-buffer) - (condition-case nil - (insert-file-contents dun-log-file) - (error (setq ferror t))) - (unless ferror - (goto-char (point-max)) - (dun-minsert (current-time-string)) - (dun-minsert " ") - (dun-minsert (user-login-name)) - (dun-minsert " ") - (if (eq type 'save) - (dun-minsert "saved ") - (if (= (dun-endgame-score) 110) - (dun-minsert "won ") - (if (not how) - (dun-minsert "quit ") - (dun-minsert "killed by ") - (dun-minsert how) - (dun-minsert " ")))) - (dun-minsert "at ") - (dun-minsert (cadr (nth (abs dun-room) dun-rooms))) - (dun-minsert ". score: ") - (if (> (dun-endgame-score) 0) - (dun-minsert (+ 90 (dun-endgame-score))) - (dun-minsert (dun-reg-score))) - (dun-minsert " saves: ") - (dun-minsert dun-numsaves) - (dun-minsert " commands: ") - (dun-minsert dun-numcmds) - (dun-minsert "\n") - (write-region 1 (point-max) dun-log-file nil 1)) - (kill-buffer (current-buffer)))) + (with-temp-buffer + (condition-case err + (insert-file-contents dun-log-file) + (error + (setq ferror t) + (dun-mprincl (error-message-string err)))) + (when (null ferror) + (goto-char (point-max)) + (dun-minsert (current-time-string)) + (dun-minsert " ") + (dun-minsert (user-login-name)) + (dun-minsert " ") + (if (eq type 'save) + (dun-minsert "saved ") + (if (= (dun-endgame-score) 110) + (dun-minsert "won ") + (if (not how) + (dun-minsert "quit ") + (dun-minsert "killed by ") + (dun-minsert how) + (dun-minsert " ")))) + (dun-minsert "at ") + (dun-minsert (cadr (nth (abs dun-room) dun-rooms))) + (dun-minsert ". score: ") + (if (> (dun-endgame-score) 0) + (dun-minsert (+ 90 (dun-endgame-score))) + (dun-minsert (dun-reg-score))) + (dun-minsert " saves: ") + (dun-minsert dun-numsaves) + (dun-minsert " commands: ") + (dun-minsert dun-numcmds) + (dun-minsert "\n") + (write-region 1 (point-max) dun-log-file nil 1))))) ;;;; |