ScottyB / ac-js2

Javascript auto-completion in Emacs using Js2-mode's parser and Skewer-mode.
123 stars 8 forks source link

Fixed problem with void ac-define-source. Unicode symbol on ac. #9

Closed marcinant closed 10 years ago

marcinant commented 11 years ago

We definetly use differend indentation settings. So this diff is huge, but the only important part is:

(defvar ac-source-js2
  '((candidates . ac-js2-ac-candidates)
    (document . ac-js2-ac-document)
    (prefix .  ac-js2-ac-prefix)
    (symbol . "")
    (requires . -1)))

(defun ac-js2-setup-auto-complete-mode ()
  "Setup ac-js2 to be SED with auto-complete-mode."
  (add-to-list 'ac-sources 'ac-source-js2)
  (auto-complete-mode))

This solved problem with ac-define-source function void on my setup.

PuercoPop commented 10 years ago

I have a similar error without tampering with the default sources.

Debugger entered--Lisp error: (invalid-function ac-define-source)
  ac-define-source("js2" ((candidates . ac-js2-ac-candidates)
                                   (document . ac-js2-ac-document) (prefix . ac-js2-ac-prefix) (requires . -1)))
  ac-js2-setup-auto-complete-mode()
  ac-js2-mode()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook js2-mode-hook)

The macro ac-define-source is defined in the autocomplete package. I have made sure to call the setup code for autocomplete before the ac-js2 code.

I have tried adding the auto-complete requirement to no avail. @marcinant any pointers as to why does it think it is undefined?

marcinant commented 10 years ago

@PuercoPop No idea. I'm not an advanced Lisp hacker. This language is so incredible weird that sometimes I really don't understand why something is ok, and why sometimes is not :)

I just copied solutions from other modes related to auto-complete. ac-define-source is described in documentation but doesn't work for some reason. You should file an issue on auto-complete repo.

yibe commented 10 years ago

@PuercoPop I got the same error and in my case it was a byte compilation issue.

When you byte-compile Emacs Lisp code, if there are macro calls in it, those macros must already be defined at that point in order to be properly expanded (see Macros and Byte Compilation). In the case of ac-js2.el, however, where the dependency on AC is optional, AC is not required in the file and thus the macro ac-define-source is not defined during compilation.

The solution I can think of is to prevent the (ac-define-source ...) part from being byte-compiled by replacing it with (eval '(ac-define-source ...)). (Of course remember to byte-recompile the file after editing it.)

ScottyB commented 10 years ago

@marcinant Sorry for taking so long to get back to you on this issue! Could you please modify the pull request, removing all the whitespace changes? What was the issue relating to the unicode symbol? I think I must be missing something.

ScottyB commented 10 years ago

@yibe Thanks for the informative comment. Just out of curiosity is there another way to solve this problem? Once this pull request has been merged in I'll make that change so others don't have the same issue.

vampolo commented 10 years ago

I had the same issue and I've fixed with the code by @marcinant

marcinant commented 10 years ago

Apparently something has changed in auto-complete, because on my config your new code is working out of the box. So I think that we could drop this PR.