comparison lisp/play/zone.el @ 109157:76b683a5339b

Minor zone.el fixes for bug#6483. Zone did not like the intangible newlines etc in the gomoku buffer. * lisp/play/zone.el (top-level): Do not require timer, tabify, or cl. (zone-shift-left): Ignore intangibility, and any errors from forward-char. (zone-shift-right): Remove no-op end-of-line. Ignore intangibility. (zone-pgm-putz-with-case): Use upcase-region rather than inserting, deleting, and copying text properties. (zone-line-specs, zone-pgm-stress): Check forward-line exit status. (zone-pgm-rotate): Handle odd buffers like that of gomoku, where getting to point-max is hard. (zone-fret, zone-fill-out-screen): Replace cl's do with dotimes. (zone-fill-out-screen): Ignore intangibility.
author Glenn Morris <rgm@gnu.org>
date Tue, 06 Jul 2010 21:16:27 -0700
parents 1d1d5d9bd884
children 60516122d066
comparison
equal deleted inserted replaced
109156:32bdba8ef7f4 109157:76b683a5339b
1 ;;; zone.el --- idle display hacks 1 ;;; zone.el --- idle display hacks
2 2
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 4 ;; 2009, 2010 Free Software Foundation, Inc.
5 5
6 ;; Author: Victor Zandy <zandy@cs.wisc.edu> 6 ;; Author: Victor Zandy <zandy@cs.wisc.edu>
7 ;; Maintainer: Thien-Thi Nguyen <ttn@gnu.org> 7 ;; Maintainer: Thien-Thi Nguyen <ttn@gnu.org>
8 ;; Keywords: games 8 ;; Keywords: games
9 ;; Created: June 6, 1998 9 ;; Created: June 6, 1998
37 ;; THANKS: Christopher Mayer, Scott Flinchbaugh, 37 ;; THANKS: Christopher Mayer, Scott Flinchbaugh,
38 ;; Rachel Kalmar, Max Froumentin, Juri Linkov, 38 ;; Rachel Kalmar, Max Froumentin, Juri Linkov,
39 ;; Luigi Panzeri, John Paul Wallington. 39 ;; Luigi Panzeri, John Paul Wallington.
40 40
41 ;;; Code: 41 ;;; Code:
42
43 (require 'timer)
44 (require 'tabify)
45 (eval-when-compile (require 'cl))
46 42
47 (defvar zone-timer nil 43 (defvar zone-timer nil
48 "The timer we use to decide when to zone out, or nil if none.") 44 "The timer we use to decide when to zone out, or nil if none.")
49 45
50 (defvar zone-timeout nil 46 (defvar zone-timeout nil
208 (delete-region b e) 204 (delete-region b e)
209 (goto-char (point-min)) 205 (goto-char (point-min))
210 (insert s))) 206 (insert s)))
211 207
212 (defun zone-shift-left () 208 (defun zone-shift-left ()
213 (let (s) 209 (let ((inhibit-point-motion-hooks t)
210 s)
214 (while (not (eobp)) 211 (while (not (eobp))
215 (unless (eolp) 212 (unless (eolp)
216 (setq s (buffer-substring (point) (1+ (point)))) 213 (setq s (buffer-substring (point) (1+ (point))))
217 (delete-char 1) 214 (delete-char 1)
218 (end-of-line) 215 (end-of-line)
219 (insert s)) 216 (insert s))
220 (forward-char 1)))) 217 (ignore-errors (forward-char 1)))))
221 218
222 (defun zone-shift-right () 219 (defun zone-shift-right ()
223 (goto-char (point-max)) 220 (goto-char (point-max))
224 (end-of-line) 221 (let ((inhibit-point-motion-hooks t)
225 (let (s) 222 s)
226 (while (not (bobp)) 223 (while (not (bobp))
227 (unless (bolp) 224 (unless (bolp)
228 (setq s (buffer-substring (1- (point)) (point))) 225 (setq s (buffer-substring (1- (point)) (point)))
229 (delete-char -1) 226 (delete-char -1)
230 (beginning-of-line) 227 (beginning-of-line)
346 (goto-char (point-min)) 343 (goto-char (point-min))
347 (while (not (input-pending-p)) 344 (while (not (input-pending-p))
348 (let ((np (+ 2 (random 5))) 345 (let ((np (+ 2 (random 5)))
349 (pm (point-max))) 346 (pm (point-max)))
350 (while (< np pm) 347 (while (< np pm)
351 (goto-char np) 348 (funcall (if (zerop (random 2)) 'upcase-region
352 (let ((prec (preceding-char)) 349 'downcase-region) (1- np) np)
353 (props (text-properties-at (1- (point)))))
354 (insert (if (zerop (random 2))
355 (upcase prec)
356 (downcase prec)))
357 (set-text-properties (1- (point)) (point) props))
358 (backward-char 2)
359 (delete-char 1)
360 (setq np (+ np (1+ (random 5)))))) 350 (setq np (+ np (1+ (random 5))))))
361 (goto-char (point-min)) 351 (goto-char (point-min))
362 (sit-for 0 2))) 352 (sit-for 0 2)))
363 353
364 354
365 ;;;; rotating 355 ;;;; rotating
366 356
367 (defun zone-line-specs () 357 (defun zone-line-specs ()
368 (let (ret) 358 (let ((ok t)
359 ret)
369 (save-excursion 360 (save-excursion
370 (goto-char (window-start)) 361 (goto-char (window-start))
371 (while (< (point) (window-end)) 362 (while (and ok (< (point) (window-end)))
372 (when (looking-at "[\t ]*\\([^\n]+\\)") 363 (when (looking-at "[\t ]*\\([^\n]+\\)")
373 (setq ret (cons (cons (match-beginning 1) (match-end 1)) ret))) 364 (setq ret (cons (cons (match-beginning 1) (match-end 1)) ret)))
374 (forward-line 1))) 365 (setq ok (zerop (forward-line 1)))))
375 ret)) 366 ret))
376 367
377 (defun zone-pgm-rotate (&optional random-style) 368 (defun zone-pgm-rotate (&optional random-style)
378 (let* ((specs (apply 369 (let* ((specs (apply
379 'vector 370 'vector
402 (setq amt (aref ent 0) aamt (abs amt)) 393 (setq amt (aref ent 0) aamt (abs amt))
403 (if (> 0 amt) 394 (if (> 0 amt)
404 (setq cut 1 paste 2) 395 (setq cut 1 paste 2)
405 (setq cut 2 paste 1)) 396 (setq cut 2 paste 1))
406 (goto-char (aref ent cut)) 397 (goto-char (aref ent cut))
398 (setq aamt (min aamt (- (point-max) (point))))
407 (setq txt (buffer-substring (point) (+ (point) aamt))) 399 (setq txt (buffer-substring (point) (+ (point) aamt)))
408 (delete-char aamt) 400 (delete-char aamt)
409 (goto-char (aref ent paste)) 401 (goto-char (aref ent paste))
410 (insert txt) 402 (insert txt)
411 (setq i (1+ i))) 403 (setq i (1+ i)))
445 (c-string (zone-cpos pos)) 437 (c-string (zone-cpos pos))
446 (cw-ceil (ceiling (char-width (aref c-string 0)))) 438 (cw-ceil (ceiling (char-width (aref c-string 0))))
447 (hmm (cond 439 (hmm (cond
448 ((string-match "[a-z]" c-string) (upcase c-string)) 440 ((string-match "[a-z]" c-string) (upcase c-string))
449 ((string-match "[A-Z]" c-string) (downcase c-string)) 441 ((string-match "[A-Z]" c-string) (downcase c-string))
450 (t (propertize " " 'display `(space :width ,cw-ceil)))))) 442 (t (propertize " " 'display `(space :width ,cw-ceil)))))
451 (do ((i 0 (1+ i)) 443 (wait 0.5))
452 (wait 0.5 (* wait 0.8))) 444 (dotimes (i 20)
453 ((= i 20))
454 (goto-char pos) 445 (goto-char pos)
455 (delete-char 1) 446 (delete-char 1)
456 (insert (if (= 0 (% i 2)) hmm c-string)) 447 (insert (if (= 0 (% i 2)) hmm c-string))
457 (zone-park/sit-for wbeg wait)) 448 (zone-park/sit-for wbeg (setq wait (* wait 0.8))))
458 (delete-char -1) (insert c-string))) 449 (delete-char -1) (insert c-string)))
459 450
460 (defun zone-fill-out-screen (width height) 451 (defun zone-fill-out-screen (width height)
461 (let ((start (window-start)) 452 (let ((start (window-start))
462 (line (make-string width 32))) 453 (line (make-string width 32))
454 (inhibit-point-motion-hooks t))
463 (goto-char start) 455 (goto-char start)
464 ;; fill out rectangular ws block 456 ;; fill out rectangular ws block
465 (while (progn (end-of-line) 457 (while (progn (end-of-line)
466 (let ((cc (current-column))) 458 (let ((cc (current-column)))
467 (if (< cc width) 459 (if (< cc width)
471 (t (forward-char 1) t))))) 463 (t (forward-char 1) t)))))
472 ;; pad ws past bottom of screen 464 ;; pad ws past bottom of screen
473 (let ((nl (- height (count-lines (point-min) (point))))) 465 (let ((nl (- height (count-lines (point-min) (point)))))
474 (when (> nl 0) 466 (when (> nl 0)
475 (setq line (concat line "\n")) 467 (setq line (concat line "\n"))
476 (do ((i 0 (1+ i))) 468 (dotimes (i nl)
477 ((= i nl))
478 (insert line)))) 469 (insert line))))
479 (goto-char start) 470 (goto-char start)
480 (recenter 0) 471 (recenter 0)
481 (sit-for 0))) 472 (sit-for 0)))
482 473
585 576
586 ;;;; stressing and destressing 577 ;;;; stressing and destressing
587 578
588 (defun zone-pgm-stress () 579 (defun zone-pgm-stress ()
589 (goto-char (point-min)) 580 (goto-char (point-min))
590 (let (lines) 581 (let ((ok t)
591 (while (< (point) (point-max)) 582 lines)
583 (while (and ok (< (point) (point-max)))
592 (let ((p (point))) 584 (let ((p (point)))
593 (forward-line 1) 585 (setq ok (zerop (forward-line 1))
594 (setq lines (cons (buffer-substring p (point)) lines)))) 586 lines (cons (buffer-substring p (point)) lines))))
595 (sit-for 5) 587 (sit-for 5)
596 (zone-hiding-modeline 588 (zone-hiding-modeline
597 (let ((msg "Zoning... (zone-pgm-stress)")) 589 (let ((msg "Zoning... (zone-pgm-stress)"))
598 (while (not (string= msg "")) 590 (while (not (string= msg ""))
599 (message (setq msg (substring msg 1))) 591 (message (setq msg (substring msg 1)))
669 (goto-char bot) 661 (goto-char bot)
670 (while (< top (point)) 662 (while (< top (point))
671 (setq c (point)) 663 (setq c (point))
672 (move-to-column 9) 664 (move-to-column 9)
673 (setq col (cons (buffer-substring (point) c) col)) 665 (setq col (cons (buffer-substring (point) c) col))
674 (end-of-line 0) 666 ; (let ((inhibit-point-motion-hooks t))
667 (end-of-line 0);)
675 (forward-char -10)) 668 (forward-char -10))
676 (let ((life-patterns (vector 669 (let ((life-patterns (vector
677 (if (and col (search-forward "@" max t)) 670 (if (and col (search-forward "@" max t))
678 (cons (make-string (length (car col)) 32) col) 671 (cons (make-string (length (car col)) 32) col)
679 (list (mapconcat 'identity 672 (list (mapconcat 'identity