emacs-php / php-auto-yasnippets Goto Github PK
View Code? Open in Web Editor NEWDynamically Generated YASnippets for PHP Code in GNU Emacs
License: GNU General Public License v3.0
Dynamically Generated YASnippets for PHP Code in GNU Emacs
License: GNU General Public License v3.0
Right now the package sets payas/remove-extra-whitespace
as a hook to run after expanding any snippet. That can cause problems with snippets written for other modes since the function expects to only ever deal with PHP code. Instead of being a global hook payas/remove-extra-whitespace
should be restricted only to PHP Mode snippets.
It looks like somehow, (thing-at-point 'sexp)
is returning nil
when I call (yas/create-php-snippet)
inside a class method. If I bring the cursor out of the method, then the function works correctly.
Is this a problem with thing-at-point
or php-auto-yasnippets
? (Calling (thing-at-point 'string)
is also returning nil
).
I'm not sure.
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
string-match("[ \f \n
�]+" nil 0)
split-string(nil)
payas/create-template(nil)
payas/define-template(nil)
yas/create-php-snippet(nil)
funcall-interactively(yas/create-php-snippet nil)
call-interactively(yas/create-php-snippet nil nil)
command-execute(yas/create-php-snippet)
When loading php-auto-yasnippets with my normal .emacs I get the above errors
wrong-type-argument stringp nil
)But when running :
$ emacs -nw -D -Q --debug-init a.php
(load-file ~/.emacs.d/php-mode.el)
(load-file ~/.emacs.d/dropdown-list.el)
(load-file ~/.emacs.d/yasnippet.el)
(load-file ~/.emacs.d/php-auto-yasnippets.el)
M-: (setq php-auto-yasnippet-php-program "/tmp/Create-PHP-YASnippet.php")
M-: (define-key php-mode-map (kbd "C-c C-y") 'yas/create-php-snippet)
Then going on implode
and for the example, putting my cursor after the "i" then M-x yas/create-php-snippet
:
You can run the command
yas/create-php-snippet' with C-c C-y`My hypothesis is that it's not impossible that 2 bugs live here, one about the snippet builder itself (backtrace1) and another one about the interactive/non-interactive function call and empty argument (or something related).
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
string-match("[ \f \n
]+" nil 0)
split-string(nil)
(let* ((input-chunks (split-string input)) (function-or-method-name (first input-chunks)) (class-name (or (second input-chunks) "")) (args (list php-executable nil (current-buffer) nil php-auto-yasnippet-php-program))) (setq command-args (list function-or-method-name class-name)) (progn (let ((--dolist-tail-- php-auto-yasnippet-required-files) elt) (while --dolist-tail-- (setq elt (car --dolist-tail--)) (setq command-args (cons elt command-args)) (setq command-args (cons "--require-once" command-args)) (setq --dolist-tail-- (cdr --dolist-tail--))) (setq elt nil) command-args)) (setq args (append args command-args)) (apply (quote call-process) args))
(progn (let* ((input-chunks (split-string input)) (function-or-method-name (first input-chunks)) (class-name (or (second input-chunks) "")) (args (list php-executable nil (current-buffer) nil php-auto-yasnippet-php-program))) (setq command-args (list function-or-method-name class-name)) (progn (let ((--dolist-tail-- php-auto-yasnippet-required-files) elt) (while --dolist-tail-- (setq elt (car --dolist-tail--)) (setq command-args (cons elt command-args)) (setq command-args (cons "--require-once" command-args)) (setq --dolist-tail-- (cdr --dolist-tail--))) (setq elt nil) command-args)) (setq args (append args command-args)) (apply (quote call-process) args)))
(unwind-protect (progn (let* ((input-chunks (split-string input)) (function-or-method-name (first input-chunks)) (class-name (or (second input-chunks) "")) (args (list php-executable nil (current-buffer) nil php-auto-yasnippet-php-program))) (setq command-args (list function-or-method-name class-name)) (progn (let ((--dolist-tail-- php-auto-yasnippet-required-files) elt) (while --dolist-tail-- (setq elt (car --dolist-tail--)) (setq command-args (cons elt command-args)) (setq command-args (cons "--require-once" command-args)) (setq --dolist-tail-- (cdr --dolist-tail--))) (setq elt nil) command-args)) (setq args (append args command-args)) (apply (quote call-process) args))) (set-match-data save-match-data-internal (quote evaporate)))
(let ((save-match-data-internal (match-data))) (unwind-protect (progn (let* ((input-chunks (split-string input)) (function-or-method-name (first input-chunks)) (class-name (or (second input-chunks) "")) (args (list php-executable nil (current-buffer) nil php-auto-yasnippet-php-program))) (setq command-args (list function-or-method-name class-name)) (progn (let ((--dolist-tail-- php-auto-yasnippet-required-files) elt) (while --dolist-tail-- (setq elt ...) (setq command-args ...) (setq command-args ...) (setq --dolist-tail-- ...)) (setq elt nil) command-args)) (setq args (append args command-args)) (apply (quote call-process) args))) (set-match-data save-match-data-internal (quote evaporate))))
payas/create-template(nil)
(let ((exit-code (payas/create-template input))) (if (/= exit-code 0) (payas/report-error exit-code input)) (yas-define-snippets (quote php-mode) (list (yas--parse-template))))
(progn (let ((exit-code (payas/create-template input))) (if (/= exit-code 0) (payas/report-error exit-code input)) (yas-define-snippets (quote php-mode) (list (yas--parse-template)))))
(unwind-protect (progn (let ((exit-code (payas/create-template input))) (if (/= exit-code 0) (payas/report-error exit-code input)) (yas-define-snippets (quote php-mode) (list (yas--parse-template))))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let ((exit-code (payas/create-template input))) (if (/= exit-code 0) (payas/report-error exit-code input)) (yas-define-snippets (quote php-mode) (list (yas--parse-template))))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
(let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let ((exit-code (payas/create-template input))) (if (/= exit-code 0) (payas/report-error exit-code input)) (yas-define-snippets (quote php-mode) (list (yas--parse-template))))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
(if (yas--get-template-by-uuid (quote php-mode) input) nil (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (let ((exit-code ...)) (if (/= exit-code 0) (payas/report-error exit-code input)) (yas-define-snippets (quote php-mode) (list ...)))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))))
payas/define-template(nil)
(if class (payas/define-template (concat function " " class)) (payas/define-template function))
(let ((function (thing-at-point (quote symbol))) (class (if prefix (read-from-minibuffer "Class: ")))) (if class (payas/define-template (concat function " " class)) (payas/define-template function)) (setq php-auto-yasnippet-executing t) (yas-expand))
yas/create-php-snippet(nil)
call-interactively(yas/create-php-snippet record nil)
command-execute(yas/create-php-snippet record)
execute-extended-command(nil "yas/create-php-snippet")
call-interactively(execute-extended-command nil nil)
As of 2.1.0 and using php-mode 2.12 the variable php-auto-yasnippet-php-program does not seem expanded (the ~ [tidla] isn't replaced by $HOME).
That brings spurious "Cannot run the program ~/.emacs.d/php/Create-PHP-YASnippet.php"
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?
php-auto-yasnippets looks like an awesome package - I'm always forgetting the order of args to PHP's numerous array functions. Thanks very much for writing it.
I took some time this weekend to try it out. It seems to work very nicely, and this coming week at work I'll be trying it out in-depth.
Being a lazy sort, after playing with it a bit, I thought, "It must be possible to auto-trigger the auto-snippets after auto-completing a function name."
After reading some code and playing, I came up with a working prototype. It's just an auto-complete source, based strongly on the yasnippet source that ships with auto-complete.
I tossed a demo video on my webserver if you'd like to see what it looks like.
The prototype code is in my .emacs.d repo.
Is this something you'd be interested in adding to php-auto-yasnippets? If so, what cleanup/improvements would be necessary?
If not, do you have any thoughts on how to make it available to anyone else who's interested?
Hello.
I get this message if I press . On FreeBSD php is placed on /usr/local/bin/. How can I do?
I was thinking it might be useful to add support for snippets for end-user functions/methods.
Maybe something like:
--require_once
option to Create-PHP-Yasnippet.php
that calls require_once
for the passed path. It could be specified multiple times.php-auto-yasnippet-requires
(or something along those lines) to the elisp package, defaulting it to the empty list. Every path in it is passed to the PHP script via the new --require_once
option.Users could use .dir-locals (or other mechanisms) to set the php-auto-yasnippet-requires
list for a given project.
A lot of modern PHP projects rely on autoloads, and even the ones that don't usually have some "include all the things" option, so this should be fairly usable in practice.
I verified that adding a require_once does let the code work with user code.
Does this sound like a worthwhile addition? If I got this working, do you think you'd merge it?
When I add (payas/ac-setup)
to my config, I get:
Debugger entered--Lisp error: (void-variable php-auto-yasnippets)
payas/ac-setup()
eval((payas/ac-setup) nil)
eval-last-sexp-1(nil)
eval-last-sexp(nil)
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)
Is this working for others?
I installed your package following the README.
When I type 'preg_match' in a php file and they type 'C-c C-y', I get this error:
split-string: Wrong type argument: stringp, nil
This is my config:
https://gist.github.com/dhaley/5707041
Here is the message from emacs debug:
https://gist.github.com/dhaley/5707074
I'm using php mode 1.10 and my php-executable (5.3.13) is: /Applications/MAMP/bin/php/php5.3.13/bin/php
What might I be doing wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.