bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#25525: 25.1.90; add color highlighting to css mode


From: Andreas Schwab
Subject: bug#25525: 25.1.90; add color highlighting to css mode
Date: Fri, 21 Apr 2017 11:33:42 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

On Apr 20 2017, Tom Tromey <address@hidden> wrote:

> +(defun css--named-color (str)
> +  "Check whether STR, seen at point, is CSS named color.
> +Returns STR if it is a valid color.  Special care is taken
> +to exclude some SCSS contructs."
> +  (when-let ((color (assoc str css--color-map)))
> +    (save-excursion
> +      ;; We still have the match from the caller of
> +      ;; css--compute-color.
> +      (goto-char (match-beginning 0))
> +      (forward-comment (- (point)))
> +      (skip-chars-backward "@[:alpha:]")
> +      (unless (looking-at-p "@\\(mixin\\|include\\)")
> +        (cdr color)))))
> +
> +(defun css--compute-color ()
> +  "Return the CSS color at point.
> +Point should be just after the start of a CSS color, as recognized
> +by `css--colors-regexp'.  This function will either return the color,
> +as a hex RGB string; or `nil' if no color could be recognized.  When
> +this function returns, point will be at the end of the recognized
> +color."
> +  (let ((match (downcase (match-string 0))))
> +    (cond
> +     ((eq (aref match 0) ?#)
> +      (css--hex-color match))
> +     ((member match '("rgb(" "rgba("))
> +      (css--rgb-color))
> +     ((member match '("hsl(" "hsla("))
> +      (css--hsl-color))
> +     ;; Evaluate to the color if the name is found.
> +     ((css--named-color match)))))

It would be better to pass the match string as an argument instead of
depending on the caller to establish a match.

Andreas.

-- 
Andreas Schwab, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





reply via email to

[Prev in Thread] Current Thread [Next in Thread]