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 14:32:45 +0200 Message-ID: <1462451565.2892.0@smtp.gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-JZ17QS6ty4mvouVPSs7e" X-Trace: ger.gmane.org 1462451685 12304 80.91.229.3 (5 May 2016 12:34:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 May 2016 12:34:45 +0000 (UTC) Cc: Stefan Monnier , Dmitry Gutov To: 23458@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 05 14:34:34 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 1ayIUB-0003PP-VW for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 May 2016 14:34:32 +0200 Original-Received: from localhost ([::1]:53341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayIU8-0008Qa-10 for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 May 2016 08:34:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayITy-0008GB-AL for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 08:34:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayITm-0005w5-Eh for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 08:34:12 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54726) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayITl-0005v5-9J for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 08:34:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ayITh-00085n-SD for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 08:34: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 12:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 23458 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.146245163431090 (code B ref -1); Thu, 05 May 2016 12:34:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 May 2016 12:33:54 +0000 Original-Received: from localhost ([127.0.0.1]:38830 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayITa-00085O-Gx for submit@debbugs.gnu.org; Thu, 05 May 2016 08:33:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43028) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayITY-00085A-D5 for submit@debbugs.gnu.org; Thu, 05 May 2016 08:33:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayITJ-0005pX-Cs for submit@debbugs.gnu.org; Thu, 05 May 2016 08:33:43 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:33201) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayITI-0005ol-6K for submit@debbugs.gnu.org; Thu, 05 May 2016 08:33:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayIT5-0007Eh-Ml for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 08:33:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayISq-0005lG-81 for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 08:33:16 -0400 Original-Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]:36404) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayISo-0005g6-It for bug-gnu-emacs@gnu.org; Thu, 05 May 2016 08:33:08 -0400 Original-Received: by mail-lf0-x22b.google.com with SMTP id u64so94388107lff.3 for ; Thu, 05 May 2016 05:32:51 -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:mime-version; bh=a1ywzS8Gj1JYEQWxHCQsoGtDVAN6RXfveXF7r+mM83g=; b=Wqni4rrCtt/yYh6WFMcqWn/5xo43W4Xuqcc60uIy0aq+Pe7SN0LaTVZPJvFHrwFStR eRplgUbZiGv8GVnMGVJeZgHw9OELCndXIoyrf1fotMpyG9sJGuPLXv6EYSupCWdyQDQz Y/HIDS7VSLbkp3DzLKj3LSNZex6KR5oUMnA/i5llNHgtRWCgIqUpAiYo7Mc7+w9Of0c5 kFS/a7yKTkRYufZMqnR6UdkleYmlxgh6LfQw6JjU6hbQyLPE+Ud46mW/y3flGWOtIDqk aGAfQ0JGK1rHRA9PCoTmzvfnThxaG8rvClgxe34qlBNuu+SdzsrEXFVPxp11oMCq0QX6 8HBQ== 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:mime-version; bh=a1ywzS8Gj1JYEQWxHCQsoGtDVAN6RXfveXF7r+mM83g=; b=mEY51hHvj508nnW7+tfu6Sw0WqvMecLFs0BIeAY/q/eAHEfGvAMnJac8/PwQBffUMQ FPaJzlhavu9GJhg2R65WSebWA3HGK/oMzCL/5nZmsX+CTWCYQTx3pQ2eiGqW57dBTiDD 5mgfFQ2YmnCD5m0xMutIQxVmIT5t0swMPqI7YWEEicttuyqiS60woqR61cua/PJlmCkZ /uvTcB4O/Kx16nbNPKGAKxw7mgGBAsoEeeMRvSc7zGfK/dzyEqxH/w6lDqwvSmSDq5d9 sfutXpUbEq+Cy+0biys5F0JsYSHA6hWpfjHCXLuLp71ymJc9Jm8lvwI9KCUJRxAl7fJ8 YFWg== X-Gm-Message-State: AOPr4FXCCG53/WOFmsDEJsGqGYIPAAjhScJ/EEPKBHC9TfY0HQUzYjObyzdtwpcButB1tQ== X-Received: by 10.112.52.196 with SMTP id v4mr6044466lbo.59.1462451567887; Thu, 05 May 2016 05:32:47 -0700 (PDT) Original-Received: from [10.0.0.38] (ti0117a400-4543.bb.online.no. [85.166.100.207]) by smtp.gmail.com with ESMTPSA id n13sm1480991lfb.28.2016.05.05.05.32.46 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 May 2016 05:32:47 -0700 (PDT) X-Mailer: geary/0.10.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:117841 Archived-At: --=-JZ17QS6ty4mvouVPSs7e Content-Type: multipart/alternative; boundary="=-cljR0H1lgDR93trekiW+" --=-cljR0H1lgDR93trekiW+ Content-Type: text/plain; charset=utf-8; format=flowed The attached patch adds support for completion of HTML tags in CSS selectors for CSS- and SCSS mode. -- Simen --=-cljR0H1lgDR93trekiW+ Content-Type: text/html; charset=utf-8
The attached patch adds support for completion of HTML tags in CSS
selectors for CSS- and SCSS mode.

-- Simen
--=-cljR0H1lgDR93trekiW+-- --=-JZ17QS6ty4mvouVPSs7e Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Support-completion-of-HTML-tags-in-CSS-selectors.patch >From 4af469d4a67c020eef90e3c19ca9094bf7b59696 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--complete-property): Make completion non-exclusive to allow mixing with selector completions. (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): Removed in favor of adding several completion functions to `completion-at-point-functions'. (css-mode): Add each completion function to `completion-at-point-functions' instead of using `css-completion-at-point'. (scss-mode): Allow nested selectors. --- etc/NEWS | 4 ++-- lisp/textmodes/css-mode.el | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 14 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..77e2e77 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 @@ -747,7 +749,7 @@ css--complete-property (let ((start (point))) (skip-chars-backward " \t\r\n") (when (memq (char-before) '(?\{ ?\;)) - (list start pos css-property-ids)))))) + (list start pos css-property-ids :exclusive 'no)))))) (defun css--complete-bang-rule () "Complete bang-rule at point." @@ -824,15 +826,24 @@ css--complete-property-value (list (point) end (cons "inherit" (css--property-values property)))))))) -(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) - (css--complete-property-value) - (css--complete-pseudo-element-or-class) - (css--complete-at-rule))) +(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))))) ;;;###autoload (define-derived-mode css-mode prog-mode "CSS" @@ -852,8 +863,13 @@ css-mode :backward-token #'css-smie--backward-token) (setq-local electric-indent-chars (append css-electric-keys electric-indent-chars)) - (add-hook 'completion-at-point-functions - #'css-completion-at-point nil 'local)) + (dolist (func (list #'css--complete-bang-rule + #'css--complete-property-value + #'css--complete-pseudo-element-or-class + #'css--complete-at-rule + #'css--complete-property + #'css--complete-selector)) + (add-hook 'completion-at-point-functions func t 'local))) (defvar comment-continue) @@ -990,6 +1006,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 --=-JZ17QS6ty4mvouVPSs7e--