2013-07-02 28 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