2010-02-07 10 views
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 

어떻게 작업하나요? 감사합니다.

+1

FWIW, "N"에 대한 프롬프트가 필요하면 N 뒤에 프롬프트 텍스트를 추가하십시오. '(대화 형 "NType 번호 :")'. – jrockway

답변

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: "))))) 
+2

+1. 근원을 사용하십시오, 루크! – Bahbar