aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2010-10-24 14:43:31 -0400
committerChong Yidong2010-10-24 14:43:31 -0400
commit9317e49920455cb4481bf728cc0dce381ec905a8 (patch)
tree08a4be48e46fadfd08424e61a57e2610ad46f72e
parent59dd6f738c165a6808a924f0628764af70a898a1 (diff)
downloademacs-9317e49920455cb4481bf728cc0dce381ec905a8.tar.gz
emacs-9317e49920455cb4481bf728cc0dce381ec905a8.zip
Merge read-color and facemenu-read-color (Bug#7242).
* lisp/facemenu.el (facemenu-read-color): Alias for read-color. (facemenu-set-foreground, facemenu-set-background): Use read-color. * lisp/faces.el (read-color): Use the completion code from facemenu-read-color. Require match in completion. Doc fix. * lisp/frame.el (set-background-color, set-foreground-color) (set-cursor-color, set-mouse-color, set-border-color): Use read-color.
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/facemenu.el22
-rw-r--r--lisp/faces.el135
-rw-r--r--lisp/frame.el10
5 files changed, 90 insertions, 98 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 871f225a154..489beb523ed 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -663,6 +663,12 @@ argument is supplied (see Trash changes, above).
663 663
664** New completion style `substring'. 664** New completion style `substring'.
665 665
666** `facemenu-read-color' is now an alias for `read-color'.
667The command `read-color' now requires a match for a color name or RGB
668triplet, instead of signalling an error if the user provides a invalid
669input.
670
671
666** Image API 672** Image API
667 673
668*** When the image type is one of listed in `image-animated-types' 674*** When the image type is one of listed in `image-animated-types'
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7d45513f853..e96b764a7de 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12010-10-24 Chong Yidong <cyd@stupidchicken.com>
2
3 Merge read-color and facemenu-read-color (Bug#7242).
4
5 * faces.el (read-color): Use the completion code from
6 facemenu-read-color. Require match in completion. Doc fix.
7
8 * facemenu.el (facemenu-read-color): Alias for read-color.
9 (facemenu-set-foreground, facemenu-set-background): Use
10 read-color.
11
12 * frame.el (set-background-color, set-foreground-color)
13 (set-cursor-color, set-mouse-color, set-border-color): Use
14 read-color.
15
12010-10-24 Leo <sdl.web@gmail.com> 162010-10-24 Leo <sdl.web@gmail.com>
2 17
3 * eshell/em-unix.el (eshell-remove-entries): Use the TRASH 18 * eshell/em-unix.el (eshell-remove-entries): Use the TRASH
diff --git a/lisp/facemenu.el b/lisp/facemenu.el
index 5249538d711..f2a7958d93b 100644
--- a/lisp/facemenu.el
+++ b/lisp/facemenu.el
@@ -358,7 +358,7 @@ inserted. Moving point or switching buffers before
358typing a character to insert cancels the specification." 358typing a character to insert cancels the specification."
359 (interactive (list (progn 359 (interactive (list (progn
360 (barf-if-buffer-read-only) 360 (barf-if-buffer-read-only)
361 (facemenu-read-color "Foreground color: ")) 361 (read-color "Foreground color: "))
362 (if (and mark-active (not current-prefix-arg)) 362 (if (and mark-active (not current-prefix-arg))
363 (region-beginning)) 363 (region-beginning))
364 (if (and mark-active (not current-prefix-arg)) 364 (if (and mark-active (not current-prefix-arg))
@@ -380,7 +380,7 @@ inserted. Moving point or switching buffers before
380typing a character to insert cancels the specification." 380typing a character to insert cancels the specification."
381 (interactive (list (progn 381 (interactive (list (progn
382 (barf-if-buffer-read-only) 382 (barf-if-buffer-read-only)
383 (facemenu-read-color "Background color: ")) 383 (read-color "Background color: "))
384 (if (and mark-active (not current-prefix-arg)) 384 (if (and mark-active (not current-prefix-arg))
385 (region-beginning)) 385 (region-beginning))
386 (if (and mark-active (not current-prefix-arg)) 386 (if (and mark-active (not current-prefix-arg))
@@ -462,23 +462,7 @@ These special properties include `invisible', `intangible' and `read-only'."
462 (remove-text-properties 462 (remove-text-properties
463 start end '(invisible nil intangible nil read-only nil)))) 463 start end '(invisible nil intangible nil read-only nil))))
464 464
465(defun facemenu-read-color (&optional prompt) 465(defalias 'facemenu-read-color 'read-color)
466 "Read a color using the minibuffer."
467 (let* ((completion-ignore-case t)
468 (color-list (or facemenu-color-alist (defined-colors)))
469 (completer
470 (lambda (string pred all-completions)
471 (if all-completions
472 (or (all-completions string color-list pred)
473 (if (color-defined-p string)
474 (list string)))
475 (or (try-completion string color-list pred)
476 (if (color-defined-p string)
477 string)))))
478 (col (completing-read (or prompt "Color: ") completer nil t)))
479 (if (equal "" col)
480 nil
481 col)))
482 466
483(defun color-rgb-to-hsv (r g b) 467(defun color-rgb-to-hsv (r g b)
484 "For R, G, B color components return a list of hue, saturation, value. 468 "For R, G, B color components return a list of hue, saturation, value.
diff --git a/lisp/faces.el b/lisp/faces.el
index 23dc51e33ed..8b17e9ad59b 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -1676,89 +1676,76 @@ If omitted or nil, that stands for the selected frame's display."
1676 (t 1676 (t
1677 (> (tty-color-gray-shades display) 2))))) 1677 (> (tty-color-gray-shades display) 2)))))
1678 1678
1679(defun read-color (&optional prompt convert-to-RGB-p allow-empty-name-p msg-p) 1679(defun read-color (&optional prompt convert-to-RGB allow-empty-name msg)
1680 "Read a color name or RGB hex value: #RRRRGGGGBBBB. 1680 "Read a color name or RGB triplet of the form \"#RRRRGGGGBBBB\".
1681Completion is available for color names, but not for RGB hex strings. 1681Completion is available for color names, but not for RGB triplets.
1682If the user inputs an RGB hex string, it must have the form 1682
1683#XXXXXXXXXXXX or XXXXXXXXXXXX, where each X is a hex digit. The 1683RGB triplets have the form #XXXXXXXXXXXX, where each X is a hex
1684number of Xs must be a multiple of 3, with the same number of Xs for 1684digit. The number of Xs must be a multiple of 3, with the same
1685each of red, green, and blue. The order is red, green, blue. 1685number of Xs for each of red, green, and blue. The order is red,
1686 1686green, blue.
1687In addition to standard color names and RGB hex values, the following 1687
1688are available as color candidates. In each case, the corresponding 1688In addition to standard color names and RGB hex values, the
1689color is used. 1689following are available as color candidates. In each case, the
1690corresponding color is used.
1690 1691
1691 * `foreground at point' - foreground under the cursor 1692 * `foreground at point' - foreground under the cursor
1692 * `background at point' - background under the cursor 1693 * `background at point' - background under the cursor
1693 1694
1694Checks input to be sure it represents a valid color. If not, raises 1695Optional arg PROMPT is the prompt; if nil, use a default prompt.
1695an error (but see exception for empty input with non-nil
1696ALLOW-EMPTY-NAME-P).
1697 1696
1698Optional arg PROMPT is the prompt; if nil, uses a default prompt. 1697Interactively, or with optional arg CONVERT-TO-RGB-P non-nil,
1698convert an input color name to an RGB hex string. Return the RGB
1699hex string.
1699 1700
1700Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, converts 1701If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed
1701an input color name to an RGB hex string. Returns the RGB hex string. 1702to enter an empty color name (the empty string).
1702 1703
1703Optional arg ALLOW-EMPTY-NAME-P controls what happens if the user 1704Interactively, or with optional arg MSG non-nil, print the
1704enters an empty color name (that is, just hits `RET'). If non-nil, 1705resulting color name in the echo area."
1705then returns an empty color name, \"\". If nil, then raises an error.
1706Programs must test for \"\" if ALLOW-EMPTY-NAME-P is non-nil. They
1707can then perform an appropriate action in case of empty input.
1708
1709Interactively, or with optional arg MSG-P non-nil, echoes the color in
1710a message."
1711 (interactive "i\np\ni\np") ; Always convert to RGB interactively. 1706 (interactive "i\np\ni\np") ; Always convert to RGB interactively.
1712 (let* ((completion-ignore-case t) 1707 (let* ((completion-ignore-case t)
1713 (colors (append '("foreground at point" "background at point") 1708 (colors (or facemenu-color-alist
1714 (defined-colors))) 1709 (append '("foreground at point" "background at point")
1715 (color (completing-read (or prompt "Color (name or #R+G+B+): ") 1710 (if allow-empty-name '(""))
1716 colors)) 1711 (defined-colors))))
1717 hex-string) 1712 (color (completing-read
1718 (cond ((string= "foreground at point" color) 1713 (or prompt "Color (name or #RGB triplet): ")
1719 (setq color (foreground-color-at-point))) 1714 ;; Completing function for reading colors, accepting
1720 ((string= "background at point" color) 1715 ;; both color names and RGB triplets.
1721 (setq color (background-color-at-point)))) 1716 (lambda (string pred flag)
1722 (unless color 1717 (cond
1723 (setq color "")) 1718 ((null flag) ; Try completion.
1724 (setq hex-string 1719 (or (try-completion string colors pred)
1725 (string-match "^#?\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)) 1720 (if (color-defined-p string)
1726 (if (and allow-empty-name-p (string= "" color)) 1721 string)))
1727 "" 1722 ((eq flag t) ; List all completions.
1728 (when (and hex-string (not (eq (aref color 0) ?#))) 1723 (or (all-completions string colors pred)
1729 (setq color (concat "#" color))) ; No #; add it. 1724 (if (color-defined-p string)
1730 (unless hex-string 1725 (list string))))
1731 (when (or (string= "" color) (not (test-completion color colors))) 1726 ((eq flag 'lambda) ; Test completion.
1732 (error "No such color: %S" color)) 1727 (or (memq string colors)
1733 (when convert-to-RGB-p 1728 (color-defined-p string)))))
1734 (let ((components (x-color-values color))) 1729 nil t))
1735 (unless components (error "No such color: %S" color)) 1730 hex-string)
1736 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color) 1731
1737 (setq color (format "#%04X%04X%04X" 1732 ;; Process named colors.
1738 (logand 65535 (nth 0 components)) 1733 (when (member color colors)
1739 (logand 65535 (nth 1 components)) 1734 (cond ((string-equal color "foreground at point")
1740 (logand 65535 (nth 2 components)))))))) 1735 (setq color (foreground-color-at-point)))
1741 (when msg-p (message "Color: `%s'" color)) 1736 ((string-equal color "background at point")
1742 color))) 1737 (setq color (background-color-at-point))))
1743 1738 (when (and convert-to-RGB
1744;; Commented out because I decided it is better to include the 1739 (not (string-equal color "")))
1745;; duplicates in read-color's completion list. 1740 (let ((components (x-color-values color)))
1746 1741 (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
1747;; (defun defined-colors-without-duplicates () 1742 (setq color (format "#%04X%04X%04X"
1748;; "Return the list of defined colors, without the no-space versions. 1743 (logand 65535 (nth 0 components))
1749;; For each color name, we keep the variant that DOES have spaces." 1744 (logand 65535 (nth 1 components))
1750;; (let ((result (copy-sequence (defined-colors))) 1745 (logand 65535 (nth 2 components))))))))
1751;; to-be-rejected) 1746 (when msg (message "Color: `%s'" color))
1752;; (save-match-data 1747 color))
1753;; (dolist (this result) 1748
1754;; (if (string-match " " this)
1755;; (push (replace-regexp-in-string " " ""
1756;; this)
1757;; to-be-rejected)))
1758;; (dolist (elt to-be-rejected)
1759;; (let ((as-found (car (member-ignore-case elt result))))
1760;; (setq result (delete as-found result)))))
1761;; result))
1762 1749
1763(defun face-at-point () 1750(defun face-at-point ()
1764 "Return the face of the character after point. 1751 "Return the face of the character after point.
diff --git a/lisp/frame.el b/lisp/frame.el
index 8210363610c..06e2268c697 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -1067,7 +1067,7 @@ See `modify-frame-parameters'."
1067 "Set the background color of the selected frame to COLOR-NAME. 1067 "Set the background color of the selected frame to COLOR-NAME.
1068When called interactively, prompt for the name of the color to use. 1068When called interactively, prompt for the name of the color to use.
1069To get the frame's current background color, use `frame-parameters'." 1069To get the frame's current background color, use `frame-parameters'."
1070 (interactive (list (facemenu-read-color "Background color: "))) 1070 (interactive (list (read-color "Background color: ")))
1071 (modify-frame-parameters (selected-frame) 1071 (modify-frame-parameters (selected-frame)
1072 (list (cons 'background-color color-name))) 1072 (list (cons 'background-color color-name)))
1073 (or window-system 1073 (or window-system
@@ -1077,7 +1077,7 @@ To get the frame's current background color, use `frame-parameters'."
1077 "Set the foreground color of the selected frame to COLOR-NAME. 1077 "Set the foreground color of the selected frame to COLOR-NAME.
1078When called interactively, prompt for the name of the color to use. 1078When called interactively, prompt for the name of the color to use.
1079To get the frame's current foreground color, use `frame-parameters'." 1079To get the frame's current foreground color, use `frame-parameters'."
1080 (interactive (list (facemenu-read-color "Foreground color: "))) 1080 (interactive (list (read-color "Foreground color: ")))
1081 (modify-frame-parameters (selected-frame) 1081 (modify-frame-parameters (selected-frame)
1082 (list (cons 'foreground-color color-name))) 1082 (list (cons 'foreground-color color-name)))
1083 (or window-system 1083 (or window-system
@@ -1087,7 +1087,7 @@ To get the frame's current foreground color, use `frame-parameters'."
1087 "Set the text cursor color of the selected frame to COLOR-NAME. 1087 "Set the text cursor color of the selected frame to COLOR-NAME.
1088When called interactively, prompt for the name of the color to use. 1088When called interactively, prompt for the name of the color to use.
1089To get the frame's current cursor color, use `frame-parameters'." 1089To get the frame's current cursor color, use `frame-parameters'."
1090 (interactive (list (facemenu-read-color "Cursor color: "))) 1090 (interactive (list (read-color "Cursor color: ")))
1091 (modify-frame-parameters (selected-frame) 1091 (modify-frame-parameters (selected-frame)
1092 (list (cons 'cursor-color color-name)))) 1092 (list (cons 'cursor-color color-name))))
1093 1093
@@ -1095,7 +1095,7 @@ To get the frame's current cursor color, use `frame-parameters'."
1095 "Set the color of the mouse pointer of the selected frame to COLOR-NAME. 1095 "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
1096When called interactively, prompt for the name of the color to use. 1096When called interactively, prompt for the name of the color to use.
1097To get the frame's current mouse color, use `frame-parameters'." 1097To get the frame's current mouse color, use `frame-parameters'."
1098 (interactive (list (facemenu-read-color "Mouse color: "))) 1098 (interactive (list (read-color "Mouse color: ")))
1099 (modify-frame-parameters (selected-frame) 1099 (modify-frame-parameters (selected-frame)
1100 (list (cons 'mouse-color 1100 (list (cons 'mouse-color
1101 (or color-name 1101 (or color-name
@@ -1106,7 +1106,7 @@ To get the frame's current mouse color, use `frame-parameters'."
1106 "Set the color of the border of the selected frame to COLOR-NAME. 1106 "Set the color of the border of the selected frame to COLOR-NAME.
1107When called interactively, prompt for the name of the color to use. 1107When called interactively, prompt for the name of the color to use.
1108To get the frame's current border color, use `frame-parameters'." 1108To get the frame's current border color, use `frame-parameters'."
1109 (interactive (list (facemenu-read-color "Border color: "))) 1109 (interactive (list (read-color "Border color: ")))
1110 (modify-frame-parameters (selected-frame) 1110 (modify-frame-parameters (selected-frame)
1111 (list (cons 'border-color color-name)))) 1111 (list (cons 'border-color color-name))))
1112 1112