(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-17 Bozhidar Batsov <bozhidar@batsov.com>
;; - electric ; and }
;; - filling code with auto-fill-mode
-;; - completion
+;; - attribute value completion
;; - fix font-lock errors with multi-line selectors
;;; Code:
(`(: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."
: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)