unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Patch to display "System" colors
@ 2003-11-15  0:26 Michael Mauger
  2003-11-15 14:17 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Mauger @ 2003-11-15  0:26 UTC (permalink / raw)


Several months ago, support for the colors defined in the W32 control
panel was added.  These colors are logical colors rather than physical
colors (i.e., "SystemActiveTitleText" vs "LightGreen").  The logical
colors can be identified by the "System" prefix.

I noticed that `list-colors-display' was not showing all the logical
colors.  This is because it skips colors that have the same color value
as the previous color value in the list.  (Thus "LightGreen" is skipped
when the previous color was "light green" because they both have the
color value (43052688).)  However, the System colors should not be
skipped just because they have the same color value as the previous
system color.

This small patch will show all of the logical system colors in
`list-colors-display' while still filtering similiar physical colors.

-- Michael

Index: emacs/lisp/facemenu.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/facemenu.el,v
retrieving revision 1.71
diff -u -b -r1.71 facemenu.el
--- emacs/lisp/facemenu.el      1 Sep 2003 15:45:11 -0000       1.71
+++ emacs/lisp/facemenu.el      15 Nov 2003 00:22:27 -0000
@@ -482,9 +482,18 @@
     ;; Delete duplicate colors.
     (let ((l list))
       (while (cdr l)
-       (if (facemenu-color-equal (car l) (car (cdr l)))
-           (setcdr l (cdr (cdr l)))
-         (setq l (cdr l)))))
+       (let ((this (car l))
+             (next (car (cdr l))))
+         (if (and
+              ;; Avoid filtering out "System" logical colors.
+              (or (<= (length this) 6)
+                  (not (equal (substring this 0 6) "System")))
+              (or (<= (length next) 6)
+                  (not (equal (substring next 0 6) "System")))
+              ;; If neither is a System color, compare them.
+              (facemenu-color-equal this next))
+             (setcdr l (cdr (cdr l)))))
+           (setq l (cdr l))))
     (when (memq (display-visual-class) '(gray-scale pseudo-color
direct-color))
       ;; Don't show more than what the display can handle.
       (let ((lc (nthcdr (1- (display-color-cells)) list)))


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-15  0:26 Patch to display "System" colors Michael Mauger
@ 2003-11-15 14:17 ` Eli Zaretskii
  2003-11-15 14:28   ` Jason Rumney
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2003-11-15 14:17 UTC (permalink / raw)
  Cc: emacs-devel

> Date: Fri, 14 Nov 2003 16:26:57 -0800 (PST)
> From: Michael Mauger <mmaug@yahoo.com>
> 
> This small patch will show all of the logical system colors in
> `list-colors-display' while still filtering similiar physical colors.

I think this change should at least be conditioned on the MS-Windows
platform.  (Actually, I'm not even sure I understand the reson for the
different treatment of the ``system'' colors, but I'll let Windows
experts to judge that.)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-15 14:17 ` Eli Zaretskii
@ 2003-11-15 14:28   ` Jason Rumney
  2003-11-15 14:47     ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Rumney @ 2003-11-15 14:28 UTC (permalink / raw)
  Cc: Michael Mauger, emacs-devel

"Eli Zaretskii" <eliz@elta.co.il> writes:

> (Actually, I'm not even sure I understand the reson for the
> different treatment of the ``system'' colors, but I'll let Windows
> experts to judge that.)

I think the idea is to let users know that these exist so they can
use them in their own customizations. The other duplicates that are
suppressed are spelling variations, so it is not important to show
all of those in list-colors-display.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-15 14:28   ` Jason Rumney
@ 2003-11-15 14:47     ` Eli Zaretskii
  2003-11-15 15:41       ` Jason Rumney
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2003-11-15 14:47 UTC (permalink / raw)
  Cc: mmaug, emacs-devel

> From: Jason Rumney <jasonr@gnu.org>
> Date: 15 Nov 2003 14:28:16 +0000
> 
> I think the idea is to let users know that these exist so they can
> use them in their own customizations. The other duplicates that are
> suppressed are spelling variations, so it is not important to show
> all of those in list-colors-display.

Then perhaps we should modify the code that rejects colors so that it
only rejects based on spelling, not on pixel values.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-15 14:47     ` Eli Zaretskii
@ 2003-11-15 15:41       ` Jason Rumney
  2003-11-18  1:10         ` Michael Mauger
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Rumney @ 2003-11-15 15:41 UTC (permalink / raw)
  Cc: mmaug, emacs-devel

"Eli Zaretskii" <eliz@elta.co.il> writes:

> > From: Jason Rumney <jasonr@gnu.org>
> > Date: 15 Nov 2003 14:28:16 +0000
> > 
> > I think the idea is to let users know that these exist so they can
> > use them in their own customizations. The other duplicates that are
> > suppressed are spelling variations, so it is not important to show
> > all of those in list-colors-display.
> 
> Then perhaps we should modify the code that rejects colors so that it
> only rejects based on spelling, not on pixel values.

It might be enough to remove spaces, downcase and standardize
gray/grey before doing the comparison.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-15 15:41       ` Jason Rumney
@ 2003-11-18  1:10         ` Michael Mauger
  2003-11-18 10:01           ` Kim F. Storm
  2003-11-18 23:03           ` Richard Stallman
  0 siblings, 2 replies; 9+ messages in thread
From: Michael Mauger @ 2003-11-18  1:10 UTC (permalink / raw)
  Cc: emacs-devel

--- Jason Rumney <jasonr@gnu.org> wrote:
> "Eli Zaretskii" <eliz@elta.co.il> writes:
> > > From: Jason Rumney <jasonr@gnu.org>
> > > Date: 15 Nov 2003 14:28:16 +0000
> > > 
> > > I think the idea is to let users know that these exist so they can
> > > use them in their own customizations. The other duplicates that are
> > > suppressed are spelling variations, so it is not important to show
> > > all of those in list-colors-display.
> > 
> > Then perhaps we should modify the code that rejects colors so that it
> > only rejects based on spelling, not on pixel values.
> 
> It might be enough to remove spaces, downcase and standardize
> gray/grey before doing the comparison.
> 

Here's a patch that normalizes the color names as Jason suggests.  Use
this in place of my original patch.  This does not look at the color
values at all.

Is there an existing elisp function to replace substrings within an
original string with replacement substrings?  See
`facemenu-string-match-and-replace' in the patch below.

Index: emacs/lisp/facemenu.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/facemenu.el,v
retrieving revision 1.71
diff -u -b -r1.71 facemenu.el
--- emacs/lisp/facemenu.el	1 Sep 2003 15:45:11 -0000	1.71
+++ emacs/lisp/facemenu.el	18 Nov 2003 00:57:51 -0000
@@ -512,5 +514,25 @@
 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)))))
