I tried using ac-html recently since I'm an auto-complete user and I'd like to have HTML completion in html-mode and web-mode buffers. However, it has been acting somewhat strangely and throws an error whenever I type anything in an html-mode or web-mode buffer:

auto-complete error: (args-out-of-range <name-of-current-buffer> 0 2)

As a result of this error, auto-complete-mode is disabled in the current buffer. However, perhaps even more strangely, if I turn on auto-complete-mode after it was disabled by the error, everything works as expected and I get auto-completion. Yet, this only seems to happen in html-mode buffers; i.e., I do not get auto-completion after re-enabling auto-complete-mode in web-mode buffers.

I have ac-html set up for both html-mode and web-mode like so in my init files:

;; Better completion for html-mode
(defun setup-ac-for-html ()
  (require 'ac-html)
  (require 'ac-html-default-data-provider)
  (ac-html-enable-data-provider 'ac-html-default-data-provider)
  (setq ac-sources '(ac-source-html-tag

;; Better completion for web-mode
(defun setup-ac-for-web-mode ()
  (require 'ac-html)
  (require 'ac-html-default-data-provider)

  (add-to-list 'web-mode-ac-sources-alist
               '("html" . (ac-source-html-tag


(add-hook 'html-mode-hook                      'setup-ac-for-html)
(add-hook 'web-mode-before-auto-complete-hooks 'setup-ac-for-web-mode)

How can I get this error to stop happening so that I don't have to re-enable auto-complete-mode after said error? Also, why does this re-enabling seemingly not work for web-mode?

I'm using Emacs 25.1.1 on OS X 10.11.6.

1 Answer 1


Okay, so I've come up with a couple of hacky fixes for these problems and have been able to sufficiently enable auto-completion with auto-complete-mode via said fixes. I managed to get web-mode completion working by adjusting my configuration to be in accordance with the code from their website for setting up auto-completion:

(defun setup-ac-for-web-mode ()
       (setq web-mode-ac-sources-alist
             '(("css"  . (ac-source-css-property))
               ("html" . (ac-source-words-in-buffer ac-source-abbrev)))))
    (add-to-list 'ac-modes 'web-mode)
    (add-hook 'web-mode-before-auto-complete-hooks 'setup-ac-for-web-mode)

Mind you this new setup for web-mode is no longer using ac-html, but it seems that web-mode has provided their own auto-complete sources, which work well enough for me. The next fix that I've made enables ac-htmlto work for html-mode itself:

(add-hook 'html-mode-hook
          #'(lambda ()
              (run-with-idle-timer 0.1 nil (lambda () (progn
                                                        (auto-complete-mode 1)
                                                        (auto-complete-mode -1)
                                                        (auto-complete-mode 1))))))

As you can see, it's quite crude and all that it does is automate the process of turning auto-complete-mode on, off, and on again shortly after html-mode is initially invoked in a given buffer. I'm not sure why that works, but it does and now I have auto-completion for html-mode as well as web-mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.