Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS completion in web-mode #1559

Closed
louy2 opened this issue May 10, 2015 · 8 comments
Closed

CSS completion in web-mode #1559

louy2 opened this issue May 10, 2015 · 8 comments

Comments

@louy2
Copy link
Contributor

louy2 commented May 10, 2015

I cannot trigger CSS completion in <style> tag in html file.

Sample:

.complete {
  text-<cursor>
}

I'd like it to show me various text related properties, but I get nothing.

@CestDiego
Copy link
Contributor

Isn't it a better practice to have a separate CSS file?

@louy2
Copy link
Contributor Author

louy2 commented May 10, 2015

I am writing some riotjs tags, and there are certain specific style I'd like to embed in it. And I'd really like the complete funtion to go with the code whereever it is. I am a believer in Literate Programming.

I am considering mmm-mode. Any suggestions?

@mkcode
Copy link
Contributor

mkcode commented May 10, 2015

@louy2 - web-mode is a successor to mmm-mode so switching to mmm-mode would be a step backwards. Adding this feature to web-mode is a much shorter path.

@mkcode
Copy link
Contributor

mkcode commented May 10, 2015

From web-mode.org:

Context-aware auto-completion
If you have auto-complete installed, you can set up per-language ac-sources with web-mode-ac-sources-alist:

(setq web-mode-ac-sources-alist
  '(("css" . (ac-source-css-property))
    ("html" . (ac-source-words-in-buffer ac-source-abbrev)))
To find a language's name, run the function web-mode-language-at-pos while in a block of it.

All hooks in web-mode-before-auto-complete-hooks are run just before auto-completion starts. This is useful for adapting ac-sources meant for a single language to web-mode, like ac-source-yasnippet.

Here is a sample config for editing PHP templates, using php-auto-yasnippets, emmet-mode, and ac-emmet:

(setq web-mode-ac-sources-alist
  '(("php" . (ac-source-yasnippet ac-source-php-auto-yasnippets))
    ("html" . (ac-source-emmet-html-aliases ac-source-emmet-html-snippets))
    ("css" . (ac-source-css-property ac-source-emmet-css-snippets))))

(add-hook 'web-mode-before-auto-complete-hooks
          '(lambda ()
             (let ((web-mode-cur-language
                    (web-mode-language-at-pos)))
               (if (string= web-mode-cur-language "php")
                   (yas-activate-extra-mode 'php-mode)
                 (yas-deactivate-extra-mode 'php-mode))
               (if (string= web-mode-cur-language "css")
                   (setq emmet-use-css-transform t)
                 (setq emmet-use-css-transform nil)))))

@louy2
Copy link
Contributor Author

louy2 commented May 11, 2015

And where shall I put those config?

@TheBB
Copy link
Collaborator

TheBB commented Oct 28, 2015

We use company, so I wouldn't recommend going with auto-complete to get this working. The right way to do this is probably to add company-css to the backends in web-mode.

@TheBB
Copy link
Collaborator

TheBB commented Oct 28, 2015

PR: #3579

@louy2
Copy link
Contributor Author

louy2 commented Oct 29, 2015

Thank you! @TheBB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants