Function: css--rgb-to-named-color-or-hex
css--rgb-to-named-color-or-hex is a byte-compiled function defined in
css-mode.el.gz.
Signature
(css--rgb-to-named-color-or-hex)
Documentation
Convert CSS RGB color at point to a named color or hex format.
Convert to a named color if the color at point has a name, else convert to hex format. Return non-nil if a conversion was made.
Note that this function handles CSS colors specifically, and should not be mixed with those in color.el.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/css-mode.el.gz
(defun css--rgb-to-named-color-or-hex ()
"Convert CSS RGB color at point to a named color or hex format.
Convert to a named color if the color at point has a name, else
convert to hex format. Return non-nil if a conversion was made.
Note that this function handles CSS colors specifically, and
should not be mixed with those in color.el."
(save-excursion
(when-let* ((open-paren-pos (nth 1 (syntax-ppss))))
(when (save-excursion
(goto-char open-paren-pos)
(looking-back "rgba?" (- (point) 4)))
(goto-char (nth 1 (syntax-ppss)))))
(when (eq (char-before) ?\))
(backward-sexp))
(skip-chars-backward "rgba")
(when (looking-at css--colors-regexp)
(let* ((start (match-end 0))
(color (save-excursion
(goto-char start)
(css--rgb-color t))))
(when color
(kill-sexp)
(kill-sexp)
(let ((named-color (seq-find (lambda (x) (equal (cdr x) color))
css--color-map)))
(insert (if named-color
(car named-color)
(css--format-hex color))))
t)))))