2009-07-17 15 views
7

私はhaxeプログラミング言語のためのemacsでオートコンプリートの実装に取り​​組んでいます。emacsでオートコンプリートの選択肢を表示するには?

私が提示したいオートコンプリートのリストを取得する方法はすでにわかっています。リストの形式は次のとおりです。

'((name1 type1 desc1) 
    (name2 type2 desc2) ... 

私はミニバッファで現在選択されている項目のカーソル(オートコンプリート・モードのように)位置とDESC後フォーマット「NAME1のTYPE1」のテキストを含むユーザリストに表示したいです。ユーザーは補完を選択するか、自動補完モードのように終了する必要があります。

ユーザが何かを選択した場合、カーソル位置にname1を挿入する必要があります。

これを行う最も簡単な方法は何ですか?これを行うためのいくつかの標準的なemacsの方法はありますか、私は自分で何かをコード化する必要がありますか?

EDIT:バッファに基づいて自動補完候補のリストを取得する関数があります。今私はそれをオートコンプリートモードに統合する方法に苦労しています。 get-completesは重い操作なので、カーソルが "on"の場合にのみトリガしたいと思います。キャラクター。

ここに私のコードがあります。

(defun get-completes-from-haxe (hxml-file file pos) 
    (let* ((completion-buffer (get-buffer-create "*haxe-completions*")) 
     (cmd (concat "cd " (file-name-directory hxml-file) "; haxe " hxml-file " --display " file "@" (number-to-string pos)))) 
    (ignore-errors 
     (shell-command cmd completion-buffer) 
     (let ((clist (xml-parse-region 1 (buffer-size completion-buffer) completion-buffer)) 
      (completes nil)) 
     (dolist (s (cddar clist)) 
      (when (listp s) 
      (let* ((item (cdr s)) 
        (name (cdaar item)) 
        (type (car (cddadr item))) 
        (desc (cdddr item))) 
       (setf completes (cons name completes))))) 
     completes)))) 

(defun file-find-upwards (buffer file-name) 
    ;; Chase links in the source file and search in the dir where it points. 
    (setq dir-name (or (and (buffer-file-name buffer) 
          (file-name-directory (file-chase-links 
               (buffer-file-name buffer)))) 
        default-directory)) 
    ;; Chase links before visiting the file. This makes it easier to 
    ;; use a single file for several related directories. 
    (setq dir-name (file-chase-links dir-name)) 
    (setq dir-name (expand-file-name dir-name)) 
    ;; Move up in the dir hierarchy till we find a change log file. 
    (let ((file1 (concat dir-name file-name)) 
     parent-dir) 
    (while (and (not (file-exists-p file1)) 
       (progn (setq parent-dir 
          (file-name-directory 
           (directory-file-name 
           (file-name-directory file1)))) 
         ;; Give up if we are already at the root dir. 
         (not (string= (file-name-directory file1) 
            parent-dir)))) 
     ;; Move up to the parent dir and try again. 
     (setq file1 (expand-file-name file-name parent-dir))) 
    ;; If we found the file in a parent dir, use that. Otherwise, 
    ;; return nil 
    (if (or (get-file-buffer file1) (file-exists-p file1)) 
     file1 
     nil))) 


(defun get-candidate-list (buffer pos) 
    (get-completes-from-haxe 
    (file-find-upwards buffer "compile.hxml") 
    (buffer-file-name buffer) 
    pos)) 

答えて

7

私は、優れたパッケージオートコンプリートをお勧めしたい:あなたはオートコンプリートのカスタム・ソースを定義することができますし、それはかなりまっすぐ進むようだhttp://www.emacswiki.org/emacs/AutoComplete

を。

+0

私はそれを見ましたが、ツールチップとドキュメントを表示する方法を理解できませんでした。それが提供するものは、私が望むものではない自動補完のようなvimです。 – Marko

+1

オートプレットモードのように見えますが、現在の選択候補を表示するにはAC選択候補機能が使用されます。ミニバッファにdescを表示するには、その機能のアドバイスを定義できます – user49117

1

ido.elからのido-completing-readは、それを行う別の方法です。

正規表現を使用して候補を除外し、この機能をオンザフライでオン/オフできる便利な機能があります。詳細はido.elを参照してください。

1

idoパッケージには、「ido-completing-read」という便利な機能があります。例えば、ここでは、ラインごとにリストを表示させるための簡単な微調整だ:

(defun x-ido-completing-read 
    (prompt choices &optional predicate require-match initial-input hist def) 
    (let* ((indent (concat "\n" (make-string (length prompt) ?))) 
     (ido-decorations 
     `("" "" ,indent ,(concat indent "...") 
      "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]"))) 
    (ido-completing-read prompt choices predicate require-match initial-input hist def))) 
1

yasnippetコードの内部では、Googleのコードから利用できる、彼らはJaeyounチョンよる「ドロップダウン-list.el」を使用しますポイントで使用できるスニペットを表示します。これにより、カーソルキーの位置にポップアップ(ツールチップのような)メニューが表示され、矢印キーで選択して入力するか、番号で選択することができます。

http://www.emacswiki.org/emacs/dropdown-list.el

+0

右側のセルライト:) – Marko

3

なぜ車輪の再発明保ちますか?会社モードではいくつかの言語をサポートしています

+0

これは行く方法です。なぜ私は会社モードを逃してしまったのか分かりませんし、明らかに劣ったオートコンプリートモードで時間を無駄にしています。おそらく醜い名前;) – Marko

+1

唯一の問題は会社モードのドキュメントです。その使い方ははっきりしていません。会社の設定を求める人から多くのメールを受け取りました。ここにリンクされている設定ファイルで見ることができます: http://richardriley.net/projects/emacs/dotemacs – RichieHH

関連する問題