I am trying to use auto-complete + php-auto-yasnippets with web-mode, but I can't get the snippets to work correctly.

If I start typing imp, I correctly get auto-completion to implode but if I press TAB then RET I get an error

payas/ac-insert-func-and-create-snippet: Wrong number of arguments: #[(arg) "Æ ?] [ac-menu string ac-prefix arg last-command cl-struct-popup-tags ac-expand-common popup-selected-item ac-next ac-previous ...] 5 ("d:/UnixLike/home/.emacs.d/elpa/auto-complete-20160107.8/auto-complete.elc" . 42072) "P"], 0

If I type imp, then press TAB to get autocompletion, and then use C-c C-y to call yes/create-php-snippet, it works, and after that I can use TAB + RET to get yasnippets... (but only for implode, if I type another PHP functions, I have to call C-c C-y before TAB + RET).

Here is a part of my .emacs.el:

(require 'auto-complete-config)

(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")

(require 'yasnippet)
(yas-global-mode 1)
(require 'php-auto-yasnippets)

(require 'emmet-mode)
(require 'ac-emmet)

(require 'web-mode)


(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
               (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)))))

(define-key web-mode-map (kbd "C-c C-y") 'yas/create-php-snippet)

Below are the payas/ac-insert-func-and-create-snippet and payas/ac-setup function from php-auto-yasnippets:

(defun payas/ac-insert-func-and-create-snippet ()
  "Insert the selected function name then create its auto-snippet."
  (yas/create-php-snippet nil))

(defun payas/ac-setup ()
  "Add ac-source-php-auto-yasnippets to ac-sources."

  (ac-define-source php-auto-yasnippets
    '((depends yasnippet)
      ;; TODO The php-mode dictionary contains a few things (keywords and
      ;; the like) that should not be included
      (candidates . (ac-mode-dictionary 'php-mode))
      (action . payas/ac-insert-func-and-create-snippet)

      ;; Since these trigger yasnippet, use the yasnippet face.
      (candidate-face . ac-yasnippet-candidate-face)
      (selection-face . ac-yasnippet-selection-face)

      ;; The 'p' suffix on auto-complete entries stands for 'PHP', and helps
      ;; distinguish them from regular yasnippet entries.
      (symbol . "p")))
  (add-to-list 'ac-sources 'ac-source-php-auto-yasnippets))
  • You don't show the code that defines the very function, payas/ac-insert-func-and-create-snippet, that raises an error. Surely it is that definition that is problematic. Please consider providing that definition, or your question risks being closed as unclear.
    – Drew
    Commented Feb 15, 2016 at 2:12
  • @Drew All these functions are defined by php-auto-yasnippets, this one is defined here.
    – Holt
    Commented Feb 15, 2016 at 7:32


Your Answer

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