php-auto-yasnippets icon indicating copy to clipboard operation
php-auto-yasnippets copied to clipboard

Error while configuring user-defined function (composer)

Open krystalcode opened this issue 10 years ago • 6 comments

Following the guide for getting user-defined functions via Composer to work. I have created a .dir-locals.el file at the root of the project with the following content.

((php-mode . ((php-auto-yasnippet-required-files (list "~/project/vendor/autoload.php")))))

When I do a M-x yas/create-php-snippet I get the following error. Wrong type argument: stringp, (list "~/project/vendor/autoload.php")

Probably a syntax error, any ideas?

krystalcode avatar Dec 31 '14 02:12 krystalcode

Sorry about the late reply. Off the top of my head I think php-auto-yasnippet-required-files needs to be a cons, e.g.:

(php-auto-yasnippet-required-files . (list "~/project/vendor/autoload.php"))

And if that's the case then I need to correct the example in the README.

ejmr avatar Jan 01 '15 23:01 ejmr

@ejmr perhaps related: I'm not seeing the error message that @krystalcode noted, but I don't get any output either. Weirdly, I can't seem to set the php-auto-yasnippet-required-files variable through M-x set-variable.

In my .dir-locals.el file at ~/src/myproject/.dir-locals.el, I have:

(php-auto-yasnippet-required-files . (list "~/src/myproject/vendor/autoload.php"))

If I run this command in my terminal:

php ~/.emacs.d/elpa/php-auto-yasnippets-20141128.1411/Create-PHP-YASnippet.php base_path --require-once ~/src/myproject/vendor/autoload.php

Then I get this output which is correct:

#key: base_path
#name: base_path
# --
base_path(${1:[$path = ]}

kostajh avatar May 22 '15 02:05 kostajh

@kostajh Thanks for the information. I'll see if I can replicate the problem on my end and (assuming I get the same issue) see if I can figure out a solution.

ejmr avatar May 22 '15 11:05 ejmr

Getting same error: tried ((php-mode . ((php-auto-yasnippet-required-files (list "~/project/vendor/autoload.php"))))) and ((php-mode . ((php-auto-yasnippet-required-files . (list "~/project/vendor/autoload.php"))))). No luck

shanavas786 avatar May 05 '16 10:05 shanavas786

Hey, as the original author of the support for user-defined functions, I noticed the latest notification for this thread, and thought I'd see what's up.

It's been years since I actively used this library (not writing PHP these days), but I did discover the root issue here is that somehow, I submitted bogus instructions on setting .dir-locals.el.

To call functions in .dir-locals.el, you have to use the magic eval pseudo-variable.

Something like this should work a lot better:

((php-mode . ((eval . (setq-local php-auto-yasnippet-required-files
                     (list "~/project/vendor/autoload.php"))))))

and someone should update the example in the docs accordingly.

I haven't actually tested this - just verified that the code I pasted above does set the var correctly.

Hopefully this is some help.

NateEag avatar May 27 '16 20:05 NateEag

I think there was a problem with an invalid required filepath resulting in messed up hash tables. The latest commit should fix this. (I'm not quite sure how, but it seems to have fixed it for me, something about errors not being handled properly?).

((php-mode . ((eval . (setq-local php-auto-yasnippet-required-files
                     (list "~/project/vendor/autoload.php"))))))

works for me

MarTango avatar Mar 30 '17 20:03 MarTango