# Emacs

## Compile

https://protesilaos.com/codelog/2022-07-06-build-emacs-arch-linux/

https://git.sr.ht/~protesilaos/emacs-arch-linux-pkgbuild

```ini
# Maintainer: Protesilaos Stavrou <info@protesilaos.com>

# This is not on the AUR.  It is loosely based on the 'emacs-git'
# package found there.  It is highly opinionated to only use stuff I
# need (or will most likely need).
#
# About the choice of font backend, read this from the NEWS file of
# Emacs 28:
#
#     ** The Cairo graphics library is now used by default if present.
#     '--with-cairo' is now the default, if the appropriate development
#     files are found by 'configure'.  Building with Cairo is known to cause
#     some problems with bitmap fonts.  This may require you to adjust your
#     font settings, or to build with Xft support instead.
#
#     Note also that 'FontBackend' settings in ".Xdefaults" or
#     ".Xresources", or 'font-backend' frame parameter settings in your init
#     files, may need to be adjusted, as 'xft' is no longer a valid backend
#     when using Cairo.  Use 'ftcrhb' if your Emacs was built with HarfBuzz
#     text shaping support, and 'ftcr' otherwise.  You can determine this by
#     checking 'system-configuration-features'.  The 'ftcr' backend will
#     still be available when HarfBuzz is supported, but will not be used by
#     default.  We strongly recommend building with HarfBuzz support.  'x' is
#     still a valid backend.
#
#     ** 'configure' now warns about building with libXft support.
#     libXft is unmaintained, and causes a number of problems with modern
#     fonts including but not limited to crashes; support for it may be
#     removed in a future version of Emacs.  Please consider using
#     Cairo + HarfBuzz instead.
#
#     ** 'configure' now warns about not using HarfBuzz if using Cairo.
#     We want to encourage people to use the most modern font features
#     available, and this is the Cairo graphics library + HarfBuzz for font
#     shaping, so 'configure' now recommends that combination.

_wayland="NOX" # NO = Lucid, YES = Pure GTK, NOX = No X

pkgname="emacs-git"
pkgver=30.0.50.170054
pkgrel=1
pkgdesc="GNU Emacs.  Custom build of current development target."
arch=('x86_64')
url="http://www.gnu.org/software/emacs/"
license=('GPL3')
depends=(
    'cairo'
    'dbus'
    'harfbuzz'
    'hicolor-icon-theme'
    'libgccjit'
    'librsvg'
    'libsm'
    'libxcb'
    'sqlite3'
    'tree-sitter'
    'xcb-util'
)
makedepends=('git' 'libxi' 'xorgproto')

_flags=(
    --prefix=/usr
    --sysconfdir=/etc
    --libexecdir=/usr/lib
    --localstatedir=/var
    --mandir=/usr/share/man
    # General settings
    --without-xinput2
    --without-compress-install
    --without-gpm
    --without-selinux
    --with-native-compilation=yes
    --with-sound=no
    # Image settings
    --without-gif
    --without-tiff
    # Font settings
	--with-cairo
	--with-harfbuzz
    # Editor settings
    --with-tree-sitter=ifavailable
	--with-json
    # Toolkit settings
    --without-gsettings
    --without-gconf
    # Others: error
    --with-xpm=ifavailable
)

if [ "$_wayland" = "YES" ]
then
    depends+=(
        'gtk3'
    );
    _flags+=(
        '--with-pgtk'
    );
elif [ "$_wayland" = "NOX" ]
then
    depends+=(
        'gnutls'
        'libxml2'
        'jansson'
    );
    _flags+=(
        '--with-x-toolkit=no'
        '--without-toolkit-scroll-bars'
        '--without-xft'
        '--without-xaw3d'
    );
else
    depends+=(
        'lcms2'
        'libxfixes'
        'libxinerama'
        'libxrandr'
    );
    _flags+=(
        '--with-x-toolkit=lucid'
        '--without-toolkit-scroll-bars'
        '--without-xft'
        '--without-xaw3d'
    );
fi

provides=('emacs')
conflicts=('emacs')
source=("emacs-git::git+https://git.savannah.gnu.org/git/emacs.git")
options=(!strip)
b2sums=('SKIP')

pkgver()
{
    cd "$srcdir/emacs-git"

    printf "%s.%s" \
           $(grep AC_INIT configure.ac | \
                 awk -F',' '{ gsub("[ \\[\\]]","",$2); print $2 }') \
           $(git rev-list --count HEAD)
}

# There is no need to run autogen.sh after first checkout.
# Doing so, breaks incremental compilation.
prepare()
{
    cd "$srcdir/emacs-git"
    [[ -x configure ]] || ( ./autogen.sh git && ./autogen.sh autoconf )
    mkdir -p "$srcdir/emacs-git/build"
}

build()
{
    cd "$srcdir/emacs-git/build"
    ../configure "${_flags[@]}"
    make
}

package()
{
    cd "$srcdir/emacs-git/build"

    make DESTDIR="$pkgdir/" install

    # fix user/root permissions on usr/share files
    find "$pkgdir"/usr/share/emacs/ | xargs chown root:root

    # fix permssions on /var/games
    mkdir -p "$pkgdir"/var/games/emacs
    chmod 775 "$pkgdir"/var/games
    chmod 775 "$pkgdir"/var/games/emacs
    chown -R root:games "$pkgdir"/var/games
}

post_install() {
    # fix user/root permissions on usr/share files
    find "$pkgdir"/usr/share/emacs/ | xargs chown root:root
    # make sure directory has the correct owner and group
    chown -R root:games "$pkgdir"/var/games
    # Remove all desktop files beside the main one
    find "$pkgdir"/usr/share/emacs/ -regex '.*\(emacsclient\|emacs-mail\).*\.desktop' -print0 | xargs -r0 rm
}
```

