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.
This commit is contained in:
parent
64db0c26fa
commit
62fde9ee0f
2 changed files with 51 additions and 2 deletions
|
@ -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-17 Bozhidar Batsov <bozhidar@batsov.com>
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
;; - electric ; and }
|
||||
;; - filling code with auto-fill-mode
|
||||
;; - completion
|
||||
;; - attribute value completion
|
||||
;; - fix font-lock errors with multi-line selectors
|
||||
|
||||
;;; Code:
|
||||
|
@ -346,6 +346,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."
|
||||
|
@ -361,7 +400,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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue