2009-07-17 73 views
7

我正在使用emacs为haxe编程语言实现自动完成。如何在emacs中显示自动完成选项?

我已经想出了如何获取我想呈现的自动填充列表。该列表是在格式:

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

我想显示到包含在格式文本“NAME1 TYPE1”后的光标位置(如在自动填充模式)用户列表和desc在小缓冲区当前选择的项目。用户应该能够选择完成或放弃,就像在自动完成模式下一样。

当用户选择某些内容时,应在光标位置插入name1。

什么是最好/最简单的方法来做到这一点?有没有一些标准的emacs方式来做到这一点,或者我应该自己编码?

编辑:我有函数来获取基于缓冲区的自动完成候选列表。现在我正在努力如何将它集成到自动完成模式。由于完成操作很繁重,我只想在光标打开的情况下触发它。“字符。

这是我的代码。

(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 2009-07-17 22:32:04

+1

看起来像在自动完成模式下,ac-select-candidate函数用于显示当前候选人的选择,您可以为该函数定义一个建议,以在小型缓冲区中显示desc – user49117 2009-07-22 11:47:37

1

ido.el的ido-completion-read是另一种方法。

它的一个有用的功能是,您可以使用正则表达式筛选候选项,并且可以实时地打开和关闭此功能。有关更多详细信息,请参阅ido.el。

1

ido包具有称为'ido-completion-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代码,可从谷歌代码,他们使用“下拉-list.el”的全在娟钟以显示可能在点使用的可能的片段。这样可以在光标位置提供一个弹出式(类似工具提示)菜单,您可以使用箭头键选择并进入,也可以按数字进行选择。

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

+0

好极了,如果只有这样才有可能摆脱selid在右侧:) – Marko 2009-07-23 10:55:44

3

为什么要保持车轮重塑?公司模式支持几种语言

相关问题