From: "Simen Heggestøyl" <simenheg@gmail.com>
To: 20107@debbugs.gnu.org
Subject: bug#20107: [PATCH 2/3] css-mode: Add support for completion in `css-mode'
Date: Sat, 14 Mar 2015 12:21:33 +0100 [thread overview]
Message-ID: <1426332093.18090.1@smtp.gmail.com> (raw)
In-Reply-To: <1426331941.18090.0@smtp.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3878 bytes --]
Hi.
The following patch adds support for completion at point to
`css-mode'.
From e312007cab0bfc72b59bab16ca56d8c5f6e29fa8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Sat, 14 Mar 2015 11:05:55 +0100
Subject: [PATCH 2/3] Add support for completion in `css-mode'
* textmodes/css-mode.el (css--complete-property): New function for
completing CSS properties.
(css--complete-pseudo-element-or-class): New function for
completing CSS pseudo-elements and pseudo-classes.
(css--complete-at-rule): New function for completing CSS at-rules.
(css-completion-at-point): New function providing completion for
`css-mode'.
(css-mode): Add support for completion.
---
lisp/ChangeLog | 8 ++++++++
lisp/textmodes/css-mode.el | 45
+++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 70122c7..36a1f87 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -5,6 +5,14 @@
(css-pseudo-ids): Remove.
(css-pseudo-class-ids): New variable.
(css-pseudo-element-ids): New variable.
+ (css--complete-property): New function for completing CSS
+ properties.
+ (css--complete-pseudo-element-or-class): New function for
+ completing CSS pseudo-elements and pseudo-classes.
+ (css--complete-at-rule): New function for completing CSS at-rules.
+ (css-completion-at-point): New function providing completion for
+ `css-mode'.
+ (css-mode): Add support for completion.
2015-03-13 Kevin Ryde <user42_kevin@yahoo.com.au>
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index dc11d44..d467343 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -28,7 +28,7 @@
;; - electric ; and }
;; - filling code with auto-fill-mode
-;; - completion
+;; - attribute value completion
;; - fix font-lock errors with multi-line selectors
;;; Code:
@@ -345,6 +345,45 @@
(`(:before . ,(or "{" "("))
(if (smie-rule-hanging-p) (smie-rule-parent 0)))))
+;;; Completion
+
+(defun css--complete-property ()
+ "Complete property at point."
+ (save-excursion
+ (let ((pos (point)))
+ (skip-chars-backward "-[:alnum:]")
+ (let ((start (point)))
+ (skip-chars-backward " \t\r\n")
+ (when (memq (char-before) '(?\{ ?\;))
+ (list start pos css-property-ids))))))
+
+(defun css--complete-pseudo-element-or-class ()
+ "Complete pseudo-element or pseudo-class at point."
+ (save-excursion
+ (let ((pos (point)))
+ (skip-chars-backward "-[:alnum:]")
+ (when (eq (char-before) ?\:)
+ (list (point) pos
+ (if (eq (char-before (- (point) 1)) ?\:)
+ css-pseudo-element-ids
+ css-pseudo-class-ids))))))
+
+(defun css--complete-at-rule ()
+ "Complete at-rule (statement beginning with `@') at point."
+ (save-excursion
+ (let ((pos (point)))
+ (skip-chars-backward "-[:alnum:]")
+ (when (eq (char-before) ?\@)
+ (list (point) pos css-at-ids)))))
+
+(defun css-completion-at-point ()
+ "Complete current symbol at point.
+Currently supports completion of CSS properties, pseudo-elements,
+pesudo-classes, and at-rules."
+ (or (css--complete-property)
+ (css--complete-pseudo-element-or-class)
+ (css--complete-at-rule)))
+
;;;###autoload
(define-derived-mode css-mode fundamental-mode "CSS"
"Major mode to edit Cascading Style Sheets."
@@ -360,7 +399,9 @@
:forward-token #'css-smie--forward-token
:backward-token #'css-smie--backward-token)
(setq-local electric-indent-chars
- (append css-electric-keys electric-indent-chars)))
+ (append css-electric-keys electric-indent-chars))
+ (add-hook 'completion-at-point-functions
+ #'css-completion-at-point nil 'local))
(defvar comment-continue)
--
2.1.4
[-- Attachment #2: Type: text/html, Size: 6529 bytes --]
next prev parent reply other threads:[~2015-03-14 11:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-14 11:19 bug#20107: [PATCH 1/3] css-mode: Discriminate between pseudo-classes and -elements Simen Heggestøyl
2015-03-14 11:21 ` Simen Heggestøyl [this message]
2015-03-14 11:22 ` bug#20107: [PATCH 3/3] css-mode: Update CSS property list Simen Heggestøyl
2015-03-14 14:05 ` Stefan Monnier
2015-03-15 12:46 ` Simen Heggestøyl
2015-03-18 17:41 ` Simen Heggestøyl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1426332093.18090.1@smtp.gmail.com \
--to=simenheg@gmail.com \
--cc=20107@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).