nothing to say.. @caizhiyuannn@gmail.com
Use-package 是一个宏, 它能让你将一个包的 require 和它的相关的初始化等配置组织 在一起, 避免对同一个包的配置代码散落在不同的文件中.
简单的声明 use-package 的例子
;; This is only needed once, near the top of the file
(eval-when-compile
;; Following line is not needed if use-package.el is in ~/.emacs.d
(add-to-list 'load-path "<path where use-package is installed>")
(require 'use-package))
(use-package foo)
*Messages*
进行告警:init
关键字在包加载前执行需要的指令,它接受一个或多个参数,直到下一个关键字的出现 (use-package foo
:init
(setq foo-variable t))
:config
关键字在包加载后执行需要的指令,在懒加载的情况(autoloads),会推迟到自动加载之后。可以和 :init
一起使用 (use-package foo
:init
(setq foo-variable t)
:config
(foo-mode 1))
:commands
关键字可以生成autoload方式进行加载, :bind
关键字来绑定按键, :map
指定map模式来绑定 (use-package color-moccur
:commands (isearch-moccur isearch-all)
:bind (("M-s O" . moccur)
:map isearch-mode-map
("M-o" . isearch-moccur)
("M-O" . isearch-moccur-all))
:init
(setq isearch-lazy-highlight t)
:config
(use-package moccur-edit))
(use-package ace-jump-mode
:bind ("C-." . ace-jump-mode))
:bind
主要做两件事情:
- 为ace-jump-mode 创建自动加载(autoload),推迟加载指定需要使用的时候。
- 为ace-jump-mode 绑定按键 C-. 可以通过 M-x describe-personal-keybindings 来查看所有的按键绑定
下面例子与上面行为一直:
(use-package ace-jump-mode
:commands ace-jump-mode
:init
(bind-key "C-." 'ace-jump-mode))
##