Introduction

Emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish.

– Neal Stephenson, In the Beginning was the Command Line (1998)

Install Emacs With Homebrew

First, Doom’s dependencies:

brew install git ripgrep
brew install coreutils fd
xcode-selected --install

emacs-mac. It offers good integration with macOS, native emojis and better childframe support.

brew tap d12frosted/emacs-plus
brew install emacs-plus --with-native-comp --with-modern-vscode-icon
ln -s /usr/local/opt/emacs-plus@29/Emacs.app /Applications

Doom Emacs

With Emacs and Doom’s dependencies installed, next is to install Doom Emacs itself:

git clone https://github.com/hlissner/doom-emacs ~/.emacs.d
~/.emacs.d/bin/doom install

如果提示 .emacs.d 已存在,删除重新执行上述命令即可。

.zshrc 中需要添加 export PATH="$HOME/.emacs.d/bin:$PATH ,这样就可以直接使用 doom 命令了。

Doom Doctor 问题

  1. Warning: unable to detect fonts because fontconfig isn’t installed
brew install fontconfig
  1. ! Couldn’t find shellcheck. Shell script linting will not work
brew install shellcheck
  1. Couldn’t find the dot executable (from graphviz). org-roam will not be able to generate graph visualizations.
brew install graphviz
  1. This installed grep binary was not built with support for PCRE lookaheads. Some advanced consult filtering features will not work as a result, see the module readme.
#  因为 Mac 本身安装的是 BSD 的。
grep --version
# 可以看到 grep (BSD grep, GNU compatible) 2.6.0-FreeBSD ,即 BSD 版本。
brew install grep
# 安装 GNU 的 grep,并在 .zshrc 中配置 PATH="/usr/local/opt/grep/libexec/gnubin:$PATH" 即可。再次查看版本可以看到如下。
# grep (GNU grep) 3.7
# Packaged by Homebrew
# Copyright (C) 2021 Free Software Foundation, Inc.
# License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law.

Org-roam

具体的配置文件在 .doom.d/ 下,参见 .doom.d

Shortcuts

Shortcuts 功能 备注
C-RET 在当前 headline 所属的内容后建立一个同级 headline 无 headline 时创建一个一级 headline
M-RET 在当前 headline 后建立一个同级 headline 同上
M-right 降低当前 headline 的层级
M-left 提高当前 headline 的层级
M-up 将当前 headline 及其内容作为整体向上移动
M-down 将当前 headline 及其内容作为整体向下移动
C-return 在当前列表项的内容后建立一个同级列表项 光标在列表项同一行时有效
M-RET 在当前列表项后建立一个同级列表项 同上
M-right 降低当前列表项的层级 同上
M-left 提高当前列表项的层级 同上
M-up 将当前列表项及其内容作为整体向上移动 同上
M-down 将当前列表项及其内容作为整体向下移动 同上
C-x-o 切换窗口 C-x 中有很多操作,可以看提示。
C-c C-c 在创建 node 编写完毕后快速保存
C-g 取消操作
C-x-d 进入 dired 模式
SPC f r 查找最近文件
C-c C-x C-v 显示图片
Shortcuts 功能 备注
C-c C-s 设置任务开始时间
C-c C-d 设置任务截止时间
C-c C-t 改变任务状态
S-Up/Down 设置任务优先级 [#A], [#B], [#C]
C-c C-x C-i 开始任务计时
C-c C-x C-o 终止任务计时
C-c [ 将当前文件加入 Org-Agenda
C-c ] 将当前文件从 Org-Agenda 移除
Shortcuts 功能 备注
t 在 Org-Agenda 的任务条目上, 修改任务状态。
C-c C-x C-a 归档
C-c C-w activate refile
I 在 Org-Agenda 的任务条目上, 开始计时。
O 在 Org-Agenda 的任务条目上, 终止计时。
z 在任务上添加 note
R clock mode, 显示耗时。
C-c C-x C-l 预览 Latex
C-c \ 按 tag 搜索 好像只能单文件内
C-C C-o 打开链接

Org grammar

basic

This is almost anything you need to know about Org mode syntax:

* This Is A Heading
** This Is A Sub-Heading
*** And A Sub-Sub-Heading

Paragraphs are separated by at least one empty line.
*bold* /italic/ _underlined_ +strikethrough+ =monospaced=
[[http://Karl-Voit.at][Link description]]
http://Karl-Voit.at → link without description

- list item
- another item
  - sub-item
    1. also enumerated
    2. if you like
- [ ] yet to be done
- [X] item which is done

: Simple pre-formatted text such as for source code.
: This also respects the line breaks. *bold* is not bold here.

code block

myresult = 42 * 23
print('Hello Europe! ' + str(myresult))

table

| My Column 1 | My Column 2 | Last Column |
|-------------+-------------+-------------|
|          42 | foo         | bar         |
|          23 | baz         | abcdefg     |
|-------------+-------------+-------------|
|          65 |             |             |

Export

对于只需要导出某个 header 下的内容的需求,只需要在 header 上加上 :export: 即可。

Markdown file

这里用的是 ox-pandocM-x org-pandoc-export-as-gfm 算是我找到最符合 MarkDown 语法的转换了,Emacs 自己的转换会将 Table 转换成 HTML 标签的格式。

Hugo

在文件头部添加

#+HUGO_BASE_DIR: ~/Dropbox/hugo/
#+HUGO_SECTION: posts/main
#+HUGO_WEIGHT: auto
#+HUGO_AUTO_SET_LASTMOD: t

需要导出为 <mark></mark>1

#+begin_mark
marked text
#+end_mark

需要导出为块级 <mark></mark> 时,也就是前后的空格不进行 trim。

#+header: :trim-pre nil :trim-post nil
#+begin_mark
marked text
#+end_mark

Latex

Dependency

需要安装 texlive

brew install texlive

Latex 语法

Latex 语法

PDF 导出报错

  • Unicode character 考 (U+8003) not set up for use with LaTeX. 是因为 Latex 本身不支持中文。

中文 PDF 导出设置

  1. 使用 ElegantPaper,需要将 elegantpaper.cls 文件放在 org 目录下。
  2. 安装依赖
brew install pygments
  1. 导出文件头部增加
#+LATEX_COMPILER: xelatex
#+LATEX_CLASS: elegantpaper
#+OPTIONS: prop:t

No notes link to this note