1

I'm using web-mode and yasnippet for coding PHP and HTML.

To use yasnippet in web-mode, will have to install php-mode, php-auto-yasnippets, emmet-mode and ac-emmet as suggested in web-mode.org. But I prefer to make it happen just with web-mode and yasnippet.

Part of my web-mode configuration is like this:

(defadvice yas-expand-from-trigger-key (before web-mode-before-yas-expand activate)
        (run-hooks 'web-mode-cur-language-mode-hook))


(add-hook 'web-mode-cur-language-mode-hook
      '(lambda ()
         (let ((web-mode-cur-language
                (web-mode-language-at-pos)))
           (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 "html")
                (yas-activate-extra-mode 'html-mode)
              (yas-deactivate-extra-mode 'html-mode))
           )))

And following is my yasnippet configuration:

(add-to-list 'load-path (expand-file-name "elpa/yasnippet" user-emacs-directory))

(require 'yasnippet)

(yas-global-mode 1)

It works very well when edit php file in web-mode.

Then open a html file in emacs, input "form" then "tab", everything works fine. But if input "href" then "tab", nothing happened. It supposed to call the "href" snippet in nxml-mode as written in html-mode's .yas-parents.

How could I make this right? I really don't want copy all those snippets from nxml-mode to html-mode.

0

Code changes was made to yasnippet.el (with 1 addition and 2 deletions), to let it find parents for extra-modes too. Here is the link fix #619

Around line 744:

                     append (funcall dfs neighbour explored)))))
 (remove-duplicates (if mode
                        (funcall dfs mode)
-                    (append yas--extra-modes
-                            (funcall dfs major-mode))))))
+                    (apply #'append (mapcar dfs (cons major-mode yas--extra-modes)))))))
  • 1
    Please make this a complete answer by putting the necessary code in the post rather than just a link. – Dan Oct 9 '15 at 9:44
  • Sorry about that, made another answer, is that OK now? – Jasondf Oct 9 '15 at 14:35
  • please edit your original post rather than posting a new answer. Also, please clarify what one is supposed to do. It's hard to tell what the answer is without more explanation. – Dan Oct 9 '15 at 15:00
  • Roger. Edited the original answer. I'm new to stackechange, sorry for the blurred answer before, and thanks for your advice. – Jasondf Oct 10 '15 at 5:25
  • Not a problem. Thanks for updating. – Dan Oct 10 '15 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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