diff options
| author | Simen Heggestøyl | 2016-03-31 21:18:00 +0200 |
|---|---|---|
| committer | Simen Heggestøyl | 2016-03-31 21:21:34 +0200 |
| commit | 750e1e19429cd781e2e60b462d19ef827d4da943 (patch) | |
| tree | 41b5281e283acb3f5fb5e64baf0a4f896d7a593d | |
| parent | 09462b95484ebf75899c64e8ddb7ffce50ef6ca0 (diff) | |
| download | emacs-750e1e19429cd781e2e60b462d19ef827d4da943.tar.gz emacs-750e1e19429cd781e2e60b462d19ef827d4da943.zip | |
Support completion of bang-rules in CSS mode
lisp/textmodes/css-mode.el (css--bang-ids): New buffer-local variable
holding the list of bang-rules for the current mode.
(css--font-lock-keywords): Retrieve bang-rules from `css--bang-ids'
instead of computing them.
(css--complete-bang-rule): New function for completing a bang-rule.
(css-completion-at-point): Add support for completing bang-rules.
(scss-font-lock-keywords): Change from a variable to a function in
order to recompute `css--font-lock-keywords' when `css--bang-ids' has
changed.
(scss-mode): Set `css--bang-ids' and recompute font-lock keywords.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/textmodes/css-mode.el | 25 |
2 files changed, 21 insertions, 8 deletions
| @@ -144,8 +144,8 @@ different group ID. | |||
| 144 | ** CSS mode | 144 | ** CSS mode |
| 145 | 145 | ||
| 146 | --- | 146 | --- |
| 147 | *** Support for completing attribute values using the 'completion-at-point' | 147 | *** Support for completing attribute values and bang-rules using the |
| 148 | command. | 148 | 'completion-at-point' command. |
| 149 | 149 | ||
| 150 | 150 | ||
| 151 | * New Modes and Packages in Emacs 25.2 | 151 | * New Modes and Packages in Emacs 25.2 |
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index fd3459efe78..cbef3d4026a 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el | |||
| @@ -64,6 +64,10 @@ | |||
| 64 | '("default" "global" "optional") | 64 | '("default" "global" "optional") |
| 65 | "Additional identifiers that appear in the form !foo in SCSS.") | 65 | "Additional identifiers that appear in the form !foo in SCSS.") |
| 66 | 66 | ||
| 67 | (defvar css--bang-ids css-bang-ids | ||
| 68 | "List of bang-rules for the current mode.") | ||
| 69 | (make-variable-buffer-local 'css--bang-ids) | ||
| 70 | |||
| 67 | (defconst css-descriptor-ids | 71 | (defconst css-descriptor-ids |
| 68 | '("ascent" "baseline" "bbox" "cap-height" "centerline" "definition-src" | 72 | '("ascent" "baseline" "bbox" "cap-height" "centerline" "definition-src" |
| 69 | "descent" "font-family" "font-size" "font-stretch" "font-style" | 73 | "descent" "font-family" "font-size" "font-stretch" "font-style" |
| @@ -600,9 +604,7 @@ cannot be completed sensibly: `angle', `element-reference', | |||
| 600 | "Face to use for vendor-specific properties.") | 604 | "Face to use for vendor-specific properties.") |
| 601 | 605 | ||
| 602 | (defun css--font-lock-keywords (&optional sassy) | 606 | (defun css--font-lock-keywords (&optional sassy) |
| 603 | `((,(concat "!\\s-*" | 607 | `((,(concat "!\\s-*" (regexp-opt css--bang-ids)) |
| 604 | (regexp-opt (append (if sassy scss-bang-ids) | ||
| 605 | css-bang-ids))) | ||
| 606 | (0 font-lock-builtin-face)) | 608 | (0 font-lock-builtin-face)) |
| 607 | ;; Atrules keywords. IDs not in css-at-ids are valid (ignored). | 609 | ;; Atrules keywords. IDs not in css-at-ids are valid (ignored). |
| 608 | ;; In fact the regexp should probably be | 610 | ;; In fact the regexp should probably be |
| @@ -732,6 +734,14 @@ cannot be completed sensibly: `angle', `element-reference', | |||
| 732 | (when (memq (char-before) '(?\{ ?\;)) | 734 | (when (memq (char-before) '(?\{ ?\;)) |
| 733 | (list start pos css-property-ids)))))) | 735 | (list start pos css-property-ids)))))) |
| 734 | 736 | ||
| 737 | (defun css--complete-bang-rule () | ||
| 738 | "Complete bang-rule at point." | ||
| 739 | (save-excursion | ||
| 740 | (let ((pos (point))) | ||
| 741 | (skip-chars-backward "-[:alnum:]") | ||
| 742 | (when (eq (char-before) ?\!) | ||
| 743 | (list (point) pos css--bang-ids))))) | ||
| 744 | |||
| 735 | (defun css--complete-pseudo-element-or-class () | 745 | (defun css--complete-pseudo-element-or-class () |
| 736 | "Complete pseudo-element or pseudo-class at point." | 746 | "Complete pseudo-element or pseudo-class at point." |
| 737 | (save-excursion | 747 | (save-excursion |
| @@ -798,8 +808,9 @@ the string PROPERTY." | |||
| 798 | (defun css-completion-at-point () | 808 | (defun css-completion-at-point () |
| 799 | "Complete current symbol at point. | 809 | "Complete current symbol at point. |
| 800 | Currently supports completion of CSS properties, property values, | 810 | Currently supports completion of CSS properties, property values, |
| 801 | pseudo-elements, pseudo-classes, and at-rules." | 811 | pseudo-elements, pseudo-classes, at-rules, and bang-rules." |
| 802 | (or (css--complete-property) | 812 | (or (css--complete-property) |
| 813 | (css--complete-bang-rule) | ||
| 803 | (css--complete-property-value) | 814 | (css--complete-property-value) |
| 804 | (css--complete-pseudo-element-or-class) | 815 | (css--complete-pseudo-element-or-class) |
| 805 | (css--complete-at-rule))) | 816 | (css--complete-at-rule))) |
| @@ -937,7 +948,7 @@ pseudo-elements, pseudo-classes, and at-rules." | |||
| 937 | (modify-syntax-entry ?$ "'" st) | 948 | (modify-syntax-entry ?$ "'" st) |
| 938 | st)) | 949 | st)) |
| 939 | 950 | ||
| 940 | (defvar scss-font-lock-keywords | 951 | (defun scss-font-lock-keywords () |
| 941 | (append `((,(concat "$" css-ident-re) (0 font-lock-variable-name-face))) | 952 | (append `((,(concat "$" css-ident-re) (0 font-lock-variable-name-face))) |
| 942 | (css--font-lock-keywords 'sassy) | 953 | (css--font-lock-keywords 'sassy) |
| 943 | `((,(concat "@mixin[ \t]+\\(" css-ident-re "\\)[ \t]*(") | 954 | `((,(concat "@mixin[ \t]+\\(" css-ident-re "\\)[ \t]*(") |
| @@ -958,7 +969,9 @@ pseudo-elements, pseudo-classes, and at-rules." | |||
| 958 | (setq-local comment-continue " *") | 969 | (setq-local comment-continue " *") |
| 959 | (setq-local comment-start-skip "/[*/]+[ \t]*") | 970 | (setq-local comment-start-skip "/[*/]+[ \t]*") |
| 960 | (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)") | 971 | (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)") |
| 961 | (setq-local font-lock-defaults '(scss-font-lock-keywords nil t))) | 972 | (setq-local css--bang-ids (append css-bang-ids scss-bang-ids)) |
| 973 | (setq-local font-lock-defaults | ||
| 974 | (list (scss-font-lock-keywords) nil t))) | ||
| 962 | 975 | ||
| 963 | (provide 'css-mode) | 976 | (provide 'css-mode) |
| 964 | ;;; css-mode.el ends here | 977 | ;;; css-mode.el ends here |