From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andreas Schwab Newsgroups: gmane.emacs.bugs Subject: bug#25525: 25.1.90; add color highlighting to css mode Date: Fri, 21 Apr 2017 11:33:42 +0200 Message-ID: <871ssmyuix.fsf@linux-m68k.org> References: <87mvefh8br.fsf@tromey.com> <1485375833.1960.0@smtp.gmail.com> <1485455113.4245.1@smtp.gmail.com> <1487359774.1998.0@smtp.gmail.com> <1488653191.6153.0@smtp.gmail.com> <1488738524.13864.0@smtp.gmail.com> <871str3b48.fsf@tromey.com> <1490812056.14782.1@smtp.gmail.com> <874lxi5sxt.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1492767258 11229 195.159.176.226 (21 Apr 2017 09:34:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 21 Apr 2017 09:34:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: 25525@debbugs.gnu.org, Simen =?UTF-8?Q?Heggest=C3=B8yl?= To: Tom Tromey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 21 11:34:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1UxB-0002ku-Sd for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Apr 2017 11:34:14 +0200 Original-Received: from localhost ([::1]:58183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1UxE-0004s7-K7 for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Apr 2017 05:34:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1Ux4-0004qe-1x for bug-gnu-emacs@gnu.org; Fri, 21 Apr 2017 05:34:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1Ux0-0006G0-Uu for bug-gnu-emacs@gnu.org; Fri, 21 Apr 2017 05:34:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33358) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d1Ux0-0006Fw-Rg for bug-gnu-emacs@gnu.org; Fri, 21 Apr 2017 05:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d1Ux0-0005mY-JM for bug-gnu-emacs@gnu.org; Fri, 21 Apr 2017 05:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andreas Schwab Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 21 Apr 2017 09:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25525 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 25525-submit@debbugs.gnu.org id=B25525.149276722922207 (code B ref 25525); Fri, 21 Apr 2017 09:34:02 +0000 Original-Received: (at 25525) by debbugs.gnu.org; 21 Apr 2017 09:33:49 +0000 Original-Received: from localhost ([127.0.0.1]:59790 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Uwn-0005m7-1t for submit@debbugs.gnu.org; Fri, 21 Apr 2017 05:33:49 -0400 Original-Received: from mail-out.m-online.net ([212.18.0.10]:42174) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Uwj-0005lx-O5 for 25525@debbugs.gnu.org; Fri, 21 Apr 2017 05:33:47 -0400 Original-Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3w8Vt04fw3z1qsfh; Fri, 21 Apr 2017 11:33:44 +0200 (CEST) Original-Received: from localhost (dynscan01.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3w8Vt02gSBz3hhtH; Fri, 21 Apr 2017 11:33:44 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Original-Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan01.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id Bw4y3VTNkYvq; Fri, 21 Apr 2017 11:33:43 +0200 (CEST) X-Auth-Info: 0kbbk9eKY5RKFcSKvxmHP1LQSxO+EdAfTkPSkyewOvGef5PBlSthAFkI/sfl2uOT Original-Received: from igel.home (ppp-88-217-8-198.dynamic.mnet-online.de [88.217.8.198]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 21 Apr 2017 11:33:43 +0200 (CEST) Original-Received: by igel.home (Postfix, from userid 1000) id 0492F2C3049; Fri, 21 Apr 2017 11:33:42 +0200 (CEST) X-Yow: ... I live in a FUR-LINE FALLOUT SHELTER In-Reply-To: <874lxi5sxt.fsf@tromey.com> (Tom Tromey's message of "Thu, 20 Apr 2017 21:40:46 -0600") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:131818 Archived-At: On Apr 20 2017, Tom Tromey 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, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."