Commit 27a76829 authored by Mark Oteiza's avatar Mark Oteiza

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.
parent e546d3d9
......@@ -1176,7 +1176,7 @@ treasures for points?" "4" "four")
(defun dunnet ()
"Switch to *dungeon* buffer and start game."
(switch-to-buffer "*dungeon*")
(pop-to-buffer-same-window "*dungeon*")
(setq dun-dead nil)
(setq dun-room 0)
......@@ -2343,10 +2343,8 @@ 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*"))
(let ((result t))
(condition-case nil
(insert-file-contents filename)
(error (setq result nil)))
......@@ -2354,9 +2352,7 @@ for a moment, then straighten yourself up.
(condition-case nil
(error (yank)))
(kill-buffer (current-buffer)))
(switch-to-buffer old-buffer)
;;; 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*"))
(insert "(setq ")
(insert varname)
(insert " ")
(insert value)
(insert ")")
(setq eval-error nil)
(insert "(setq " varname " " value ")")
(condition-case nil
(error (setq eval-error t)))
(kill-buffer (current-buffer))
(switch-to-buffer "*dungeon*")
(if eval-error
(dun-mprincl "Invalid syntax."))))
(error (dun-mprincl "Invalid syntax.")))))
(defun dun-unix-interface ()
......@@ -3012,10 +2996,9 @@ 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-save-val "dun-current-room")
(dun-save-val "dun-computer")
(dun-save-val "dun-combination")
......@@ -3047,14 +3030,9 @@ File not found")))
(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*")
(dun-do-logfile 'save nil)))
(princ "")
(dun-mprincl "Done."))))
(defun dun-make-save-buffer ()
(switch-to-buffer (get-buffer-create "*save-dungeon*"))
(dun-mprincl "Done.")))
(defun dun-compile-save-out (filename)
(let (ferror)
......@@ -3100,13 +3078,13 @@ File not found")))
(defun dun-do-logfile (type how)
(let (ferror)
(setq ferror nil)
(switch-to-buffer (get-buffer-create "*score*"))
(condition-case nil
(condition-case err
(insert-file-contents dun-log-file)
(error (setq ferror t)))
(unless ferror
(setq ferror t)
(dun-mprincl (error-message-string err))))
(when (null ferror)
(goto-char (point-max))
(dun-minsert (current-time-string))
(dun-minsert " ")
......@@ -3132,8 +3110,7 @@ File not found")))
(dun-minsert " commands: ")
(dun-minsert dun-numcmds)
(dun-minsert "\n")
(write-region 1 (point-max) dun-log-file nil 1))
(kill-buffer (current-buffer))))
(write-region 1 (point-max) dun-log-file nil 1)))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment