与emacs一起使用prefix参数的目的/用法是什么?

pro*_*eek 5 emacs

正如我在这里问的,我可以选择运行带有前缀参数(Cu)的SLIME的lisp,我写在这里,我看到Cu是一种在当前缓冲区中插入输出的方法.

我使用'Cu 10 SOMETHING',以便运行SOMETHING 10次.

使用前缀参数(Cu)的用途/目的是什么?Cu是唯一的前缀参数吗?

小智 7

还要记住,Cu作为自己的前缀默认为传递'(4)作为参数,并且在命令之前插入的每个Cu将此乘以4.

因此,您可以通过使用ctrl-u前缀快速编写一些简单的选项,例如:

(defun insert-date (prefix)
  "Insert the current date. With prefix-argument, use ISO format. With
   two prefix arguments, write out the day and month name."
  (interactive "P")
  (let ((format (cond
                 ((not prefix) "%A, %d %B %Y %H:%M %Z" )
                 ((equal prefix '(4)) "%d/%m/%Y %H:%M")
                 ((equal prefix '(16)) "%d/%m/%Y")
                 ((equal prefix '(64)) "%H:%M:%S")
                 ))
        (system-time-locale "en_GB"))
    (insert (format-time-string format))))

(global-set-key (kbd "C-c d") 'insert-date)
Run Code Online (Sandbox Code Playgroud)

(上面的elisp生成一个函数,在键上插入长格式日期(在本例中为Cc d),Cu Cc d上的短格式日期+时间,Cu Cu Cc d上的短格式日期,以及短格式Cu Cu Cu Cc上的时间d)

你可以使用这个技巧来制作一个默认使用clojure的'start-slime'替换,但是如果你在键绑定之前按下Cu则使用sbcl.


Tre*_*son 6

查看前缀命令参数文档.

但是,简而言之,它是一种以交互方式为命令提供更多信息的方法.

  • 对于通常绑定的alpha-numberic键,'self-insert它告诉他们要插入多少个字符
  • 对于某些命令(M-x comment-region),它意味着反转命令,即C-u M-x comment-region 取消注释该区域.
  • 对一些人来说只是调整的行为,C-u C-s做了'isearch-forward-regexp而不是常规的'isearch-forward.

所以,这完全取决于命令如何使用prefix参数.

至于其他的"前缀参数",有C--,M--,M-3(或任何其他数字),和其他一些人.