子龙山人Learn Emacs in 21 Days: day 3 学习笔记
Youtube
youku
用git 来管理emacs配置文件
外部程序修改init.el 自动重新加载
(global-auto-revert-mode t)
禁止auto save
(setq auto-save-default nil)
光标自动出现在新的窗口
(require 'popwin)
(popwin-mode t)
autoload
;;;###autoload
(define-globalized-minor-mode global-company-mode company-mode company-mode-on)
(defun company-mode-on ()
(when (and (not (or noninteractive (eq (aref (buffer-name) 0) ?\s)))
(cond ((eq company-global-modes t) t)
((eq (car-safe company-global-modes) 'not) (not (memq major-mode (cdr company-global-modes))))
(t (memq major-mode company-global-modes))))
(company-mode 1)))
(defsubst company-assert-enabled ()
(unless company-mode
(company-uninstall-map)
(user-error "Company not enabled")))
(package-initialize)
company-autoloads.el
扫描所有的魔法注释生成autloads.el 可以不require 调用
features, provide and require, autoload
Emacs Lisp: require, load, load-file, autoload, feature, Explained
abbrev-mode
(abbrev-mode t)
(define-abbrev-table 'global-abbrev-table '(
;; signature
("8zl" "zilongshanren")
;; emacs regex
))
输入8zl 后按空格会补全
init-packages.el
经过整理后的init-packages.el 文件
(require 'cl)
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list 'package-archives '("gnu" . "http://elpa.emacs-china.org/gnu/") t)
(add-to-list 'package-archives '("melpa" . "http://elpa.emacs-china.org/melpa/") t)
)
;;add whatever packages you want here
(defvar sandwich/packages '(
company
monokai-theme
hungry-delete
swiper
counsel
smartparens
js2-mode
nodejs-repl
exec-path-from-shell
popwin
) "Default packages")
(setq package-selected-packages sandwich/packages)
(defun sandwich/packages-installed-p ()
(loop for pkg in sandwich/packages
when (not (package-installed-p pkg)) do (return nil)
finally (return t)))
(unless (sandwich/packages-installed-p)
(message "%s" "Refreshing package database...")
(package-refresh-contents)
(dolist (pkg sandwich/packages)
(when (not (package-installed-p pkg))
(package-install pkg))))
;;let emacs could find the excuable
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize))
(global-hungry-delete-mode)
;;(add-hook 'emacs-lisp-mode-hook 'smartparens-mode)
(smartparens-global-mode t)
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
;; config js2-mode for js file
(setq auto-mode-alist
(append
'(("\\.js\\'" . js2-mode))
auto-mode-alist))
(global-company-mode t)
(load-theme 'monokai t)
(require 'popwin)
(popwin-mode t)
(provide 'init-packages)
init-ui.el
经过整理后的init-ui.el 文件
(tool-bar-mode -1)
(scroll-bar-mode -1)
(setq inhibit-splash-screen t)
(setq-default cursor-type 'bar)
(setq initial-frame-alist (quote ((fullscreen . maximized))))
(global-hl-line-mode t)
(provide 'init-ui)
init-better-defaults.el
经过整理后的init-better-defaults.el 文件
(setq ring-bell-function 'ignore)
(global-auto-revert-mode t)
(global-linum-mode t)
(abbrev-mode t)
(define-abbrev-table 'global-abbrev-table '(
;; signature
("8zl" "zilongshanren")
;; emacs regex
))
(setq make-backup-files nil)
(setq auto-save-default nil)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(add-hook 'emacs-lisp-mode-hook 'show-paren-mode)
(electric-indent-mode t)
(delete-selection-mode t)
(provide 'init-better-defaults)
init-keybindings.el
经过整理后的init-keybindings.el 文件
(global-set-key "\C-s" 'swiper)
(global-set-key (kbd "C-c C-r") 'ivyq-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "C-h f") 'counsel-describe-function)
(global-set-key (kbd "C-h v") 'counsel-describe-variable)
(global-set-key (kbd "<f2>") 'open-my-init-file)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
(global-set-key (kbd "C-h C-f") 'find-function)
(global-set-key (kbd "C-h C-v") 'find-variable)
(global-set-key (kbd "C-h C-k") 'find-function-on-key)
(global-set-key (kbd "C-c p f") 'counsel-git)
(global-set-key (kbd "C-c a") 'org-agenda)
(provide 'init-keybindings)
(global-set-key (kbd “C-c p f”) ‘counsel-git)
利用 counsel-git 来打开文件
custom.el
经过整理后的custom.el 文件
((custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(company-idle-delay 0.1)
'(company-minimum-prefix-length 1))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
init-org.el
经过整理后的init-org.el 文件
(require 'org)
(setq org-src-fontify-natively t)
(setq org-agenda-files '("~/org"))
(provide 'init-org)
init.el
经过整理后的init.el 文件
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
(add-to-list 'load-path "./.emacs.d/lisp/")
(defun open-my-init-file()
(interactive)
(find-file "~/.emacs.d/init.el"))
(require 'init-packages)
(require 'init-ui)
(require 'init-better-defaults)
(require 'init-keybindings)
(require 'init-org)
(setq custom-file (expand-file-name "lisp/custom.el" user-emacs-directory))
(load-file custom-file)
主要require 各个init 文件,并把通过customize-group 配置的参数写在custom.el