Emacs (简体中文)

From ArchWiki
Jump to navigation Jump to search
翻译状态:本文是 Emacs翻译。上次翻译日期:2018-03-07。如果英文版本有所更改,则您可以帮助同步翻译。

Emacs是一个可扩展、可定制、自文档化的实时显示编辑器。Emacs的核心构建在Emacs Lisp解释器之上,Emacs Lisp是大部分Emacs内建函数和拓展模块的实现语言。在图形界面系统下,Emacs使用GTK作为默认的X工具,在命令行界面下(CLI),Emacs也可以工作良好。在文本编辑能力上,Emacs常被拿来和vim比较。

安装

Emacs有众多发行版本(有时候称作emacsen)。 最常见的莫过于 GNU Emacs

official repositories 中可以安装 emacs 。如果你经常使用命令行,你可能更喜欢没有GTK+支持的 emacs-nox(也没有声音或其它花哨的东西)。值得注意的是,文字模式的Emacs有一些缺点:它支持的颜色和字体设置功能都要更少(实时改变字体大小,单文档多字体,等等)。而且emacs-nox存在一些高级功能上的缺陷,比如Speedbar和GUD(调试环境),处理复杂的外观(face,文本在Emacs中呈现的样子)的时候速度也会变慢。

如果要用 feature/native-comp 分支的 Emacs(参考 GccEmacs),请安装 emacs-native-comp-gitAUR 包。如果你需求是使用原生编译分支和使用新的渲染引擎 pgtk,你可以安装 emacs-pgtk-native-comp-gitAUR 或者 emacs-native-comp-git-enhancedAUR,这两个包都是用于安装非官方克隆的 pgtk-nativecomp

运行Emacs

启动Emacs之前,你应该知道怎样关掉它(特别是你在终端里运行时):使用 Ctrl+xCtrl+c 按键顺序。

启动Emacs:

$ emacs

或者以文字模式启动:

$ emacs -nw

又或者,快速启动(不解析.emacs文件)并以文字模式启动:

$ emacs -Q -nw

如果你安装的是nox版本,'emacs' 和 'emacs -nw' 效果是一样的。

可以提供文件名直接打开文件:

$ emacs filename.txt

没有颜色

默认情况下,Emacs以颜色主题开始,显示超链接为深蓝色。

以文本模式,不使用任何颜色主题启动Emacs:

$ emacs -nw --color=no

这将导致所有的文本采用终端的字体颜色 –– 通常是黑色背景之上的白色文本,或白色背景上的黑色文本。

作为守护进程

如过不想让Emacs每次启动都读取配置文件的话,可以以守护进程运行Emacs:

$ emacs --daemon

连接到守护进程:

$ emacsclient -nc

这个命令会创建一个新的frame -c(如果你更喜欢文字模式,使用 -t )并且不会独占终端 -n--no-wait)。 有的程序,如Mutt和Git,(为了提交信息)会等待编辑器完成编辑,所以不能使用 -n 参数。 如果你的默认编辑器是默认使用-n,你需要为那些程序指定一个替代编辑器(比如 emacsclient -a "" -t)。

作为systemd单元

旧的systemd单元方法有一些需要注意的地方。 它给了一个限制shell调用的有限的shell环境,所以我们需要使用一个user单元,它往往比调用emacs --daemon好得多。 为Emacs创建一个systemd单元:

注意: 这样一个单元文件将会包含在Emacs 26.1中, 参见 emacs bug 16507.
~/.config/systemd/user/emacs.service
[Unit]
Description=Emacs: the extensible, self-documenting text editor

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Restart=always

[Install]
WantedBy=default.target

需要启动并启用该单元,以便其在每次电脑启动时启动(请注意 - 请勿“以root运行” - 我们希望它以user,而不是根root user运行):

$ systemctl --user enable --now emacs

请注意,systemd user单元不会从登录shell(例如〜/.bash_profile)继承环境变量,因此你可能需要在〜/.pam_environment中设置变量。有关更多信息,请参见Systemd/User

