emacs小白请教 prefix argument 应如何理解?

在阅读org文档时,有这样的一句: C-c - (org-table-insert-hline) Insert a horizontal line below current row. With a prefix argument, the line is created above the current line.`

翻译作“在当前行上面添加一行。 如果有前缀,则在下面添加一行” 请问这里的prefix argument应该是指代什么? 我猜测这里指代 C-u 这快捷键,不知道我理解的对否? 请大佬们不吝指教。

1 个赞

argument 指参数、函数参数。prefix 指前缀,因为这个参数在命令(Emacs 命令就是函数)之前指定。

没错,prefix argument 最常见、最简单用途就是 flag,默认是没有 flag 的,加 C-u 表示启用 flag:

(defun foo (ready-p)
  (interactive "P")
  (message "%s"
           (if ready-p
               "Ready"
             "Not ready")))

prefix argument 还有一个常见用户是作为数字参数,应用如插入 5 个字母 a 或者向下移动 7 行。

C-u 5 a
C-u 7 C-n
4 个赞

谢谢大佬!非常专业