fgallina/multi-web-mode

request for reindentation via TAB key invokes php-mode-hook

Closed this issue · 2 comments

Hi,

at first I would like to thank you for making this mode! It's the only "multiple mode" extension for Emacs that works for me when editing mixed HTML/PHP files. :-)

Unfortunately I am experiencing a small hitch. The following code is the only thing that I have in my init.el file.

(add-to-list 'load-path "~/.emacs.d/plugins/php-mode/")
(require 'php-mode)

(add-hook 'php-mode-hook (lambda () (message "Hello")))

(add-to-list 'load-path "~/.emacs.d/plugins/multi-web-mode/")
(require 'multi-web-mode)

(setq mweb-default-major-mode 'html-mode)
(setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
                  (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
                  (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
(setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
(multi-web-global-mode 1)

The problem is that whenever I press a TAB key to automatically indent some line within a PHP chunk the php-mode-hook is invoked (according to those Hello messages printed into the Messages buffer). Is this a correct behaviour? For me it's a little bit annoying and it slows me down during editing (I have some nontrivial config hooked to that hook and it takes some time to fulfill it).

Please will you find some time to look at this issue? I'm currently using Emacs 24.2.1 with the latest version of your mode.

Thank you very much!

I was about to create a new issue but felt this is related to bbatsov/prelude#222

The problem is multi-web-mode activates modes on the fly for every chunk, and therefore initialization hooks are run, one thing that might help you is to wrap your conflicting hook code with a condition checking wether multi-web-mode is enabled or not and prevent running it.

(add-hook 'some-mode-hook
(when (not multi-web-mode)
(my-mode-setup)))

More than a bug, this is a limitation on multi-web-mode itself.