如启动emacs作为守护程序,你可能会想把VISUALEDITOR环境变量设置为emacsclient,以便启动编辑器的程序使用emacsclient而不是一个完整的编辑器。使用外部编辑器的程序,包括电子邮件程序(用于编辑消息),Git(用于编辑提交消息)和less(用于编辑显示文件的v命令)。 不要对emacsclient使用-n--nowait)选项,因为程序通常要求在编辑器退出时编辑完成。

建议将Emacs的任何GUI开始菜单条目(或等效条目)更改为指向emacsclient而不是emacs,以便使用emacs守护程序而不是启动新的emacs进程。

获得帮助

尽管Emacs很复杂,但了解定制和可扩展性带来的好处并不需要很长时间。此外,已有的各种扩展允许将其转变为针对几乎任何形式的强大文本编辑环境。

Emacs有一个很好的内置教程,可以通过点击启动画面上的第一个链接进行访问; 通过从菜单中选择帮助-> Emacs 教程或按F1 + t,亦或者按 C-h t (C 默认是 Ctrl 键, - 符号代表同时按下,也就是说你需要按 Ctrl 键的同时按 h 键,然后放开再按 t 键)

Emacs设计为良好的自文档化。 因此,你很容易知道一些特定命令和快捷键是什么意思,比如命令 find-file ,而它的默认快捷键是 C-x C-f, f 键可联想为file。Emacs 提供大量文档给使用者,建议频繁使用C-h C-h查看所有命令,快捷键和方法。

Emacs还包含一组参考卡,对初学者和专家都很有用,请参阅/usr/share/emacs/<version>/etc/refcards/(用您的emacs版本替换<version>)。

手册

如果你真的想要掌握Emacs,最推荐的文档来源仍然是官方手册:

  • Emacs:完整的Emacs用户手册。
  • Emacs 常见问题。
  • Emacs Lisp简介:如果你以前从未使用任何编程语言。
  • Elisp:如果你已经熟悉一门编程语言。

通过内置'info'阅读器,你可以从官网的 PDF 文档GNU.org 或直接从 Emacs 本身访问:C-h i。 可以按 m 键快速选择特定章节。

有些用户更喜欢使用'info'阅读器来阅读文本,因为它有很方便的默认快捷键来帮使用者浏览整本书。另外其段落会适应窗口宽度,字体会适应当前屏幕分辨率。有些人觉得这样不那么刺激眼睛。最后,你可以轻松地将章节中的内容复制到任何Emacs缓冲区,甚至可以直接从文本的示例中执行Lisp代码片段。

尝试用 C-h i m info <RET> 快捷键获取更多 info reader 的信息。 在info模式下按 ? 可以快速查看快捷键列表。

定制化

Emacs 其中一个主要的特点就是拥有极高自由度的扩展性,而且配置起来很容易。Emacs 内置自定义页面,你可以通过M-x customize快捷键查看自定义选项列表,亦或者用M-x customize-group查询特定插件的自定义列表。更多详细请查询 Emacs manual C-h r 里的 Easy Customization

配置文件

当Emacs启动时,通常会自动加载初始化配置文件。这些配置文件由 lisp 语言编写(准确地来说是Emacs lisp),配置文件默认是在~/.emacs.el或者~/.emacs。你也可以把配置文件放在目录里方便管理,默认下是在~/.emacs/init.el。更多详细请看 Emacs manual 里的 Init File 章节。

提示和技巧

TRAMP

TRAMP (Transparent Remote Access, Multiple Protocols) ,顾名思义,是一个可以通过很多协议透明访问远程文件的一个扩展。当提示输入文件名时,输入特定的格式就可以使用TRAMPP。比如:

在打开/etc/hosts文件之前提示输入root的密码以获取root权限:

C-x C-f /su::/etc/hosts

要通过SSH使用'you'用户名登录'remotehost'主机打开文件~/example.txt

C-x C-f /ssh:you@remotehost:~/example.txt

TRAMP的路径一般是这种格式'/[protocol]:[[user@]host]:<file>'。

作为用户'you'连接至'myhost'并以sudo编辑/etc/hosts

/ssh:you@remotehost|sudo:remotehost:/etc/hosts

TRAMP支持的不只上面的两个简单例子。请查看Emacs里面的TRAMPP info手册了解更多的信息。

使用Emacs作为git mergetool

默认情况下,Git支持使用Emacs的Emerge模式作为合并工具。但是你可能更喜欢Ediff模式。不幸的是,由于技术原因,这种模式不被git支持。通过在emacs调用时对一些elisp代码赋值,仍然有一种方法可以使用Ediff。

.gitconfig
[mergetool.ediff]
    cmd = emacs --eval \" (progn (defun ediff-write-merge-buffer () (let ((file ediff-merge-store-file)) (set-buffer ediff-buffer-C) (write-region (point-min) (point-max) file) (message \\\"Merge buffer saved in: %s\\\" file) (set-buffer-modified-p nil) (sit-for 1))) (setq ediff-quit-hook 'kill-emacs ediff-quit-merge-hook 'ediff-write-merge-buffer) (ediff-merge-files-with-ancestor \\\"$LOCAL\\\" \\\"$REMOTE\\\" \\\"$BASE\\\" nil \\\"$MERGED\\\"))\" 

[merge]
	tool = ediff

请注意,该命令必须在同一行上。在上面的例子中,我们启动了一个Emacs的新实例。你可能想要使用emacsclient更快地启动; 不建议这样做,因为Ediff调用不是很干净:它可能会打断当前的Emacs会话。

如果你想要一个即时启动,可以使用-q参数。如果想在保留至少一部分配置的情况下快速启动Emacs,则可以这样使用Emacs:

emacs -q -l ~/.emacs-light

light配置文件仅加载Ediff所需的内容。

关于这个技巧的细节和Ediff问题,参见kerneltrap.org[失效链接 2020-08-02 ⓘ]stackoverflow

使用大写锁定作为控制键

一些用户喜欢这种个修改,以避免所谓的'emacs pinky'。如果你想在 X Keyboard 上试用它,运行

$ setxkbmap -option 'ctrl:nocaps'

或者,交换键值,运行

$ setxkbmap -option 'ctrl:swapcaps'

要永久更改它,请考虑将其添加到.xinitrc文件中。

如果要将一个区域变为大写,只需使用默认的C-x C-u键绑定,调用upcase-region函数。

参见[1]了解另一种方法。

如果缺少Caps Lock功能,请同时将其映射为“Shift”。

$ setxkbmap -option "shift:both_capslock"

某些桌面环境包含图形工具以简化键盘重新映射。 例如,在Plasma 5中打开系统设置并点击输入设备。选择键盘,然后在高级选项卡中会看到Caps Lock设置,可以在其中选择Caps Lock也是一个Ctrl。

emacsclient

emacsclient

多种配置

你可以使用少量配置然后告诉Emacs来加载其他配置。

例如,我们来定义两个配置文件。

.emacs
(load "~/.emacs.d/main" nil t)
(load "~/.emacs.d/functions" nil t)
(load "~/.emacs.d/modes" nil t)
(load "~/.emacs.d/plugins" nil t)
(load "~/.emacs.d/theme" nil t)

这是我们在后台载入的完整配置。但是plugins文件太大导致载入太慢,如果我们要打开一个新的Emacs窗口,可能就不会使用plugins配置,每次加载它实在是太笨重了。

.emacs-light
(load "~/.emacs.d/main" nil t)
(load "~/.emacs.d/functions" nil t)
(load "~/.emacs.d/modes" nil t)
(load "~/.emacs.d/theme" nil t)

现在我们这样来加载Emacs:

emacs -q -l ~/.emacs-light

你可以为这个命令创建一个别名。

Local and custom variables

You can define variables in your configuration file that can be later one modified locally for a file.

(defcustom my-compiler "gcc" "Some documentation")

Now in any file you can define local variables in two ways:

  • On the very first line, write
// -*- my-compiler:g++; mode:c++ -*-
  • If you cannot (or do not want to) write this on the first line, you can put it at the end:
// Local Variables:
// my-compiler: g++
// mode: c++
// End:

Note that the beginning characters need to be comments for the current language, that's why here we used two backslashes for C++. For Elisp you would use

;; -*- mode:emacs-lisp -*-

There is two functions that may help you in defining the variables: add-file-local-variable and add-file-local-variable-prop-line.

