How to toggle off c-electric-flag and c-syntactic-indentation only when editing ".html.php" files in Emacs?

StackOverflow https://stackoverflow.com/questions/20452375

  •  30-08-2022
  •  | 
  •  

質問

I need to unset the c-electric-flag and c-syntactic-indentation flags in Emacs23.4 when I open php files which name ends with .html.php, and only for that "name-pattern", because I use php-mode within html-mode and those flags indent the php code not in a proper way.

However, I would like to keep those flags on while editing pure .php files (php controllers, which contain only php source).

How can I do that?

役に立ちましたか?

解決

You can archive this by checking file name in php-mode-hook and disable them if file name is matched to .html.php like following code.

(defun my-php-mode-hook ()
  (when (and (buffer-file-name)
         (string-match-p "\\.html\\.php\\'" (buffer-file-name)))
    (c-toggle-electric-state -1)
    (setq c-syntactic-indentation nil)))
(add-hook 'php-mode-hook 'my-php-mode-hook)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top