配置原则: 如无必要, 勿增实体
配置的每行代码争取做到 减无可减
的状态, 增加的每一行都有其原因。
- 安装 Doom
git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d ~/.emacs.d/bin/doom install
- 下载本配置文件到本地
git clone [email protected]:lijigang/emacs.d.git
- Tangle 代码生成配置
;; emacs readme.org M-x: org-babel-tangle
;;; init.el -*- lexical-binding: t; -*-
(doom!
:completion
(vertico +icons)
:ui
doom ; what makes DOOM look the way it does
modeline
hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW
(ligatures +extra)
ophints ; highlight the region an operation acts on
(popup
+all
+defaults) ; tame sudden yet inevitable temporary windows
unicode
zen ; distraction-free coding or writing
:editor
(evil +everywhere) ; come to the dark side, we have cookies
file-templates ; auto-snippets for empty files
fold ; (nigh) universal code folding
(format +onsave) ; automated prettiness
snippets ; my elves. They type so I don't have to
word-wrap
:emacs
;; electric ; smarter, keyword-based electric-indent
(ibuffer +icons) ; interactive buffer management
undo ; persistent, smarter undo for your inevitable mistakes
:checkers
syntax ; tasing you for every semicolon you forget
:tools
(eval +overlay) ; run code, run (also, repls)
lookup ; navigate your code and its documentation
magit ; a git porcelain for Emacs
pdf ; pdf enhancements
:os
(:if IS-MAC macos) ; improve compatibility with macOS
:lang
emacs-lisp ; drown in parentheses
latex ; writing papers in Emacs has never been so fun
markdown
(org ; organize your plain life in plain text
+dragndrop
+gnuplot
+hugo
+pandoc
+pretty
+present)
plantuml ; diagrams for confusing people more
rest ; for use restclient
sh ; she sells {ba,z,fi}sh shells on the C xor
yaml ; JSON, but readable
:config
(default +bindings +smartparens))
;;; $DOOMDIR/packages.el --- -*- no-byte-compile: t; -*-
;; 快速跳转到任意位置, 通过汉字拼音的方式
(package! ace-pinyin
:recipe (:host github :repo "cute-jumper/ace-pinyin"))
(package! denote)
(package! consult-notes)
(package! denote-explore)
;; 导出时支持src block 语法高亮
(package! engrave-faces
:recipe (:host github :repo "tecosaur/engrave-faces"))
(package! gptel)
(package! imenu-list)
(package! olivetti)
;; 鼠标放到加粗字符上, 可编辑修饰符, 离开即显示加粗后的效果
(package! org-appear
:recipe (:host github :repo "awth13/org-appear"))
;; 好用的统计字符包
(package! org-count-words
:recipe (:host github :repo "Elilif/org-count-words"))
;; 在Orgmode 文件中插入图片
(package! org-download)
(package! org-fragtog)
(package! org-imenu
:recipe (:host github :repo "rougier/org-imenu"))
;; 便捷插入网页到org 文件
(package! org-web-tools)
;; 中英文字符之间自动插入空格, 增加可阅读性
(package! pangu-spacing)
;; 每个标识符显示一个颜色, 花里胡哨的开始
(package! rainbow-identifiers)
;; 在Emacs 中使用rime, 减少切换中英文状态
(package! rime)
(package! spacious-padding)
;; 完美解决中英文字符在表格中对齐的问题
(package! valign)
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;; Set package archives
(use-package! package
:config
(setq package-archives '(("gnu" . "http://elpa.emacs-china.org/gnu/")
("melpa" . "http://elpa.emacs-china.org/melpa/")))
(package-initialize))
;; Package Management
(use-package! use-package
:custom
(use-package-always-ensure nil)
(package-native-compile t)
(warning-minimum-level :emergency))
(setq mac-command-modifier 'super)
(setq mac-option-modifier 'meta)
(setq confirm-kill-emacs nil ; 关闭 emacs 时无需额外确认
system-time-locale "C" ; 设置系统时间显示方式
pop-up-windows nil ; no pop-up window
scroll-margin 2 ; It's nice to maintain a little margin
widget-image-enable nil)
;; Shut up
(setq byte-compile-warnings '(not obsolete))
(setq warning-suppress-log-types '((comp) (bytecomp)))
(setq native-comp-async-report-warnings-errors 'silent)
(setq inhibit-startup-echo-area-message (user-login-name))
(setq visible-bell t)
(setq ring-bell-function 'ignore)
(setq set-message-beep 'silent)
;; encoding system
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
;; 删除文件先进垃圾筒
(setq delete-by-moving-to-trash t)
(setq word-wrap-by-category t)
(add-hook 'org-mode-hook 'adaptive-wrap-prefix-mode)
;; 打开文件时, 光标自动定位到上次停留的位置
(save-place-mode 1)
(global-auto-revert-mode)
(setq initial-major-mode 'org-mode) ;; org!
(setq initial-scratch-message nil)
;; Smooth mouse scrolling
(setq mouse-wheel-scroll-amount '(2 ((shift) . 1)) ; scroll two lines at a time
mouse-wheel-progressive-speed nil ; don't accelerate scrolling
mouse-wheel-follow-mouse t ; scroll window under mouse
scroll-step 1)
;; personal information
(setq user-full-name "李继刚"
user-mail-address "[email protected]")
;; FIXME
;; 通过iCloud 自动同步Documents 目录, 多台电脑可以无缝迁移使用
(setq org-directory "~/Documents/notes/")
;;; Look and Feel
;; for night
(setq doom-theme 'doom-badger)
;; for day
;; (setq doom-theme 'doom-flatwhite)
(use-package! doom-modeline
:custom
(doom-modeline-buffer-encoding nil)
(doom-modeline-enable-word-count nil)
(doom-modeline-height 10))
;; Doom 自带的字体变量配置
;; Plan A: 中文苹方, 英文Roboto Mono
(setq doom-font (font-spec :family "Roboto Mono" :size 22)
doom-serif-font doom-font
doom-symbol-font (font-spec :family "PingFang SC")
doom-variable-pitch-font (font-spec :family "PingFang SC" :weight 'extra-bold))
;; Plan B: 中英文仓耳今楷
;; (setq doom-font (font-spec :family "TsangerJinKai03" :size 22)
;; doom-serif-font doom-font
;; doom-symbol-font (font-spec :family "TsangerJinKai03")
;; doom-variable-pitch-font (font-spec :family "TsangerJinKai03"))
;; 如果不把这玩意设置为 nil, 会默认去用 fontset-default 来展示, 配置无效
(setq use-default-font-for-symbols nil)
;; Doom 的字体加载顺序问题, 如果不设定这个 hook, 配置会被覆盖失效
(add-hook! 'after-setting-font-hook
(set-fontset-font t 'symbol (font-spec :family "Symbola"))
(set-fontset-font t 'mathematical (font-spec :family "Symbola"))
(set-fontset-font t 'emoji (font-spec :family "Symbola")))
;; 全局打开visual line
(global-visual-line-mode)
(setq display-line-numbers-type nil)
(show-paren-mode t)
(setq use-short-answers t)
(blink-cursor-mode 0)
(fringe-mode '(0 . 0)) ;; No fringe
(setq frame-title-format "生产知识")
;; 指定启动时的窗口位置和大小
(setq initial-frame-alist '((top . 45)
(left . 1200)
(width . 100)
(height . 45)))
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(setq-default x-stretch-cursor t
x-underline-at-descent-line t)
;; MINIBUFFER COMPLETION
(use-package! vertico
:init (vertico-mode)
:custom
(vertico-sort-function 'vertico-sort-history-alpha))
;; Search for partial matches in any order
(use-package! orderless
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides
'((file (styles partial-completion)))))
;; Improve keyboard shortcut discoverability
(use-package! which-key
:config (which-key-mode)
:custom
(which-key-max-description-length 40)
(which-key-lighter nil)
(which-key-sort-order 'which-key-description-order))
;; Consult convenience functions
(use-package! consult
:bind
(("C-c M-x" . consult-mode-command)
("C-c h" . consult-history)
("C-c k" . consult-kmacro)
("C-c m" . consult-man)
("C-c i" . consult-info)
([remap Info-search] . consult-info)))
;; Improved help buffers
(use-package! helpful
:bind
(("C-h f" . helpful-function)
("C-h x" . helpful-command)
("C-h k" . helpful-key)
("C-h v" . helpful-variable)))
default config to rice org-mode
;;; Ricing Org mode
(after! org
(setq org-confirm-babel-evaluate nil
org-edit-src-content-indentation 0
org-ellipsis "▾"
org-fold-catch-invisible-edits 'show
org-fontify-quote-and-verse-blocks t
org-fontify-whole-heading-line t
org-fontify-done-headline t
org-hide-block-startup t
org-hide-emphasis-markers t
org-hide-leading-stars t
org-id-link-to-org-use-id t
org-image-actual-width '(450)
org-list-allow-alphabetical t
org-pretty-entities t
org-return-follows-link t
org-special-ctrl-a/e t
org-special-ctrl-k t
org-src-preserve-indentation nil
org-src-tab-acts-natively t
org-startup-indented t
org-startup-with-inline-images t
org-use-speed-commands t
org-use-sub-superscripts "{}"))
(setq org-todo-keywords '((sequence "TODO" "|" "DONE")))
(add-hook! 'org-babel-after-execute-hook 'org-display-inline-images 'append)
(add-hook! 'org-babel-after-execute-hook 'org-toggle-latex-fragment 'append)
(setq-default prettify-symbols-alist '(("#+title:" . "✍")
("#+author:" . "👨")
("#+caption:" . "☰")
("#+filetags:" . "🎃")
("#+identifier:" . "👺")
("#+results:" . "🎁")
("#+attr_latex:" . "🍄")
("#+attr_org:" . "🔔")
("#+date:" . "⚓")
("#+property:" . "☸")
(":PROPERTIES:" . "⚙")
(":END:" . ".")
("[ ]" . "☐")
("[X]" . "☑︎")
("#+options:" . "⌥")
("\\pagebreak" . 128204)
("#+begin_quote" . "❮")
("#+end_quote" . "❯")
("#+begin_src" . "❮")
("#+end_src" . "❯")))
(add-hook! 'org-mode-hook 'prettify-symbols-mode)
(after! org-superstar
(setq org-superstar-headline-bullets-list '("🙘" "🙙" "🙚" "🙛")
org-superstar-special-todo-items t
org-superstar-item-bullet-alist '((?- . ?➤) (?* . ?🔻) (?+ . ?△))
org-superstar-prettify-item-bullets t ))
(defun org-mode-remove-stars ()
;; 关掉 Headline 前面的 * 符号显示
(font-lock-add-keywords
nil
'(("^\\*+ "
(0
(prog1 nil
(put-text-property (match-beginning 0) (match-end 0)
'invisible t)))))))
(add-hook! 'org-mode-hook #'org-mode-remove-stars)
(after! org
(custom-set-faces!
'(outline-1 :weight extra-bold :height 1.25)
'(outline-2 :weight bold :height 1.15)
'(outline-3 :weight bold :height 1.12)
'(outline-4 :weight semi-bold :height 1.09)
'(outline-5 :weight semi-bold :height 1.06)
'(outline-6 :weight semi-bold :height 1.03)
'(outline-8 :weight semi-bold)
'(outline-9 :weight semi-bold))
(custom-set-faces
'(region ((t (:foreground "green" :background "#464646")))))
(custom-set-faces!
'(org-document-title :height 1.2)))
;; 关闭indent
(after! org
(custom-set-variables '(org-startup-indented nil)))
other package to rice org-mode
;; Show hidden emphasis markers
(use-package! org-appear
:hook (org-mode . org-appear-mode)
:config
(setq org-appear-autoemphasis t
org-appear-autosubmarkers t
org-appear-autolinks nil))
;; LaTeX previews
(use-package! org-fragtog
:after org
:hook
(org-mode . org-fragtog-mode)
:custom
(org-format-latex-options
(plist-put org-format-latex-options :scale 2)
(plist-put org-format-latex-options :foreground 'auto)
(plist-put org-format-latex-options :background 'auto)))
(use-package! spacious-padding
:custom (line-spacing 3)
:init (spacious-padding-mode 1))
(use-package! valign
:config
(setq valign-fancy-bar t)
(add-hook 'org-mode-hook #'valign-mode))
(use-package! pangu-spacing
:config
(global-pangu-spacing-mode 1)
;; 在中英文符号之间, 真正地插入空格
(setq pangu-spacing-real-insert-separtor t))
(use-package! org-count-words
:hook (org-mode . org-count-words-mode))
(use-package! olivetti
:hook (org-mode . olivetti-mode)
:config (setq olivetti-body-width 80))
(use-package! ace-pinyin
:config
(ace-pinyin-global-mode +1))
custom functions to rice org-mode
(defvar-keymap ct/org-emphasis-map
:doc "Keymap for quickly applying Org emphasis rules."
:name "[b]old [i]talic [u]nderscore [v]erbatim [c]ode [s]trike-though"
"b" (lambda () (interactive) (ct/org-emphasize-below-point ?*))
"i" (lambda () (interactive) (ct/org-emphasize-below-point ?/))
"u" (lambda () (interactive) (ct/org-emphasize-below-point ?_))
"v" (lambda () (interactive) (ct/org-emphasize-below-point ?=))
"c" (lambda () (interactive) (ct/org-emphasize-below-point ?~))
"s" (lambda () (interactive) (ct/org-emphasize-below-point ?+)))
(defun ct/org-emphasize-below-point (&optional char)
"Emphasisez region with CHAR.
If there's no region, marks the closest s-expression, first.
Opposed to word boundaries, sexp's work with `subword-mode' enabled."
(interactive)
(unless (region-active-p)
(backward-sexp)
(mark-sexp))
(org-emphasize char))
(after! org
;; @Eli 帮忙写的解决标记符号前后空格问题的代码, 感谢.
(setq org-emphasis-regexp-components '("-[:space:]('\"{[:nonascii:]"
"-[:space:].,:!?;'\")}\\[[:nonascii:]"
"[:space:]"
"."
1))
(setq org-match-substring-regexp
(concat
;; 限制上标和下标的匹配范围,org 中对其的介绍见:(org) Subscripts and superscripts
"\\([0-9a-zA-Zα-γΑ-Ω]\\)\\([_^]\\)\\("
"\\(?:" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
"\\|"
"\\(?:" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
"\\|"
"\\(?:\\*\\|[+-]?[[:alnum:].,\\]*[[:alnum:]]\\)\\)"))
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
(org-element-update-syntax))
读网页链接
;; Easy insertion of weblinks
(use-package! org-web-tools
:init
(map!
:leader
:prefix "i"
:desc "insert weblinks" "l" #'org-web-tools-insert-link-for-url))
加密文件
;; GnuPG
(use-package! epa-file
:config
(epa-file-enable)
(setq epa-file-encrypt-to "[email protected]"))
读 markdown
(defun convert-markdown-links-to-org ()
"将 markdown 语法的链接转换成 orgmode 的链接"
(interactive)
(goto-char (point-min))
(while (re-search-forward "\\[\\(.*?\\)\\](\\(.*?\\))" nil t)
(replace-match "[[\\2][\\1]]")))
org-capture 快速记录 idea
(use-package! org
:bind (("s-c" . org-capture))
:custom
(org-default-notes-file "~/Documents/notes/.notes")
(org-goto-interface 'outline-path-completion)
(org-capture-templates
'(("f" "Fleeting note"
item
(file+headline org-default-notes-file "Notes")
"- [ ] %?")
("t" "New task" entry
(file+headline org-default-notes-file "Tasks")
"* TODO %i%?"))))
Oh, GPTel!
;; auth-sources
(setq auth-sources '("~/Documents/emacs/org/roam/authinfo.gpg"))
(setq epa-pinentry-mode 'loopback)
;; for claude
(use-package! gptel
:config
(setq gptel-api-key
(lambda ()
(auth-source-pick-first-password :host "api.anthropic.com" :user "apikey")))
(setq gptel-model "claude-3-5-sonnet-20241022"
gptel-backend (gptel-make-anthropic "Claude"
:stream t
:key 'gptel-api-key)))
(global-set-key (kbd "s-l") 'gptel-send)
Oh, Denote!
(use-package! denote
:defer t
:config
(setq denote-directory (expand-file-name "~/Documents/notes/"))
(setq denote-known-keywords '("emacs" "prompt" "claude"))
:custom
(denote-sort-keywords t)
:hook
(dired-mode . denote-dired-mode)
:custom-face
(denote-faces-link ((t (:slant italic))))
:init
(require 'denote-org-extras)
:bind
(("s-n" . denote-open-or-create)))
Consult-Notes for easy access to notes
(use-package! consult-notes
:bind
(("s-o" . consult-notes)
("s-f" . consult-notes-search-in-all-notes))
:init
(consult-notes-denote-mode))
Explore and manage your Denote collection
(use-package! denote-explore
:bind
(;; Statistics
("C-c w x c" . denote-explore-count-notes)
("C-c w x C" . denote-explore-count-keywords)
("C-c w x b" . denote-explore-barchart-keywords)
("C-c w x e" . denote-explore-barchart-filetypes)
;; Visualise denote
("C-c w x n" . denote-explore-network)
("C-c w x v" . denote-explore-network-regenerate)
("C-c w x D" . denote-explore-degree-barchart)))
Oh, Rime!
(use-package! rime
:custom
(default-input-method "rime")
(rime-librime-root "~/Documents/emacs/depend/librime/dist")
(rime-emacs-module-header-root "/opt/homebrew/Cellar/emacs-plus@29/29.4/include")
;; (rime-emacs-module-header-root "/usr/local/opt/emacs-mac/include")
:config
(define-key rime-mode-map (kbd "C-i") 'rime-force-enable)
(setq rime-disable-predicates
'(rime-predicate-evil-mode-p
rime-predicate-after-alphabet-char-p
rime-predicate-current-input-punctuation-p
rime-predicate-current-uppercase-letter-p
rime-predicate-punctuation-line-begin-p))
(setq rime-user-data-dir "~/Library/Rime"))
Yasnippet, quickly!
(after! yasnippet
(setq yas-snippet-dirs '("~/Documents/emacs/ljg-snippets")))
PlantUML for drawing
(after! plantuml-mode
(setq plantuml-jar-path (expand-file-name "~/Documents/emacs/org/private/plantuml.jar"))
(setq plantuml-default-exec-mode 'jar))
Org-download for images
(use-package! org-download
:defer nil
:custom
(org-download-image-dir "~/Documents/emacs/notes/images")
(org-image-actual-width '(400))
(org-download-heading-lvl nil)
(org-download-timestamp "")
:config
(require 'org-download))
(after! org-download
(setq org-download-method 'directory)
(setq org-download-link-format "[[file:images/%s]]\n"))
(use-package! org
:custom
(org-export-with-drawers nil)
(org-export-with-todo-keywords nil)
(org-export-with-broken-links t)
(org-export-with-toc nil)
(org-export-with-smart-quotes t)
(org-export-with-date t)
(org-export-with-author t)
(org-export-with-section-numbers nil)
(org-export-with-sub-superscripts nil)
(org-export-headline-levels 5)
(org-export-in-background nil)
(org-export-use-babel t))
export for html
;; Coding system for HTML export.
(setq org-html-coding-system 'utf-8)
(setq org-html-doctype "html5")
(setq org-html-head
"<link rel='stylesheet' type='text/css' href='https://gongzhitaao.org/orgcss/org.css'/> ")
export for pdf
;; texlive 安装路径
(setenv "PATH" (concat (getenv "PATH") ":/usr/local/texlive/2024/bin/universal-darwin"))
(setq exec-path (append exec-path '("/usr/local/texlive/2024/bin/universal-darwin")))
(setq org-highlight-latex-and-related '(native script entities))
(pdf-loader-install)
(setq Tex-command-default "XeLaTeX")
;; LaTeX PDF Export settings
(use-package ox-latex
:demand t
:custom
(org-latex-pdf-process
'("xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"
"rm -fr %b.out %b.log %b.tex auto")))
(with-eval-after-load 'ox-latex
(add-to-list 'org-latex-classes
'("ctexart" "\\documentclass[12pt,titlepage,a5paper]{ctexart}
% 设置中文字体
\\setCJKmainfont{KingHwa_OldSong}
% for use notin math symbol
\\usepackage{unicode-math}
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
% Document title
\\usepackage{titling}
% Page Margins: important
% https://ctan.math.illinois.edu/macros/latex/contrib/geometry/geometry.pdf
\\usepackage[scale=0.8,centering]{geometry}
% Page head and foot
% lhead/chead/rhead
% lfoot/cfoot/rfoot
\\usepackage{lastpage}
\\usepackage{fancyhdr}
\\pagestyle{fancy}
\\chead{\\textsc{\\title}}
\\rfoot{}
\\cfoot{\\color{gray} \\textsc{\\thepage~/~\\pageref*{LastPage}}}
\\lfoot{}
\\usepackage[most]{tcolorbox}
\\usepackage[colorinlistoftodos]{todonotes}
% xcolor is more powerful than color
% \\color{red!70} %70 percent red color
% \\textcolor{red}
% \\colorbox{gray}
\\usepackage[RGB,dvipsnames,svgnames]{xcolor}
% colortble is for org-table
% \\rowclor{gray}
\\usepackage{colortbl}
% Format of section and subsection headers
% [rm sf tt bf up it sl sc]
% Select the corresponding family/series/shape. Default is bf.
\\usepackage{titlesec}
% Hyperlinks and bookmarks
\\usepackage{hyperref}
\\hypersetup{colorlinks=true,linkcolor=blue}
% Include graphics
\\usepackage{graphicx}
\\usepackage{longtable}
\\usepackage{float}
\\usepackage{wrapfig}
% List items
\\usepackage{enumerate}
%% \\usepackage{enumitem}
% Line spread
\\usepackage{parskip}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(setq org-latex-default-class "ctexart")
(setq org-latex-compiler "xelatex"))
engrave-faces, 导出时语法高亮
(use-package! engrave-faces
:config
(setq org-latex-src-block-backend 'engraved)
;; 配置导出时语法高亮的Theme
(setq org-latex-engraved-theme 'doom-material-dark))
(map! :leader :desc "All in M-x" "SPC" #'execute-extended-command)
(map! :leader :desc "open export dispatch" "e" #'org-export-dispatch)
(global-set-key (kbd "s-j") 'avy-goto-word-1)
(define-key org-mode-map (kbd "s-i") ct/org-emphasis-map)