Code completion for HTML/JS/CSS in Emacs

  |   Source

CREATED: <2015-11-27 Fri>

UPDATED: <2020-03-27 Fri>

You need install Ctags or universal-ctags at first.

People using macOS will find there already exists a built in program named "ctags". This program should be deleted!

If you want a quick start, jump to the end of this article.

You can use company-ctags plus company-mode to complete HTML/JS/CSS code.

Setup is easy.

Step 1, create TAGS:

cd ~/myproj/ && ctags -e -R .

Step 2, done.

That's OK for most programming languages.

But not enough for web developers who use web-mode.

You need upgrade web-mode to latest version so that when inputting "btn-" or "data-" code completion still works.

One issue is company-mode disables code completion in string and comment by default. We need disable this feature in web-mode temporarily,

(with-eval-after-load 'company
  ;; @see
  (defadvice company-in-string-or-comment (around company-in-string-or-comment-hack activate)
    (if (memq major-mode '(php-mode html-mode web-mode nxml-mode))
        (setq ad-return-value nil)

Tested on Emacs24, 25, 26.



Comments powered by Disqus