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
autocomplete-mode not working in web-mode #116
Comments
Fore the record: I already added a |
Ahhh, never mind… it was my mistake, I had it in an alwayse-false-conditional and therefore never getting executed. Sorry! |
@ckruse I do not use this autocomplete-mode. Could you add a comment to this issue with a little howto. I will then add this howto to web-mode.org ps: I am relieved by the fact that some minor modes are compatible with web-mode !! |
It is very easy to use. Just install autocomplete-mode somewhere and add the following lines to your
That's it – now it works (well, it should) :) |
The above snippet is not enough to have a satisfying auto-complete. One still needs to add a web-mode dictionary to the ac-dictionary-directories folder. But auto-complete-mode does not distinguish between block types. It would be nice to have auto completions for javascript, php, html, css depending on the current block type. |
As an elisp novice, I hesitate to suggest ideas about whose implementation I know little. However... I think it would be possible to write a web-mode-specific auto-complete source that uses Just an idea. I don't know how much work would actually be involved there. |
what could be nice is to have a little example ... I do not use autocomplete |
I hacked up a quick proof-of-concept this morning: (defun ac-web-mode-candidates ()
"Pick the right set of candidates based on position of point context."
(let ((cur-web-mode-lang (plist-get (web-mode-point-context (point)) :language)))
(cond ((string= cur-web-mode-lang "php")
(ac-mode-dictionary 'php-mode))
((string= cur-web-mode-lang "css")
css-property-ids)
((string= cur-web-mode-lang "html")
'("div" "script" "testing")))
)
)
(ac-define-source web-mode
'((candidates . ac-web-mode-candidates))) If you load auto-complete and css-mode, turn on auto-complete in web-mode, then run Making a useful ac-source would take some work - web-mode supports a ton of different server-side systems, and people will want completion sources for different ones. Just stacking all the possible candidates into one set of candidates might not be good enough - some completion candidates need different actions, and actions are defined in That makes me think dynamically choosing ac-sources is the right approach, not what I did here. Anyway, this should at least give some idea what I'm thinking of. I may experiment with the ac-sources idea later. |
Okay, I have a prototype of picking auto-complete sources dynamically. You can see the diff here in my .emacs.d. The relevant file is web-mode-init.el (the file where I set up my preferences for web-mode). The other changes were to tweak some auto-complete sources to be workable with web-mode. This change adds three pieces of UI to web-mode:
Known issues:
If those can be solved, I think this should work for adding auto-complete support to web-mode. Questions? Comments? |
I think I solved the |
@NateEag Hi, I'll look at all this as soon as I've finished my last big push |
Sounds good. Thanks for letting me know. |
Any idea when you might get a chance to look at this? Not a big deal - just wanted to make sure this doesn't get lost, since it's attached to a closed issue. |
You were right to ping me about this ! |
Sure. Sorry for any confusion I caused. Here's a summary of what I'm suggesting. You can refer to https://github.com/NateEag/.emacs.d/compare/web-mode-dynamic-ac-sources?expand=1&w=1#diff-d3ca732e3a4685fe2fe3c612588a2428R1 to see the prototype code I'm describing. auto-complete mode uses "sources" as backends for computing possible completions. The buffer-local variable "ac-sources" is the interface for choosing which ac-sources are active in a buffer - you just set it to the list of sources you want. My idea is to add a completion function that sets ac-sources based on the current block's language, then triggers auto-complete. That way, you get the context-aware auto-complete that thkoch2001 asked for. My function web-mode-trigger-ac does that. It relies on an alist I added (web-mode-ac-sources-alist) that maps language name to a list of ac-sources to activate. That gives users a simple way to choose their auto-complete sources for each block type. After I had context-aware auto-complete working, I tried to set up emmet-mode's auto-completions in web-mode. Emmet-mode (https://github.com/smihica/emmet-mode) assumes that you are either in an HTML file or a CSS file. To get its completions to work in both block types, I added a pre-auto-completion hook, so that I could tell emmet to be in 'html' or 'css' mode before running auto-complete. I named the hook web-mode-before-auto-complete-hooks. Does that help? -Nate On Feb 26, 2014, at 10:15 AM, fxbois wrote:
|
@NateEag I ve added the method |
A revamped, simpler POC for context-aware auto-complete in web-mode can be seen in my .emacs.d repo: is the setup code, and is the code to register actual ac-sources by programming language. |
I don't know whole lot of lisp stuff, but the below lines does auto-completion of both css property name and value: ;; important for css property name auto-complete (defun my-css-mode-hook () Could these be incorporated with NateEag's code? |
@NateEag why do you use |
@fxbois Oops, oversight on my part - I updated most of my config to use @eN-Joy You should be able to use any ac-source with my code. If you look at https://github.com/NateEag/.emacs.d/blob/86c923c3bae1622633dad1d68143a21845259d00/site-lisp/mode-configs/web-mode-init.el#L25-L55, you would just add |
Updated code in my repo, more clearly divided into "proposed addition" and "my config". Proposed code to add to web-mode: my config: This look pull-request-worthy? If so, I can add this to web-mode, add some docs, and issue one. |
@NateEag no problem to add this to web-mode. I just need to test it before. Morevoer everything needs to work even is the user does not have ac installed |
yep, makes sense. I'll do that in my PR. |
Some docs will soon be added on http://web-mode.org |
Until then, how does getting ac-mode set up actually work? I have auto-complete-mode enabled in web-mode, but nothing ever happens. |
I ve added the docs written by @NateEag on web-mode.org |
Hey,
I'm an enthusiastic user of both, web-mode and autocomplete-mode. Unfortunately it does not work with web-mode buffers. A I doing it wrong or is this a bug?
The text was updated successfully, but these errors were encountered: