如何在编辑python代码时加载我的.el文件

Sch*_*tti 1 python emacs

我收集了一个文件中的emacs自定义列表my-python-setup.el.我怎样才能确保emacs首先加载python-mode然后只在我编辑python文件时加载这个库?

我试过试试

(load-library "my-python-setup")
Run Code Online (Sandbox Code Playgroud)

在我的.emacs文件中,但是会为所有类型的文件加载这些自定义项.

这些自定义位于python-mode之上,auto-mode-alist当前值为("\\.py\\'" . python-mode).

Wil*_*hen 5

我绝不是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)
Run Code Online (Sandbox Code Playgroud)

这是我个人的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)
Run Code Online (Sandbox Code Playgroud)