php - 如何在 emacs 中添加 php 模式 Hook

标签 php emacs

我有一个 emacs 模式 Hook 代码

(defun php-mode-hook ()
  (setq tab-width 4
        c-basic-offset 4
        c-hanging-comment-ender-p nil
        indent-tabs-mode
          (not
            (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name))
              (string-match "\.php$" (buffer-file-name))))))

我需要确保每当我在 emacs 中打开 php 文件时调用这个函数。 我已经为 emacs 安装了 php-mode 并在 .emacs 文件中添加了此代码,但它似乎不起作用..谁能告诉我如何为 emacs 添加此类自定义代码?

注意:我最近迁移到 emacs..请在回答时更具描述性..:)

更新代码1

(add-hook 'php-mode-hook
   '(lambda()
     (setq tab-width 4
      c-basic-offset 4
      c-hanging-comment-ender-p nil
      indent-tabs-mode
      (not
       (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name))
            (string-match "\.php$" (buffer-file-name)))))))

最佳答案

通常使用add-hook函数将钩子(Hook)添加到各种模式提供的位置。您使用要使用的钩子(Hook)的名称定义了一个函数。相反,您应该使用另一个名称定义一个函数,将其添加到 php-mode-hook 中:

(defun my-php-settings ()
  ...)

(add-hook 'php-mode-hook 'my-php-settings)

事实上,您甚至根本不需要创建命名函数:

(add-hook 'php-mode-hook
          (lambda ()
            (setq tab-width 4 ...)))

关于php - 如何在 emacs 中添加 php 模式 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3852824/

相关文章:

php - Android 的 MySQL 连接问题

php - post/redirect/get 并在 SESSION 中保存数据库查询

emacs find-grep grep

emacs - 使用 Emacs 文件名补全优先选择某些文件扩展名

emacs - 制作 M-( 当输入 "("时 Emacs 中的默认行为

php - 如何为特定 session 设置过期时间

php - 如何将 Stripe 支付集成到 Yii2 中?

php - 如何将 setInterval 与 mouseenter 结合起来?

emacs - #+NAME 和 #+LABEL 在组织模式下有什么区别?

macos - mac os x上的showkey等效项?