X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/9c6348ecbc8f5403aafe2b3dfccd678a60f921c0..d97c98fed8fb5e6a03804d96031591e9c433cf58:/company-css.el diff --git a/company-css.el b/company-css.el index b2d4c6aea..cf8c683ce 100644 --- a/company-css.el +++ b/company-css.el @@ -1,24 +1,32 @@ -;;; company-css.el --- a company-mode completion back-end for css-mode -;; -;; Copyright (C) 2009 Nikolaj Schumacher -;; -;; This file is part of company 0.4.3. -;; -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License -;; as published by the Free Software Foundation; either version 2 -;; of the License, or (at your option) any later version. -;; -;; This program is distributed in the hope that it will be useful, +;;; company-css.el --- company-mode completion backend for css-mode -*- lexical-binding: t -*- + +;; Copyright (C) 2009, 2011, 2014 Free Software Foundation, Inc. + +;; Author: Nikolaj Schumacher + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. -;; + ;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: (require 'company) -(eval-when-compile (require 'cl)) +(require 'cl-lib) + +(declare-function web-mode-language-at-pos "web-mode" (&optional pos)) (defconst company-css-property-alist ;; see http://www.w3.org/TR/CSS21/propidx.html @@ -26,7 +34,8 @@ "center-right" "right" "far-right" "right-side" "behind" "leftwards" "rightwards") ("background" background-color background-image background-repeat - background-attachment background-position) + background-attachment background-position + background-clip background-origin background-size) ("background-attachment" "scroll" "fixed") ("background-color" color "transparent") ("background-image" uri "none") @@ -79,13 +88,14 @@ ("elevation" angle "below" "level" "above" "higher" "lower") ("empty-cells" "show" "hide") ("float" "left" "right" "none") - ("font" font-style font-variant font-weight font-size "/" line-height + ("font" font-style font-weight font-size "/" line-height font-family "caption" "icon" "menu" "message-box" "small-caption" - "status-bar") + "status-bar" "normal" "small-caps" + ;; CSS3 + font-stretch) ("font-family" family-name generic-family) ("font-size" absolute-size relative-size length percentage) ("font-style" "normal" "italic" "oblique") - ("font-variant" "normal" "small-caps") ("font-weight" "normal" "bold" "bolder" "lighter" "100" "200" "300" "400" "500" "600" "700" "800" "900") ("height" length percentage "auto") @@ -112,7 +122,9 @@ ("outline-color" color "invert") ("outline-style" border-style) ("outline-width" border-width) - ("overflow" "visible" "hidden" "scroll" "auto") + ("overflow" "visible" "hidden" "scroll" "auto" + ;; CSS3: + "no-display" "no-content") ("padding" padding-width) ("padding-bottom" padding-width) ("padding-left" padding-width) @@ -140,7 +152,6 @@ ("stress" number) ("table-layout" "auto" "fixed") ("text-align" "left" "right" "center" "justify") - ("text-decoration" "none" "underline" "overline" "line-through" "blink") ("text-indent" length percentage) ("text-transform" "capitalize" "uppercase" "lowercase" "none") ("top" length percentage "auto") @@ -156,14 +167,137 @@ ("widows" integer) ("width" length percentage "auto") ("word-spacing" "normal" length) - ("z-index" "auto" integer)) + ("z-index" "auto" integer) + ;; CSS3 + ("align-content" align-stretch "space-between" "space-around") + ("align-items" align-stretch "baseline") + ("align-self" align-items "auto") + ("animation" animation-name animation-duration animation-timing-function + animation-delay animation-iteration-count animation-direction + animation-fill-mode) + ("animation-delay" time) + ("animation-direction" "normal" "reverse" "alternate" "alternate-reverse") + ("animation-duration" time) + ("animation-fill-mode" "none" "forwards" "backwards" "both") + ("animation-iteration-count" integer "infinite") + ("animation-name" "none") + ("animation-play-state" "paused" "running") + ("animation-timing-function" transition-timing-function + "step-start" "step-end" "steps(,)") + ("backface-visibility" "visible" "hidden") + ("background-clip" background-origin) + ("background-origin" "border-box" "padding-box" "content-box") + ("background-size" length percentage "auto" "cover" "contain") + ("border-image" border-image-outset border-image-repeat border-image-source + border-image-slice border-image-width) + ("border-image-outset" length) + ("border-image-repeat" "stretch" "repeat" "round" "space") + ("border-image-source" uri "none") + ("border-image-slice" length) + ("border-image-width" length percentage) + ("border-radius" length) + ("border-top-left-radius" length) + ("border-top-right-radius" length) + ("border-bottom-left-radius" length) + ("border-bottom-right-radius" length) + ("box-decoration-break" "slice" "clone") + ("box-shadow" length color) + ("box-sizing" "content-box" "border-box") + ("break-after" "auto" "always" "avoid" "left" "right" "page" "column" + "avoid-page" "avoid-column") + ("break-before" break-after) + ("break-inside" "avoid" "auto") + ("columns" column-width column-count) + ("column-count" integer) + ("column-fill" "auto" "balance") + ("column-gap" length "normal") + ("column-rule" column-rule-width column-rule-style column-rule-color) + ("column-rule-color" color) + ("column-rule-style" border-style) + ("column-rule-width" border-width) + ("column-span" "all" "none") + ("column-width" length "auto") + ("filter" url "blur()" "brightness()" "contrast()" "drop-shadow()" + "grayscale()" "hue-rotate()" "invert()" "opacity()" "saturate()" "sepia()") + ("flex" flex-grow flex-shrink flex-basis) + ("flex-basis" percentage length "auto") + ("flex-direction" "row" "row-reverse" "column" "column-reverse") + ("flex-flow" flex-direction flex-wrap) + ("flex-grow" number) + ("flex-shrink" number) + ("flex-wrap" "nowrap" "wrap" "wrap-reverse") + ("font-feature-setting" normal string number) + ("font-kerning" "auto" "normal" "none") + ("font-language-override" "normal" string) + ("font-size-adjust" "none" number) + ("font-stretch" "normal" "ultra-condensed" "extra-condensed" "condensed" + "semi-condensed" "semi-expanded" "expanded" "extra-expanded" "ultra-expanded") + ("font-synthesis" "none" "weight" "style") + ("font-variant" font-variant-alternates font-variant-caps + font-variant-east-asian font-variant-ligatures font-variant-numeric + font-variant-position) + ("font-variant-alternates" "normal" "historical-forms" "stylistic()" + "styleset()" "character-variant()" "swash()" "ornaments()" "annotation()") + ("font-variant-caps" "normal" "small-caps" "all-small-caps" "petite-caps" + "all-petite-caps" "unicase" "titling-caps") + ("font-variant-east-asian" "jis78" "jis83" "jis90" "jis04" "simplified" + "traditional" "full-width" "proportional-width" "ruby") + ("font-variant-ligatures" "normal" "none" "common-ligatures" + "no-common-ligatures" "discretionary-ligatures" "no-discretionary-ligatures" + "historical-ligatures" "no-historical-ligatures" "contextual" "no-contextual") + ("font-variant-numeric" "normal" "ordinal" "slashed-zero" + "lining-nums" "oldstyle-nums" "proportional-nums" "tabular-nums" + "diagonal-fractions" "stacked-fractions") + ("font-variant-position" "normal" "sub" "super") + ("hyphens" "none" "manual" "auto") + ("justify-content" align-common "space-between" "space-around") + ("line-break" "auto" "loose" "normal" "strict") + ("marquee-direction" "forward" "reverse") + ("marquee-play-count" integer "infinite") + ("marquee-speed" "slow" "normal" "fast") + ("marquee-style" "scroll" "slide" "alternate") + ("opacity" number) + ("order" number) + ("outline-offset" length) + ("overflow-x" overflow) + ("overflow-y" overflow) + ("overflow-style" "auto" "marquee-line" "marquee-block") + ("overflow-wrap" "normal" "break-word") + ("perspective" "none" length) + ("perspective-origin" percentage length "left" "center" "right" "top" "bottom") + ("resize" "none" "both" "horizontal" "vertical") + ("tab-size" integer length) + ("text-align-last" "auto" "start" "end" "left" "right" "center" "justify") + ("text-decoration" text-decoration-color text-decoration-line text-decoration-style) + ("text-decoration-color" color) + ("text-decoration-line" "none" "underline" "overline" "line-through" "blink") + ("text-decoration-style" "solid" "double" "dotted" "dashed" "wavy") + ("text-overflow" "clip" "ellipsis") + ("text-shadow" color length) + ("text-underline-position" "auto" "under" "left" "right") + ("transform" "matrix(,,,,,)" "translate(,)" "translateX()" "translateY()" + "scale()" "scaleX()" "scaleY()" "rotate()" "skewX()" "skewY()" "none") + ("transform-origin" perspective-origin) + ("transform-style" "flat" "preserve-3d") + ("transition" transition-property transition-duration + transition-timing-function transition-delay) + ("transition-delay" time) + ("transition-duration" time) + ("transition-timing-function" + "ease" "linear" "ease-in" "ease-out" "ease-in-out" "cubic-bezier(,,,)") + ("transition-property" "none" "all" identifier) + ("word-wrap" overflow-wrap) + ("word-break" "normal" "break-all" "keep-all")) "A list of CSS properties and their possible values.") (defconst company-css-value-classes '((absolute-size "xx-small" "x-small" "small" "medium" "large" "x-large" "xx-large") + (align-common "flex-start" "flex-end" "center") + (align-stretch align-common "stretch") (border-style "none" "hidden" "dotted" "dashed" "solid" "double" "groove" "ridge" "inset" "outset") + (border-width "thick" "medium" "thin") (color "aqua" "black" "blue" "fuchsia" "gray" "green" "lime" "maroon" "navy" "olive" "orange" "purple" "red" "silver" "teal" "white" "yellow") (counter "counter(,)") @@ -188,7 +322,10 @@ "li" "link" "map" "menu" "meta" "noframes" "noscript" "object" "ol" "optgroup" "option" "p" "param" "pre" "q" "s" "samp" "script" "select" "small" "span" "strike" "strong" "style" "sub" "sup" "table" "tbody" "td" - "textarea" "tfoot" "th" "thead" "title" "tr" "tt" "u" "ul" "var") + "textarea" "tfoot" "th" "thead" "title" "tr" "tt" "u" "ul" "var" + ;; HTML5 + "section" "article" "aside" "header" "footer" "nav" "figure" "figcaption" + "time" "mark" "main") "A list of HTML tags for use in CSS completion.") (defconst company-css-pseudo-classes @@ -207,10 +344,14 @@ (dolist (child (or (cdr (assoc value company-css-value-classes)) (company-css-property-values (symbol-name value)))) - (add-to-list 'results child)) - (add-to-list 'results value))) + (push child results)) + (push value results))) (setq results (sort results 'string<)) - (puthash attribute results company-css-property-cache) + (puthash attribute + (if (fboundp 'delete-consecutive-dups) + (delete-consecutive-dups results) + (delete-dups results)) + company-css-property-cache) results))) ;;; bracket detection @@ -241,7 +382,7 @@ "\\)*" "\\(\\(?:#\\|\\_<[[:alpha:]]\\)\\(?:[[:alnum:]-#]*\\_>\\)?\\_>\\|\\)" "\\=") - "A regular expression matching CSS tags") + "A regular expression matching CSS tags.") ;;; pseudo id (defconst company-css-pseudo-regexp @@ -255,7 +396,7 @@ "\\)*" "\\(?:\\(?:\\#\\|\\_<[[:alpha:]]\\)[[:alnum:]-#]*\\):" "\\([[:alpha:]-]+\\_>\\|\\)\\_>\\=") - "A regular expression matching CSS pseudo classes") + "A regular expression matching CSS pseudo classes.") ;;; properties @@ -267,21 +408,23 @@ Returns \"\" if no property found, but feasible at this position." ;;; values (defconst company-css-property-value-regexp - "\\_<\\([[:alpha:]-]+\\):\\(?:[^};]*[[:space:]]+\\)?\\([^};]*\\_>\\|\\)\\=" - "A regular expression matching CSS tags") + "\\_<\\([[:alpha:]-]+\\):\\(?:[^{};]*[[:space:]]+\\)?\\([^{};]*\\_>\\|\\)\\=" + "A regular expression matching CSS tags.") ;;;###autoload (defun company-css (command &optional arg &rest ignored) - "A `company-mode' completion back-end for `css-mode'." + "`company-mode' completion backend for `css-mode'." (interactive (list 'interactive)) - (case command - ('interactive (company-begin-backend 'company-css)) - ('prefix (and (derived-mode-p 'css-mode) - (or (company-grab company-css-tag-regexp 1) - (company-grab company-css-pseudo-regexp 1) - (company-grab company-css-property-value-regexp 2) - (company-css-grab-property)))) - ('candidates + (cl-case command + (interactive (company-begin-backend 'company-css)) + (prefix (and (or (derived-mode-p 'css-mode) + (and (derived-mode-p 'web-mode) + (string= (web-mode-language-at-pos) "css"))) + (or (company-grab company-css-tag-regexp 1) + (company-grab company-css-pseudo-regexp 1) + (company-grab company-css-property-value-regexp 2) + (company-css-grab-property)))) + (candidates (cond ((company-grab company-css-tag-regexp 1) (all-completions arg company-css-html-tags)) @@ -293,7 +436,7 @@ Returns \"\" if no property found, but feasible at this position." (company-grab company-css-property-value-regexp 1)))) ((company-css-grab-property) (all-completions arg company-css-property-alist)))) - ('sorted t))) + (sorted t))) (provide 'company-css) ;;; company-css.el ends here