January 4, 2021
By: Kevin

建议的emacs配置

在purcell配置的基础上修改, 增加了若干个人配置, 我会不断与purcell的库同步, 推荐作为默认配置, 大家可以在此基础上定制

一方面从purcell的repo做获得更新, 本地自己的配置修改合并后push到自己的远端repo.

   +--------------------+      +--------------------+
   |  purcell git       |      |     lizy git       |
   +---------+----------+      +---------+----------+
             | git fetch purcell         |  git fetch lizy
             | git rebase purcell/master |  git rebase lizy/master
             |                           |  git push
             |                           |
   +---------+---------------------------+----------+
   |            local git repo                      |
   +------------------------------------------------+

适用于emacs的26, 27版本, 在mac上, 建议使用 emacsplus 的版本, 可以直接brew安装.

本人的emacs配置的github的地址, 可以作为你的的基础配置, 用上面图表中的方式做版本管理和同步.

推荐使用这个配置, 使我们有统一的编辑体验.

git clone https://github.com/zhaoyul/.emacs.d ~/.emacs.d 

个人修改都放到init-local.el, 增加的配置都做了解释. 主要增加的功能:

  1. org文件导出为markdown
  2. org文件导出为PPT(reveal.js)
  3. 默认安装cnfonts
  4. 标点符号全角自动映射为半角
  5. 开启换页线
  6. 增加org的bulletin
  7. 使用clj-kondo做clojure代码检查

依赖几个外部的工具, mac上均可以用brew 安装(包括上面提到的emacsplus), windows可以使用scoop作为包管理工具, 参考windows配置

  1. brew install pandoc
  2. brew install emacs-plus@27
  3. brew install ag
  4. brew install borkdude/brew/clj-kondo
;; 中文对齐
(require-package 'cnfonts)
;; 我喜欢undotree
(require-package 'undo-tree)
(global-undo-tree-mode)

;; 分享快捷键
(require-package 'keycast)

;; 使用clj-kondo来做clj/cljc/cljs的语法检查, 需要安装clj-kondo
(require-package 'flycheck-clj-kondo)
(dolist (checker '(clj-kondo-clj clj-kondo-cljs clj-kondo-cljc clj-kondo-edn))
  (setq flycheck-checkers (cons checker (delq checker flycheck-checkers))))

;; 开启换页线
(global-page-break-lines-mode)

(add-hook 'clojure-mode-hook
          (lambda ()
            (page-break-lines-mode)))
(add-hook 'clojurescript-mode-hook
          (lambda ()
            (page-break-lines-mode)))

;; 80个字符处放置竖线
(setq-default fill-column 80)

;; 使用cua做矩形区域编辑
(cua-mode 1)
(setq cua-enable-cua-keys nil)
(global-set-key
 (kbd "<C-return>")
 'cua-set-rectangle-mark)

;; org文件生成reveal.js PPT
(require-package 'ox-reveal)
(load-library "ox-reveal")


;; 需要expand-region
(require-package 'expand-region)
(global-set-key (kbd "C-=") 'er/expand-region)

;; 映射全角字符到半角字符
(let (
      ($replacePairs
       [
        ["," ","]
        ["。" "."]
        [";" ";"]
        [":" ":"]
        ["【" "["]
        ["】" "]"]
        ["(" "("]
        [")" ")"]
        ["!" "!"]
        ["、" "\\"]
        ["/" "/"]
        ["《" "<"]
        ["》" ">"]
        ["‘" "'"]
        ["’" "'"]
        ["“" "\""]
        ["”" "\""]
        ]
       ))
  (mapcar (lambda(x) (define-key key-translation-map
                       (kbd (elt x 0)) (kbd (elt x 1)))) $replacePairs))


;; 使用org-bullets
(require-package 'org-bullets)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))


;; 使用pandoc把org文件转为md, 需要安装pandoc
(require-package 'ox-pandoc)
(load-library "ox-pandoc")

;; counsel & ivy, 管理自动完成和搜索
(require-package 'counsel)
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
(global-set-key (kbd "C-s") 'swiper-isearch)
;;(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "M-y") 'counsel-yank-pop)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> l") 'counsel-find-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "<f2> j") 'counsel-set-variable)
(global-set-key (kbd "C-x b") 'ivy-switch-buffer)
(global-set-key (kbd "C-c v") 'ivy-push-view)
(global-set-key (kbd "C-c V") 'ivy-pop-view)

(global-set-key (kbd "C-c c") 'counsel-compile)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c j") 'counsel-git-grep)
(global-set-key (kbd "C-c L") 'counsel-git-log)
(global-set-key (kbd "C-c k") 'counsel-rg)
(global-set-key (kbd "C-c m") 'counsel-linux-app)
(global-set-key (kbd "C-c n") 'counsel-fzf)
(global-set-key (kbd "C-x l") 'counsel-locate)
(global-set-key (kbd "C-c J") 'counsel-file-jump)
(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
(global-set-key (kbd "C-c w") 'counsel-wmctrl)

(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "C-c b") 'counsel-bookmark)
(global-set-key (kbd "C-c d") 'counsel-descbinds)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c o") 'counsel-outline)
(global-set-key (kbd "C-c t") 'counsel-load-theme)
(global-set-key (kbd "C-c F") 'counsel-org-file)

;; eval ditaa block in org file
(defun my-org-confirm-babel-evaluate (lang body)
  (not (string= lang "ditaa")))  ;don't ask for ditaa
(setq org-confirm-babel-evaluate #'my-org-confirm-babel-evaluate)

(provide 'init-locales)
;;; init-locales.el ends here
Tags: emacs