我正在使用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))
我看到了,但無法弄清楚如何顯示工具提示和文檔。它提供的只是vim自動完成,這不是我想要的。 – Marko 2009-07-17 22:32:04
看起來像在自動完成模式下,ac-select-candidate函數用於顯示當前候選人的選擇,您可以爲該函數定義一個建議,以在小型緩衝區中顯示desc – user49117 2009-07-22 11:47:37