8

オプションの数値プレフィックスを持つ関数を指定するにはどうすればよいですか?そうでない場合は、数値の入力を求められますか?基本的にgoto-lineはどのように動作しますか?

(defun my-function(&optional  n)
  ; I have tried
  (interactive "N") ; reads string, no prompt
  (interactive "p") ; defaults to one
  (interactive (if (not n) (read-number "N: "))) ; runtime error

では、どうすれば仕事をすることができますか?ありがとう

4

1 に答える 1

9

がどのよう'goto-lineに定義されているかを見てください(M-x find-function goto-line RET)。

(defun my-function (n)
  "Example function taking a prefix arg, or reading a number if no prefix arg"
  (interactive
   (if (and current-prefix-arg (not (consp current-prefix-arg)))
       (list (prefix-numeric-value current-prefix-arg))
     (list (read-number "N: ")))))
于 2010-02-07T00:20:20.777 に答える