2012-07-17 93 views

回答

2

有很多方法可以做到這一點。

  • 類型apropos,然後pymacs。如果它找到這些符號,它就會被加載。

  • (需要「pymacs) - 如果它不返回錯誤,它裝載

  • ,如果你已經裝好了,叫(提供」 pymacs),以及可變負載歷史保持符號

還有其他的方法來改變它。

+2

你也可以調用require('require'pymacs nil'noerror)'。然後,如果庫無法加載而不是錯誤,則返回false。如果庫已經加載或成功加載,則返回非零。 – jpkotta 2012-07-17 22:08:06

3

M-x locate-library會告訴你emacs是否可以在load-path中找到該庫。如果它不返回任何內容,您可能需要首先編輯load-path

1

不知道你在談論ELPA包,但我有我的.emacs以下定義:

 
    (defun sh-elpa-ensure-package (name) 
     "Make sure that a particular package is installed; if not then 
    automatically download, compile and install it. 

    This is primarily used by sh-elpa-require to allow deployment of 
    the configuration to a new machine - packages will therefore be 
    downloaded on that fresh machine (following installation they are 
    automatically kept up to date by the package manager). 

    Use this as follows: 
    (sh-elpa-ensure-package 'org)" 
     (if (not (package-installed-p name)) 
      (package-install name))) 

    (defun sh-elpa-require (name) 
     "A replacement for the standard Emacs 'require' 
    function. This uses sh-elpa-require to download and install a 
    package if necessary prior to using the standard 'require' 
    function to import it. This is useful to allow the configuration 
    to just 'sh-elpa-require' a package and not have to bother 
    checking whether it has been installed yet." 
     (sh-elpa-ensure-package name) 
     (require name)) 

然後我就可以包括代碼,如我的.emacs啓動包下 - 如果它尚未安裝,那麼這將來自ELPA下載它,並「要求」之前字節編譯:

(sh-elpa-require 'pymacs) 

如果你只是在談論檢查是否包從elisp的安裝,那麼你也可以從上述代碼片段中挑選骨骼 - 請參閱(if (not (package-installed-p name))位。

+0

首先確保'(package-initialize)'已被調用。否則'(package-installed -p name)'返回'nil',用於安裝在〜/ .emacs.d/elpa /中的軟件包,這是相當緩衝的,因爲嘗試'(package-install name)'然後抱怨文件已經存在。 – 2013-03-20 02:28:33