這裏是我的嘗試:如何只在linux中加載模塊?
(if (eq system-type 'gnu/linux)
(load "/usr/share/emacs/site-lisp/site-gentoo")
(require 'site-gentoo))
但不管怎麼說我收到錯誤的窗口:
/.emacs':
File error: Cannot open load file, site-gentoo
這裏是我的嘗試:如何只在linux中加載模塊?
(if (eq system-type 'gnu/linux)
(load "/usr/share/emacs/site-lisp/site-gentoo")
(require 'site-gentoo))
但不管怎麼說我收到錯誤的窗口:
/.emacs':
File error: Cannot open load file, site-gentoo
你的問題是你用if
的方式:它的文檔說,這是
(if COND THEN ELSE...)
即您的(require 'site-gentoo)
得到執行當且僅當它是而不是 GNU/Linux系統。
改爲使用when
,那應該做你想要的。
此外,實際上不需要同時使用load
和require
,它們的使用應該具有相同的結果。差異主要在於require
將搜索load-path
並且不再加載之前已經加載的內容。
它應該是:
(if (eq system-type 'gnu/linux)
(progn
(load "/usr/share/emacs/site-lisp/site-gentoo")
(require 'site-gentoo)))
或
(when (eq system-type 'gnu/linux)
(load "/usr/share/emacs/site-lisp/site-gentoo")
(require 'site-gentoo))
相反的(load "/usr/share/emacs/site-lisp/site-gentoo")
你應該加入一個包含裝載文件到load-path
文件夾:
(add-to-list 'load-path "/usr/share/emacs/site-lisp/")
這應該做的伎倆。 require
僅適用於load-path
,load
上的文件,另一方面只是將其作爲參數給出的lisp文件進行評估。
Rörd和Bozhidar Batsov已經提供瞭如何解決這個問題的答案,但只是爲了補充原始代碼失敗的原因。
(if COND THEN ELSE...)
只接受單個THEN
命令。爲了能夠在返回true時評估多個命令,必須將這些命令包裝在(progn BODY...)
中。
你的代碼是指出:
如果在Linux上:(load "/usr/share/emacs/site-lisp/site-gentoo")
如果沒有在Linux上:(require 'site-gentoo)
在(progn ...)
使用(when ...)
或包裹都將提供所需的解決方案。
謝謝:)更改爲何時 – Cynede