Commits

duyanning committed dfc0f0a

继续用add-package替换

Comments (0)

Files changed (1)

     (add-to-list 'load-path (file-name-directory dir-or-file-path))))
 
 
-;; elpa中的包优先,然后是自己下载的包(这个顺序好吗?)
+;; 自己下载的包优先于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))
+  (cond ((file-exists-p dir-or-file-path) (add-to-load-path dir-or-file-path) t)
+        ((package-installed-p package) t)
+        (t (message "no %s" (symbol-name package)) nil)
+        )
   )
 
 
 
 (defun configure-auto-complete ()
   (when (add-package 'auto-complete auto-complete-path)
-    
-    
     (require 'auto-complete-config)
     (add-to-list 'ac-dictionary-directories (concat auto-complete-path "ac-dict"))
     (ac-config-default)
 
 
 (defun configure-emacs-lisp-mode ()
+  (message "configure-emacs-lisp-mode")
   (add-hook 'emacs-lisp-mode-hook 'tweak-emacs-lisp-mode))
 
 
 
 
 (defun configure-ntcmd-mode ()
-  (if (not (file-exists-p ntcmd-path))
-      (message "no ntcmd-mode")
-    (add-to-load-path ntcmd-path)
+  (when (add-package 'ntcmd ntcmd-path)
     (add-to-list 'auto-mode-alist '("\\.bat\\'" . ntcmd-mode))
-    (autoload 'ntcmd-mode "ntcmd" "ntcmd-mode" t)))
+    (autoload 'ntcmd-mode "ntcmd" "ntcmd-mode" t))
+  )
 
 
 (defun configure-powershell ()
 
 
 (defun configure-markdown-mode ()
-  (if (not (file-exists-p markdown-mode-path))
-      (message "no markdown-mode")
-    (add-to-load-path markdown-mode-path)
+  (when (add-package 'markdown-mode markdown-mode-path)
     (autoload 'markdown-mode "markdown-mode.el" "Major mode for editing Markdown files" t)
     (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
-    (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))))
+    (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode)))
+  )
 
 
 (defun configure-yaml-mode ()
 
 
 (defun configure-ace-jump-mode ()
-  (if (not (file-exists-p ace-jump-mode-path))
-      (message "no ace-jump-mode")
+  (when (add-package 'ace-jump-mode ace-jump-mode-path)
     (require 'ace-jump-mode)
-    (define-key global-map (kbd "C-c SPC") 'ace-jump-mode)))
+    (define-key global-map (kbd "C-c SPC") 'ace-jump-mode))
+  )
 
 ;; 例子
 ;; (defun foo ()
 
 
 (defun tweak-emacs-lisp-mode ()
+  (message "tweak-emacs-lisp-mode")
   (define-key emacs-lisp-mode-map "\C-c\C-c" 'comment-region)
   (ws-mode)                             ; 中文分词
 
-  (when (file-exists-p paredit-path)
+  (when (add-package 'paredit paredit-path)
     (paredit-mode +1)  
     (pmh-mode t)
     ;; 在汉字中启用ws-mode,在英文中启用paredit-mode