duyanning avatar duyanning committed f9cd3a8

解决自己下载的包跟elpa管理的包共存的问题

Comments (0)

Files changed (1)

 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  以下是实现部分  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+;; 为了加快启动速度,注释掉,需要时再通过C-x C-e执行吧
+;; (require 'package)
+;; (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
+
+;; 确保在配置各个包之前先加载这些包
+(setq package-enable-at-startup nil)
+(package-initialize)
+
 ;; 程序主入口(main entry)在本文件最后
 
 
     (add-to-list 'load-path (file-name-directory dir-or-file-path))))
 
 
-(defun add-package (name dir-or-file-path)
-  (if (not (file-exists-p dir-or-file-path))
-      (progn
-        (message "no %s" name)
-        nil)
-    (add-to-load-path dir-or-file-path)
-    t)
+;; elpa中的包优先,然后是自己下载的包(这个顺序好吗?)
+;; elpa管理下的包地位仅次于built-in的包,可看作emacs的一部分。
+;; 如果该包已经通过elpa安装并加载了,啥也不用做
+;; 否则检测该包是否存在,若在就添加到load-path中,否则输出一行信息
+(defun add-package (package dir-or-file-path)
+  (cond ((package-installed-p package) t)
+        ((file-exists-p dir-or-file-path) (add-to-load-path dir-or-file-path) t)
+        (t (message "no %s" (symbol-name package)) nil))
   )
 
 
 (defun load-term-settings ()
   (load-linux-common-settings))
 
+  ;; (when (file-exists-p org-path)
+  ;;   (add-to-list 'load-path (concat org-path "lisp"))
+  ;;   (add-to-list 'load-path (concat org-path "contrib/lisp")))
+
 
 ;;;; 一次性的设置(以configure打头)
 (defun configure-org-mode ()
-  (when (file-exists-p org-path)
-    (add-to-list 'load-path (concat org-path "lisp"))
-    (add-to-list 'load-path (concat org-path "contrib/lisp")))
-  (setq org-replace-disputed-keys t)
-  (when (file-exists-p org-path)
-    (require 'org-install))
+  (when (add-package 'org (concat org-path "lisp"))
+    (add-package 'org-plus-contrib (concat org-path "contrib/lisp"))
 
-  (global-set-key (kbd "C-c l") 'org-store-link)
-  (global-set-key (kbd "C-c c") 'org-capture)
-  (global-set-key (kbd "C-c a") 'org-agenda)
-  (global-set-key (kbd "C-c b") 'org-iswitchb)
+    (setq org-replace-disputed-keys t)
 
-  ;; Setting up Remember for Org
-  (org-remember-insinuate)
-  (setq org-directory "~/orgfiles/")
-  (setq org-default-notes-file (concat org-directory "notes.org"))
-  (define-key global-map "\C-cr" 'org-remember)
+    ;; (when (file-exists-p org-path)
+    ;;   (require 'org-install))
 
+    (global-set-key (kbd "C-c l") 'org-store-link)
+    (global-set-key (kbd "C-c c") 'org-capture)
+    (global-set-key (kbd "C-c a") 'org-agenda)
+    (global-set-key (kbd "C-c b") 'org-iswitchb)
 
-  (add-to-list 'auto-mode-alist '("\\.txt\\'" . org-mode))
-  (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
-  ;;(add-to-list 'auto-mode-alist '("\\.txt\\'" . orgtbl-mode))
-  ;; (add-to-list 'auto-mode-alist '("\\.txt\\'" . orgstruct-mode))
-  ;; (add-to-list 'auto-mode-alist '("\\.txt\\'" . orgstruct++-mode))
+    ;; Setting up Remember for Org
+    (org-remember-insinuate)
+    (setq org-directory "~/orgfiles/")
+    (setq org-default-notes-file (concat org-directory "notes.org"))
+    (define-key global-map "\C-cr" 'org-remember)
 
-  ;; (global-set-key "\C-c L" 'org-insert-link-global)
-  ;; (global-set-key "\C-c o" 'org-open-at-point-global)
 
+    (add-to-list 'auto-mode-alist '("\\.txt\\'" . org-mode))
+    (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
+    ;;(add-to-list 'auto-mode-alist '("\\.txt\\'" . orgtbl-mode))
+    ;; (add-to-list 'auto-mode-alist '("\\.txt\\'" . orgstruct-mode))
+    ;; (add-to-list 'auto-mode-alist '("\\.txt\\'" . orgstruct++-mode))
 
+    ;; (global-set-key "\C-c L" 'org-insert-link-global)
+    ;; (global-set-key "\C-c o" 'org-open-at-point-global)
 
-  (setq org-src-fontify-natively t)
 
-  (add-hook 'org-mode-hook 'tweak-org-mode)
 
-  ;; (add-to-list 'load-path "~/org-7.5/contrib/lisp")
-  ;; (require 'org-toc)
-  ;; (global-set-key "\C-cs" 'org-toc-show)
-  (setq org-ctrl-k-protect-subtree 'error)
-  (require 'doc-struct)
+    (setq org-src-fontify-natively t)
 
+    (add-hook 'org-mode-hook 'tweak-org-mode)
+
+    ;; (add-to-list 'load-path "~/org-7.5/contrib/lisp")
+    ;; (require 'org-toc)
+    ;; (global-set-key "\C-cs" 'org-toc-show)
+    (setq org-ctrl-k-protect-subtree 'error)
+    (require 'doc-struct)
+
+    )
   )
 
 
 
 
 (defun configure-auto-complete ()
-  (when (add-package "auto-complete" auto-complete-path)
+  (when (add-package 'auto-complete auto-complete-path)
     
     
     (require 'auto-complete-config)
 
 
 (defun configure-yasnippet ()
-  (when (add-package "yasnippet" yasnippet-path)
+  (when (add-package 'yasnippet yasnippet-path)
     (require 'yasnippet)
     (yas/global-mode 1)
     )
 ;;         (bar a)
 ;;       (qux 2))))
 (defun configure-paredit ()
-  (when (add-package "paredit" paredit-path)
+  (when (add-package 'paredit paredit-path)
     (autoload 'paredit-mode "paredit"
       "Minor mode for pseudo-structurally editing Lisp code." t))
   )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.