From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Newsgroups: gmane.emacs.bugs Subject: bug#23458: [PATCH] Support completion of HTML tags in CSS selectors Date: Thu, 05 May 2016 18:44:35 +0200 Message-ID: <1462466675.13053.0@smtp.gmail.com> References: <1462451565.2892.0@smtp.gmail.com> <1462451565.2892.0@smtp.gmail.com> <"Simen =?UTF-8?Q?Heggest=C3=B8=3D=3FISO-8859-1=3FQ=3Fyl?="'s_message_of_"Thu, _05_May_2016_14:32:45_+0200"> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-b74hJtCZB+Y69oFPIktM" X-Trace: ger.gmane.org 1462466743 659 80.91.229.3 (5 May 2016 16:45:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 May 2016 16:45:43 +0000 (UTC) Cc: 23458@debbugs.gnu.org, dgutov@yandex.ru To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 05 18:45:33 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ayMP5-0005SG-KI for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 May 2016 18:45:31 +0200 Original-Received: from localhost ([::1]:54414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayMP1-0005BO-RH for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 May 2016 12:45:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayMOs-0004w1-8G for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 12:45:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayMOg-0006FN-9H for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 12:45:12 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56388) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayMOf-0006Ax-3S for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 12:45:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ayMOb-0007lJ-KU for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 12:45:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 May 2016 16:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23458 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 23458-submit@debbugs.gnu.org id=B23458.146246669429812 (code B ref 23458); Thu, 05 May 2016 16:45:01 +0000 Original-Received: (at 23458) by debbugs.gnu.org; 5 May 2016 16:44:54 +0000 Original-Received: from localhost ([127.0.0.1]:40492 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayMOT-0007km-Tf for submit@debbugs.gnu.org; Thu, 05 May 2016 12:44:54 -0400 Original-Received: from mail-lf0-f52.google.com ([209.85.215.52]:36480) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayMOS-0007ka-LU for 23458@debbugs.gnu.org; Thu, 05 May 2016 12:44:53 -0400 Original-Received: by mail-lf0-f52.google.com with SMTP id u64so102969808lff.3 for <23458@debbugs.gnu.org>; Thu, 05 May 2016 09:44:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:subject:to:cc:message-id:in-reply-to:references :mime-version; bh=IUdEspM7Fy1PA/JKvNygqUo/1t6NwGvHQV/ySUKKZsQ=; b=UqQea/iT+6z8c9fvfUZE8OBkAG9iX7o0PPVvPHnAS9MGlr6GqmpWj3HcBRNGjfdYFy yaN7rbgx0CDtryYSNxG/XKCLFXyIPBL8webfyC/P0XtMVt70Ow5jIy5PTzkUU+3ZjApV tGZvhn3H7km+HeoqmO+hK9kaCtnTneOdvSug37rGvGMxnrxfzCcAVtGTxnd63pnCGER7 Xa7fW3BG7eQ0fijXSrDu+dy0Itg2oAUDV3cd6gQbv44GEZ2A5mHctxc697/Y1CUAeKW3 UXnZjBDsQCCG3TKRGAEu62GGfwZgKYGAk7RefFADrpB93fdz9r+l5SYSGFK/JTVq+wxM NgqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:subject:to:cc:message-id:in-reply-to :references:mime-version; bh=IUdEspM7Fy1PA/JKvNygqUo/1t6NwGvHQV/ySUKKZsQ=; b=MsplrrXWgNNdHdCrmc25+rRqNFRUsCW9cEu1gF5AX84bnywFM/DwI3JUKKMenIPd+D G9B/dnpq17tplKQ9Omx+ZlXAHm/Xb7iEgVR1nrZ6W82nF0ilcg/Yx1wwoJmg3tvULIIF l0DqypJf06ni2T6Q7oOeo45pjmkZVNViBSyfVmEgVoNGKf617Pr+zsPljhsM0wt+SRVz UjOQmfMqb7SKDb3pYzhV/0jwQXzdNDx1lgcYGfplIuuIJ8uUv2S+hVH0WsXeYehzDm/R 7TDjoBWNRbX6DB1eHXuE/2i0s/xUXlap9oveq8CpFd9LxMvM/fPBW/RRbEuB5qOjxdte dO4w== X-Gm-Message-State: AOPr4FXTJaXEwNkNmiMXXSMUfOYEKhP6iATXUcUazDDReR2u0fUK41Llk88vr/pugAr2ag== X-Received: by 10.112.35.162 with SMTP id i2mr7357305lbj.13.1462466686657; Thu, 05 May 2016 09:44:46 -0700 (PDT) Original-Received: from [192.168.1.10] (45-126-11.connect.netcom.no. [176.11.126.45]) by smtp.gmail.com with ESMTPSA id d1sm1639794lbm.3.2016.05.05.09.44.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 May 2016 09:44:45 -0700 (PDT) In-Reply-To: X-Mailer: geary/0.10.0 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:117851 Archived-At: --=-b74hJtCZB+Y69oFPIktM Content-Type: multipart/alternative; boundary="=-sDCV57mWvzPNDj2i11HS" --=-sDCV57mWvzPNDj2i11HS Content-Type: text/plain; charset=utf-8; format=flowed On Thu, May 5, 2016 at 5:02 PM, Stefan Monnier wrote: > It'd be better to avoid the :exclusive thingy, and use something like > completion-table-merge instead. > > :exclusive basically prevents any completion style other than prefix > completion, so it's better avoid it when possible. This said, it's > not > a real objection. Something along these lines? -- Simen --=-sDCV57mWvzPNDj2i11HS Content-Type: text/html; charset=utf-8 On Thu, May 5, 2016 at 5:02 PM, Stefan Monnier <monnier@IRO.UMontreal.CA> wrote:
It'd be better to avoid the :exclusive thingy, and use something like completion-table-merge instead. :exclusive basically prevents any completion style other than prefix completion, so it's better avoid it when possible. This said, it's not a real objection.

