Skip to content

Latest commit

 

History

History
177 lines (141 loc) · 8.08 KB

starter-kit.md

File metadata and controls

177 lines (141 loc) · 8.08 KB

About Start kit

Start kit是来源于一个通过文本方式编程的想法,它将代码与相应的文字描述,通过写作的方式进行了整合,以达到自动生成可用代码的工具。详细可参考地址:https://github.com/eschulte/emacs24-starter-kit Start kit的使用需要一些工程初使配置,而初使配置即在此文件中,文件中增加了 starter-kit-load 方法,通过此方法即可让Emacs直接加载 .org 文件,并自动运行。它的实现原理实际是采用了 org-babel 这个技术,通过 org-babel 可以实现不同的语言代码写在同一个文件中,并互不影响的执行。详细可参考地址:http://orgmode.org/worg/org-contrib/babel/intro.html

Starter-kit base

  • Load path etc.

    (let ((elisp-dir (expand-file-name "src" starter-kit-dir)))
      ;; add the src directory to the load path
      (add-to-list 'load-path elisp-dir)
      ;; load specific files
      (when (file-exists-p elisp-dir)
        (let ((default-directory elisp-dir))
          (normal-top-level-add-subdirs-to-load-path))))
    
    ;; defuns, utilities for whole configuration
    (setq autoload-file (concat starter-kit-dir "09-defuns/init-defuns.el"))
    (setq package-user-dir (concat starter-kit-dir "elpa"))
    (setq custom-file (concat starter-kit-dir "custom.el"))
    
  • Function to check if a packages exist in the load path. This may be used to preempt the installation of ELPA versions of packages whose source may already be found in the load path.

    (defun starter-kit-loadable-p (package)
      "Check if PACKAGE is loadable from a directory in `load-path'."
      (let ((load-file (concat (symbol-name package) ".el")))
        (catch 'file-found
          (dolist (dir load-path)
            (let ((path (expand-file-name load-file dir)))
              (when (file-exists-p path)
                (throw 'file-found path)))))))
    
  • ELPA archive repositories and two packages to install by default.

    (setq package-archives
          '(("gnu"         . "http://elpa.gnu.org/packages/")
            ("org"         . "http://orgmode.org/elpa/")
            ("melpa"       . "http://melpa.org/packages/")
            ("marmalade"   . "http://marmalade-repo.org/packages/")))
    (package-initialize)
    
    (defvar starter-kit-packages nil
      "Libraries that should be installed by default (currently none).")
    
    (defun starter-kit-install-if-needed (&rest packages)
      "Install PACKAGES using ELPA if they are not loadable or installed locally."
      (when packages
        (unless package-archive-contents
          (package-refresh-contents))
        (dolist (package packages)
          (unless (or (starter-kit-loadable-p package)
                      (package-installed-p package))
            (package-install package)))))
    
  • Function for loading other parts of the starter kit

    (defun starter-kit-load (file &optional header-or-tag)
      "Load configuration from other starter-kit-*.org files.
    If the optional argument is the id of a subtree then only
    configuration from within that subtree will be loaded.  If it is
    not an id then it will be interpreted as a tag, and only subtrees
    marked with the given tag will be loaded.
    
    For example, to load all of starter-kit-lisp.org simply
    add (starter-kit-load \"lisp\") to your configuration.
    
    To load only the 'window-system' config from
    starter-kit-misc-recommended.org add
     (starter-kit-load \"misc-recommended\" \"window-system\")
    to your configuration."
      (let ((file (expand-file-name (if (string-match "init-.+\.org" file)
                                        file
                                      (format "starter-kit-%s.org" file))
                                    starter-kit-dir)))
        (org-babel-load-file
         (if header-or-tag
             (let* ((base (file-name-nondirectory file))
                    (dir  (file-name-directory file))
                    (partial-file (expand-file-name
                                   (concat "." (file-name-sans-extension base)
                                           ".part." header-or-tag ".org")
                                   dir)))
               (unless (file-exists-p partial-file)
                 (with-temp-file partial-file
                   (insert
                    (with-temp-buffer
                      (insert-file-contents file)
                      (save-excursion
                        (condition-case nil ;; collect as a header
                            (progn
                              (org-link-search (concat"#"header-or-tag))
                              (org-narrow-to-subtree)
                              (buffer-string))
                          (error ;; collect all entries with as tags
                           (let (body)
                             (org-map-entries
                              (lambda ()
                                (save-restriction
                                  (org-narrow-to-subtree)
                                  (setq body (concat body "\n" (buffer-string)))))
                              header-or-tag)
                             body))))))))
               partial-file)
           file))))
    

DONE Add package source and package management tools

在Emacs第一次初使化打开时,需要初使化reporitories和自动包安装工具,这里引用了Starter-kit中的的 (starter-kit-insall-if-needed) 来进行包的自动检查和安装,这里用它来自动安装 (use-package) ,从而后面再就只使用 (use-package) 来进行包的安装和配置相关,以规范加载代码和提升包的加载速度。

(use-package), which can be using for package loading, check detail at: https://github.com/jwiegley/use-package

;; 初使安装use-package

(defvar use-package-verbose t)

(starter-kit-install-if-needed 'use-package)

加载相应配置文件

  • 常用工具函数集合

    (starter-kit-load "09-defuns/init-defuns.org")
    
  • Emacs基础编辑提升

    (starter-kit-load "02-base-using/init-base-using.org")
    ;; change a theme
    (starter-kit-load "02-base-using/init-theme-changing.org")
    ;; 编辑功能提升
    (starter-kit-load "02-base-using/init-editing-upgrade.org")
    ;; 搜索功能提升
    (starter-kit-load "02-base-using/init-ace-isearch.org")
    
  • 日常工作使用Emacs

    (starter-kit-load "03-editing/init-daily-using.org") 
    (starter-kit-load "03-editing/init-org-mode.org")
    (starter-kit-load "03-editing/init-markdown-mode.org")
    (starter-kit-load "03-editing/init-gtd-management.org")
    (starter-kit-load "03-editing/init-projectile-management.org")
    (starter-kit-load "03-editing/init-mu4e.org")
    (starter-kit-load "03-editing/init-magit.org")
    ;; 添加org导出jekyll支持
    (starter-kit-load "03-editing/init-org-jekyll.org")
    
  • 应用开发编辑提升

    (starter-kit-load "04-development/init-java-development.org")
    
  • 资源索引

    (starter-kit-load "10-index/init-index.org")
    

配置默认样式

;;(dark)
(mu4e)