Finally, custom variable are considered insecure by default. If you try to open a file that contains local variable redefining insecure custom variables, Emacs will ask you for confirmation.

If you know what you are doing, you can declare the variable as secure, thus removing the Emacs prompt for confirmation. You need to specify a predicate that any new value has to verify so that it can be considered safe.

(defcustom my-compiler "gcc" "Some documentation" :safe 'stringp)

In the previous example, if you attempt to set anything else than a string, Emacs will consider it insecure.

Custom colors and theme

Colors can be easily customized using the face facility.

(set-face-background  'region                 "color-17")
(set-face-foreground  'region                 "white")
(set-face-bold-p      'font-lock-builtin-face t ) 

You can have let Emacs tell you the name of the face where the point is. Use the customize-face function for that. The facility will show you how to set colors, bold, underline, etc.

Emacs in console can handle 256 colors, but you will have to use an appropriate terminal for that. For instance URxvt has support for 256 colors. You can use the list-colors-display for a comprehensive list of supported colors. This is highly terminal-dependent.

SyncTeX support

Emacs is definitely one of the most powerful LaTeX editor. This is mostly due to the fact you can adapt or create a LaTeX mode to fit your needs best.

Still, there might be some challenges, like SyncTeX support. First you need to make sure your TeX distribution has it. If you installed TeX Live manually, you may need to install the synctex package.

# umask 022 && tlmgr install synctex

SyncTeX support is viewer-dependent. Here we will use Zathura as an example, so the code needs to be adapted if you want to use another PDF viewer.

(defcustom tex-my-viewer "zathura --fork -s -x \"emacsclient --eval '(progn (switch-to-buffer  (file-name-nondirectory \"'\"'\"%{input}\"'\"'\")) (goto-line %{line}))'\"" 
  "PDF Viewer for TeX documents. You may want to fork the viewer
so that it detects when the same document is launched twice, and
persists when Emacs gets closed.

Simple command:

  zathura --fork

We can use

  emacsclient --eval '(progn (switch-to-buffer  (file-name-nondirectory \"%{input}\")) (goto-line %{line}))'

to reverse-search a pdf using SyncTeX. Note that the quotes and double-quotes matter and must be escaped appropriately."
:safe 'stringp)

Here we define our custom variable. If you are using AucTeX or Emacs default LaTeX-mode, you will have to set the viewer accordingly.

Now open a LaTeX source file with Emacs, compile the document, and launch the viewer. Zathura will spawn. If you press Ctrl+Left click Emacs should place the point at the corresponding position.

Syntax highlighting for systemd Files

You can use systemd-mode.

Alternatively, you can simply tell emacs to colour systemd files (services, timer, etc.), by adding this to your init file:

 (add-to-list 'auto-mode-alist '("\\.service\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.timer\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.target\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.mount\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.automount\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.slice\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.socket\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.path\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.netdev\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.network\\'" . conf-unix-mode))
 (add-to-list 'auto-mode-alist '("\\.link\\'" . conf-unix-mode))


Clipboard support for emacs-nox

To use the Xorg clipboard in emacs-nox, install xclip and add the following function to ~/.emacs [2]

;; use xclip to copy/paste in emacs-nox
(unless window-system
  (when (getenv "DISPLAY")
    (defun xclip-cut-function (text &optional push)
      (with-temp-buffer
	(insert text)
	(call-process-region (point-min) (point-max) "xclip" nil 0 nil "-i" "-selection" "clipboard")))
    (defun xclip-paste-function()
      (let ((xclip-output (shell-command-to-string "xclip -o -selection clipboard")))
	(unless (string= (car kill-ring) xclip-output)
	  xclip-output )))
    (setq interprogram-cut-function 'xclip-cut-function)
    (setq interprogram-paste-function 'xclip-paste-function)
    ))
Tip: You may also enable terminal mouse support by adding:
;; xterm mouse support
(require 'mouse)
(xterm-mouse-mode t)
See also mwheel.el[失效链接 2020-12-24 ⓘ].

Packages

Emacs's functionality can be extended with third-party packages. The built-in package manager package.el is the officially supported way to do this, though there are several other package managers written by members of the Emacs community. package.el relies on the variable package-archives to find packages. By default, this includes the Emacs Lisp Package Archive (ELPA). M-x list-packages will create a buffer listing all the packages your Emacs knows about. The manual ((info "(emacs) Packages")) contains much more information.

Third-party package archives can be added. The most widely used of these is MELPA.

A number of popular extensions are available as packages in the [community] repository, and more still, via the AUR. The name of such packages usually have a 'emacs-' prefix (for example, emacs-lua-mode), though not always (for example, auctexAUR).

Tip: Arch Linux Wiki contributors may be interested in the Emacs Mediawiki package.

Some packages may require you to make changes to your configuration file in order to activate them so that their features are available during an Emacs session. For example, if you install auctexAUR, you will need to add

(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

to your configuration file. Other packages should let you know how to activate them in the commentary section of their source code or in their README.

疑难杂症

彩色输出的问题

Emacs默认使用原生的转义串来输出颜色。也就是说,它会在要显示颜色的地方显示奇怪的字符。

~/.emacs中加入下面的代码解决这个问题:

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

菜单显示为空

一些菜单显示为空,这是GNU Emacs 23.1的一个bug(使用GTK toolkit的时候)。好像在Emacs的CVS trunk中已经修复了。对应的Debian bug report 有一个应对措施。

X 窗口下的字符显示问题

当你使用X窗口启动emacs时,如果发现主窗口中的所有字符都是黑框白块(就像你没有安装正确的字体看到的字符一样),那么你需要安装 xorg-fonts-75dpi 或者 xorg-fonts-100dpi 并且重启X窗口。

启动速度慢

启动速度慢经常是由下面两种情况引起的。

要确定是哪种情况,这样打开Emacs:

$ emacs -q

如果Emacs还是启动很慢,则是错误的网络配置[断开的链接:无效的部分]。如果不是,则可以确定是.emacs的问题[断开的链接:无效的部分]

错误的网络配置

当启动Emacs的时候,一些错误,特别是在/etc/hosts中的,经常会导致5秒以上的延迟。在网络配置指南中查看'set the hostname' 了解更多内容。

初始化文件加载慢

一个很简单的方法查找原因是注释掉(比如在行开头使用';')你的~/.emacs(或者~/.emacs.d/init.el)里面可疑的地方,然后再启动Emacs,看速度是否有改善。记住,使用"require"和"load"会减慢启动速度,特别是用在很大的插件上。一般来说,他们应该用在当目标是Emacs启动的时候就需要或者提供仅仅是一个扩展的"autoloads"。否则,直接使用'autoload'函数。比如,不是这样:

(require 'anything)

你应该这样:

(autoload 'anything "anything" "Select anything" t)

不能打开配置文件: ...

这个错误最常见的原因是'load-path'变量没有包含某些插件的目录。要解决这个问题,在加载插件前,把需要加载的插件目录加入到要搜索的list中:

 (add-to-list 'load-path "/path/to/directory/")

当尝试使用一个插件的包,而这个包又被Emacs加上了非'/usr'的前缀时,load-path需要更新。把下面的代码放到使用这个插件的包的代码的前面:

 (add-to-list 'load-path "/usr/share/emacs/site-lisp")

如果手动编译Emacs,记住默认的前缀是'/usr/local'。

Dead-accent keys problem: '<dead-acute> is undefined'

Searching about this bug on Google, we find this link: https://lists.gnu.org/archive/html/help-gnu-emacs/2009-05/msg00167.html

Explaining the problem: in recent versions of b72

Emacs, the normal way to use accent keys doesn't work as expected. Trying to accent a word like 'fiancé' will produce the message above.

A way to solve it is just put the line above on your startup file, ~/.emacs:

  (require 'iso-transl)

And no, it isn't a bug, but a feature of new Emacs versions. Reading the subsequent messages about it on the mail list, we found it (https://lists.gnu.org/archive/html/help-gnu-emacs/2009-05/msg00179.html):

It seems that nothing is loaded automatically because there is a choice betwee iso-transl and iso-acc. Both seem to provide an input method with C-x 8 or Alt-<accent> prefix, but what you and I are doing is just pressing a dead key (^, ´, `, ~, ¨) for the accent and then another key to "compose" the accented character. And there is no Alt key used in this! And according to documentation it seems be appropriate for 8-bit encodings, so it should be pretty useless in UTF-8. I reported this bug when it was introduced, but the bug seems to be

a3b

classified as a feature ... Maybe it's just because the file is auto-loaded though pretty useless. 

C-M-% and some other bindings do not work in emacs nox

This is because terminals are more limited than Xorg. Some terminals may handle more bindings than other, though. Two solutions:

  • either use the graphical version,
  • or change the binding to a supported one.

Example:

.emacs
(global-set-key (kbd "C-M-y") 'query-replace-regexp)

Emacs client gets stuck when switching back to it

If you are using Emacs daemon, then you should know that input is blocking. If one Emacs instance is in the minibuffer (after an M-x for instance), then all other instance will wait for it to finish. Press C-g to cancel any input to make sure this Emacs session is not blocking.

Emacs-nox output gets messy

When working in a terminal, the color, indentation, or anything related to the output might become crazy. This is (probably?) because Emacs was sent a special character at some point which may conflict with the current terminal. There is not much to be done but restarting emacs. If someone has a workaround or a more detailed explanation on the issue, feel free to contribute.

Graphical Emacs does not suffer from this issue.

Shift + Arrow keys not working in emacs within tmux

First you must enable xterm-keys in your tmux config.

.tmux.conf
setw -g xterm-keys on

But, this will break other key combinations. To fix them, put the following in your emacs config.

.emacs
;; handle tmux's xterm-keys
;; put the following line in your ~/.tmux.conf:
;;   setw -g xterm-keys on
(if (getenv "TMUX")
    (progn
      (let ((x 2) (tkey ""))
	(while (<= x 8)
	  ;; shift
	  (if (= x 2)
	      (setq tkey "S-"))
	  ;; alt
	  (if (= x 3)
	      (setq tkey "M-"))
	  ;; alt + shift
	  (if (= x 4)
	      (setq tkey "M-S-"))
	  ;; ctrl
	  (if (= x 5)
	      (setq tkey "C-"))
	  ;; ctrl + shift
	  (if (= x 6)
	      (setq tkey "C-S-"))
	  ;; ctrl + alt
	  (if (= x 7)
	      (setq tkey "C-M-"))
	  ;; ctrl + alt + shift
	  (if (= x 8)
	      (setq tkey "C-M-S-"))

	  ;; arrows
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
	  ;; home
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
	  ;; end
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
	  ;; page up
	  (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
	  ;; page down
	  (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
	  ;; insert
	  (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
	  ;; delete
	  (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
	  ;; f1
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
	  ;; f2
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
	  ;; f3
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
	  ;; f4
	  (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
	  ;; f5
	  (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
	  ;; f6
	  (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
	  ;; f7
	  (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
	  ;; f8
	  (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
	  ;; f9
	  (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
	  ;; f10
	  (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
	  ;; f11
	  (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
	  ;; f12
	  (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
	  ;; f13
	  (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
	  ;; f14
	  (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
	  ;; f15
	  (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
	  ;; f16
	  (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
	  ;; f17
	  (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
	  ;; f18
	  (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
	  ;; f19
	  (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
	  ;; f20
	  (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))

	  (setq x (+ x 1))
	  ))
      )
  )

替代方案

这里有几个类似 Emacs的工具。 你也可以尝试在在Arch仓库或在AUR中找相似 Emacs 的工具。

  • mg — C 语言编写实现轻量级 emacs。注意这软件不支持 UTF-8。
http://homepage.boetes.org/software/mg/ || mg
  • Zile — "Zile Is Lossy Emacs", 一个轻量级的克隆版本,编写得尽可能类似 Emacs 。
https://www.gnu.org/software/zile/ || zile
  • uemacs — 由 Linus Torvalds定制的“ Micro-emacs”版本。
https://git.kernel.org/pub/scm/editors/uemacs/uemacs.git || uemacs-gitAUR
  • remacs — Rust 主打的 emacs。
https://github.com/remacs/remacs || remacsAUR


资源