+  (progn
+    (setq a (facemenu-string-match-and-replace
+	     (facemenu-string-match-and-replace
+	      (downcase a)		; downcase
+	      " " "")			; remove spaces
+	     "grey" "gray")		; translate `grey' to `gray'
+	  b (facemenu-string-match-and-replace
+	     (facemenu-string-match-and-replace
+	      (downcase b)
+	      " " "")
+	     "grey" "gray"))
+
+    (equal a b)))
+
+(defun facemenu-string-match-and-replace (str from to)
+  "Return the string STR with all occurences of the regular
+expression FROM replaced by TO."
+  (while (string-match from str)
+    (setq str (concat (substring str 0 (match-beginning 0))
+		      to
+		      (substring str (match-end 0)))))
+  str)

 (defun facemenu-add-face (face &optional start end)
   "Add FACE to text between START and END.


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-18  1:10         ` Michael Mauger
@ 2003-11-18 10:01           ` Kim F. Storm
  2003-11-18 18:17             ` Michael Mauger
  2003-11-18 23:03           ` Richard Stallman
  1 sibling, 1 reply; 9+ messages in thread
From: Kim F. Storm @ 2003-11-18 10:01 UTC (permalink / raw)
  Cc: emacs-devel

Michael Mauger <mmaug@yahoo.com> writes:

> Is there an existing elisp function to replace substrings within an
> original string with replacement substrings?  See
> `facemenu-string-match-and-replace' in the patch below.

replace-regexp-in-string

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-18 10:01           ` Kim F. Storm
@ 2003-11-18 18:17             ` Michael Mauger
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Mauger @ 2003-11-18 18:17 UTC (permalink / raw)
  Cc: emacs-devel

--- "Kim F. Storm" <storm@cua.dk> wrote:
> Michael Mauger <mmaug@yahoo.com> writes:
> 
> > Is there an existing elisp function to replace substrings within an
> > original string with replacement substrings?  See
> > `facemenu-string-match-and-replace' in the patch below.
> 
> replace-regexp-in-string
> 

Thanks.  I'm not sure how I missed that one...

Here's the updated patch...

Index: emacs/lisp/facemenu.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/facemenu.el,v
retrieving revision 1.71
diff -u -b -r1.71 facemenu.el
--- emacs/lisp/facemenu.el      1 Sep 2003 15:45:11 -0000       1.71
+++ emacs/lisp/facemenu.el      18 Nov 2003 18:04:08 -0000
@@ -508,12 +510,19 @@

 (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)))

 (defun facemenu-add-face (face &optional start end)
   "Add FACE to text between START and END.


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Patch to display "System" colors
  2003-11-18  1:10         ` Michael Mauger
  2003-11-18 10:01           ` Kim F. Storm
@ 2003-11-18 23:03           ` Richard Stallman
  1 sibling, 0 replies; 9+ messages in thread
From: Richard Stallman @ 2003-11-18 23:03 UTC (permalink / raw)
  Cc: eliz, emacs-devel, jasonr

    +(defun facemenu-string-match-and-replace (str from to)
    +  "Return the string STR with all occurences of the regular
    +expression FROM replaced by TO."

This doc string doesn't follow the conventions -- please
see the Tips appendix in the Emacs Lisp manual.

However, you don't need the function, since you can use
replace-regexp-in-string.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-11-18 23:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-15  0:26 Patch to display "System" colors Michael Mauger
2003-11-15 14:17 ` Eli Zaretskii
2003-11-15 14:28   ` Jason Rumney
2003-11-15 14:47     ` Eli Zaretskii
2003-11-15 15:41       ` Jason Rumney
2003-11-18  1:10         ` Michael Mauger
2003-11-18 10:01           ` Kim F. Storm
2003-11-18 18:17             ` Michael Mauger
2003-11-18 23:03           ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).