我收集了一个文件my-python-setup.el中的emacs定制列表。如何确保emacs将首先加载python-mode,然后仅在编辑python文件时才加载此库?
我试着把它
(load-library "my-python-setup")在我的.emacs文件中,但是这会为所有类型的文件加载这些定制。
这些定制是在python-mode之上的,auto-mode-alist的当前值是("\\.py\\'" . python-mode)。
发布于 2011-03-10 07:26:04
我绝对不是Emacs专家,但我认为你可以坚持添加一个python-mode-hook函数并在其中加载你的库。类似于:
;; define your hook function
(defun python-mode-setup ()
(message "Custom python hook run")
(load-library "my-python-setup"))
;; install your hook so it is called when python-mode is invoked
(add-hook 'python-mode-hook 'python-mode-setup)下面是我的个人python-mode-hook,例如:
(defun python-mode-setup ()
(setq python-indent-offset 4
python-indent 4
;; turn off indentation guessing in various python modes
python-guess-indent nil
python-indent-guess-indent-offset nil
py-smart-indentation nil
;; fix mark-defun in new python.el
python-use-beginning-of-innermost-defun t))
(add-hook 'python-mode-hook 'python-mode-setup)发布于 2011-03-10 16:12:04
如果你只想在编辑python代码时加载你的代码,你可以考虑把你的lisp代码放在你自己的主模式中,它扩展了python模式。
(define-derived-mode 'my-python-mode 'python-mode "MyPy"
"A customized version of python-mode"
... here goes your code ...
)然后,您必须通过调整auto-mode-alist将emacs配置为加载'my-python-mode而不是python-mode。
https://stackoverflow.com/questions/5253482
复制相似问题