Something along these lines?

-- Simen
--=-sDCV57mWvzPNDj2i11HS-- --=-b74hJtCZB+Y69oFPIktM Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Support-completion-of-HTML-tags-in-CSS-selectors.patch >From 1fcc84e66167d464194716e05994706742184155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Sun, 1 May 2016 14:59:11 +0200 Subject: [PATCH] Support completion of HTML tags in CSS selectors * lisp/textmodes/css-mode.el (css--html-tags): New variable holding a list of HTML tags for completion. (css--nested-selectors-allowed): New variable for determining whether nested selectors are allowed in the current mode. (css--complete-selector): New function for completing part of a CSS selector. (css-completion-at-point): Support completion of selectors. (scss-mode): Allow nested selectors. --- etc/NEWS | 4 ++-- lisp/textmodes/css-mode.el | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 21602ff..e202612 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -282,8 +282,8 @@ different group ID. ** CSS mode --- -*** Support for completing attribute values and bang-rules using the -'completion-at-point' command. +*** Support for completing attribute values, at-rules, bang-rules, and +HTML tags using the 'completion-at-point' command. +++ ** Emacs now supports character name escape sequences in character and diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index e30fb3e..cf407ef 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -30,10 +30,12 @@ ;; - electric ; and } ;; - filling code with auto-fill-mode ;; - fix font-lock errors with multi-line selectors +;; - support completion of user-defined classes names and IDs ;;; Code: (require 'seq) +(require 'sgml-mode) (require 'smie) (defgroup css nil @@ -824,15 +826,40 @@ css--complete-property-value (list (point) end (cons "inherit" (css--property-values property)))))))) +(defvar css--html-tags (mapcar #'car html-tag-alist) + "List of HTML tags. +Used to provide completion of HTML tags in selectors.") + +(defvar css--nested-selectors-allowed nil + "Non-nil if nested selectors are allowed in the current mode.") +(make-variable-buffer-local 'css--nested-selectors-allowed) + +;; TODO: Currently only supports completion of HTML tags. By looking +;; at open HTML mode buffers we should be able to provide completion +;; of user-defined classes and IDs too. +(defun css--complete-selector () + "Complete part of a CSS selector at point." + (when (or (= (nth 0 (syntax-ppss)) 0) css--nested-selectors-allowed) + (save-excursion + (let ((end (point))) + (skip-chars-backward "-[:alnum:]") + (list (point) end css--html-tags))))) + (defun css-completion-at-point () "Complete current symbol at point. Currently supports completion of CSS properties, property values, pseudo-elements, pseudo-classes, at-rules, and bang-rules." - (or (css--complete-property) - (css--complete-bang-rule) + (or (css--complete-bang-rule) (css--complete-property-value) (css--complete-pseudo-element-or-class) - (css--complete-at-rule))) + (css--complete-at-rule) + (seq-let (prop-beg prop-end prop-table) (css--complete-property) + (seq-let (sel-beg sel-end sel-table) (css--complete-selector) + (when (or prop-table sel-table) + `(,@(if prop-table + (list prop-beg prop-end) + (list sel-beg sel-end)) + ,(completion-table-merge prop-table sel-table))))))) ;;;###autoload (define-derived-mode css-mode prog-mode "CSS" @@ -990,6 +1017,7 @@ scss-mode (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)") (setq-local css--at-ids (append css-at-ids scss-at-ids)) (setq-local css--bang-ids (append css-bang-ids scss-bang-ids)) + (setq-local css--nested-selectors-allowed t) (setq-local font-lock-defaults (list (scss-font-lock-keywords) nil t))) -- 2.8.1 --=-b74hJtCZB+Y69oFPIktM--