2010-04-01 17 views
6

Diciamo che ho una funzione di Erlang, con specifiche.Erlang Edoc in Emacs

-spec foo(integer(), string()) -> 
     boolean(). 
foo(_Integer, _String) -> 
     true. 

Il mio sogno sarebbe quello di generare l'edoc da queste informazioni all'interno di Emacs automaticamente. Il codice generato dovrebbe essere simile:

%%-------------------------------------------------------------------- 
%% @doc 
%% Your description goes here 
%% @spec foo(_Integer::integer(), _String::string()) -> 
%%%  boolean() 
%% @end 
%%-------------------------------------------------------------------- 
-spec foo(integer(), string()) -> 
     boolean(). 
foo(_Integer, _String) -> 
     true. 

Fa una funzionalità simile già esiste?

risposta

5

Non so Erlang, ma questo potrebbe iniziare:

EDIT: Closer, ma funziona solo se args sono sulla stessa linea :(

EDIT: sembra funzionare per args su righe separate ora

(defun my-erlang-insert-edoc() 
    "Insert edoc." 
    (interactive) 
    (save-excursion 
    (when (re-search-forward "^\\s *-spec\\s +\\([a-zA-Z0-9_]+\\)\\s *(\\(\\(.\\|\n\\)*?\\))\\s *->[ \t\n]*\\(.+?\\)\\." nil t) 
     (let* ((beg (match-beginning 0)) 
      (funcname (match-string-no-properties 1)) 
      (arg-string (match-string-no-properties 2)) 
      (retval (match-string-no-properties 4)) 
      (args (split-string arg-string "[ \t\n,]" t))) 
     (when (re-search-forward (concat "^\\s *" funcname "\\s *(\\(\\(.\\|\n\\)*?\\))\\s *->") nil t) 
      (let ((arg-types (split-string (match-string-no-properties 1) "[ \t\n,]" t))) 
      (goto-char beg) 
      (insert "%%-----------------------------------------------------------------------------\n") 
      (insert "%% @doc\n") 
      (insert "%% Your description goes here\n") 
      (insert "%% @spec " funcname "(") 
      (dolist (arg args) 
       (insert (car arg-types) "::" arg) 
       (setq arg-types (cdr arg-types)) 
       (when arg-types 
       (insert ", "))) 
      (insert ") ->\n") 
      (insert "%%  " retval "\n") 
      (insert "%% @end\n") 
      (insert "%%-----------------------------------------------------------------------------\n"))))))) 
+0

+1. Grazie molte per questo. A parte la parte Integer :: integer() funziona bene per un paio di funzioni di esempio :) –

+0

Ora è un po 'più vicino, ma se metti argomenti su linee separate dovrai analizzarli in modo diverso. La modalità erlang ha qualche parsing da cui potresti trarre vantaggio? – scottfrazer

+0

Sembra che ora funzioni per argomenti su righe separate. – scottfrazer

1

La suite CEDET ha sostenuto Erlang a un certo livello per un bel po '. le versioni precedenti di CEDET, come 1.0pre3 o giù di lì ha avuto anche il supporto per la generazione automatica edoc commenti simili a quelli di discutere sopra. Il sistema di generazione di commenti cha di recente, in modo tale che il supporto non sia più lì, quindi sarebbe bello che qualcuno volesse inserire i modelli per il nuovo sistema di generazione di commenti che funziona tramite il pacchetto SRPode del sottopagamento CEDET. Non è richiesta alcuna conoscenza di Emacs Lisp.

http://cedet.sourceforge.net/

http://cedet.sourceforge.net/codegen.shtml