I'm currently using autoheader.
I have this configuration, which causes the
<?php tag to be inserted in other modes:
(defsubst my/header-title () "Insert buffer's first row." (insert "<?php \n \n" (concat comment-start " Foo bar " (and (= 1 (length comment-start)) header-prefix-string ) (if (buffer-file-name) (file-name-nondirectory (buffer-file-name)) (buffer-name)) " " "\n")) ) (setq make-header-hook '( my/header-title)) ;; To have Emacs add a file header whenever you create a new file in some mode: (autoload 'auto-make-header "header2") (add-hook 'php-mode-hook 'auto-make-header) (add-hook 'emacs-lisp-mode-hook 'auto-make-header) (add-hook 'web-mode-hook 'auto-make-header) (add-hook 'html-mode-hook 'auto-make-header) (add-hook 'js-mode-hook 'auto-make-header)
When I'm creating a new file with the extension
.lisp, then the
<?php opening tag will be inserted too. I want the
<?php opening tag inserted in the header only when the newly created buffer is in PHP-mode. When PHP-mode is not enabled, it should not insert the PHP tag.
I tried to solve this with the following modifications:
(defsubst my/header-title () (insert ;; comparison major mode with the PHP-mode (if equal major-mode "PHP-mode" ;; If true, insert this: ("<?php \n \n") ;; If false, insert empty string " \n") (concat[...] rest of the function)))
But it doesn't work. The comparison seems logical, following the Emacs manual. So I couldn't figure it out. So I'm wondering how I could detect if there is PHP-mode enabled, then insert the
<?php tag, or otherwise do nothing?
Any answer would be greatly appreciated.