2011-03-09 44 views
1

我收集了文件my-python-setup.el中的emacs自定義列表。我如何確保emacs首先加載python-mode,然後只在編輯python文件時加載這個庫?如何在編輯python代碼時加載我的.el文件

我試圖把

(load-library "my-python-setup") 

在我.emacs文件,但加載這些自定義的各種文件。

這些自定義設置位於Python模式之上,auto-mode-alist的值當前爲("\\.py\\'" . python-mode)

回答

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) 

這是我個人的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) 
+0

請問,這不適合我,但使用eval-after-load工作。 (eval-after-load「python-mode」 '(progn ;;無論你需要做什麼,它只會在python-mode.el加載後執行 load-library「my-python-setup」 ))) – Schitti 2011-03-10 03:19:15

1

如果你只想在編輯Python代碼加載你的代碼,你可能要考慮堅持你的Lisp代碼在你自己的擴展python模式的主要模式中。

(define-derived-mode 'my-python-mode 'python-mode "MyPy" 
"A customized version of python-mode" 

... here goes your code ... 

) 

然後你必須配置的emacs通過調整auto-mode-alist加載'my-python-mode而不是python-mode

+0

我發現這是最好的方法。撫摸我的自我也有自己的模式:) – Schitti 2011-03-10 12:17:57

+0

我不知道當我提出這個答案時我在想什麼。 「加載後評估」絕對是標準(更好)的方法。 – Thomas 2013-03-22 14:44:35

相關問題