21

で呼び出すと効果が異なるC-u関数(たとえば、正規表現)で使用したいと思います。C-uEmacsでこれを行うにはどうすればよいですか?ドキュメントには、EmacsLispでこれを行う方法は示されていません。

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

2 に答える 2

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

お役に立てば幸いです。

于 2012-10-10T23:14:18.833 に答える
12

私は自分の関数がCuで呼び出されたかどうかを検出する方法を探してここに到着しました。これがあなたのやり方です:

(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")))

元の投稿者が求めていたのは、関数内からCuを使用して別の関数を呼び出す方法です。他の人に役立つことを願って、上記の@codyChanのコメントの説明としてこれを投稿します。

于 2019-07-02T13:01:21.700 に答える