## Setup

### Emacs Hunspell

<https://github.com/hunspell/hunspell#usage>

```bash
# mkdir /usr/share/hunspell
# cd /usr/share/hunspell
# wget -O en_US.aff  https://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_US.aff?id=a4473e06b56bfe35187e302754f6baaa8d75e54f
# wget -O en_US.dic https://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_US.dic?id=a4473e06b56bfe35187e302754f6baaa8d75e54f
```

## Emacs 资料

- <https://wiki.systemcrafters.net/emacs/>
- <https://www.emacswiki.org/>

## 我想用 Emacs 做什么

### 搜索多个文件

`M-x rgrep`

### 用 Org-agenda 做 GTD

### 使用 Org 表格

|              | 腾讯云        | 阿里云     |
| --- | --- | --- |
| 地域         | 上海          |            |
| 系统镜像     | Ubuntu20.04   |            |
| vCPU         | 2 核          |            |
| 内存         | 2G            |            |
| 每月流量     | 300G          | 800G       |
| 系统盘       | 40G SSD       | 50G ESSD   |
| 限峰值带宽   | 4Mbps         |            |
| 价格         | 50 元/月      | 90 元/月   |

我想让属性值相同的部分（地域、系统镜像、vCPU、内存、限峰值带宽）两列合并。

目前使用 HTML：

<table>
<thead>
<tr>
<th></th>
<th>腾讯云</th>
<th>阿里云</th>
</tr>
</thead>
<tbody>
<tr>
<td>地域</td>
<td colspan="2" align="center">上海</td>
</tr>
<tr>
<td>系统镜像</td>
<td colspan="2" align="center">Ubuntu20.04</td>
</tr>
<tr>
<td>vCPU</td>
<td colspan="2" align="center">2 核</td>
</tr>
<tr>
<td>内存</td>
<td colspan="2" align="center">2G</td>
</tr>
<tr>
<td>每月流量</td>
<td>300G</td>
<td>800G</td>
</tr>
<tr>
<td>系统盘</td>
<td>40G SSD</td>
<td>50G ESSD</td>
</tr>
<tr>
<td>限峰值带宽</td>
<td colspan="2" align="center">4Mbps</td>
</tr>
<tr>
<td>价格</td>
<td>50 元/月</td>
<td>90 元/月</td>
</tr>
</tbody>
</table>

其他参考：

<!-- This HTML table template is generated by emacs/table.el -->
<table border="1">
  <tr>
    <td rowspan="2" align="left" valign="top">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
    <td colspan="3" align="left" valign="top">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Singular&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;Plural&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">
      &nbsp;Masculine&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;Neuter&nbsp;&nbsp;&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;Feminine&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;All&nbsp;genders&nbsp;
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">
      &nbsp;Nominative&nbsp;<br />
      &nbsp;Accusative&nbsp;<br />
      &nbsp;Dative&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;Genitive&nbsp;&nbsp;&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;*der*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*den*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*dem*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*dessen*&nbsp;&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;*das*&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*das*&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*dem*&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*dessen*&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;*die*&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*die*&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*der*&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*deren*&nbsp;&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;*die*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*die*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*denen*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;*deren*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
  </tr>
</table>

<!-- This HTML table template is generated by emacs/table.el -->
<table border="1">
  <tr>
    <td colspan="2" align="left" valign="top">table-capture&nbsp;is&nbsp;a&nbsp;powerful&nbsp;command.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />Here&nbsp;are&nbsp;some&nbsp;things&nbsp;it&nbsp;can&nbsp;do:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">
      Parse&nbsp;Cell&nbsp;Items&nbsp;<br />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
    <td align="left" valign="top">
      &nbsp;Using&nbsp;row&nbsp;and&nbsp;column&nbsp;delimiter&nbsp;regexps,<br />
      &nbsp;it&nbsp;parses&nbsp;the&nbsp;specified&nbsp;text&nbsp;area&nbsp;and&nbsp;&nbsp;<br />
      &nbsp;extracts&nbsp;cell&nbsp;items&nbsp;into&nbsp;a&nbsp;table.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>
  </tr>
</table>

---

1. <https://developer.mozilla.org/en-US/docs/Learn/HTML/Tables/Basics>
2. <https://emacs.stackexchange.com/a/7313>
3. <https://orgmode.org/guide/Tables.html#Tables>
4. <https://orgmode.org/manual/Tables.html#Tables>

### 使用 Org Mode checkbox

`C-c C-x C-r (org-toggle-radio-button)` 添加新的 checkbox

## 输入法及字体

我在终端环境下用 Emacs 更多，所以基本上系统输入法配置好 Fcitx5，使用我的
.emacs.d
配置，就可以正常输入中文了。但是，最近使用发现------输入中文引号时，会占据实际上没有的空白（终于找到原因：在启动
Emacs 时设置了 =LC_CTYPE=zh_CN.UTF-8= ）。

## 升级包

<https://github.com/purcell/emacs.d/issues/33#issuecomment-6039572>

通过定期执行 `M-x package-list-packages RET` ，然后按下 `U` 键，之后按下
`x` 键。

## 不使用 use-package

<https://github.com/jwiegley/use-package> 安装

```
    (require 'package)
    (add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)

    (unless (package-installed-p 'use-package)
      (package-install 'use-package))
```

配置入门

当需要安装包的时候，输入：

```
    (use-package ox-hugo
      :ensure t
      :pin melpa)
```

- `:init` 在加载包前执行代码
- `:config`
