2010-02-07 4 views
8

Comment spécifier une fonction qui a un préfixe numérique optionnel, sinon, elle demande un nombre? fondamentalement comment se comporte goto-ligne?Fonction interactive d'emacs avec préfixe numérique optionnel

(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 

alors comment puis-je travailler? merci

+1

'(interactive" NType un nombre: ")'. – jrockway

Répondre

9

Regardez comment 'goto-line est défini (M-x find-function goto-line RET). FWIW, si vous voulez une invite pour "N", ajoutez simplement le texte de l'invite après le N;

(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. Utilise la source, Luke! – Bahbar