diff options
| -rw-r--r-- | doc/lispref/minibuf.texi | 8 | ||||
| -rw-r--r-- | lisp/faces.el | 64 |
2 files changed, 48 insertions, 24 deletions
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 31b020db57c..4ed36edb8c1 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi | |||
| @@ -1537,7 +1537,8 @@ that it uses the predicate @code{custom-variable-p} instead of | |||
| 1537 | @code{commandp}. | 1537 | @code{commandp}. |
| 1538 | @end defun | 1538 | @end defun |
| 1539 | 1539 | ||
| 1540 | @deffn Command read-color &optional prompt convert allow-empty display | 1540 | @deffn Command read-color &optional prompt convert allow-empty @ |
| 1541 | display foreground face | ||
| 1541 | This function reads a string that is a color specification, either the | 1542 | This function reads a string that is a color specification, either the |
| 1542 | color's name or an RGB hex value such as @code{#RRRGGGBBB}. It | 1543 | color's name or an RGB hex value such as @code{#RRRGGGBBB}. It |
| 1543 | prompts with @var{prompt} (default: @code{"Color (name or #RGB triplet):"}) | 1544 | prompts with @var{prompt} (default: @code{"Color (name or #RGB triplet):"}) |
| @@ -1557,6 +1558,11 @@ non-@code{nil} and the user enters null input. | |||
| 1557 | 1558 | ||
| 1558 | Interactively, or when @var{display} is non-@code{nil}, the return | 1559 | Interactively, or when @var{display} is non-@code{nil}, the return |
| 1559 | value is also displayed in the echo area. | 1560 | value is also displayed in the echo area. |
| 1561 | |||
| 1562 | The optional arguments FOREGROUND and FACE control the appearence of | ||
| 1563 | the completion candidates. The candidates are displayed like FACE but | ||
| 1564 | with different colors. If FOREGROUND is non-@code{nil} the foreground | ||
| 1565 | varies, otherwise the background. | ||
| 1560 | @end deffn | 1566 | @end deffn |
| 1561 | 1567 | ||
| 1562 | See also the functions @code{read-coding-system} and | 1568 | See also the functions @code{read-coding-system} and |
diff --git a/lisp/faces.el b/lisp/faces.el index 44d64c743ba..4f51a031156 100644 --- a/lisp/faces.el +++ b/lisp/faces.el | |||
| @@ -1340,10 +1340,11 @@ of a global face. Value is the new attribute value." | |||
| 1340 | (format "%s" old-value)))) | 1340 | (format "%s" old-value)))) |
| 1341 | (setq new-value | 1341 | (setq new-value |
| 1342 | (if (memq attribute '(:foreground :background)) | 1342 | (if (memq attribute '(:foreground :background)) |
| 1343 | (let ((color | 1343 | (let* ((prompt (format-prompt |
| 1344 | (read-color | 1344 | "%s for face `%s'" |
| 1345 | (format-prompt "%s for face `%s'" | 1345 | default attribute-name face)) |
| 1346 | default attribute-name face)))) | 1346 | (fg (eq attribute ':foreground)) |
| 1347 | (color (read-color prompt nil nil nil fg face))) | ||
| 1347 | (if (equal (string-trim color) "") | 1348 | (if (equal (string-trim color) "") |
| 1348 | default | 1349 | default |
| 1349 | color)) | 1350 | color)) |
| @@ -1870,15 +1871,26 @@ to `defined-colors' the elements of the returned list are color | |||
| 1870 | strings with text properties, that make the color names render | 1871 | strings with text properties, that make the color names render |
| 1871 | with the color they represent as background color (if FOREGROUND | 1872 | with the color they represent as background color (if FOREGROUND |
| 1872 | is nil; otherwise use the foreground color)." | 1873 | is nil; otherwise use the foreground color)." |
| 1873 | (mapcar | 1874 | (mapcar (lambda (color-name) |
| 1874 | (lambda (color-name) | 1875 | (faces--string-with-color color-name color-name foreground)) |
| 1875 | (let ((color (copy-sequence color-name))) | 1876 | (defined-colors frame))) |
| 1876 | (propertize color 'face | 1877 | |
| 1877 | (if foreground | 1878 | (defun faces--string-with-color (string color &optional foreground face) |
| 1878 | (list :foreground color) | 1879 | "Return a copy of STRING with face attributes for COLOR. |
| 1879 | (list :foreground (readable-foreground-color color-name) | 1880 | Set the :background or :foreground attribute to COLOR, depending |
| 1880 | :background color))))) | 1881 | on the argument FOREGROUND. |
| 1881 | (defined-colors frame))) | 1882 | |
| 1883 | The optional FACE argument controls the values for other | ||
| 1884 | attributes." | ||
| 1885 | (let* ((defaults (if face (list face) '())) | ||
| 1886 | (colors (cond (foreground | ||
| 1887 | (list :foreground color)) | ||
| 1888 | (face | ||
| 1889 | (list :background color)) | ||
| 1890 | (t | ||
| 1891 | (list :foreground (readable-foreground-color color) | ||
| 1892 | :background color))))) | ||
| 1893 | (propertize string 'face (cons colors defaults)))) | ||
| 1882 | 1894 | ||
| 1883 | (defun readable-foreground-color (color) | 1895 | (defun readable-foreground-color (color) |
| 1884 | "Return a readable foreground color for background COLOR. | 1896 | "Return a readable foreground color for background COLOR. |
| @@ -1987,7 +1999,7 @@ If omitted or nil, that stands for the selected frame's display." | |||
| 1987 | (> (tty-color-gray-shades display) 2))) | 1999 | (> (tty-color-gray-shades display) 2))) |
| 1988 | 2000 | ||
| 1989 | (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg | 2001 | (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg |
| 1990 | foreground) | 2002 | foreground face) |
| 1991 | "Read a color name or RGB triplet. | 2003 | "Read a color name or RGB triplet. |
| 1992 | Completion is available for color names, but not for RGB triplets. | 2004 | Completion is available for color names, but not for RGB triplets. |
| 1993 | 2005 | ||
| @@ -2016,17 +2028,23 @@ to enter an empty color name (the empty string). | |||
| 2016 | Interactively, or with optional arg MSG non-nil, print the | 2028 | Interactively, or with optional arg MSG non-nil, print the |
| 2017 | resulting color name in the echo area. | 2029 | resulting color name in the echo area. |
| 2018 | 2030 | ||
| 2019 | Interactively, displays a list of colored completions. If optional | 2031 | Interactively, displays a list of colored completions. If |
| 2020 | argument FOREGROUND is non-nil, shows them as foregrounds, otherwise | 2032 | optional argument FOREGROUND is non-nil, shows them as |
| 2021 | as backgrounds." | 2033 | foregrounds, otherwise as backgrounds. The optional argument |
| 2034 | FACE controls the default appearance." | ||
| 2022 | (interactive "i\np\ni\np") ; Always convert to RGB interactively. | 2035 | (interactive "i\np\ni\np") ; Always convert to RGB interactively. |
| 2023 | (let* ((completion-ignore-case t) | 2036 | (let* ((completion-ignore-case t) |
| 2024 | (colors (append '("foreground at point" "background at point") | 2037 | (color-alist |
| 2025 | (if allow-empty-name '("")) | 2038 | `(("foreground at point" . ,(foreground-color-at-point)) |
| 2026 | (if (display-color-p) | 2039 | ("background at point" . ,(background-color-at-point)) |
| 2027 | (defined-colors-with-face-attributes | 2040 | ,@(if allow-empty-name '(("" . unspecified))) |
| 2028 | nil foreground) | 2041 | ,@(mapcar (lambda (c) (cons c c)) (defined-colors)))) |
| 2029 | (defined-colors)))) | 2042 | (colors (mapcar (lambda (pair) |
| 2043 | (let* ((name (car pair)) | ||
| 2044 | (color (cdr pair))) | ||
| 2045 | (faces--string-with-color name color | ||
| 2046 | foreground face))) | ||
| 2047 | color-alist)) | ||
| 2030 | (color (completing-read | 2048 | (color (completing-read |
| 2031 | (or prompt "Color (name or #RGB triplet): ") | 2049 | (or prompt "Color (name or #RGB triplet): ") |
| 2032 | ;; Completing function for reading colors, accepting | 2050 | ;; Completing function for reading colors, accepting |