emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: list-colors-display: filter same adjecent colors


From: Michael Mauger
Subject: Re: list-colors-display: filter same adjecent colors
Date: Fri, 5 Mar 2004 15:49:19 -0800 (PST)

--- Eli Zaretskii <address@hidden> wrote:
> > Date: Mon, 23 Feb 2004 19:43:58 -0800 (PST)
> > From: Michael Mauger <address@hidden>
> > 
> > This was another conversation from November.  
> > 
> > See
> http://mail.gnu.org/archive/html/emacs-devel/2003-11/msg00189.html
> 
> Thanks for following up.
> 
> >  (defun facemenu-color-equal (a b)
> >    "Return t if colors A and B are the same color.
> > -A and B should be strings naming colors.
> > -This function queries the display system to find out what the color
> > -names mean.  It returns nil if the colors differ or if it can't
> > -determine the correct answer."
> > -  (cond ((equal a b) t)
> > -       ((equal (color-values a) (color-values b)))))
> > +A and B should be strings naming colors.  These names are
> > +downcased, stripped of spaces and the string `grey' is turned
> > +into `gray'.  This accomidates alternative spellings of colors
> > +found commonly in the list.  It returns nil if the colors differ."
> > +  (progn
> > +    (setq a (replace-regexp-in-string "grey" "gray"
> > +            (replace-regexp-in-string " " ""
> > +             (downcase a)))
> > +         b (replace-regexp-in-string "grey" "gray"
> > +            (replace-regexp-in-string " " ""
> > +             (downcase b))))
> > +
> > +    (equal a b)))
> 
> Hmm, how about making this a new function, and leaving the original
> facemenu-color-equal alone?  None of the Lisp files bundled with
> Emacs use facemenu-color-equal, but perhaps some add-on packages do,
> as it sounds like useful functionality and is there since 1994.
> 
> Also, I think we should mention the MS-Windows case and the special
> color names used there explicitly, at least in a comment to the
> function's code, if not in the doc string.  A year from now, no one
> will remember why we modified the way colors are compared.
> 

How does this patch look:

Index: emacs/lisp/facemenu.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/facemenu.el,v
retrieving revision 1.71
diff -u -r1.71 facemenu.el
--- emacs/lisp/facemenu.el      1 Sep 2003 15:45:11 -0000       1.71
+++ emacs/lisp/facemenu.el      27 Feb 2004 04:57:36 -0000
@@ -480,9 +480,15 @@
   (when (and (null list) (> (display-color-cells) 0))
     (setq list (defined-colors))
     ;; Delete duplicate colors.
+
+    ;; Identify duplicate colors by the name rather than the color
+    ;; value.  On w32, logical colors are added to the list that might
+    ;; have the same value but have different names and meanings.
+    ;; Detecting duplicates by name insures that all of these logical
+    ;; colors remain despite similar color values.
     (let ((l list))
       (while (cdr l)
-       (if (facemenu-color-equal (car l) (car (cdr l)))
+       (if (facemenu-color-name-equal (car l) (car (cdr l)))
            (setcdr l (cdr (cdr l)))
          (setq l (cdr l)))))
     (when (memq (display-visual-class) '(gray-scale pseudo-color
direct-color))
@@ -514,6 +520,22 @@
 determine the correct answer."
   (cond ((equal a b) t)
        ((equal (color-values a) (color-values b)))))
+
+(defun facemenu-color-name-equal (a b)
+  "Return t if colors A and B are the same color.
+A and B should be strings naming colors.  These names are
+downcased, stripped of spaces and the string `grey' is turned
+into `gray'.  This accomidates alternative spellings of colors
+found commonly in the list.  It returns nil if the colors differ."
+  (progn
+    (setq a (replace-regexp-in-string "grey" "gray"
+            (replace-regexp-in-string " " ""
+             (downcase a)))
+         b (replace-regexp-in-string "grey" "gray"
+            (replace-regexp-in-string " " ""
+             (downcase b))))
+
+    (equal a b)))
 
 (defun facemenu-add-face (face &optional start end)
   "Add FACE to text between START and END.


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what youÂ’re looking for faster
http://search.yahoo.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]