Subject: bug#14719: 24.3; Crashing when setting frames to random colors

From: Steve Wainstead <[email-masked]>
Date: Tue, 25 Jun 2013 15:00:09 -0700

I have a Lisp function that is run every time I do M-x compile:

;; choose random colors every time we compile, just for fun
(defun sw-make-random-hex-color-string ()
  "Return a string in the form of #FFFFFF. Choose the number for
   #xffffff randomly using Emacs Lisp's builtin function (random)."
  ;; seed our random number generator: current datetime plus Emacs's
  ;; process ID
  (random t)
  (format "#%06x" (random #xffffff))
  )

(defun sw-randomize-frame-colors ()
  "Change foreground and background colors of the current frame to
random colors."
  (interactive)
  (let 
      (
       (fg-color (sw-make-random-hex-color-string)) 
       (bg-color (sw-make-random-hex-color-string))
       (color-distance #x3fffff)
       )
    (set-foreground-color fg-color)
    (set-background-color bg-color)
    )
  )

I *think* sometimes the color values come out the same and it causes
Emacs to crash. I'm not sure because it's almost instantaneous when I
run compile.

Note that color-distance is unused, a feature I've yet to implement.

In GNU Emacs 24.3.1 (x86_64-apple-darwin12.3.0, NS apple-appkit-1187.37)
of 2013-03-20 on swain.socialserve.com
Windowing system distributor `Apple', version 10.3.1187
Configured using:
`configure '--with-ns''

Important settings:
  locale-coding-system: nil
  default enable-multibyte-characters: t

Major mode: Emacs-Lisp

Minor modes in effect:
  display-time-mode: t
  desktop-save-mode: t
  show-paren-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t

Recent input:
y <menu-bar> <options> <menu-set-font> <ns-change-font> 
<ns-change-font> <help-echo> <help-echo> M-x s e SPC 
t SPC f o r e <tab> <return> r e d <return> M-x s e 
t SPC b a c k <tab> <return> r e d <return> M-x s e 
t SPC b a c k g r o u n d SPC c o l o r <return> b 
l a c k <return> M-x s e t SPC f o r e <tab> <return> 
g o l d e n r o d <return> C-e <f1> k <f15> C-x o C-n 
C-e M-b C-x . <return> C-g C-x k <return> <return> 
C-x 1 M-x s e t SPC c u r <tab> <return> c <backspace> 
r e d <return> C-e C-n C-n C-n C-n C-n C-n C-n C-n 
M-x b u g s <tab> C-g M-x r e p o r t - e m a c s - 
b u g <return>

Recent messages:
Using the CPython shell
Local value of py-indent-offset set to 4
Using the CPython shell
Desktop: 9 buffers restored.
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...
Type C-x 1 to delete the help window.
Local value of py-indent-offset set to 4
Using the CPython shell
Mark set
Quit [2 times]

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils find-func etags help-mode vc-git imenu
csv-mode-autoloads package derived diff-mode- two-column edmacro kmacro
python-mode info-look info cl-macs gv easymenu compile cl comint
ansi-color ring byte-opt warnings bytecomp byte-compile cconv advice
help-fns cl-lib advice-preload server time ibuffer desktop paren
time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel ns-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer loaddefs button faces cus-face macroexp files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process ns multi-tty
emacs)

---
Steve Wainstead
SocialServe.com