diff options
| author | Chong Yidong | 2010-10-24 14:43:31 -0400 |
|---|---|---|
| committer | Chong Yidong | 2010-10-24 14:43:31 -0400 |
| commit | 9317e49920455cb4481bf728cc0dce381ec905a8 (patch) | |
| tree | 08a4be48e46fadfd08424e61a57e2610ad46f72e | |
| parent | 59dd6f738c165a6808a924f0628764af70a898a1 (diff) | |
| download | emacs-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/NEWS | 6 | ||||
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/facemenu.el | 22 | ||||
| -rw-r--r-- | lisp/faces.el | 135 | ||||
| -rw-r--r-- | lisp/frame.el | 10 |
5 files changed, 90 insertions, 98 deletions
| @@ -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'. | ||
| 667 | The command `read-color' now requires a match for a color name or RGB | ||
| 668 | triplet, instead of signalling an error if the user provides a invalid | ||
| 669 | input. | ||
| 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 @@ | |||
| 1 | 2010-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 | |||
| 1 | 2010-10-24 Leo <sdl.web@gmail.com> | 16 | 2010-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 | |||
| 358 | typing a character to insert cancels the specification." | 358 | typing 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 | |||
| 380 | typing a character to insert cancels the specification." | 380 | typing 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\". |
| 1681 | Completion is available for color names, but not for RGB hex strings. | 1681 | Completion is available for color names, but not for RGB triplets. |
| 1682 | If 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 | 1683 | RGB triplets have the form #XXXXXXXXXXXX, where each X is a hex |
| 1684 | number of Xs must be a multiple of 3, with the same number of Xs for | 1684 | digit. The number of Xs must be a multiple of 3, with the same |
| 1685 | each of red, green, and blue. The order is red, green, blue. | 1685 | number of Xs for each of red, green, and blue. The order is red, |
| 1686 | 1686 | green, blue. | |
| 1687 | In addition to standard color names and RGB hex values, the following | 1687 | |
| 1688 | are available as color candidates. In each case, the corresponding | 1688 | In addition to standard color names and RGB hex values, the |
| 1689 | color is used. | 1689 | following are available as color candidates. In each case, the |
| 1690 | corresponding 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 | ||
| 1694 | Checks input to be sure it represents a valid color. If not, raises | 1695 | Optional arg PROMPT is the prompt; if nil, use a default prompt. |
| 1695 | an error (but see exception for empty input with non-nil | ||
| 1696 | ALLOW-EMPTY-NAME-P). | ||
| 1697 | 1696 | ||
| 1698 | Optional arg PROMPT is the prompt; if nil, uses a default prompt. | 1697 | Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, |
| 1698 | convert an input color name to an RGB hex string. Return the RGB | ||
| 1699 | hex string. | ||
| 1699 | 1700 | ||
| 1700 | Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, converts | 1701 | If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed |
| 1701 | an input color name to an RGB hex string. Returns the RGB hex string. | 1702 | to enter an empty color name (the empty string). |
| 1702 | 1703 | ||
| 1703 | Optional arg ALLOW-EMPTY-NAME-P controls what happens if the user | 1704 | Interactively, or with optional arg MSG non-nil, print the |
| 1704 | enters an empty color name (that is, just hits `RET'). If non-nil, | 1705 | resulting color name in the echo area." |
| 1705 | then returns an empty color name, \"\". If nil, then raises an error. | ||
| 1706 | Programs must test for \"\" if ALLOW-EMPTY-NAME-P is non-nil. They | ||
| 1707 | can then perform an appropriate action in case of empty input. | ||
| 1708 | |||
| 1709 | Interactively, or with optional arg MSG-P non-nil, echoes the color in | ||
| 1710 | a 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. |
| 1068 | When called interactively, prompt for the name of the color to use. | 1068 | When called interactively, prompt for the name of the color to use. |
| 1069 | To get the frame's current background color, use `frame-parameters'." | 1069 | To 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. |
| 1078 | When called interactively, prompt for the name of the color to use. | 1078 | When called interactively, prompt for the name of the color to use. |
| 1079 | To get the frame's current foreground color, use `frame-parameters'." | 1079 | To 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. |
| 1088 | When called interactively, prompt for the name of the color to use. | 1088 | When called interactively, prompt for the name of the color to use. |
| 1089 | To get the frame's current cursor color, use `frame-parameters'." | 1089 | To 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. |
| 1096 | When called interactively, prompt for the name of the color to use. | 1096 | When called interactively, prompt for the name of the color to use. |
| 1097 | To get the frame's current mouse color, use `frame-parameters'." | 1097 | To 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. |
| 1107 | When called interactively, prompt for the name of the color to use. | 1107 | When called interactively, prompt for the name of the color to use. |
| 1108 | To get the frame's current border color, use `frame-parameters'." | 1108 | To 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 | ||