2013-07-02 26 views
11

我一直在試驗org-babel tutorial,它描述瞭如何將大部分emacs init.el文件放入組織文件中。然而,我想使用組織模式8(主要用於新的出口商),我在gnu emacs 24.3.1(用於windows),它帶有內置的org-mode 7.9,所以我安裝了組織模式從elpa package manager而不是使用內置版本。Emacs初始化爲org文件:我如何獲得org-mode的正確版本?

我的問題是,emacs加載了emacs自帶的組織模式,而不是我在elpa中安裝的組織模式。有沒有加載elpa組織模式的方法?

這裏是我的init.el,從org-babel教程修改爲指向(我認爲)我的組織模式分佈 - 但我的emacs-lisp知識很少,所以我不知道它在做什麼。

;;; From http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming 
;;; init.el --- Where all the magic begins 
;; 
;; This file loads Org-mode and then loads the rest of our Emacs initialization from Emacs lisp 
;; embedded in literate Org-mode files. 
;; Load up Org Mode and (now included) Org Babel for elisp embedded in Org Mode files 
(setq dotfiles-dir (file-name-directory (or (buffer-file-name) load-file-name))) 
(let* ((org-dir (expand-file-name 
      "elpa" (expand-file-name 
        "org-plus-contrib-20130624"))) 
    (org-contrib-dir (expand-file-name 
        "lisp" (expand-file-name 
          "contrib" (expand-file-name 
             ".." org-dir)))) 
     (load-path (append (list org-dir org-contrib-dir) 
         (or load-path nil)))) 
    ;; load up Org-mode and Org-babel 
    (require 'org-install) 
    (require 'ob-tangle)) 

;; load up all literate org-mode files in this directory 
(mapC#'org-babel-load-file (directory-files dotfiles-dir t "\\.org$")) 

;;; init.el ends here 

回答

8

在撥打org-babel-load-file或任何其他組織功能之前,請撥(package-initialize),您將獲得ELPA版本。

+1

實際上你必須確保'(package-initialize)'在任何調用任何具有自動載入的組織函數之前。這可能是'org-babel-load-file',但不能保證。 –

+0

這工作得很好。我把(package-initialize)放在init.el的開頭,並且加載了org-mode 8。 –

+0

@ JonathanLeech-Pepin:很好,更新。 – legoscia

1

卸載運組織模式和安裝開發版本這樣

(defun unload-org-mode() 
    (interactive) 
    (and (featurep 'org-agenda)(unload-feature 'org-agenda t)) 
    (and (featurep 'org-bbdb)(unload-feature 'org-bbdb t)) 
    (and (featurep 'org-bibtex)(unload-feature 'org-bibtex t)) 
    (and (featurep 'org-compat)(unload-feature 'org-compat t)) 
    (and (featurep 'org-exp)(unload-feature 'org-exp t)) 
    (and (featurep 'org-exp-blocks)(unload-feature 'org-exp-blocks t)) 
    (and (featurep 'org-faces)(unload-feature 'org-faces t)) 
    (and (featurep 'org-footnote)(unload-feature 'org-footnote t)) 
    (and (featurep 'org-gnus)(unload-feature 'org-gnus t)) 
    (and (featurep 'org-html)(unload-feature 'org-html t)) 
    (and (featurep 'org-info)(unload-feature 'org-info t)) 
    (and (featurep 'org-infojs)(unload-feature 'org-infojs t)) 
    (and (featurep 'org-irc)(unload-feature 'org-irc t)) 
    (and (featurep 'org-jsinfo)(unload-feature 'org-jsinfo t)) 
    (and (featurep 'org-list)(unload-feature 'org-list t)) 
    (and (featurep 'org-macs)(unload-feature 'org-macs t)) 
    (and (featurep 'org-mew)(unload-feature 'org-mew t)) 
    (and (featurep 'org-mhe)(unload-feature 'org-mhe t)) 
    (and (featurep 'org-rmail)(unload-feature 'org-rmail t)) 
    (and (featurep 'org-src)(unload-feature 'org-src t)) 
    (and (featurep 'org-vm)(unload-feature 'org-vm t)) 
    (and (featurep 'org-w3m)(unload-feature 'org-w3m t)) 
    (and (featurep 'org-wl)(unload-feature 'org-wl t))) 

(defun ar-load-PATH-TO-NEW-org-mode() 
    (interactive) 
    (unload-org-mode) 
    (find-file "~/PATH-TO-NEW-org-mode/lisp/ob-python.el") 
    (add-to-list 'load-path "~/PATH-TO-NEW-org-mode") 
    (add-to-list 'load-path "~/PATH-TO-NEW-org-mode/lisp") 
    (load "~/PATH-TO-NEW-org-mode/lisp/ob-comint.el" nil t) 
    (load "~/PATH-TO-NEW-org-mode/lisp/ob-emacs-lisp.el" nil t) 
    (load "~/PATH-TO-NEW-org-mode/lisp/org.el" nil t) 
    (load "~/PATH-TO-NEW-org-mode/lisp/ob-eval.el" nil t) 
    (load "~/PATH-TO-NEW-org-mode/lisp/ob.el" nil t) 
    (load "~/PATH-TO-NEW-org-mode/lisp/ob-python.el") 
    ;; (load "~/PATH-TO-NEW-org-mode/testing/org-test-ob-consts.el" nil t) 
    ;; (load "~/PATH-TO-NEW-org-mode/testing/org-test.el" nil t) 
    (load-this-directory "~/PATH-TO-NEW-org-mode/lisp") 
    (org-babel-do-load-languages 
    'org-babel-load-languages 
    '(
    (sh . t) 
    (python . t) 
    (emacs-lisp . t) 
    (perl . t) 
    (R . t) 
    )) 
) 

(ar-load-PATH-TO-NEW-org-mode) 

與您的版本whished所在的目錄替換PATH-TO-NEW-org-mode

2

我配置包存儲庫在基於有機的配置文件一樣,所以,要調整的負載路徑我有這個在我init.el裝載組織之前:

;; remove org-mode shipped with emacs from the load-path 
(setq custom-org-path (car (file-expand-wildcards 
          (concat my-init-dir "elpa/org-plus-contrib-20*")))) 
(when custom-org-path 
    (setq load-path (remove-if (lambda (x) (string-match-p "org$" x)) load-path)) 

    (add-to-list 'load-path custom-org-path)) 
2

雖然已經解決,只是有點關係,我以爲我會提供這對於那些誰不使用基於包的解決方案,但需要卸載之類的東西組織和cedet /語義等機智hout重啓emacs。

一般來說,根據起始名稱regexp卸載一組功能,我會做這樣的事情 - 這似乎比來自Andreas的答案的硬編碼版本更完整,似乎並未涵蓋所有已加載的組織特徵(至少在我的情況下)。

load-history是文件的海量assoc命令列表 - >請求數,提供,defuns,...

(mapc 
#'(lambda (f) (and (featurep f) (unload-feature f t))) 
(loop for file-syms in load-history 
     for prov = (assoc 'provide file-syms) 
     with features 
     if (and prov (string-match "^org" (symbol-name (cdr prov)))) 
     collect (cdr prov) into features 
     finally return features)) 

更換正則表達式"^org",以滿足您的需求,或者去野外,使之成爲defun定義。

這也可以修改,以從load-history中抓取所有已加載的組織特徵,卸載它們,添加新的加載路徑,並從新位置重新加載這些相同的特徵。

+0

謝謝!深知我的做法不是那麼聰明:) –

+0

恰恰相反!你的方法和答案是我到目前爲止=) – assem