diff options
| author | Mark Oteiza | 2017-02-20 13:53:41 -0500 |
|---|---|---|
| committer | Mark Oteiza | 2017-02-20 13:53:41 -0500 |
| commit | 27a76829fe71efcb048686a3c42221aec1020f10 (patch) | |
| tree | 4ae99afca3144301dc9a3dd43c190a7a4e91b182 | |
| parent | e546d3d967e12741394774f2d3aeadc07cf78483 (diff) | |
| download | emacs-27a76829fe71efcb048686a3c42221aec1020f10.tar.gz emacs-27a76829fe71efcb048686a3c42221aec1020f10.zip | |
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.
| -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") | |||
| 1176 | (defun dunnet () | 1176 | (defun dunnet () |
| 1177 | "Switch to *dungeon* buffer and start game." | 1177 | "Switch to *dungeon* buffer and start game." |
| 1178 | (interactive) | 1178 | (interactive) |
| 1179 | (switch-to-buffer "*dungeon*") | 1179 | (pop-to-buffer-same-window "*dungeon*") |
| 1180 | (dun-mode) | 1180 | (dun-mode) |
| 1181 | (setq dun-dead nil) | 1181 | (setq dun-dead nil) |
| 1182 | (setq dun-room 0) | 1182 | (setq dun-room 0) |
| @@ -2343,20 +2343,16 @@ for a moment, then straighten yourself up. | |||
| 2343 | ;;; Load an encrypted file, and eval it. | 2343 | ;;; Load an encrypted file, and eval it. |
| 2344 | 2344 | ||
| 2345 | (defun dun-load-d (filename) | 2345 | (defun dun-load-d (filename) |
| 2346 | (let ((old-buffer (current-buffer)) | 2346 | (let ((result t)) |
| 2347 | (result t)) | 2347 | (with-temp-buffer |
| 2348 | (switch-to-buffer (get-buffer-create "*loadc*")) | ||
| 2349 | (erase-buffer) | ||
| 2350 | (condition-case nil | ||
| 2351 | (insert-file-contents filename) | ||
| 2352 | (error (setq result nil))) | ||
| 2353 | (when result | ||
| 2354 | (condition-case nil | 2348 | (condition-case nil |
| 2355 | (dun-rot13) | 2349 | (insert-file-contents filename) |
| 2356 | (error (yank))) | 2350 | (error (setq result nil))) |
| 2357 | (eval-buffer) | 2351 | (when result |
| 2358 | (kill-buffer (current-buffer))) | 2352 | (condition-case nil |
| 2359 | (switch-to-buffer old-buffer) | 2353 | (dun-rot13) |
| 2354 | (error (yank))) | ||
| 2355 | (eval-buffer))) | ||
| 2360 | result)) | 2356 | result)) |
| 2361 | 2357 | ||
| 2362 | ;;; Functions to remove an object either from a room, or from inventory. | 2358 | ;;; Functions to remove an object either from a room, or from inventory. |
| @@ -2466,23 +2462,11 @@ for a moment, then straighten yourself up. | |||
| 2466 | (dun-eval varname value))))) | 2462 | (dun-eval varname value))))) |
| 2467 | 2463 | ||
| 2468 | (defun dun-eval (varname value) | 2464 | (defun dun-eval (varname value) |
| 2469 | (let (eval-error) | 2465 | (with-temp-buffer |
| 2470 | (switch-to-buffer (get-buffer-create "*dungeon-eval*")) | 2466 | (insert "(setq " varname " " value ")") |
| 2471 | (erase-buffer) | ||
| 2472 | (insert "(setq ") | ||
| 2473 | (insert varname) | ||
| 2474 | (insert " ") | ||
| 2475 | (insert value) | ||
| 2476 | (insert ")") | ||
| 2477 | (setq eval-error nil) | ||
| 2478 | (condition-case nil | 2467 | (condition-case nil |
| 2479 | (eval-buffer) | 2468 | (eval-buffer) |
| 2480 | (error (setq eval-error t))) | 2469 | (error (dun-mprincl "Invalid syntax."))))) |
| 2481 | (kill-buffer (current-buffer)) | ||
| 2482 | (switch-to-buffer "*dungeon*") | ||
| 2483 | (if eval-error | ||
| 2484 | (dun-mprincl "Invalid syntax.")))) | ||
| 2485 | |||
| 2486 | 2470 | ||
| 2487 | (defun dun-unix-interface () | 2471 | (defun dun-unix-interface () |
| 2488 | (dun-login) | 2472 | (dun-login) |
| @@ -3012,49 +2996,43 @@ File not found"))) | |||
| 3012 | (defun dun-save-game (filename) | 2996 | (defun dun-save-game (filename) |
| 3013 | (if (not (setq filename (car filename))) | 2997 | (if (not (setq filename (car filename))) |
| 3014 | (dun-mprincl "You must supply a filename for the save.") | 2998 | (dun-mprincl "You must supply a filename for the save.") |
| 3015 | (if (file-exists-p filename) | 2999 | (when (file-exists-p filename) (delete-file filename)) |
| 3016 | (delete-file filename)) | ||
| 3017 | (setq dun-numsaves (1+ dun-numsaves)) | 3000 | (setq dun-numsaves (1+ dun-numsaves)) |
| 3018 | (dun-make-save-buffer) | 3001 | (with-temp-buffer |
| 3019 | (dun-save-val "dun-current-room") | 3002 | (dun-save-val "dun-current-room") |
| 3020 | (dun-save-val "dun-computer") | 3003 | (dun-save-val "dun-computer") |
| 3021 | (dun-save-val "dun-combination") | 3004 | (dun-save-val "dun-combination") |
| 3022 | (dun-save-val "dun-visited") | 3005 | (dun-save-val "dun-visited") |
| 3023 | (dun-save-val "dun-diggables") | 3006 | (dun-save-val "dun-diggables") |
| 3024 | (dun-save-val "dun-key-level") | 3007 | (dun-save-val "dun-key-level") |
| 3025 | (dun-save-val "dun-floppy") | 3008 | (dun-save-val "dun-floppy") |
| 3026 | (dun-save-val "dun-numsaves") | 3009 | (dun-save-val "dun-numsaves") |
| 3027 | (dun-save-val "dun-numcmds") | 3010 | (dun-save-val "dun-numcmds") |
| 3028 | (dun-save-val "dun-logged-in") | 3011 | (dun-save-val "dun-logged-in") |
| 3029 | (dun-save-val "dungeon-mode") | 3012 | (dun-save-val "dungeon-mode") |
| 3030 | (dun-save-val "dun-jar") | 3013 | (dun-save-val "dun-jar") |
| 3031 | (dun-save-val "dun-lastdir") | 3014 | (dun-save-val "dun-lastdir") |
| 3032 | (dun-save-val "dun-black") | 3015 | (dun-save-val "dun-black") |
| 3033 | (dun-save-val "dun-nomail") | 3016 | (dun-save-val "dun-nomail") |
| 3034 | (dun-save-val "dun-unix-verbs") | 3017 | (dun-save-val "dun-unix-verbs") |
| 3035 | (dun-save-val "dun-hole") | 3018 | (dun-save-val "dun-hole") |
| 3036 | (dun-save-val "dun-uncompressed") | 3019 | (dun-save-val "dun-uncompressed") |
| 3037 | (dun-save-val "dun-ethernet") | 3020 | (dun-save-val "dun-ethernet") |
| 3038 | (dun-save-val "dun-sauna-level") | 3021 | (dun-save-val "dun-sauna-level") |
| 3039 | (dun-save-val "dun-room-objects") | 3022 | (dun-save-val "dun-room-objects") |
| 3040 | (dun-save-val "dun-room-silents") | 3023 | (dun-save-val "dun-room-silents") |
| 3041 | (dun-save-val "dun-inventory") | 3024 | (dun-save-val "dun-inventory") |
| 3042 | (dun-save-val "dun-endgame-questions") | 3025 | (dun-save-val "dun-endgame-questions") |
| 3043 | (dun-save-val "dun-endgame") | 3026 | (dun-save-val "dun-endgame") |
| 3044 | (dun-save-val "dun-cdroom") | 3027 | (dun-save-val "dun-cdroom") |
| 3045 | (dun-save-val "dun-cdpath") | 3028 | (dun-save-val "dun-cdpath") |
| 3046 | (dun-save-val "dun-correct-answer") | 3029 | (dun-save-val "dun-correct-answer") |
| 3047 | (dun-save-val "dun-inbus") | 3030 | (dun-save-val "dun-inbus") |
| 3048 | (if (dun-compile-save-out filename) | 3031 | (if (dun-compile-save-out filename) |
| 3049 | (dun-mprincl "Error saving to file.") | 3032 | (dun-mprincl "Error saving to file.") |
| 3050 | (dun-do-logfile 'save nil) | 3033 | (dun-do-logfile 'save nil))) |
| 3051 | (switch-to-buffer "*dungeon*") | 3034 | (princ "") |
| 3052 | (princ "") | 3035 | (dun-mprincl "Done."))) |
| 3053 | (dun-mprincl "Done.")))) | ||
| 3054 | |||
| 3055 | (defun dun-make-save-buffer () | ||
| 3056 | (switch-to-buffer (get-buffer-create "*save-dungeon*")) | ||
| 3057 | (erase-buffer)) | ||
| 3058 | 3036 | ||
| 3059 | (defun dun-compile-save-out (filename) | 3037 | (defun dun-compile-save-out (filename) |
| 3060 | (let (ferror) | 3038 | (let (ferror) |
| @@ -3100,40 +3078,39 @@ File not found"))) | |||
| 3100 | 3078 | ||
| 3101 | (defun dun-do-logfile (type how) | 3079 | (defun dun-do-logfile (type how) |
| 3102 | (let (ferror) | 3080 | (let (ferror) |
| 3103 | (setq ferror nil) | 3081 | (with-temp-buffer |
| 3104 | (switch-to-buffer (get-buffer-create "*score*")) | 3082 | (condition-case err |
| 3105 | (erase-buffer) | 3083 | (insert-file-contents dun-log-file) |
| 3106 | (condition-case nil | 3084 | (error |
| 3107 | (insert-file-contents dun-log-file) | 3085 | (setq ferror t) |
| 3108 | (error (setq ferror t))) | 3086 | (dun-mprincl (error-message-string err)))) |
| 3109 | (unless ferror | 3087 | (when (null ferror) |
| 3110 | (goto-char (point-max)) | 3088 | (goto-char (point-max)) |
| 3111 | (dun-minsert (current-time-string)) | 3089 | (dun-minsert (current-time-string)) |
| 3112 | (dun-minsert " ") | 3090 | (dun-minsert " ") |
| 3113 | (dun-minsert (user-login-name)) | 3091 | (dun-minsert (user-login-name)) |
| 3114 | (dun-minsert " ") | 3092 | (dun-minsert " ") |
| 3115 | (if (eq type 'save) | 3093 | (if (eq type 'save) |
| 3116 | (dun-minsert "saved ") | 3094 | (dun-minsert "saved ") |
| 3117 | (if (= (dun-endgame-score) 110) | 3095 | (if (= (dun-endgame-score) 110) |
| 3118 | (dun-minsert "won ") | 3096 | (dun-minsert "won ") |
| 3119 | (if (not how) | 3097 | (if (not how) |
| 3120 | (dun-minsert "quit ") | 3098 | (dun-minsert "quit ") |
| 3121 | (dun-minsert "killed by ") | 3099 | (dun-minsert "killed by ") |
| 3122 | (dun-minsert how) | 3100 | (dun-minsert how) |
| 3123 | (dun-minsert " ")))) | 3101 | (dun-minsert " ")))) |
| 3124 | (dun-minsert "at ") | 3102 | (dun-minsert "at ") |
| 3125 | (dun-minsert (cadr (nth (abs dun-room) dun-rooms))) | 3103 | (dun-minsert (cadr (nth (abs dun-room) dun-rooms))) |
| 3126 | (dun-minsert ". score: ") | 3104 | (dun-minsert ". score: ") |
| 3127 | (if (> (dun-endgame-score) 0) | 3105 | (if (> (dun-endgame-score) 0) |
| 3128 | (dun-minsert (+ 90 (dun-endgame-score))) | 3106 | (dun-minsert (+ 90 (dun-endgame-score))) |
| 3129 | (dun-minsert (dun-reg-score))) | 3107 | (dun-minsert (dun-reg-score))) |
| 3130 | (dun-minsert " saves: ") | 3108 | (dun-minsert " saves: ") |
| 3131 | (dun-minsert dun-numsaves) | 3109 | (dun-minsert dun-numsaves) |
| 3132 | (dun-minsert " commands: ") | 3110 | (dun-minsert " commands: ") |
| 3133 | (dun-minsert dun-numcmds) | 3111 | (dun-minsert dun-numcmds) |
| 3134 | (dun-minsert "\n") | 3112 | (dun-minsert "\n") |
| 3135 | (write-region 1 (point-max) dun-log-file nil 1)) | 3113 | (write-region 1 (point-max) dun-log-file nil 1))))) |
| 3136 | (kill-buffer (current-buffer)))) | ||
| 3137 | 3114 | ||
| 3138 | 3115 | ||
| 3139 | ;;;; | 3116 | ;;;; |