Emacs:函数中的通用参数(C-u)

时间:2012-10-10 20:34:17

标签: function emacs arguments

我想在函数(例如,regexp)中使用 C-u ,其中使用 C-u 调用它会产生不同的效果。我怎么能在Emacs中做到这一点?该文档没有说明如何使用Emacs Lisp执行此操作。

(defun test ()
  (interactive)
  (align-regexp)) ; I would like to add the C-u prefix to this.

2 个答案:

答案 0 :(得分:18)

(defun my/test ()
  (interactive)
  (let ((current-prefix-arg 4)) ;; emulate C-u
    (call-interactively 'align-regexp) ;; invoke align-regexp interactively
    )
  )

希望有所帮助。

答案 1 :(得分:0)

我到这里来的是寻找一种方法来检测C-u是否调用了 my 函数。这是您的操作方式:

(defun my-function ()
 (interactive)
  (if (equal current-prefix-arg nil) ; no C-u
   ;; then
    (message "my-function was called normally")
   ;; else
    (message "my-function was called with C-u")))

原始发布者要问的是如何使用C-u在其功能内调用另一个功能。 我将此作为对@codyChan上面评论的澄清,希望对其他人有帮助。