加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何将php模式设置从.emacs移动到.dir-locals.el?

发布时间:2020-12-13 18:12:35 所属栏目:PHP教程 来源:网络整理
导读:这是我的.emacs文件中的内容. (add-hook 'php-mode-hook (lambda () (c-set-style "bsd") (setq indent-tabs-mode t) (setq c-basic-offset 4) (setq tab-width 4) (c-set-offset 'arglist-close 'c-lineup-arglist-operators) (c-set-offset 'arglist-intro
这是我的.emacs文件中的内容.
(add-hook 'php-mode-hook
        (lambda ()
        (c-set-style "bsd")
        (setq indent-tabs-mode t)
        (setq c-basic-offset 4)
        (setq tab-width 4)
        (c-set-offset 'arglist-close 'c-lineup-arglist-operators)
        (c-set-offset 'arglist-intro '+)
        (c-set-offset 'arglist-cont-nonempty 'c-lineup-math)
        (c-set-offset 'case-label '+)       
        ))

我想将这些格式设置移动到项目特定目录.虽然我可以轻松地为setq语句(例如(setq indent-tabs-mode t))执行此操作,但我无法对以下函数调用执行此操作:(c-set-offset’arglist-intro’).

这是我放入.dir-locals.el的内容:

;;; Directory Local Variables
;;; See Info node `(emacs) Directory Variables' for more information.

    ((php-mode
        (c-set-style "bsd")
        (indent-tabs-mode . t)
        (c-basic-offset . 4)
        (tab-width . 4)
        (c-set-offset 'arglist-close 'c-lineup-arglist-operators)
        (c-set-offset 'arglist-intro 'c-basic-offset)
        (c-set-offset 'arglist-cont-nonempty 'c-lineup-math)
        (c-set-offset 'case-label '+)       
      ))

这有什么不对?

目录局部变量只是 – 变量;不是要评估的elisp表格.幸运的是,这是通过eval伪变量提供的:
((php-mode
  (indent-tabs-mode . t)
  (c-basic-offset . 4)
  (tab-width . 4)
  (eval . (progn
            (c-set-style "bsd")
            (c-set-offset 'arglist-close 'c-lineup-arglist-operators)
            (c-set-offset 'arglist-intro 'c-basic-offset)
            (c-set-offset 'arglist-cont-nonempty 'c-lineup-math)
            (c-set-offset 'case-label '+)))))

当遇到代码时,Emacs会要求您确认代码是否安全,如果您愿意,它会将其保存到init文件的custom-set-variables部分的safe-local-variable-values列表中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读